001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.replication; 019 020import static org.hamcrest.CoreMatchers.endsWith; 021import static org.hamcrest.MatcherAssert.assertThat; 022import static org.junit.jupiter.api.Assertions.assertEquals; 023import static org.junit.jupiter.api.Assertions.assertTrue; 024 025import org.apache.hadoop.fs.FileStatus; 026import org.apache.hadoop.fs.Path; 027import org.apache.hadoop.hbase.master.MasterFileSystem; 028import org.apache.hadoop.hbase.regionserver.HRegionServer; 029import org.apache.hadoop.hbase.testclassification.LargeTests; 030import org.apache.hadoop.hbase.testclassification.ReplicationTests; 031import org.junit.jupiter.api.Tag; 032import org.junit.jupiter.api.Test; 033 034@Tag(ReplicationTests.TAG) 035@Tag(LargeTests.TAG) 036public class TestSyncReplicationRemoveRemoteWAL extends SyncReplicationTestBase { 037 038 @Test 039 public void testRemoveRemoteWAL() throws Exception { 040 UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, 041 SyncReplicationState.STANDBY); 042 UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, 043 SyncReplicationState.ACTIVE); 044 045 MasterFileSystem mfs = UTIL2.getMiniHBaseCluster().getMaster().getMasterFileSystem(); 046 Path remoteWALDir = ReplicationUtils.getPeerRemoteWALDir( 047 new Path(mfs.getWALRootDir(), ReplicationUtils.REMOTE_WAL_DIR_NAME), PEER_ID); 048 FileStatus[] remoteWALStatus = mfs.getWALFileSystem().listStatus(remoteWALDir); 049 assertEquals(1, remoteWALStatus.length); 050 Path remoteWAL = remoteWALStatus[0].getPath(); 051 assertThat(remoteWAL.getName(), endsWith(ReplicationUtils.SYNC_WAL_SUFFIX)); 052 writeAndVerifyReplication(UTIL1, UTIL2, 0, 100); 053 054 HRegionServer rs = UTIL1.getRSForFirstRegionInTable(TABLE_NAME); 055 rs.getWalRoller().requestRollAll(); 056 // The replicated wal file should be deleted finally 057 waitUntilDeleted(UTIL2, remoteWAL); 058 remoteWALStatus = mfs.getWALFileSystem().listStatus(remoteWALDir); 059 assertEquals(1, remoteWALStatus.length); 060 remoteWAL = remoteWALStatus[0].getPath(); 061 assertThat(remoteWAL.getName(), endsWith(ReplicationUtils.SYNC_WAL_SUFFIX)); 062 063 UTIL1.getAdmin().disableReplicationPeer(PEER_ID); 064 write(UTIL1, 100, 200); 065 UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, 066 SyncReplicationState.DOWNGRADE_ACTIVE); 067 068 // should still be there since the peer is disabled and we haven't replicated the data yet 069 assertTrue(mfs.getWALFileSystem().exists(remoteWAL)); 070 071 UTIL1.getAdmin().enableReplicationPeer(PEER_ID); 072 waitUntilReplicationDone(UTIL2, 200); 073 verifyThroughRegion(UTIL2, 100, 200); 074 075 // Confirm that we will also remove the remote wal files in DA state 076 waitUntilDeleted(UTIL2, remoteWAL); 077 } 078}