Skip to content

Commit 82b6fed

Browse files
authored
Make statusDir and tmpDir namespaced (#53)
To achieve parity with other paths/dirs (such as storageDir), this commit makes statusDir and tmpDir namespaced. The following is the example: statusDir: /zkbackup/statusDir -> /zkbackup/statusDir/<namespace> When the namespace is not given, the paths will be namespaced with a string "UNKNOWN_NAMESPACE".
1 parent 33d63ac commit 82b6fed

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

zookeeper-server/src/main/java/org/apache/zookeeper/server/backup/BackupConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class BackupConfig {
7272
* <backupStoragePath>/<namespace>/translog-123456
7373
*/
7474
private final String namespace;
75-
private static final String UNKNOWN_NAMESPACE = "UNKNOWN";
75+
private static final String UNKNOWN_NAMESPACE = "UNKNOWN_NAMESPACE";
7676

7777
/*
7878
* Optional timetable configs

zookeeper-server/src/main/java/org/apache/zookeeper/server/backup/BackupManager.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,17 @@ public BackupManager(File snapDir, File dataLogDir, long serverId, BackupConfig
502502
this.snapDir = snapDir;
503503
this.dataLogDir = dataLogDir;
504504
this.backupConfig = backupConfig;
505-
this.tmpDir = backupConfig.getTmpDir();
506-
this.backupStatus = new BackupStatus(backupConfig.getStatusDir());
505+
// Note: tmpDir is namespaced
506+
this.tmpDir = new File(String.join(File.separator, backupConfig.getTmpDir().getAbsolutePath(),
507+
backupConfig.getNamespace()));
508+
// Note: statusDir is namespaced
509+
this.backupStatus = new BackupStatus(new File(String
510+
.join(File.separator, backupConfig.getStatusDir().getAbsolutePath(),
511+
backupConfig.getNamespace())));
507512
this.backupIntervalInMilliseconds =
508513
TimeUnit.MINUTES.toMillis(backupConfig.getBackupIntervalInMinutes());
509514
this.serverId = serverId;
510-
this.namespace = backupConfig.getNamespace() == null ? "UNKNOWN" : backupConfig.getNamespace();
515+
this.namespace = backupConfig.getNamespace();
511516
try {
512517
backupStorage = BackupUtil.createStorageProviderImpl(backupConfig);
513518
} catch (ReflectiveOperationException e) {

zookeeper-server/src/test/java/org/apache/zookeeper/test/BackupManagerTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ public void testEmptyDirectory() throws Exception {
153153
Assert.assertFalse("No files should have been backed up.", backupDir.list() == null);
154154
Assert.assertFalse("No temporary files should have been created.",
155155
backupTmpDir.list() == null);
156-
BackupStatus bs = new BackupStatus(dataDir);
156+
BackupStatus bs = new BackupStatus(new File(String
157+
.join(File.separator, backupConfig.getStatusDir().getAbsolutePath(),
158+
backupConfig.getNamespace())));
157159
BackupPoint bp = bs.read();
158160
Assert.assertEquals("backupStatus should be set to min for log",
159161
bp.getLogZxid(), BackupUtil.INVALID_LOG_ZXID);

0 commit comments

Comments
 (0)