Committed by
Yuta Higuchi
IntentStores: clear transient states, after transitioning to parking state
Fix for ONOS-372 Change-Id: I2e397f7f9a60855945fd49a8170c41ab0166f6d3
Showing
2 changed files
with
19 additions
and
0 deletions
... | @@ -53,6 +53,7 @@ import org.slf4j.Logger; | ... | @@ -53,6 +53,7 @@ import org.slf4j.Logger; |
53 | 53 | ||
54 | import java.util.ArrayList; | 54 | import java.util.ArrayList; |
55 | import java.util.EnumSet; | 55 | import java.util.EnumSet; |
56 | +import java.util.HashSet; | ||
56 | import java.util.List; | 57 | import java.util.List; |
57 | import java.util.Map; | 58 | import java.util.Map; |
58 | import java.util.Set; | 59 | import java.util.Set; |
... | @@ -76,6 +77,8 @@ public class DistributedIntentStore | ... | @@ -76,6 +77,8 @@ public class DistributedIntentStore |
76 | /** Valid parking state, which can transition to WITHDRAWN. */ | 77 | /** Valid parking state, which can transition to WITHDRAWN. */ |
77 | private static final Set<IntentState> PRE_WITHDRAWN = EnumSet.of(INSTALLED, FAILED); | 78 | private static final Set<IntentState> PRE_WITHDRAWN = EnumSet.of(INSTALLED, FAILED); |
78 | 79 | ||
80 | + private static final Set<IntentState> PARKING = EnumSet.of(SUBMITTED, INSTALLED, WITHDRAWN, FAILED); | ||
81 | + | ||
79 | private final Logger log = getLogger(getClass()); | 82 | private final Logger log = getLogger(getClass()); |
80 | 83 | ||
81 | // Assumption: IntentId will not have synonyms | 84 | // Assumption: IntentId will not have synonyms |
... | @@ -415,6 +418,8 @@ public class DistributedIntentStore | ... | @@ -415,6 +418,8 @@ public class DistributedIntentStore |
415 | List<Operation> failed = new ArrayList<>(); | 418 | List<Operation> failed = new ArrayList<>(); |
416 | final Builder builder = BatchWriteRequest.newBuilder(); | 419 | final Builder builder = BatchWriteRequest.newBuilder(); |
417 | 420 | ||
421 | + final Set<IntentId> transitionedToParking = new HashSet<>(); | ||
422 | + | ||
418 | for (Operation op : batch.operations()) { | 423 | for (Operation op : batch.operations()) { |
419 | switch (op.type()) { | 424 | switch (op.type()) { |
420 | case CREATE_INTENT: | 425 | case CREATE_INTENT: |
... | @@ -440,6 +445,11 @@ public class DistributedIntentStore | ... | @@ -440,6 +445,11 @@ public class DistributedIntentStore |
440 | intent = op.arg(0); | 445 | intent = op.arg(0); |
441 | IntentState newState = op.arg(1); | 446 | IntentState newState = op.arg(1); |
442 | builder.put(STATES_TABLE, strIntentId(intent.id()), serializer.encode(newState)); | 447 | builder.put(STATES_TABLE, strIntentId(intent.id()), serializer.encode(newState)); |
448 | + if (PARKING.contains(newState)) { | ||
449 | + transitionedToParking.add(intent.id()); | ||
450 | + } else { | ||
451 | + transitionedToParking.remove(intent.id()); | ||
452 | + } | ||
443 | break; | 453 | break; |
444 | 454 | ||
445 | case SET_INSTALLABLE: | 455 | case SET_INSTALLABLE: |
... | @@ -467,6 +477,7 @@ public class DistributedIntentStore | ... | @@ -467,6 +477,7 @@ public class DistributedIntentStore |
467 | BatchWriteResult batchWriteResult = dbService.batchWrite(builder.build()); | 477 | BatchWriteResult batchWriteResult = dbService.batchWrite(builder.build()); |
468 | if (batchWriteResult.isSuccessful()) { | 478 | if (batchWriteResult.isSuccessful()) { |
469 | // no-failure (except for invalid input) | 479 | // no-failure (except for invalid input) |
480 | + transitionedToParking.forEach((intentId) -> transientStates.remove(intentId)); | ||
470 | return failed; | 481 | return failed; |
471 | } else { | 482 | } else { |
472 | // everything failed | 483 | // everything failed | ... | ... |
... | @@ -76,6 +76,8 @@ public class HazelcastIntentStore | ... | @@ -76,6 +76,8 @@ public class HazelcastIntentStore |
76 | /** Valid parking state, which can transition to WITHDRAWN. */ | 76 | /** Valid parking state, which can transition to WITHDRAWN. */ |
77 | private static final Set<IntentState> PRE_WITHDRAWN = EnumSet.of(INSTALLED, FAILED); | 77 | private static final Set<IntentState> PRE_WITHDRAWN = EnumSet.of(INSTALLED, FAILED); |
78 | 78 | ||
79 | + private static final Set<IntentState> PARKING = EnumSet.of(SUBMITTED, INSTALLED, WITHDRAWN, FAILED); | ||
80 | + | ||
79 | private final Logger log = getLogger(getClass()); | 81 | private final Logger log = getLogger(getClass()); |
80 | 82 | ||
81 | // Assumption: IntentId will not have synonyms | 83 | // Assumption: IntentId will not have synonyms |
... | @@ -348,6 +350,8 @@ public class HazelcastIntentStore | ... | @@ -348,6 +350,8 @@ public class HazelcastIntentStore |
348 | } | 350 | } |
349 | } | 351 | } |
350 | 352 | ||
353 | + // TODO slice out methods after merging Ali's patch | ||
354 | + // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES | ||
351 | @Override | 355 | @Override |
352 | public List<Operation> batchWrite(BatchWrite batch) { | 356 | public List<Operation> batchWrite(BatchWrite batch) { |
353 | // Hazelcast version will never fail for conditional failure now. | 357 | // Hazelcast version will never fail for conditional failure now. |
... | @@ -479,6 +483,10 @@ public class HazelcastIntentStore | ... | @@ -479,6 +483,10 @@ public class HazelcastIntentStore |
479 | 483 | ||
480 | try { | 484 | try { |
481 | IntentState prevIntentState = (IntentState) subops.get(0).get(); | 485 | IntentState prevIntentState = (IntentState) subops.get(0).get(); |
486 | + | ||
487 | + if (PARKING.contains(newState)) { | ||
488 | + transientStates.remove(intentId); | ||
489 | + } | ||
482 | log.trace("{} - {} -> {}", intentId, prevIntentState, newState); | 490 | log.trace("{} - {} -> {}", intentId, prevIntentState, newState); |
483 | // TODO sanity check and log? | 491 | // TODO sanity check and log? |
484 | } catch (InterruptedException e) { | 492 | } catch (InterruptedException e) { | ... | ... |
-
Please register or login to post a comment