| <!DOCTYPE HTML> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc (17) --> |
| <title>Source code</title> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <meta name="description" content="source: package: org.apache.hadoop.hbase.util, class: TestHBaseFsckReplication"> |
| <meta name="generator" content="javadoc/SourceToHTMLConverter"> |
| <link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style"> |
| </head> |
| <body class="source-page"> |
| <main role="main"> |
| <div class="source-container"> |
| <pre><span class="source-line-no">001</span><span id="line-1">/*</span> |
| <span class="source-line-no">002</span><span id="line-2"> * Licensed to the Apache Software Foundation (ASF) under one</span> |
| <span class="source-line-no">003</span><span id="line-3"> * or more contributor license agreements. See the NOTICE file</span> |
| <span class="source-line-no">004</span><span id="line-4"> * distributed with this work for additional information</span> |
| <span class="source-line-no">005</span><span id="line-5"> * regarding copyright ownership. The ASF licenses this file</span> |
| <span class="source-line-no">006</span><span id="line-6"> * to you under the Apache License, Version 2.0 (the</span> |
| <span class="source-line-no">007</span><span id="line-7"> * "License"); you may not use this file except in compliance</span> |
| <span class="source-line-no">008</span><span id="line-8"> * with the License. You may obtain a copy of the License at</span> |
| <span class="source-line-no">009</span><span id="line-9"> *</span> |
| <span class="source-line-no">010</span><span id="line-10"> * http://www.apache.org/licenses/LICENSE-2.0</span> |
| <span class="source-line-no">011</span><span id="line-11"> *</span> |
| <span class="source-line-no">012</span><span id="line-12"> * Unless required by applicable law or agreed to in writing, software</span> |
| <span class="source-line-no">013</span><span id="line-13"> * distributed under the License is distributed on an "AS IS" BASIS,</span> |
| <span class="source-line-no">014</span><span id="line-14"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span> |
| <span class="source-line-no">015</span><span id="line-15"> * See the License for the specific language governing permissions and</span> |
| <span class="source-line-no">016</span><span id="line-16"> * limitations under the License.</span> |
| <span class="source-line-no">017</span><span id="line-17"> */</span> |
| <span class="source-line-no">018</span><span id="line-18">package org.apache.hadoop.hbase.util;</span> |
| <span class="source-line-no">019</span><span id="line-19"></span> |
| <span class="source-line-no">020</span><span id="line-20">import static org.junit.Assert.assertEquals;</span> |
| <span class="source-line-no">021</span><span id="line-21"></span> |
| <span class="source-line-no">022</span><span id="line-22">import java.util.Collections;</span> |
| <span class="source-line-no">023</span><span id="line-23">import java.util.List;</span> |
| <span class="source-line-no">024</span><span id="line-24">import java.util.stream.Stream;</span> |
| <span class="source-line-no">025</span><span id="line-25">import org.apache.hadoop.hbase.HBaseClassTestRule;</span> |
| <span class="source-line-no">026</span><span id="line-26">import org.apache.hadoop.hbase.HBaseTestingUtil;</span> |
| <span class="source-line-no">027</span><span id="line-27">import org.apache.hadoop.hbase.ServerName;</span> |
| <span class="source-line-no">028</span><span id="line-28">import org.apache.hadoop.hbase.TableName;</span> |
| <span class="source-line-no">029</span><span id="line-29">import org.apache.hadoop.hbase.replication.ReplicationGroupOffset;</span> |
| <span class="source-line-no">030</span><span id="line-30">import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;</span> |
| <span class="source-line-no">031</span><span id="line-31">import org.apache.hadoop.hbase.replication.ReplicationPeerStorage;</span> |
| <span class="source-line-no">032</span><span id="line-32">import org.apache.hadoop.hbase.replication.ReplicationQueueId;</span> |
| <span class="source-line-no">033</span><span id="line-33">import org.apache.hadoop.hbase.replication.ReplicationQueueStorage;</span> |
| <span class="source-line-no">034</span><span id="line-34">import org.apache.hadoop.hbase.replication.ReplicationStorageFactory;</span> |
| <span class="source-line-no">035</span><span id="line-35">import org.apache.hadoop.hbase.replication.SyncReplicationState;</span> |
| <span class="source-line-no">036</span><span id="line-36">import org.apache.hadoop.hbase.testclassification.MediumTests;</span> |
| <span class="source-line-no">037</span><span id="line-37">import org.apache.hadoop.hbase.testclassification.ReplicationTests;</span> |
| <span class="source-line-no">038</span><span id="line-38">import org.apache.hadoop.hbase.util.HbckErrorReporter.ERROR_CODE;</span> |
| <span class="source-line-no">039</span><span id="line-39">import org.apache.hadoop.hbase.util.hbck.HbckTestingUtil;</span> |
| <span class="source-line-no">040</span><span id="line-40">import org.junit.After;</span> |
| <span class="source-line-no">041</span><span id="line-41">import org.junit.Before;</span> |
| <span class="source-line-no">042</span><span id="line-42">import org.junit.ClassRule;</span> |
| <span class="source-line-no">043</span><span id="line-43">import org.junit.Rule;</span> |
| <span class="source-line-no">044</span><span id="line-44">import org.junit.Test;</span> |
| <span class="source-line-no">045</span><span id="line-45">import org.junit.experimental.categories.Category;</span> |
| <span class="source-line-no">046</span><span id="line-46">import org.junit.rules.TestName;</span> |
| <span class="source-line-no">047</span><span id="line-47"></span> |
| <span class="source-line-no">048</span><span id="line-48">@Category({ ReplicationTests.class, MediumTests.class })</span> |
| <span class="source-line-no">049</span><span id="line-49">public class TestHBaseFsckReplication {</span> |
| <span class="source-line-no">050</span><span id="line-50"></span> |
| <span class="source-line-no">051</span><span id="line-51"> @ClassRule</span> |
| <span class="source-line-no">052</span><span id="line-52"> public static final HBaseClassTestRule CLASS_RULE =</span> |
| <span class="source-line-no">053</span><span id="line-53"> HBaseClassTestRule.forClass(TestHBaseFsckReplication.class);</span> |
| <span class="source-line-no">054</span><span id="line-54"></span> |
| <span class="source-line-no">055</span><span id="line-55"> private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();</span> |
| <span class="source-line-no">056</span><span id="line-56"> @Rule</span> |
| <span class="source-line-no">057</span><span id="line-57"> public final TestName name = new TestName();</span> |
| <span class="source-line-no">058</span><span id="line-58"></span> |
| <span class="source-line-no">059</span><span id="line-59"> @Before</span> |
| <span class="source-line-no">060</span><span id="line-60"> public void setUp() throws Exception {</span> |
| <span class="source-line-no">061</span><span id="line-61"> UTIL.getConfiguration().setBoolean("hbase.write.hbck1.lock.file", false);</span> |
| <span class="source-line-no">062</span><span id="line-62"> UTIL.startMiniCluster(1);</span> |
| <span class="source-line-no">063</span><span id="line-63"> TableName tableName = TableName.valueOf("replication_" + name.getMethodName());</span> |
| <span class="source-line-no">064</span><span id="line-64"> UTIL.getAdmin()</span> |
| <span class="source-line-no">065</span><span id="line-65"> .createTable(ReplicationStorageFactory.createReplicationQueueTableDescriptor(tableName));</span> |
| <span class="source-line-no">066</span><span id="line-66"> UTIL.getConfiguration().set(ReplicationStorageFactory.REPLICATION_QUEUE_TABLE_NAME,</span> |
| <span class="source-line-no">067</span><span id="line-67"> tableName.getNameAsString());</span> |
| <span class="source-line-no">068</span><span id="line-68"> }</span> |
| <span class="source-line-no">069</span><span id="line-69"></span> |
| <span class="source-line-no">070</span><span id="line-70"> @After</span> |
| <span class="source-line-no">071</span><span id="line-71"> public void tearDown() throws Exception {</span> |
| <span class="source-line-no">072</span><span id="line-72"> UTIL.shutdownMiniCluster();</span> |
| <span class="source-line-no">073</span><span id="line-73"> }</span> |
| <span class="source-line-no">074</span><span id="line-74"></span> |
| <span class="source-line-no">075</span><span id="line-75"> @Test</span> |
| <span class="source-line-no">076</span><span id="line-76"> public void test() throws Exception {</span> |
| <span class="source-line-no">077</span><span id="line-77"> ReplicationPeerStorage peerStorage = ReplicationStorageFactory.getReplicationPeerStorage(</span> |
| <span class="source-line-no">078</span><span id="line-78"> UTIL.getTestFileSystem(), UTIL.getZooKeeperWatcher(), UTIL.getConfiguration());</span> |
| <span class="source-line-no">079</span><span id="line-79"> ReplicationQueueStorage queueStorage = ReplicationStorageFactory</span> |
| <span class="source-line-no">080</span><span id="line-80"> .getReplicationQueueStorage(UTIL.getConnection(), UTIL.getConfiguration());</span> |
| <span class="source-line-no">081</span><span id="line-81"></span> |
| <span class="source-line-no">082</span><span id="line-82"> String peerId1 = "1";</span> |
| <span class="source-line-no">083</span><span id="line-83"> String peerId2 = "2";</span> |
| <span class="source-line-no">084</span><span id="line-84"> peerStorage.addPeer(peerId1, ReplicationPeerConfig.newBuilder().setClusterKey("key").build(),</span> |
| <span class="source-line-no">085</span><span id="line-85"> true, SyncReplicationState.NONE);</span> |
| <span class="source-line-no">086</span><span id="line-86"> peerStorage.addPeer(peerId2, ReplicationPeerConfig.newBuilder().setClusterKey("key").build(),</span> |
| <span class="source-line-no">087</span><span id="line-87"> true, SyncReplicationState.NONE);</span> |
| <span class="source-line-no">088</span><span id="line-88"> ReplicationQueueId queueId = null;</span> |
| <span class="source-line-no">089</span><span id="line-89"> for (int i = 0; i < 10; i++) {</span> |
| <span class="source-line-no">090</span><span id="line-90"> queueId = new ReplicationQueueId(getServerName(i), peerId1);</span> |
| <span class="source-line-no">091</span><span id="line-91"> queueStorage.setOffset(queueId, "group-" + i,</span> |
| <span class="source-line-no">092</span><span id="line-92"> new ReplicationGroupOffset("file-" + i, i * 100), Collections.emptyMap());</span> |
| <span class="source-line-no">093</span><span id="line-93"> }</span> |
| <span class="source-line-no">094</span><span id="line-94"> queueId = new ReplicationQueueId(getServerName(0), peerId2);</span> |
| <span class="source-line-no">095</span><span id="line-95"> queueStorage.setOffset(queueId, "group-" + 0, new ReplicationGroupOffset("file-" + 0, 100),</span> |
| <span class="source-line-no">096</span><span id="line-96"> Collections.emptyMap());</span> |
| <span class="source-line-no">097</span><span id="line-97"> HBaseFsck fsck = HbckTestingUtil.doFsck(UTIL.getConfiguration(), true);</span> |
| <span class="source-line-no">098</span><span id="line-98"> HbckTestingUtil.assertNoErrors(fsck);</span> |
| <span class="source-line-no">099</span><span id="line-99"></span> |
| <span class="source-line-no">100</span><span id="line-100"> // should not remove anything since the replication peer is still alive</span> |
| <span class="source-line-no">101</span><span id="line-101"> assertEquals(10, queueStorage.listAllReplicators().size());</span> |
| <span class="source-line-no">102</span><span id="line-102"> peerStorage.removePeer(peerId1);</span> |
| <span class="source-line-no">103</span><span id="line-103"> // there should be orphan queues</span> |
| <span class="source-line-no">104</span><span id="line-104"> assertEquals(10, queueStorage.listAllReplicators().size());</span> |
| <span class="source-line-no">105</span><span id="line-105"> fsck = HbckTestingUtil.doFsck(UTIL.getConfiguration(), false);</span> |
| <span class="source-line-no">106</span><span id="line-106"> HbckTestingUtil.assertErrors(fsck, Stream.generate(() -> {</span> |
| <span class="source-line-no">107</span><span id="line-107"> return ERROR_CODE.UNDELETED_REPLICATION_QUEUE;</span> |
| <span class="source-line-no">108</span><span id="line-108"> }).limit(10).toArray(ERROR_CODE[]::new));</span> |
| <span class="source-line-no">109</span><span id="line-109"></span> |
| <span class="source-line-no">110</span><span id="line-110"> // should not delete anything when fix is false</span> |
| <span class="source-line-no">111</span><span id="line-111"> assertEquals(10, queueStorage.listAllReplicators().size());</span> |
| <span class="source-line-no">112</span><span id="line-112"></span> |
| <span class="source-line-no">113</span><span id="line-113"> fsck = HbckTestingUtil.doFsck(UTIL.getConfiguration(), true);</span> |
| <span class="source-line-no">114</span><span id="line-114"> HbckTestingUtil.assertErrors(fsck, Stream.generate(() -> {</span> |
| <span class="source-line-no">115</span><span id="line-115"> return ERROR_CODE.UNDELETED_REPLICATION_QUEUE;</span> |
| <span class="source-line-no">116</span><span id="line-116"> }).limit(10).toArray(HbckErrorReporter.ERROR_CODE[]::new));</span> |
| <span class="source-line-no">117</span><span id="line-117"></span> |
| <span class="source-line-no">118</span><span id="line-118"> List<ServerName> replicators = queueStorage.listAllReplicators();</span> |
| <span class="source-line-no">119</span><span id="line-119"> // should not remove the server with queue for peerId2</span> |
| <span class="source-line-no">120</span><span id="line-120"> assertEquals(1, replicators.size());</span> |
| <span class="source-line-no">121</span><span id="line-121"> assertEquals(ServerName.valueOf("localhost", 10000, 100000), replicators.get(0));</span> |
| <span class="source-line-no">122</span><span id="line-122"> for (ReplicationQueueId qId : queueStorage.listAllQueueIds(replicators.get(0))) {</span> |
| <span class="source-line-no">123</span><span id="line-123"> assertEquals(peerId2, qId.getPeerId());</span> |
| <span class="source-line-no">124</span><span id="line-124"> }</span> |
| <span class="source-line-no">125</span><span id="line-125"> }</span> |
| <span class="source-line-no">126</span><span id="line-126"></span> |
| <span class="source-line-no">127</span><span id="line-127"> private ServerName getServerName(int i) {</span> |
| <span class="source-line-no">128</span><span id="line-128"> return ServerName.valueOf("localhost", 10000 + i, 100000 + i);</span> |
| <span class="source-line-no">129</span><span id="line-129"> }</span> |
| <span class="source-line-no">130</span><span id="line-130">}</span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| </pre> |
| </div> |
| </main> |
| </body> |
| </html> |