HBASE-23723 Ensure MOB compaction works in optimized mode after snapshot clone (...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / replication / TestSyncReplicationRemoveRemoteWAL.java
blob9f898260453725b5ac9ed728786616feb91679dd
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.replication;
20 import static org.hamcrest.CoreMatchers.endsWith;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertThat;
23 import static org.junit.Assert.assertTrue;
25 import org.apache.hadoop.fs.FileStatus;
26 import org.apache.hadoop.fs.Path;
27 import org.apache.hadoop.hbase.HBaseClassTestRule;
28 import org.apache.hadoop.hbase.master.MasterFileSystem;
29 import org.apache.hadoop.hbase.regionserver.HRegionServer;
30 import org.apache.hadoop.hbase.testclassification.LargeTests;
31 import org.apache.hadoop.hbase.testclassification.ReplicationTests;
32 import org.junit.ClassRule;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
36 @Category({ ReplicationTests.class, LargeTests.class })
37 public class TestSyncReplicationRemoveRemoteWAL extends SyncReplicationTestBase {
39 @ClassRule
40 public static final HBaseClassTestRule CLASS_RULE =
41 HBaseClassTestRule.forClass(TestSyncReplicationRemoveRemoteWAL.class);
43 @Test
44 public void testRemoveRemoteWAL() throws Exception {
45 UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
46 SyncReplicationState.STANDBY);
47 UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
48 SyncReplicationState.ACTIVE);
50 MasterFileSystem mfs = UTIL2.getMiniHBaseCluster().getMaster().getMasterFileSystem();
51 Path remoteWALDir = ReplicationUtils.getPeerRemoteWALDir(
52 new Path(mfs.getWALRootDir(), ReplicationUtils.REMOTE_WAL_DIR_NAME), PEER_ID);
53 FileStatus[] remoteWALStatus = mfs.getWALFileSystem().listStatus(remoteWALDir);
54 assertEquals(1, remoteWALStatus.length);
55 Path remoteWAL = remoteWALStatus[0].getPath();
56 assertThat(remoteWAL.getName(), endsWith(ReplicationUtils.SYNC_WAL_SUFFIX));
57 writeAndVerifyReplication(UTIL1, UTIL2, 0, 100);
59 HRegionServer rs = UTIL1.getRSForFirstRegionInTable(TABLE_NAME);
60 rs.getWalRoller().requestRollAll();
61 // The replicated wal file should be deleted finally
62 waitUntilDeleted(UTIL2, remoteWAL);
63 remoteWALStatus = mfs.getWALFileSystem().listStatus(remoteWALDir);
64 assertEquals(1, remoteWALStatus.length);
65 remoteWAL = remoteWALStatus[0].getPath();
66 assertThat(remoteWAL.getName(), endsWith(ReplicationUtils.SYNC_WAL_SUFFIX));
68 UTIL1.getAdmin().disableReplicationPeer(PEER_ID);
69 write(UTIL1, 100, 200);
70 UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
71 SyncReplicationState.DOWNGRADE_ACTIVE);
73 // should still be there since the peer is disabled and we haven't replicated the data yet
74 assertTrue(mfs.getWALFileSystem().exists(remoteWAL));
76 UTIL1.getAdmin().enableReplicationPeer(PEER_ID);
77 waitUntilReplicationDone(UTIL2, 200);
78 verifyThroughRegion(UTIL2, 100, 200);
80 // Confirm that we will also remove the remote wal files in DA state
81 waitUntilDeleted(UTIL2, remoteWAL);