|
| 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 |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 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. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.hbase.backup; |
| 19 | + |
| 20 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 22 | + |
| 23 | +import java.util.List; |
| 24 | +import java.util.Map; |
| 25 | +import org.apache.hadoop.fs.FileSystem; |
| 26 | +import org.apache.hadoop.fs.Path; |
| 27 | +import org.apache.hadoop.hbase.HBaseTestingUtil; |
| 28 | +import org.apache.hadoop.hbase.ServerName; |
| 29 | +import org.apache.hadoop.hbase.TableName; |
| 30 | +import org.apache.hadoop.hbase.backup.impl.BackupAdminImpl; |
| 31 | +import org.apache.hadoop.hbase.backup.impl.IncrementalBackupManager; |
| 32 | +import org.apache.hadoop.hbase.backup.util.BackupUtils; |
| 33 | +import org.apache.hadoop.hbase.client.Connection; |
| 34 | +import org.apache.hadoop.hbase.client.ConnectionFactory; |
| 35 | +import org.apache.hadoop.hbase.testclassification.LargeTests; |
| 36 | +import org.apache.hadoop.hbase.util.CommonFSUtils; |
| 37 | +import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; |
| 38 | +import org.apache.hadoop.hbase.wal.AbstractFSWALProvider; |
| 39 | +import org.junit.jupiter.api.BeforeAll; |
| 40 | +import org.junit.jupiter.api.Tag; |
| 41 | +import org.junit.jupiter.api.Test; |
| 42 | + |
| 43 | +@Tag(LargeTests.TAG) |
| 44 | +public class TestIncrementalBackupManager extends TestBackupBase { |
| 45 | + |
| 46 | + @BeforeAll |
| 47 | + public static void setUp() throws Exception { |
| 48 | + TEST_UTIL = new HBaseTestingUtil(); |
| 49 | + conf1 = TEST_UTIL.getConfiguration(); |
| 50 | + conf1.setBoolean(AbstractFSWALProvider.SEPARATE_OLDLOGDIR, true); |
| 51 | + autoRestoreOnFailure = true; |
| 52 | + useSecondCluster = false; |
| 53 | + setUpHelper(); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testCollectWALFilesFromRegionServerDirectories() throws Exception { |
| 58 | + List<TableName> tables = List.of(table1); |
| 59 | + try (Connection conn = ConnectionFactory.createConnection(conf1); |
| 60 | + BackupAdminImpl backupAdmin = new BackupAdminImpl(conn)) { |
| 61 | + String fullBackupId = |
| 62 | + backupAdmin.backupTables(createBackupRequest(BackupType.FULL, tables, BACKUP_ROOT_DIR)); |
| 63 | + assertTrue(checkSucceeded(fullBackupId)); |
| 64 | + |
| 65 | + try (IncrementalBackupManager manager = new IncrementalBackupManager(conn, conf1)) { |
| 66 | + BackupInfo backupInfo = manager.createBackupInfo("backup_test", BackupType.INCREMENTAL, |
| 67 | + tables, BACKUP_ROOT_DIR, -1, -1, false); |
| 68 | + Map<String, Long> previousTimestamps = |
| 69 | + BackupUtils.getRSLogTimestampMins(manager.readLogTimestampMap()); |
| 70 | + ServerName serverName = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0).getServerName(); |
| 71 | + Long previousTimestamp = previousTimestamps.get(serverName.getAddress().toString()); |
| 72 | + assertNotNull(previousTimestamp); |
| 73 | + |
| 74 | + TEST_UTIL.waitFor(30_000, |
| 75 | + () -> EnvironmentEdgeManager.currentTime() > previousTimestamp + 1); |
| 76 | + Path walRootDir = CommonFSUtils.getWALRootDir(conf1); |
| 77 | + Path archiveDir = new Path(walRootDir, |
| 78 | + AbstractFSWALProvider.getWALArchiveDirectoryName(conf1, serverName.toString())); |
| 79 | + Path archivedWAL = new Path(archiveDir, "wal." + (previousTimestamp + 1)); |
| 80 | + FileSystem fs = walRootDir.getFileSystem(conf1); |
| 81 | + fs.mkdirs(archiveDir); |
| 82 | + fs.create(archivedWAL).close(); |
| 83 | + |
| 84 | + manager.getIncrBackupLogFileMap(); |
| 85 | + |
| 86 | + assertTrue(backupInfo.getIncrBackupFileList().contains(archivedWAL.toString())); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments