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.backup; 019 020import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.CONTINUOUS_BACKUP_OFFSET_UPDATE_INTERVAL_MS; 021import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.CONTINUOUS_BACKUP_OFFSET_UPDATE_SIZE_THRESHOLD; 022import static org.apache.hadoop.hbase.mapreduce.WALPlayer.IGNORE_EMPTY_FILES; 023import static org.apache.hadoop.hbase.mapreduce.WALPlayer.IGNORE_MISSING_FILES; 024import static org.apache.hadoop.hbase.replication.regionserver.ReplicationMarkerChore.REPLICATION_MARKER_ENABLED_KEY; 025 026import org.apache.hadoop.conf.Configuration; 027import org.apache.hadoop.fs.FileSystem; 028import org.apache.hadoop.fs.Path; 029import org.apache.hadoop.hbase.HBaseConfiguration; 030import org.apache.hadoop.hbase.IntegrationTestingUtility; 031import org.apache.hadoop.hbase.backup.impl.BackupManager; 032import org.apache.hadoop.hbase.testclassification.IntegrationTests; 033import org.apache.hadoop.util.ToolRunner; 034import org.junit.jupiter.api.BeforeEach; 035import org.junit.jupiter.api.Tag; 036import org.junit.jupiter.api.Test; 037import org.slf4j.Logger; 038import org.slf4j.LoggerFactory; 039 040/** 041 * An integration test to detect regressions in HBASE-28957. Create a table with many regions, load 042 * data, perform series backup/load operations with continuous backup enabled, then restore and 043 * verify data. 044 * @see <a href="https://issues.apache.org/jira/browse/HBASE-28957">HBASE-28957</a> 045 */ 046@Tag(IntegrationTests.TAG) 047public class IntegrationTestContinuousBackupRestore extends IntegrationTestBackupRestoreBase { 048 private static final String CLASS_NAME = 049 IntegrationTestContinuousBackupRestore.class.getSimpleName(); 050 protected static final Logger LOG = 051 LoggerFactory.getLogger(IntegrationTestContinuousBackupRestore.class); 052 053 @Override 054 @BeforeEach 055 public void setUp() throws Exception { 056 initializeTestParameters(); 057 BackupTestUtil.enableBackup(conf); 058 conf.setBoolean(REPLICATION_MARKER_ENABLED_KEY, true); 059 conf.setBoolean(IGNORE_EMPTY_FILES, true); 060 conf.setBoolean(IGNORE_MISSING_FILES, true); 061 conf.setLong(CONTINUOUS_BACKUP_OFFSET_UPDATE_INTERVAL_MS, 2000L); // 2 seconds 062 conf.setLong(CONTINUOUS_BACKUP_OFFSET_UPDATE_SIZE_THRESHOLD, 1024L); // 1 KB 063 064 LOG.info("Initializing cluster with {} region server(s)", regionServerCount); 065 util.initializeCluster(regionServerCount); 066 LOG.info("Cluster initialized and ready"); 067 068 backupRootDir = util.getDataTestDirOnTestFS() + Path.SEPARATOR + DEFAULT_BACKUP_ROOT_DIR; 069 LOG.info("The backup root directory is: {}", backupRootDir); 070 createAndSetBackupWalDir(); 071 fs = FileSystem.get(conf); 072 } 073 074 @Test 075 public void testContinuousBackupRestore() throws Exception { 076 LOG.info("Running backup and restore integration test with continuous backup enabled"); 077 createTables(CLASS_NAME); 078 runTestMulti(true); 079 } 080 081 /** Returns status of CLI execution */ 082 @Override 083 public int runTestFromCommandLine() throws Exception { 084 // Check if backup is enabled 085 if (!BackupManager.isBackupEnabled(getConf())) { 086 System.err.println(BackupRestoreConstants.ENABLE_BACKUP); 087 return -1; 088 } 089 System.out.println(BackupRestoreConstants.VERIFY_BACKUP); 090 testContinuousBackupRestore(); 091 return 0; 092 } 093 094 public static void main(String[] args) throws Exception { 095 Configuration conf = HBaseConfiguration.create(); 096 IntegrationTestingUtility.setUseDistributedCluster(conf); 097 int status = ToolRunner.run(conf, new IntegrationTestContinuousBackupRestore(), args); 098 System.exit(status); 099 } 100}