GEODE-3047 Atomic creation flag is not set if the region is recoverd from the disk.
While creating bucket region, to satisfy the redudndancy copies the bucket regions are created on all vailable nodes. The initialization (setting persistentIDs) of these buckets are done after creating buckets on all the nodes. This introduced a race condition for the bucket region which are recovered from the disk to exchange thier old id with the peer node resulting in ConflictingPersistentData Exception. The changes are done so that the regions persistent ids are set as soon as they are created/initialized. Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/35d3a97e Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/35d3a97e Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/35d3a97e Branch: refs/heads/feature/GEODE-3503 Commit: 35d3a97edd5c6e8b3f4dd73af51771b0c4728cf6 Parents: e2c3d53 Author: Anil <aging...@pivotal.io> Authored: Thu Aug 17 16:29:57 2017 -0700 Committer: Anil <aging...@pivotal.io> Committed: Tue Aug 22 14:19:16 2017 -0700 ---------------------------------------------------------------------- .../cache/BucketPersistenceAdvisor.java | 7 +++ .../cache/BucketPersistenceAdvisorTest.java | 56 ++++++++++++++++++++ 2 files changed, 63 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/35d3a97e/geode-core/src/main/java/org/apache/geode/internal/cache/BucketPersistenceAdvisor.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/BucketPersistenceAdvisor.java b/geode-core/src/main/java/org/apache/geode/internal/cache/BucketPersistenceAdvisor.java index 367bb75..423fb64 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/BucketPersistenceAdvisor.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/BucketPersistenceAdvisor.java @@ -463,7 +463,14 @@ public class BucketPersistenceAdvisor extends PersistenceAdvisorImpl { super.setOnline(false, true, newId); } + public boolean isAtomicCreation() { + return this.atomicCreation; + } + public void setAtomicCreation(boolean atomicCreation) { + if (getPersistentID() != null) { + return; + } synchronized (lock) { this.atomicCreation = atomicCreation; } http://git-wip-us.apache.org/repos/asf/geode/blob/35d3a97e/geode-core/src/test/java/org/apache/geode/internal/cache/BucketPersistenceAdvisorTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/BucketPersistenceAdvisorTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/BucketPersistenceAdvisorTest.java new file mode 100644 index 0000000..d97f3e4 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/internal/cache/BucketPersistenceAdvisorTest.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.internal.cache; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.geode.distributed.DistributedLockService; +import org.apache.geode.internal.cache.PartitionedRegion.BucketLock; +import org.apache.geode.internal.cache.persistence.PersistentMemberID; +import org.apache.geode.internal.cache.persistence.PersistentMemberManager; +import org.apache.geode.internal.cache.persistence.PersistentMemberView; +import org.apache.geode.test.junit.categories.UnitTest; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import static org.junit.Assert.*; + +@Category(UnitTest.class) +public class BucketPersistenceAdvisorTest { + + @Test + public void shouldBeMockable() throws Exception { + BucketPersistenceAdvisor mockBucketAdvisor = mock(BucketPersistenceAdvisor.class); + when(mockBucketAdvisor.isRecovering()).thenReturn(true); + assertTrue(mockBucketAdvisor.isRecovering()); + } + + @Test + public void atomicCreationShouldNotBeSetForPersistentRegion() throws Exception { + PersistentMemberID mockPersistentID = mock(PersistentMemberID.class); + PersistentMemberView mockStorage = mock(PersistentMemberView.class); + when(mockStorage.getMyPersistentID()).thenReturn(mockPersistentID); + + BucketPersistenceAdvisor bpa = new BucketPersistenceAdvisor( + mock(CacheDistributionAdvisor.class), mock(DistributedLockService.class), mockStorage, + "/region", mock(DiskRegionStats.class), mock(PersistentMemberManager.class), + mock(BucketLock.class), mock(ProxyBucketRegion.class)); + bpa.setAtomicCreation(true); + assertFalse(bpa.isAtomicCreation()); + } + +}