[
https://issues.apache.org/jira/browse/GEODE-4083?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16289764#comment-16289764
]
ASF GitHub Bot commented on GEODE-4083:
---------------------------------------
dschneider-pivotal commented on a change in pull request #1161: GEODE-4083: fix
infinite loop caused by thread race changing version
URL: https://github.com/apache/geode/pull/1161#discussion_r156760447
##########
File path:
geode-core/src/test/java/org/apache/geode/internal/cache/versions/RegionVersionVectorTest.java
##########
@@ -567,7 +572,56 @@ public void
testRecordVersionAfterRegionInitThrowsException() {
rvv.recordVersion(ownerId, tag);
}
- public RegionVersionVector
createRegionVersionVector(InternalDistributedMember ownerId,
+ @Test
+ public void usesNewVersionIfGreaterThanOldVersion() throws Exception {
+ VersionSource<InternalDistributedMember> ownerId =
mock(VersionSource.class);
+ long oldVersion = 1;
+ long newVersion = 2;
+
+ RegionVersionVector rvv = new TestableRegionVersionVector(ownerId,
oldVersion);
+ rvv.updateLocalVersion(newVersion);
+ assertThat(rvv.getVersionForMember(ownerId)).isEqualTo(newVersion);
+ }
+
+ @Test
+ public void usesOldVersionIfGreaterThanNewVersion() throws Exception {
+ VersionSource<InternalDistributedMember> ownerId =
mock(VersionSource.class);
+ long oldVersion = 2;
+ long newVersion = 1;
+
+ RegionVersionVector rvv = new TestableRegionVersionVector(ownerId,
oldVersion);
+ rvv.updateLocalVersion(newVersion);
+ assertThat(rvv.getVersionForMember(ownerId)).isEqualTo(oldVersion);
+ }
+
+ @Test
+ public void doesNothingIfVersionsAreSame() throws Exception {
+ VersionSource<InternalDistributedMember> ownerId =
mock(VersionSource.class);
+ long oldVersion = 2;
+ long sameVersion = 2;
+
+ RegionVersionVector rvv = new TestableRegionVersionVector(ownerId,
oldVersion);
+ rvv.updateLocalVersion(sameVersion);
+ assertThat(rvv.getVersionForMember(ownerId)).isEqualTo(oldVersion);
+ }
+
+ @Test
+ public void doesNotHangIfOtherThreadChangedVersion() throws Exception {
+ VersionSource<InternalDistributedMember> ownerId =
mock(VersionSource.class);
+ long oldVersion = 1;
+ long newVersion = 2;
+
+ RegionVersionVector rvv = new
VersionRaceConditionRegionVersionVector(ownerId, oldVersion);
+ Future<Boolean> future = executor.submit(() -> {
Review comment:
I understand now that you did not want the test to hang forever if it does
hang.
I think the test method name "doesNotHangIfOtherThreadChangedVersion"
mislead me.
It made me think the test used another thread to change the version. But you
actually doing it inline in a single thread. So I suggest you rename this test
to not mention threads. Something like
"doesNotHangIfVersionChangesDuringUpdateLocalVersion".
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> RegionVersionVector.updateLocalVersion can go into an infinite loop
> -------------------------------------------------------------------
>
> Key: GEODE-4083
> URL: https://issues.apache.org/jira/browse/GEODE-4083
> Project: Geode
> Issue Type: Bug
> Components: regions
> Reporter: Darrel Schneider
> Assignee: Eric Shu
>
> RegionVersionVector.updateLocalVersion can go into an infinite loop.
> The problem is this code:
> {code}
> private void updateLocalVersion(long version) {
> boolean repeat = false;
> do {
> long myVersion = this.localVersion.get();
> if (myVersion < version) {
> repeat = !this.localVersion.compareAndSet(myVersion, version);
> }
> } while (repeat);
> }
> {code}
> if version is "1" and localVersion.get() returns "0" the first time it is
> called but then compareAndSet returns false because localVersion has changed
> to "2" then the loop will never terminate because repeat will always be false
> and myVersion ("2" or more) will never be less than version ("1").
> The simple fix is to be sure repeat is set to false when myVersion is >= to
> version.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)