GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • managed-ledger/src
    • main/java/org/apache/bookkeeper/mledger
      • ManagedCursor.java
      • impl
        • ManagedCursorImpl.java
    • test/java/org/apache/bookkeeper/mledger/impl
      • ManagedCursorUpdatePropertiesTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedCursor.java‎

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 numberDiff line numberDiff line change
@@ -150,12 +150,11 @@ default void markIdle() {
150150
* changed the state the function observed cannot be overwritten by this update. The returned
151151
* map must not be {@code null} and must not contain {@code null} keys or values; a violation
152152
* 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.
154153
*
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.
159158
*
160159
* The default implementation is a best-effort, non-atomic fallback that applies the per-key
161160
* differences through the individual property operations; implementations with an atomic
Collapse file

‎managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java‎

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 numberDiff line numberDiff line change
@@ -571,12 +571,6 @@ private CompletableFuture<Void> computeCursorProperties(
571571
updateCursorPropertiesResult.completeExceptionally(e);
572572
return updateCursorPropertiesResult;
573573
}
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-
}
580574

581575
ManagedCursorInfo copy = new ManagedCursorInfo();
582576
copy.copyFrom(ManagedCursorImpl.this.managedCursorInfo);
Collapse file

‎managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorUpdatePropertiesTest.java‎

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 numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ public void testConditionalRemovalOnlyAppliesWhileValueMatches() throws Exceptio
8989
assertThat(cursor.getCursorProperties()).doesNotContainKey("k");
9090
}
9191

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+
92108
private static Function<Map<String, String>, Map<String, String>> conditionalRemoval(
93109
String key, String expectedValue) {
94110
return properties -> {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.