use of org.apache.geode.admin.BackupStatus in project geode by apache.
the class IncrementalBackupDUnitTest method testMissingMemberInBaseline.
/**
* Successful if a member performs a full backup when its backup data is not present in the
* baseline (for whatever reason). This also tests what happens when a member is offline during
* the baseline backup.
*
* The test is regarded as successful when all of the missing members oplog files are backed up
* during an incremental backup. This means that the member peformed a full backup because its
* oplogs were missing in the baseline.
*/
@Test
public void testMissingMemberInBaseline() throws Exception {
// Simulate the missing member by forcing a persistent member
// to go offline.
final PersistentID missingMember = disconnect(Host.getHost(0).getVM(0), Host.getHost(0).getVM(1));
/*
* Perform baseline and make sure that the list of offline disk stores contains our missing
* member.
*/
BackupStatus baselineStatus = performBaseline();
assertBackupStatus(baselineStatus);
assertNotNull(baselineStatus.getOfflineDiskStores());
assertEquals(2, baselineStatus.getOfflineDiskStores().size());
// Find all of the member's oplogs in the missing member's diskstore directory structure
// (*.crf,*.krf,*.drf)
Collection<File> missingMemberOplogFiles = FileUtils.listFiles(new File(missingMember.getDirectory()), new RegexFileFilter(OPLOG_REGEX), DirectoryFileFilter.DIRECTORY);
assertFalse(missingMemberOplogFiles.isEmpty());
/*
* Restart our missing member and make sure it is back online and part of the distributed system
*/
openCache(Host.getHost(0).getVM(0));
/*
* After reconnecting make sure the other members agree that the missing member is back online.
*/
final Set<PersistentID> missingMembers = new HashSet<>();
Wait.waitForCriterion(new WaitCriterion() {
@Override
public boolean done() {
missingMembers.clear();
missingMembers.addAll(getMissingMembers(Host.getHost(0).getVM(1)));
return !missingMembers.contains(missingMember);
}
@Override
public String description() {
return "[testMissingMemberInBasline] Wait for missing member.";
}
}, 10000, 500, false);
assertEquals(0, missingMembers.size());
/*
* Peform incremental and make sure we have no offline disk stores.
*/
BackupStatus incrementalStatus = performIncremental();
assertBackupStatus(incrementalStatus);
assertNotNull(incrementalStatus.getOfflineDiskStores());
assertEquals(0, incrementalStatus.getOfflineDiskStores().size());
// Get the missing member's member id which is different from the PersistentID
String memberId = getMemberId(Host.getHost(0).getVM(0));
assertNotNull(memberId);
// Get list of backed up oplog files in the incremental backup for the missing member
File incrementalMemberDir = getBackupDirForMember(getIncrementalDir(), memberId);
Collection<File> backupOplogFiles = FileUtils.listFiles(incrementalMemberDir, new RegexFileFilter(OPLOG_REGEX), DirectoryFileFilter.DIRECTORY);
assertFalse(backupOplogFiles.isEmpty());
// Transform missing member oplogs to just their file names.
List<String> missingMemberOplogNames = new LinkedList<>();
TransformUtils.transform(missingMemberOplogFiles, missingMemberOplogNames, TransformUtils.fileNameTransformer);
// Transform missing member's incremental backup oplogs to just their file names.
List<String> backupOplogNames = new LinkedList<>();
TransformUtils.transform(backupOplogFiles, backupOplogNames, TransformUtils.fileNameTransformer);
/*
* Make sure that the incremental backup for the missing member contains all of the operation
* logs for that member. This proves that a full backup was performed for that member.
*/
assertTrue(backupOplogNames.containsAll(missingMemberOplogNames));
}
use of org.apache.geode.admin.BackupStatus in project geode by apache.
the class IncrementalBackupDUnitTest method incremental2.
/**
* Invokes {@link AdminDistributedSystem#backupAllMembers(File, File)} on a member.
*
* @param vm a member of the distributed system.
* @return a status of the backup operation.
*/
private BackupStatus incremental2(VM vm) {
return (BackupStatus) vm.invoke(new SerializableCallable("Backup all members.") {
@Override
public Object call() {
DistributedSystemConfig config;
AdminDistributedSystem adminDS = null;
try {
config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
adminDS.connect();
return adminDS.backupAllMembers(getIncremental2Dir(), getIncrementalBackupDir());
} catch (AdminException e) {
throw new RuntimeException(e);
} finally {
if (adminDS != null) {
adminDS.disconnect();
}
}
}
});
}
use of org.apache.geode.admin.BackupStatus in project geode by apache.
the class SystemAdmin method backup.
public static void backup(String targetDir) throws AdminException {
InternalDistributedSystem ads = getAdminCnx();
// Baseline directory should be null if it was not provided on the command line
BackupStatus status = AdminDistributedSystemImpl.backupAllMembers(ads.getDistributionManager(), new File(targetDir), (SystemAdmin.baselineDir == null ? null : new File(SystemAdmin.baselineDir)));
boolean incomplete = !status.getOfflineDiskStores().isEmpty();
System.out.println("The following disk stores were backed up:");
for (Set<PersistentID> memberStores : status.getBackedUpDiskStores().values()) {
for (PersistentID store : memberStores) {
System.out.println("\t" + store);
}
}
if (incomplete) {
System.err.println("The backup may be incomplete. The following disk stores are not online:");
for (PersistentID store : status.getOfflineDiskStores()) {
System.err.println("\t" + store);
}
} else {
System.out.println("Backup successful.");
}
}
use of org.apache.geode.admin.BackupStatus in project geode by apache.
the class BackupDUnitTest method testBackupWhileBucketIsCreated.
// public void testLoop() throws Throwable {
// for(int i =0 ;i < 100; i++) {
// testBackupWhileBucketIsCreated();
// setUp();
// tearDown();
// }
// }
/**
* Test for bug 42419
*/
@Test
public void testBackupWhileBucketIsCreated() throws Throwable {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final VM vm2 = host.getVM(2);
LogWriterUtils.getLogWriter().info("Creating region in VM0");
createPersistentRegion(vm0);
// create a bucket on vm0
createData(vm0, 0, 1, "A", "region1");
// create the pr on vm1, which won't have any buckets
LogWriterUtils.getLogWriter().info("Creating region in VM1");
createPersistentRegion(vm1);
final AtomicReference<BackupStatus> statusRef = new AtomicReference<BackupStatus>();
Thread thread1 = new Thread() {
public void run() {
BackupStatus status = backup(vm2);
statusRef.set(status);
}
};
thread1.start();
Thread thread2 = new Thread() {
public void run() {
createData(vm0, 1, 5, "A", "region1");
}
};
thread2.start();
thread1.join();
thread2.join();
BackupStatus status = statusRef.get();
assertEquals(2, status.getBackedUpDiskStores().size());
assertEquals(Collections.emptySet(), status.getOfflineDiskStores());
validateBackupComplete();
createData(vm0, 0, 5, "C", "region1");
assertEquals(2, status.getBackedUpDiskStores().size());
assertEquals(Collections.emptySet(), status.getOfflineDiskStores());
closeCache(vm0);
closeCache(vm1);
// Destroy the current data
Invoke.invokeInEveryVM(new SerializableRunnable("Clean disk dirs") {
public void run() {
try {
cleanDiskDirs();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
restoreBackup(2);
LogWriterUtils.getLogWriter().info("Creating region in VM0");
AsyncInvocation async0 = createPersistentRegionAsync(vm0);
LogWriterUtils.getLogWriter().info("Creating region in VM1");
AsyncInvocation async1 = createPersistentRegionAsync(vm1);
async0.getResult(MAX_WAIT);
async1.getResult(MAX_WAIT);
checkData(vm0, 0, 1, "A", "region1");
}
use of org.apache.geode.admin.BackupStatus in project geode by apache.
the class BackupDUnitTest method testBackupOverflow.
/**
* Make sure we don't report members without persistent data as backed up.
*/
@Test
public void testBackupOverflow() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
LogWriterUtils.getLogWriter().info("Creating region in VM0");
createPersistentRegion(vm0);
LogWriterUtils.getLogWriter().info("Creating region in VM1");
createOverflowRegion(vm1);
createData(vm0, 0, 5, "A", "region1");
createData(vm0, 0, 5, "B", "region2");
BackupStatus status = backup(vm2);
assertEquals("Backed up disk stores " + status, 1, status.getBackedUpDiskStores().size());
assertEquals(2, status.getBackedUpDiskStores().values().iterator().next().size());
assertEquals(Collections.emptySet(), status.getOfflineDiskStores());
validateBackupComplete();
}
Aggregations