Committed by
Yuta Higuchi
Distributed IntentStore family: relax state transition check
- allow INSTALLED -> INSTALLED - allow WITHDRWAN -> SUBMITTED Change-Id: I7ba9c7c6e29b39ce005fb15bfd68feb1751cb0af
Showing
2 changed files
with
18 additions
and
6 deletions
... | @@ -56,7 +56,7 @@ public class DistributedIntentStore | ... | @@ -56,7 +56,7 @@ public class DistributedIntentStore |
56 | implements IntentStore { | 56 | implements IntentStore { |
57 | 57 | ||
58 | /** Valid parking state, which can transition to INSTALLED. */ | 58 | /** Valid parking state, which can transition to INSTALLED. */ |
59 | - private static final Set<IntentState> PRE_INSTALLED = EnumSet.of(SUBMITTED, FAILED); | 59 | + private static final Set<IntentState> PRE_INSTALLED = EnumSet.of(SUBMITTED, INSTALLED, FAILED); |
60 | 60 | ||
61 | /** Valid parking state, which can transition to WITHDRAWN. */ | 61 | /** Valid parking state, which can transition to WITHDRAWN. */ |
62 | private static final Set<IntentState> PRE_WITHDRAWN = EnumSet.of(INSTALLED, FAILED); | 62 | private static final Set<IntentState> PRE_WITHDRAWN = EnumSet.of(INSTALLED, FAILED); |
... | @@ -177,11 +177,16 @@ public class DistributedIntentStore | ... | @@ -177,11 +177,16 @@ public class DistributedIntentStore |
177 | switch (state) { | 177 | switch (state) { |
178 | case SUBMITTED: | 178 | case SUBMITTED: |
179 | prevParking = states.get(id); | 179 | prevParking = states.get(id); |
180 | - verify(prevParking == null, | 180 | + if (prevParking == null) { |
181 | + updated = states.putIfAbsent(id, SUBMITTED); | ||
182 | + verify(updated, "Conditional replace %s => %s failed", prevParking, SUBMITTED); | ||
183 | + } else { | ||
184 | + verify(prevParking == WITHDRAWN, | ||
181 | "Illegal state transition attempted from %s to SUBMITTED", | 185 | "Illegal state transition attempted from %s to SUBMITTED", |
182 | prevParking); | 186 | prevParking); |
183 | - updated = states.putIfAbsent(id, SUBMITTED); | 187 | + updated = states.replace(id, prevParking, SUBMITTED); |
184 | verify(updated, "Conditional replace %s => %s failed", prevParking, SUBMITTED); | 188 | verify(updated, "Conditional replace %s => %s failed", prevParking, SUBMITTED); |
189 | + } | ||
185 | type = IntentEvent.Type.SUBMITTED; | 190 | type = IntentEvent.Type.SUBMITTED; |
186 | break; | 191 | break; |
187 | 192 | ... | ... |
... | @@ -56,7 +56,7 @@ public class HazelcastIntentStore | ... | @@ -56,7 +56,7 @@ public class HazelcastIntentStore |
56 | implements IntentStore { | 56 | implements IntentStore { |
57 | 57 | ||
58 | /** Valid parking state, which can transition to INSTALLED. */ | 58 | /** Valid parking state, which can transition to INSTALLED. */ |
59 | - private static final Set<IntentState> PRE_INSTALLED = EnumSet.of(SUBMITTED, FAILED); | 59 | + private static final Set<IntentState> PRE_INSTALLED = EnumSet.of(SUBMITTED, INSTALLED, FAILED); |
60 | 60 | ||
61 | /** Valid parking state, which can transition to WITHDRAWN. */ | 61 | /** Valid parking state, which can transition to WITHDRAWN. */ |
62 | private static final Set<IntentState> PRE_WITHDRAWN = EnumSet.of(INSTALLED, FAILED); | 62 | private static final Set<IntentState> PRE_WITHDRAWN = EnumSet.of(INSTALLED, FAILED); |
... | @@ -177,10 +177,17 @@ public class HazelcastIntentStore | ... | @@ -177,10 +177,17 @@ public class HazelcastIntentStore |
177 | // parking state transition | 177 | // parking state transition |
178 | switch (state) { | 178 | switch (state) { |
179 | case SUBMITTED: | 179 | case SUBMITTED: |
180 | - prevParking = states.putIfAbsent(id, SUBMITTED); | 180 | + prevParking = states.get(id); |
181 | - verify(prevParking == null, | 181 | + if (prevParking == null) { |
182 | + IntentState existing = states.putIfAbsent(id, SUBMITTED); | ||
183 | + verify(existing != null, "Conditional replace %s => %s failed", prevParking, SUBMITTED); | ||
184 | + } else { | ||
185 | + verify(prevParking == WITHDRAWN, | ||
182 | "Illegal state transition attempted from %s to SUBMITTED", | 186 | "Illegal state transition attempted from %s to SUBMITTED", |
183 | prevParking); | 187 | prevParking); |
188 | + boolean updated = states.replace(id, prevParking, SUBMITTED); | ||
189 | + verify(updated, "Conditional replace %s => %s failed", prevParking, SUBMITTED); | ||
190 | + } | ||
184 | type = IntentEvent.Type.SUBMITTED; | 191 | type = IntentEvent.Type.SUBMITTED; |
185 | break; | 192 | break; |
186 | case INSTALLED: | 193 | case INSTALLED: | ... | ... |
-
Please register or login to post a comment