private boolean canRetryFlushException(Throwable ex) { if (ex instanceof BadAttributeUpdateException) { val bau = (BadAttributeUpdateException) ex; return bau.getAttributeId() != null && bau.getAttributeId().equals(Attributes.TABLE_INDEX_OFFSET); } return false; }
/** * Creates a new instance of the BadAttributeUpdateException class. * * @param streamSegmentName The name of the StreamSegment. * @param attributeUpdate The AttributeUpdate that failed the check. * @param previousValueMissing If true, indicates that the previous value for this attempted Attribute Update was missing * and was likely the cause for the failed update. * @param errorMessage The Event Number that was given as part of the Operation. */ public BadAttributeUpdateException(String streamSegmentName, AttributeUpdate attributeUpdate, boolean previousValueMissing, String errorMessage) { super(streamSegmentName, getMessage(attributeUpdate, previousValueMissing, errorMessage)); this.previousValueMissing = previousValueMissing; this.attributeId = attributeUpdate == null ? null : attributeUpdate.getAttributeId(); }
if (ex instanceof BadAttributeUpdateException && ((BadAttributeUpdateException) ex).isPreviousValueMissing()) {
throw new BadAttributeUpdateException(this.name, u, false, String.format("Expected greater than '%s'.", previousValue)); throw new BadAttributeUpdateException(this.name, u, !hasValue, String.format("Expected existing value to be '%s', actual '%s'.", u.getComparisonValue(), previousValue)); throw new BadAttributeUpdateException(this.name, u, false, String.format("Attribute value already set (%s).", previousValue)); break; default: throw new BadAttributeUpdateException(this.name, u, !hasValue, "Unexpected update type: " + updateType);
val txn = createUpdateTransaction(metadata); BiFunction<Throwable, Boolean, Boolean> exceptionChecker = (ex, expectNoPreviousValue) -> (ex instanceof BadAttributeUpdateException) && ((BadAttributeUpdateException) ex).isPreviousValueMissing() == expectNoPreviousValue;
case ReplaceIfGreater: if (hasValue && newValue <= previousValue) { throw new BadAttributeUpdateException("Segment", update, false, "GreaterThan"); case ReplaceIfEquals: if (update.getComparisonValue() != previousValue || !hasValue) { throw new BadAttributeUpdateException("Segment", update, !hasValue, String.format("ReplaceIfEquals (E=%s, A=%s)", previousValue, update.getComparisonValue())); case None: if (hasValue) { throw new BadAttributeUpdateException("Segment", update, false, "NoUpdate"); break; default: throw new BadAttributeUpdateException("Segment", update, !hasValue, "Unsupported");
() -> localContainer.append(segmentName, getAppendData(segmentName, 0), Collections.singleton(new AttributeUpdate(ea1, AttributeUpdateType.ReplaceIfEquals, set, compare - 1)), TIMEOUT), ex -> (ex instanceof BadAttributeUpdateException) && !((BadAttributeUpdateException) ex).isPreviousValueMissing()); AssertExtensions.assertSuppliedFutureThrows( "Conditional update-attributes succeeded with incorrect compare value.", () -> localContainer.updateAttributes(segmentName, Collections.singleton(new AttributeUpdate(ea2, AttributeUpdateType.ReplaceIfEquals, set, compare - 1)), TIMEOUT), ex -> (ex instanceof BadAttributeUpdateException) && !((BadAttributeUpdateException) ex).isPreviousValueMissing());