HBASE-26921 Rewrite the counting cells part in TestMultiVersions (#4316)
[hbase.git] / hbase-backup / src / test / java / org / apache / hadoop / hbase / backup / TestRepairAfterFailedDelete.java
blob62a1f8f294cf41530b67cae1fb7f7ca7e5801f4e
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.backup;
20 import static org.junit.Assert.assertTrue;
22 import java.util.List;
23 import org.apache.hadoop.fs.FileSystem;
24 import org.apache.hadoop.fs.Path;
25 import org.apache.hadoop.hbase.HBaseClassTestRule;
26 import org.apache.hadoop.hbase.TableName;
27 import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
28 import org.apache.hadoop.hbase.client.Admin;
29 import org.apache.hadoop.hbase.client.Connection;
30 import org.apache.hadoop.hbase.testclassification.LargeTests;
31 import org.apache.hadoop.util.ToolRunner;
32 import org.junit.ClassRule;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
40 @Category(LargeTests.class)
41 public class TestRepairAfterFailedDelete extends TestBackupBase {
43 @ClassRule
44 public static final HBaseClassTestRule CLASS_RULE =
45 HBaseClassTestRule.forClass(TestRepairAfterFailedDelete.class);
47 private static final Logger LOG = LoggerFactory.getLogger(TestRepairAfterFailedDelete.class);
49 @Test
50 public void testRepairBackupDelete() throws Exception {
51 LOG.info("test repair backup delete on a single table with data");
52 List<TableName> tableList = Lists.newArrayList(table1);
53 String backupId = fullTableBackup(tableList);
54 assertTrue(checkSucceeded(backupId));
55 LOG.info("backup complete");
56 String[] backupIds = new String[] { backupId };
57 BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection());
58 BackupInfo info = table.readBackupInfo(backupId);
59 Path path = new Path(info.getBackupRootDir(), backupId);
60 FileSystem fs = FileSystem.get(path.toUri(), conf1);
61 assertTrue(fs.exists(path));
63 // Snapshot backup system table before delete
64 String snapshotName = "snapshot-backup";
65 Connection conn = TEST_UTIL.getConnection();
66 Admin admin = conn.getAdmin();
67 admin.snapshot(snapshotName, BackupSystemTable.getTableName(conf1));
69 int deleted = getBackupAdmin().deleteBackups(backupIds);
71 assertTrue(!fs.exists(path));
72 assertTrue(fs.exists(new Path(info.getBackupRootDir())));
73 assertTrue(1 == deleted);
75 // Emulate delete failure
76 // Restore backup system table
77 admin.disableTable(BackupSystemTable.getTableName(conf1));
78 admin.restoreSnapshot(snapshotName);
79 admin.enableTable(BackupSystemTable.getTableName(conf1));
80 // Start backup session
81 table.startBackupExclusiveOperation();
82 // Start delete operation
83 table.startDeleteOperation(backupIds);
85 // Now run repair command to repair "failed" delete operation
86 String[] args = new String[] {"repair"};
87 // Run restore
88 int ret = ToolRunner.run(conf1, new BackupDriver(), args);
89 assertTrue(ret == 0);
90 // Verify that history length == 0
91 assertTrue(table.getBackupHistory().size() == 0);
92 table.close();
93 admin.close();