Skip to content

Commit e4d2f16

Browse files
authored
GEODE-10419: Enhancment of backup disk-store command (#7851)
* GEODE-10419: initial commit * GEODE-10419: documentation impacts * GEODE-10419: added DT
1 parent 16627d7 commit e4d2f16

13 files changed

Lines changed: 399 additions & 14 deletions

File tree

geode-core/src/integrationTest/java/org/apache/geode/management/internal/beans/DistributedSystemBridgeIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2020
import static org.mockito.ArgumentMatchers.any;
2121
import static org.mockito.ArgumentMatchers.anyLong;
22+
import static org.mockito.ArgumentMatchers.eq;
2223
import static org.mockito.ArgumentMatchers.isA;
2324
import static org.mockito.Mockito.doReturn;
2425
import static org.mockito.Mockito.inOrder;
@@ -68,7 +69,6 @@ public void createCache() throws MalformedObjectNameException {
6869
backupService = mock(BackupService.class);
6970
when(cache.getBackupService()).thenReturn(backupService);
7071
when(cache.getPersistentMemberManager()).thenReturn(memberManager);
71-
when(cache.getBackupService()).thenReturn(backupService);
7272

7373
DLockService dlock = mock(DLockService.class);
7474
when(dlock.lock(any(), anyLong(), anyLong())).thenReturn(true);
@@ -114,7 +114,7 @@ public void testSuccessfulBackup() throws Exception {
114114

115115
InOrder inOrder = inOrder(dm, backupService);
116116
inOrder.verify(dm).putOutgoing(isA(PrepareBackupRequest.class));
117-
inOrder.verify(backupService).prepareBackup(any(), any());
117+
inOrder.verify(backupService).prepareBackup(any(), any(), eq(null));
118118
inOrder.verify(dm).putOutgoing(isA(FinishBackupRequest.class));
119119
inOrder.verify(backupService).doBackup();
120120
}

geode-core/src/main/java/org/apache/geode/distributed/internal/InternalConfigurationPersistenceService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public class InternalConfigurationPersistenceService implements ConfigurationPer
9595
*/
9696
public static final String CLUSTER_CONFIG_ARTIFACTS_DIR_NAME = "cluster_config";
9797

98-
private static final String CLUSTER_CONFIG_DISK_STORE_NAME = "cluster_config";
98+
public static final String CLUSTER_CONFIG_DISK_STORE_NAME = "cluster_config";
9999

100100
public static final String CLUSTER_CONFIG_DISK_DIR_PREFIX = "ConfigDiskDir_";
101101

geode-core/src/main/java/org/apache/geode/internal/cache/backup/BackupConfigFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static org.apache.geode.internal.cache.backup.AbstractBackupWriterConfig.TIMESTAMP;
1818
import static org.apache.geode.internal.cache.backup.AbstractBackupWriterConfig.TYPE;
1919
import static org.apache.geode.internal.cache.backup.FileSystemBackupWriterConfig.BASELINE_DIR;
20+
import static org.apache.geode.internal.cache.backup.FileSystemBackupWriterConfig.INCLUDE_DISK_STORES;
2021
import static org.apache.geode.internal.cache.backup.FileSystemBackupWriterConfig.TARGET_DIR;
2122

2223
import java.text.SimpleDateFormat;
@@ -27,6 +28,7 @@ class BackupConfigFactory {
2728

2829
private String targetDirPath;
2930
private String baselineDirPath;
31+
private String includeDiskStores;
3032

3133
BackupConfigFactory() {
3234
// nothing
@@ -42,6 +44,11 @@ BackupConfigFactory withBaselineDirPath(String baselineDirPath) {
4244
return this;
4345
}
4446

47+
BackupConfigFactory withIncludeDiskStores(String includeDiskStores) {
48+
this.includeDiskStores = includeDiskStores;
49+
return this;
50+
}
51+
4552
Properties createBackupProperties() {
4653
Properties properties = new Properties();
4754
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
@@ -51,6 +58,9 @@ Properties createBackupProperties() {
5158
if (baselineDirPath != null) {
5259
properties.setProperty(BASELINE_DIR, baselineDirPath);
5360
}
61+
if (includeDiskStores != null) {
62+
properties.setProperty(INCLUDE_DISK_STORES, includeDiskStores);
63+
}
5464
return properties;
5565
}
5666
}

geode-core/src/main/java/org/apache/geode/internal/cache/backup/BackupOperation.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ public BackupStatus backupAllMembers(String targetDirPath, String baselineDirPat
7171
return performBackup(properties);
7272
}
7373

74+
public BackupStatus backupAllMembers(String targetDirPath, String baselineDirPath,
75+
String includeDiskStores) {
76+
Properties properties = new BackupConfigFactory().withTargetDirPath(targetDirPath)
77+
.withBaselineDirPath(baselineDirPath).withIncludeDiskStores(includeDiskStores)
78+
.createBackupProperties();
79+
return performBackup(properties);
80+
}
81+
7482
private BackupStatus performBackup(Properties properties) throws ManagementException {
7583
if (backupLockService.obtainLock(dm)) {
7684
try {

geode-core/src/main/java/org/apache/geode/internal/cache/backup/BackupService.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,14 @@ public BackupService(InternalCache cache) {
5454

5555
public HashSet<PersistentID> prepareBackup(InternalDistributedMember sender, BackupWriter writer)
5656
throws IOException, InterruptedException {
57+
return prepareBackup(sender, writer, null);
58+
}
59+
60+
public HashSet<PersistentID> prepareBackup(InternalDistributedMember sender, BackupWriter writer,
61+
String includeDiskStores)
62+
throws IOException, InterruptedException {
5763
validateRequestingSender(sender);
58-
BackupTask backupTask = new BackupTask(cache, writer);
64+
BackupTask backupTask = new BackupTask(cache, writer, includeDiskStores);
5965
if (!currentTask.compareAndSet(null, backupTask)) {
6066
throw new IOException("Another backup is already in progress");
6167
}

geode-core/src/main/java/org/apache/geode/internal/cache/backup/BackupTask.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@
1414
*/
1515
package org.apache.geode.internal.cache.backup;
1616

17+
import static org.apache.geode.distributed.internal.InternalConfigurationPersistenceService.CLUSTER_CONFIG_DISK_STORE_NAME;
18+
1719
import java.io.IOException;
20+
import java.util.Arrays;
1821
import java.util.Collection;
1922
import java.util.HashMap;
2023
import java.util.HashSet;
2124
import java.util.Map;
25+
import java.util.Set;
2226
import java.util.concurrent.CountDownLatch;
27+
import java.util.stream.Collectors;
2328

29+
import org.apache.commons.lang3.StringUtils;
2430
import org.apache.logging.log4j.Logger;
2531

2632
import org.apache.geode.InternalGemFireError;
@@ -37,7 +43,6 @@
3743
*/
3844
class BackupTask {
3945
private static final Logger logger = LogService.getLogger();
40-
4146
private final Map<DiskStoreImpl, DiskStoreBackup> backupByDiskStore = new HashMap<>();
4247
private final RestoreScript restoreScript = new RestoreScript();
4348
private final InternalCache cache;
@@ -46,15 +51,25 @@ class BackupTask {
4651
private final CountDownLatch otherMembersReady = new CountDownLatch(1);
4752
private final HashSet<PersistentID> diskStoresWithData = new HashSet<>();
4853
private final BackupWriter backupWriter;
54+
private final Set<String> includeDiskStoresSet = new HashSet<>();
4955

5056
private volatile boolean isCancelled;
5157

5258
private TemporaryBackupFiles temporaryFiles;
5359
private BackupFileCopier fileCopier;
5460

55-
BackupTask(InternalCache cache, BackupWriter backupWriter) {
61+
BackupTask(InternalCache cache, BackupWriter backupWriter, String includeDiskStores) {
5662
this.cache = cache;
5763
this.backupWriter = backupWriter;
64+
if (includeDiskStores != null) {
65+
this.includeDiskStoresSet.addAll(Arrays.stream(includeDiskStores.split(","))
66+
.filter(StringUtils::isNotBlank)
67+
.collect(Collectors.toSet()));
68+
if (!this.includeDiskStoresSet.isEmpty()) {
69+
// add internal disk-store for shared configuration data
70+
this.includeDiskStoresSet.add(CLUSTER_CONFIG_DISK_STORE_NAME);
71+
}
72+
}
5873
}
5974

6075
HashSet<PersistentID> getPreparedDiskStores() throws InterruptedException {
@@ -86,7 +101,9 @@ HashSet<PersistentID> backup() throws InterruptedException, IOException {
86101
private void prepareForBackup() {
87102
for (DiskStore store : cache.listDiskStoresIncludingRegionOwned()) {
88103
DiskStoreImpl storeImpl = (DiskStoreImpl) store;
89-
104+
if (!isDiskStoreIncluded(store)) {
105+
continue;
106+
}
90107
storeImpl.lockStoreBeforeBackup();
91108
if (logger.isDebugEnabled()) {
92109
logger.debug("Acquired lock for backup on disk store {}", store.getName());
@@ -145,6 +162,9 @@ private Map<DiskStoreImpl, DiskStoreBackup> startDiskStoreBackups(
145162
Map<DiskStoreImpl, DiskStoreBackup> backupByDiskStore = new HashMap<>();
146163

147164
for (DiskStore store : diskStores) {
165+
if (!isDiskStoreIncluded(store)) {
166+
continue;
167+
}
148168
DiskStoreImpl diskStore = (DiskStoreImpl) store;
149169
try {
150170
if (diskStore.hasPersistedData()) {
@@ -161,6 +181,16 @@ private Map<DiskStoreImpl, DiskStoreBackup> startDiskStoreBackups(
161181
return backupByDiskStore;
162182
}
163183

184+
boolean isDiskStoreIncluded(DiskStore store) {
185+
if (includeDiskStoresSet.isEmpty()) {
186+
return true;
187+
}
188+
if (includeDiskStoresSet.contains(store.getName())) {
189+
return true;
190+
}
191+
return false;
192+
}
193+
164194
void abort() {
165195
isCancelled = true;
166196
otherMembersReady.countDown();

geode-core/src/main/java/org/apache/geode/internal/cache/backup/FileSystemBackupWriterConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class FileSystemBackupWriterConfig extends AbstractBackupWriterConfig {
2222

2323
static final String TARGET_DIR = "TARGET_DIRECTORY";
2424
static final String BASELINE_DIR = "BASELINE_DIRECTORY";
25+
static final String INCLUDE_DISK_STORES = "INCLUDE_DISK_STORES";
2526

2627
FileSystemBackupWriterConfig(Properties properties) {
2728
super(properties);

geode-core/src/main/java/org/apache/geode/internal/cache/backup/PrepareBackup.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,23 @@ class PrepareBackup {
2626
private final InternalDistributedMember member;
2727
private final InternalCache cache;
2828
private final BackupWriter backupWriter;
29+
private final String includeDiskStores;
2930

30-
PrepareBackup(InternalDistributedMember member, InternalCache cache, BackupWriter backupWriter) {
31+
PrepareBackup(InternalDistributedMember member, InternalCache cache, BackupWriter backupWriter,
32+
String includeDiskStores) {
3133
this.member = member;
3234
this.cache = cache;
3335
this.backupWriter = backupWriter;
36+
this.includeDiskStores = includeDiskStores;
3437
}
3538

3639
HashSet<PersistentID> run() throws IOException, InterruptedException {
3740
HashSet<PersistentID> persistentIds;
3841
if (cache == null) {
3942
persistentIds = new HashSet<>();
4043
} else {
41-
persistentIds = cache.getBackupService().prepareBackup(member, backupWriter);
44+
persistentIds =
45+
cache.getBackupService().prepareBackup(member, backupWriter, includeDiskStores);
4246
}
4347
return persistentIds;
4448
}

geode-core/src/main/java/org/apache/geode/internal/cache/backup/PrepareBackupFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.apache.geode.internal.cache.backup;
1616

1717
import static org.apache.geode.internal.cache.backup.AbstractBackupWriterConfig.TYPE;
18+
import static org.apache.geode.internal.cache.backup.FileSystemBackupWriterConfig.INCLUDE_DISK_STORES;
1819

1920
import java.util.HashSet;
2021
import java.util.Properties;
@@ -42,7 +43,9 @@ PrepareBackup createPrepareBackup(InternalDistributedMember member, InternalCach
4243
String memberId = cleanSpecialCharacters(member.toString());
4344
BackupWriter backupWriter = BackupWriterFactory.getFactoryForType(properties.getProperty(TYPE))
4445
.createWriter(properties, memberId);
45-
return new PrepareBackup(member, cache, backupWriter);
46+
47+
String includeDiskStores = properties.getProperty(INCLUDE_DISK_STORES);
48+
return new PrepareBackup(member, cache, backupWriter, includeDiskStores);
4649
}
4750

4851
BackupResponse createBackupResponse(InternalDistributedMember sender,

geode-core/src/main/java/org/apache/geode/management/internal/i18n/CliStrings.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,14 @@ public class CliStrings {
531531
public static final String BACKUP_DISK_STORE_MSG_NO_DISKSTORES_BACKED_UP =
532532
"No disk store(s) were backed up.";
533533

534+
public static final String BACKUP_INCLUDE_DISK_STORES = "include-disk-stores";
535+
public static final String BACKUP_INCLUDE_DISK_STORES__HELP = "List of disk-stores to include.";
536+
public static final String BACKUP_DISK_STORE__MSG__SPECIFY_VALID_INCLUDE_DISKSTORE_UNKNOWN_DISKSTORE_0 =
537+
"Specify valid include-disk-stores. Unknown Disk Store : \"{0}\".";
538+
539+
public static final String BACKUP_DISK_STORE__MSG__SPECIFY_VALID_INCLUDE_DISKSTORE_UNKNOWN_DISKSTORE_1 =
540+
"Specify valid include-disk-stores. Blank name added in list of disk-stores";
541+
534542
/* 'compact disk-store' command */
535543
public static final String COMPACT_DISK_STORE = "compact disk-store";
536544
public static final String COMPACT_DISK_STORE__HELP =

0 commit comments

Comments
 (0)