liuxiaocs7 commented on code in PR #8190: URL: https://github.com/apache/hbase/pull/8190#discussion_r3218378679
########## hbase-server/src/test/java/org/apache/hadoop/hbase/client/SnapshotCloneIndependenceTestBase.java: ########## @@ -0,0 +1,365 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; +import java.util.regex.Pattern; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.HBaseTestingUtil; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; +import org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy; +import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; +import org.apache.hadoop.hbase.util.Threads; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test to verify that the cloned table is independent of the table from which it was cloned + */ +public abstract class SnapshotCloneIndependenceTestBase { + + private static final Logger LOG = + LoggerFactory.getLogger(SnapshotCloneIndependenceTestBase.class); + + protected static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); + + protected static final int NUM_RS = 2; + private static final String TEST_FAM_STR = "fam"; + protected static final byte[] TEST_FAM = Bytes.toBytes(TEST_FAM_STR); + private static final int CLEANER_INTERVAL = 100; + + private FileSystem fs; + private Path rootDir; + private Admin admin; + private TableName originalTableName; + private Table originalTable; + private TableName cloneTableName; + private int countOriginalTable; + String snapshotNameAsString; + String snapshotName; + + protected static void setupConf(Configuration conf) { + // Up the handlers; this test needs more than usual. + conf.setInt(HConstants.REGION_SERVER_HIGH_PRIORITY_HANDLER_COUNT, 15); + // enable snapshot support + conf.setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true); + // change the flush size to a small amount, regulating number of store files + conf.setInt("hbase.hregion.memstore.flush.size", 25000); + // so make sure we get a compaction when doing a load, but keep around + // some files in the store + conf.setInt("hbase.hstore.compaction.min", 10); + conf.setInt("hbase.hstore.compactionThreshold", 10); + // block writes if we get to 12 store files + conf.setInt("hbase.hstore.blockingStoreFiles", 12); + conf.setInt("hbase.regionserver.msginterval", 100); + conf.setBoolean("hbase.master.enabletable.roundrobin", true); + // Avoid potentially aggressive splitting which would cause snapshot to fail + conf.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY, + ConstantSizeRegionSplitPolicy.class.getName()); + // Execute cleaner frequently to induce failures + conf.setInt("hbase.master.cleaner.interval", CLEANER_INTERVAL); + conf.setInt("hbase.master.hfilecleaner.plugins.snapshot.period", CLEANER_INTERVAL); + // Effectively disable TimeToLiveHFileCleaner. Don't want to fully disable it because that + // will even trigger races between creating the directory containing back references and + // the back reference itself. + conf.setInt("hbase.master.hfilecleaner.ttl", CLEANER_INTERVAL); + } + + @BeforeEach + public void setup(TestInfo testInfo) throws Exception { + fs = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getFileSystem(); + rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir(); + + admin = UTIL.getAdmin(); + originalTableName = TableName.valueOf("test" + testInfo.getTestMethod().get().getName()); + cloneTableName = TableName.valueOf("test-clone-" + originalTableName); + snapshotNameAsString = "snapshot_" + originalTableName; + snapshotName = snapshotNameAsString; + + originalTable = createTable(originalTableName, TEST_FAM); + loadData(originalTable, TEST_FAM); + countOriginalTable = countRows(originalTable); + System.out.println("Original table has: " + countOriginalTable + " rows"); Review Comment: avoid `System.out.println`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
