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.junit.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertTrue; 022 023import java.io.File; 024import java.util.List; 025import org.apache.hadoop.hbase.TableName; 026import org.apache.hadoop.hbase.backup.impl.BackupAdminImpl; 027import org.apache.hadoop.hbase.backup.util.BackupUtils; 028import org.apache.hadoop.hbase.client.Connection; 029import org.apache.hadoop.hbase.client.ConnectionFactory; 030import org.apache.hadoop.hbase.regionserver.HRegion; 031import org.apache.hadoop.hbase.testclassification.LargeTests; 032import org.junit.jupiter.api.Tag; 033import org.junit.jupiter.api.Test; 034 035import org.apache.hbase.thirdparty.com.google.common.collect.Lists; 036 037@Tag(LargeTests.TAG) 038public class TestIncrementalBackupRestoreWithOriginalSplitsSeperateFs 039 extends IncrementalBackupRestoreTestBase { 040 041 @Test 042 public void testIncBackupRestoreWithOriginalSplitsSeperateFs() throws Exception { 043 // prepare BACKUP_ROOT_DIR on a different filesystem from HBase. 044 try (Connection conn = ConnectionFactory.createConnection(conf1); 045 BackupAdminImpl admin = new BackupAdminImpl(conn)) { 046 String backupTargetDir = TEST_UTIL.getDataTestDir("backupTarget").toString(); 047 BACKUP_ROOT_DIR = new File(backupTargetDir).toURI().toString(); 048 049 List<TableName> tables = Lists.newArrayList(table1); 050 051 insertIntoTable(conn, table1, famName, 3, 100); 052 String fullBackupId = takeFullBackup(tables, admin, true); 053 assertTrue(checkSucceeded(fullBackupId)); 054 055 insertIntoTable(conn, table1, famName, 4, 100); 056 057 HRegion regionToBulkload = TEST_UTIL.getHBaseCluster().getRegions(table1).get(0); 058 String regionName = regionToBulkload.getRegionInfo().getEncodedName(); 059 doBulkload(table1, regionName, famName); 060 061 BackupRequest request = 062 createBackupRequest(BackupType.INCREMENTAL, tables, BACKUP_ROOT_DIR, true); 063 String incrementalBackupId = admin.backupTables(request); 064 assertTrue(checkSucceeded(incrementalBackupId)); 065 066 TableName[] fromTable = new TableName[] { table1 }; 067 TableName[] toTable = new TableName[] { table1_restore }; 068 069 // Using original splits 070 admin.restore(BackupUtils.createRestoreRequest(BACKUP_ROOT_DIR, incrementalBackupId, false, 071 fromTable, toTable, true, true)); 072 073 int actualRowCount = TEST_UTIL.countRows(table1_restore); 074 int expectedRowCount = TEST_UTIL.countRows(table1); 075 assertEquals(expectedRowCount, actualRowCount); 076 077 // Using new splits 078 admin.restore(BackupUtils.createRestoreRequest(BACKUP_ROOT_DIR, incrementalBackupId, false, 079 fromTable, toTable, true, false)); 080 081 expectedRowCount = TEST_UTIL.countRows(table1); 082 assertEquals(expectedRowCount, actualRowCount); 083 } 084 } 085}