Search in sources :

Example 6 with BackupStatus

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));
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) File(java.io.File) LinkedList(java.util.LinkedList) PersistentID(org.apache.geode.cache.persistence.PersistentID) BackupStatus(org.apache.geode.admin.BackupStatus) HashSet(java.util.HashSet) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 7 with BackupStatus

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();
                }
            }
        }
    });
}
Also used : AdminException(org.apache.geode.admin.AdminException) DistributedSystemConfig(org.apache.geode.admin.DistributedSystemConfig) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) AdminDistributedSystem(org.apache.geode.admin.AdminDistributedSystem) BackupStatus(org.apache.geode.admin.BackupStatus)

Example 8 with BackupStatus

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.");
    }
}
Also used : BackupStatus(org.apache.geode.admin.BackupStatus) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Example 9 with BackupStatus

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");
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) BackupStatus(org.apache.geode.admin.BackupStatus) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 10 with BackupStatus

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();
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) BackupStatus(org.apache.geode.admin.BackupStatus) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

BackupStatus (org.apache.geode.admin.BackupStatus)13 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7 Test (org.junit.Test)7 IOException (java.io.IOException)6 Host (org.apache.geode.test.dunit.Host)6 VM (org.apache.geode.test.dunit.VM)6 AdminDistributedSystem (org.apache.geode.admin.AdminDistributedSystem)4 AdminException (org.apache.geode.admin.AdminException)4 DistributedSystemConfig (org.apache.geode.admin.DistributedSystemConfig)4 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)4 File (java.io.File)3 PersistentID (org.apache.geode.cache.persistence.PersistentID)3 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)3 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)3 HashSet (java.util.HashSet)2 DistributedMember (org.apache.geode.distributed.DistributedMember)2 FileNotFoundException (java.io.FileNotFoundException)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1