Search in sources :

Example 16 with RebalanceOperation

use of org.apache.geode.cache.control.RebalanceOperation in project geode by apache.

the class BackupDUnitTest method backupWhileBucketIsMoved.

/**
   * Test for bug 42420. Invoke a backup when a bucket is in the middle of being moved.
   * 
   * @param observer - a message observer that triggers at the backup at the correct time.
   */
public void backupWhileBucketIsMoved(final DistributionMessageObserver observer) throws Throwable {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    vm0.invoke(new SerializableRunnable("Add listener to invoke backup") {

        public void run() {
            disconnectFromDS();
            // This listener will wait for a response to the
            // destroy region message, and then trigger a backup.
            // That will backup before this member has finished destroying
            // a bucket, but after the peer has removed the bucket.
            DistributionMessageObserver.setInstance(observer);
        }
    });
    try {
        LogWriterUtils.getLogWriter().info("Creating region in VM0");
        createPersistentRegion(vm0);
        // create twos bucket on vm0
        createData(vm0, 0, 2, "A", "region1");
        // create the pr on vm1, which won't have any buckets
        LogWriterUtils.getLogWriter().info("Creating region in VM1");
        createPersistentRegion(vm1);
        // Perform a rebalance. This will trigger the backup in the middle
        // of the bucket move.
        vm0.invoke(new SerializableRunnable("Do rebalance") {

            public void run() {
                Cache cache = getCache();
                RebalanceOperation op = cache.getResourceManager().createRebalanceFactory().start();
                RebalanceResults results;
                try {
                    results = op.getResults();
                    assertEquals(1, results.getTotalBucketTransfersCompleted());
                } catch (Exception e) {
                    Assert.fail("interupted", e);
                }
            }
        });
        validateBackupComplete();
        createData(vm0, 0, 5, "C", "region1");
        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, 2, "A", "region1");
    } finally {
        // cleanup the distribution message observer
        vm0.invoke(new SerializableRunnable() {

            public void run() {
                DistributionMessageObserver.setInstance(null);
                disconnectFromDS();
            }
        });
    }
}
Also used : RebalanceOperation(org.apache.geode.cache.control.RebalanceOperation) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) FileNotFoundException(java.io.FileNotFoundException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) IOException(java.io.IOException) Cache(org.apache.geode.cache.Cache)

Aggregations

RebalanceOperation (org.apache.geode.cache.control.RebalanceOperation)16 RebalanceResults (org.apache.geode.cache.control.RebalanceResults)11 CancellationException (java.util.concurrent.CancellationException)7 Cache (org.apache.geode.cache.Cache)7 ResourceManager (org.apache.geode.cache.control.ResourceManager)7 Host (org.apache.geode.test.dunit.Host)7 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 VM (org.apache.geode.test.dunit.VM)7 RebalanceFactory (org.apache.geode.cache.control.RebalanceFactory)6 Region (org.apache.geode.cache.Region)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 Test (org.junit.Test)5 AttributesFactory (org.apache.geode.cache.AttributesFactory)4 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)4 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)4 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)4 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 TimeoutException (java.util.concurrent.TimeoutException)2 CacheException (org.apache.geode.cache.CacheException)2 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)2