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.assertTrue; 021 022import java.util.List; 023import org.apache.hadoop.fs.Path; 024import org.apache.hadoop.hbase.TableName; 025import org.apache.hadoop.hbase.backup.impl.BackupAdminImpl; 026import org.apache.hadoop.hbase.client.Connection; 027import org.apache.hadoop.hbase.client.ConnectionFactory; 028import org.apache.hadoop.hbase.testclassification.LargeTests; 029import org.junit.jupiter.api.Tag; 030import org.junit.jupiter.api.Test; 031import org.slf4j.Logger; 032import org.slf4j.LoggerFactory; 033 034import org.apache.hbase.thirdparty.com.google.common.collect.Lists; 035 036@Tag(LargeTests.TAG) 037public class TestIncrementalBackupWithDataLoss extends TestBackupBase { 038 039 private static final Logger LOG = 040 LoggerFactory.getLogger(TestIncrementalBackupWithDataLoss.class); 041 042 @Test 043 public void testFullBackupBreaksDependencyOnOlderBackups() throws Exception { 044 LOG.info("test creation of backups after backup data was lost"); 045 046 try (Connection conn = ConnectionFactory.createConnection(conf1)) { 047 BackupAdminImpl client = new BackupAdminImpl(conn); 048 List<TableName> tables = Lists.newArrayList(table1); 049 050 insertIntoTable(conn, table1, famName, 1, 1).close(); 051 String backup1 = 052 client.backupTables(createBackupRequest(BackupType.FULL, tables, BACKUP_ROOT_DIR)); 053 insertIntoTable(conn, table1, famName, 2, 1).close(); 054 String backup2 = 055 client.backupTables(createBackupRequest(BackupType.INCREMENTAL, tables, BACKUP_ROOT_DIR)); 056 057 assertTrue(checkSucceeded(backup1)); 058 assertTrue(checkSucceeded(backup2)); 059 060 // Simulate data loss on the backup storage 061 TEST_UTIL.getTestFileSystem().delete(new Path(BACKUP_ROOT_DIR, backup2), true); 062 063 insertIntoTable(conn, table1, famName, 4, 1).close(); 064 String backup4 = 065 client.backupTables(createBackupRequest(BackupType.FULL, tables, BACKUP_ROOT_DIR)); 066 insertIntoTable(conn, table1, famName, 5, 1).close(); 067 String backup5 = 068 client.backupTables(createBackupRequest(BackupType.INCREMENTAL, tables, BACKUP_ROOT_DIR)); 069 insertIntoTable(conn, table1, famName, 6, 1).close(); 070 String backup6 = 071 client.backupTables(createBackupRequest(BackupType.INCREMENTAL, tables, BACKUP_ROOT_DIR)); 072 073 assertTrue(checkSucceeded(backup4)); 074 assertTrue(checkSucceeded(backup5)); 075 assertTrue(checkSucceeded(backup6)); 076 } 077 } 078 079}