GeezerVison is showing github.com — [fix][ml] Check metadata versions for unchanged cursor property updat… · apache/pulsar@5adb229
File tree
Expand file treeCollapse file tree
Open diff view settings
main/java/org/apache/bookkeeper/mledger test/java/org/apache/bookkeeper/mledger/impl
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedCursor.java +4-5Lines changed: 4 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -150,12 +150,11 @@ default void markIdle() { |
150 | 150 | * changed the state the function observed cannot be overwritten by this update. The returned |
151 | 151 | * map must not be {@code null} and must not contain {@code null} keys or values; a violation |
152 | 152 | * fails the returned future with the original exception and leaves the properties untouched. |
153 | | - * If the returned map equals the snapshot the function read, no write is issued. |
154 | 153 | * |
155 | | - * Note: like the other property operations, {@link ManagedLedgerException.BadVersionException} |
156 | | - * will be set in this {@link CompletableFuture} if there are concurrent modifications — a |
157 | | - * retry against a snapshot refreshed by a writer on this cursor re-applies the function, so |
158 | | - * the function must be side-effect free and must not retain the passed map. |
| 154 | + * <p>On a durable cursor, even an unchanged update can advance the metadata version |
| 155 | + * or fail with {@link ManagedLedgerException.BadVersionException}. Callers should be |
| 156 | + * prepared to retry on a version conflict; a retry re-applies the function, so the |
| 157 | + * function must be side-effect free and must not retain the passed map. |
159 | 158 | * |
160 | 159 | * The default implementation is a best-effort, non-atomic fallback that applies the per-key |
161 | 160 | * differences through the individual property operations; implementations with an atomic |
|
Collapse file
Copy file name to clipboardExpand all lines: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java -6Lines changed: 0 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -571,12 +571,6 @@ private CompletableFuture<Void> computeCursorProperties( |
571 | 571 | updateCursorPropertiesResult.completeExceptionally(e); |
572 | 572 | return updateCursorPropertiesResult; |
573 | 573 | } |
574 | | - if (newProperties.equals(currentProperties)) { |
575 | | - // Nothing changed: skip the version-bumping write, which could collide with the |
576 | | - // concurrent writer the update function just chose not to fight. |
577 | | - updateCursorPropertiesResult.complete(null); |
578 | | - return updateCursorPropertiesResult; |
579 | | - } |
580 | 574 |
|
581 | 575 | ManagedCursorInfo copy = new ManagedCursorInfo(); |
582 | 576 | copy.copyFrom(ManagedCursorImpl.this.managedCursorInfo); |
|
Collapse file
Copy file name to clipboardExpand all lines: managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorUpdatePropertiesTest.java +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -89,6 +89,22 @@ public void testConditionalRemovalOnlyAppliesWhileValueMatches() throws Exceptio |
89 | 89 | assertThat(cursor.getCursorProperties()).doesNotContainKey("k"); |
90 | 90 | } |
91 | 91 |
|
| 92 | + @Test |
| 93 | + public void testRemoveMissingPropertyRejectsStaleMetadataVersion() throws Exception { |
| 94 | + @Cleanup("shutdown") |
| 95 | + ManagedLedgerFactory externalFactory = new ManagedLedgerFactoryImpl(metadataStore, bkc); |
| 96 | + ManagedCursor externalCursor = externalFactory.open(ledger.getName()).openCursor(cursor.getName()); |
| 97 | + assertThat(externalCursor.putCursorProperty("k", "value")).succeedsWithin(5, TimeUnit.SECONDS); |
| 98 | + assertThat(cursor.getCursorProperties()).doesNotContainKey("k"); |
| 99 | + |
| 100 | + assertThat(cursor.removeCursorProperty("k")).failsWithin(5, TimeUnit.SECONDS) |
| 101 | + .withThrowableThat() |
| 102 | + .extracting(FutureUtil::unwrapCompletionException) |
| 103 | + .isInstanceOf(ManagedLedgerException.BadVersionException.class); |
| 104 | + assertThat(factory.getCursorPropertiesAsync(ledger.getName(), cursor.getName()).get(5, TimeUnit.SECONDS)) |
| 105 | + .containsEntry("k", "value"); |
| 106 | + } |
| 107 | + |
92 | 108 | private static Function<Map<String, String>, Map<String, String>> conditionalRemoval( |
93 | 109 | String key, String expectedValue) { |
94 | 110 | return properties -> { |
|