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.wal; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertFalse; 022import static org.junit.jupiter.api.Assertions.assertNotNull; 023import static org.junit.jupiter.api.Assertions.assertTrue; 024 025import java.util.ArrayList; 026import java.util.List; 027import org.apache.hadoop.fs.Path; 028import org.apache.hadoop.hbase.Cell; 029import org.apache.hadoop.hbase.CellUtil; 030import org.apache.hadoop.hbase.HBaseTestingUtil; 031import org.apache.hadoop.hbase.ServerName; 032import org.apache.hadoop.hbase.SingleProcessHBaseCluster; 033import org.apache.hadoop.hbase.TableName; 034import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; 035import org.apache.hadoop.hbase.client.Get; 036import org.apache.hadoop.hbase.client.Put; 037import org.apache.hadoop.hbase.client.Result; 038import org.apache.hadoop.hbase.client.Table; 039import org.apache.hadoop.hbase.client.TableDescriptorBuilder; 040import org.apache.hadoop.hbase.testclassification.LargeTests; 041import org.apache.hadoop.hbase.testclassification.RegionServerTests; 042import org.apache.hadoop.hbase.util.Bytes; 043import org.apache.hadoop.hbase.util.CommonFSUtils; 044import org.junit.jupiter.api.AfterAll; 045import org.junit.jupiter.api.BeforeAll; 046import org.junit.jupiter.api.Tag; 047import org.junit.jupiter.api.Test; 048 049@Tag(RegionServerTests.TAG) 050@Tag(LargeTests.TAG) 051public class TestWALSplitWithDeletedTableData { 052 053 private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 054 055 @BeforeAll 056 public static void setup() throws Exception { 057 TEST_UTIL.startMiniCluster(2); 058 } 059 060 @AfterAll 061 public static void tearDown() throws Exception { 062 TEST_UTIL.shutdownMiniCluster(); 063 } 064 065 @Test 066 public void testWALSplitWithDeletedTableData() throws Exception { 067 final byte[] CFNAME = Bytes.toBytes("f1"); 068 final byte[] QNAME = Bytes.toBytes("q1"); 069 final byte[] VALUE = Bytes.toBytes("v1"); 070 final TableName t1 = TableName.valueOf("t1"); 071 final TableName t2 = TableName.valueOf("t2"); 072 final byte[][] splitRows = 073 { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c"), Bytes.toBytes("d") }; 074 TableDescriptorBuilder htdBuilder1 = TableDescriptorBuilder.newBuilder(t1); 075 htdBuilder1.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(CFNAME).build()); 076 Table tab1 = TEST_UTIL.createTable(htdBuilder1.build(), splitRows); 077 TableDescriptorBuilder htdBuilder2 = TableDescriptorBuilder.newBuilder(t2); 078 htdBuilder2.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(CFNAME).build()); 079 Table tab2 = TEST_UTIL.createTable(htdBuilder2.build(), splitRows); 080 List<Put> puts = new ArrayList<Put>(4); 081 byte[][] rks = 082 { Bytes.toBytes("ac"), Bytes.toBytes("ba"), Bytes.toBytes("ca"), Bytes.toBytes("dd") }; 083 for (byte[] rk : rks) { 084 puts.add(new Put(rk).addColumn(CFNAME, QNAME, VALUE)); 085 } 086 tab1.put(puts); 087 tab2.put(puts); 088 SingleProcessHBaseCluster cluster = TEST_UTIL.getMiniHBaseCluster(); 089 TEST_UTIL.deleteTable(t1); 090 Path tableDir = CommonFSUtils.getWALTableDir(TEST_UTIL.getConfiguration(), t1); 091 // Dropping table 't1' removed the table directory from the WAL FS completely 092 assertFalse(TEST_UTIL.getDFSCluster().getFileSystem().exists(tableDir)); 093 ServerName rs1 = cluster.getRegionServer(1).getServerName(); 094 // Kill one RS and wait for the WAL split and replay be over. 095 cluster.killRegionServer(rs1); 096 cluster.waitForRegionServerToStop(rs1, 60 * 1000); 097 assertEquals(1, cluster.getNumLiveRegionServers()); 098 Thread.sleep(1 * 1000); 099 TEST_UTIL.waitUntilNoRegionsInTransition(60 * 1000); 100 // Table 't1' is dropped. Assert table directory does not exist in WAL FS after WAL split. 101 assertFalse(TEST_UTIL.getDFSCluster().getFileSystem().exists(tableDir)); 102 // Assert the table t2 region's data getting replayed after WAL split and available 103 for (byte[] rk : rks) { 104 Result result = tab2.get(new Get(rk)); 105 assertFalse(result.isEmpty()); 106 Cell cell = result.getColumnLatestCell(CFNAME, QNAME); 107 assertNotNull(cell); 108 assertTrue(CellUtil.matchingValue(cell, VALUE)); 109 } 110 } 111}