Repository navigation
[fix][ml] Confirm retried cursor metadata writes in ZooKeeper - #27652
poorbarcode wants to merge 4 commits into
Conversation
Assisted-by: OpenAI Codex
Assisted-by: OpenAI Codex
| file.writeText(source.replace(declaration, "import org.apache.pulsar.metadata.api.HasPublicationId;\n\n" + | ||
| "${declaration}HasPublicationId, ")) | ||
| } | ||
| } |
There was a problem hiding this comment.
This task doesn't follow Gradle best practices. It doesn't declare inputs and outputs etc. and would break up-to-date checks.
Is it really justified to add this type of solution?
HasPublicationId.getPublication() isn't called in production code in this PR. Is something missing?
There was a problem hiding this comment.
Regarding the interface question, I've added setPublication(String) and documented the contract on getPublication():
Confirming a write after a bad-version response through this getter would require deserializing the stored record. Since the publication ID is included in the serialized bytes, the metadata store can compare those bytes directly, together with the expected next version, to avoid that CPU overhead. Verification therefore does not need to call this getter.
This getter and
setPublication(String)define a readable and writable publication property for implementing records. Implementations must serialize this property as part of the record. Each logical write must use a unique publication ID and preserve it across retries of that write.
There was a problem hiding this comment.
the comment isn't addressed regarding the gradle task. If the ManagedCursorInfo were to be modified, the postprocessing should be done in an additional doLast step directly in the lightproto task. However, based on the current state of this PR, I think that the HasPublicationId interface should be completely removed. I've made the point in the comment on the interface file.
There was a problem hiding this comment.
Removed the custom doLast action and the GenerateLightProtoTask import. managed-ledger/build.gradle.kts is restored to its pre-PR contents, and ManagedCursorInfo uses the standard LightProto output. All 47 focused tests and the repository-wide sanityCheck passed.
| /** A metadata record that persists a unique ID for each logical write and reuses it on retries. */ | ||
| public interface HasPublicationId { | ||
| /** Returns the identifier stored in the record, or null or empty for a record written without one. */ | ||
| String getPublication(); | ||
| } |
There was a problem hiding this comment.
It looks like this interface is completely unnecessary since there isn't any production code that uses it
There was a problem hiding this comment.
I've added setPublication(String) and documented the contract on getPublication():
Confirming a write after a bad-version response through this getter would require deserializing the stored record. Since the publication ID is included in the serialized bytes, the metadata store can compare those bytes directly, together with the expected next version, to avoid that CPU overhead. Verification therefore does not need to call this getter.
This getter and
setPublication(String)define a readable and writable publication property for implementing records. Implementations must serialize this property as part of the record. Each logical write must use a unique publication ID and preserve it across retries of that write.
There was a problem hiding this comment.
This review comment isn't resolved. There's no production code that uses this interface and therefore it's completely unnecessary. Instead of adding this interface, you can document the behavior of VerifyPublication option and the related semantics.
There was a problem hiding this comment.
Removed HasPublicationId. The VerifyPublication Javadoc now documents the unique ID requirement, preserving the ID, serialized bytes and expected version across retries, and why comparing bytes avoids deserialization. Other record types can use the same verification path through the existing put option.
Assisted-by: OpenAI Codex
lhotari
left a comment
There was a problem hiding this comment.
Please address the comment about removing the HasPublicationId.
Assisted-by: OpenAI Codex
Background
Following a ZooKeeper connectivity interruption, a broker repeatedly failed to open a durable subscription with
BadVersion. The cursor znode already existed. Unloading the topic let the broker reload the persisted cursor, and the subscription recovered.Motivation
ZooKeeper can commit a cursor write before the client loses the response. Replaying a create then returns
NODEEXISTS, which Pulsar maps toBadVersion. Replaying an update with the original expected version also returnsBadVersion. The broker needs to recognize its own committed write while continuing to report conflicts when another writer wins.Modifications
ManagedCursorInfo. Assign a UUID on the first attempt and preserve it across retries of the same write. A new cursor property update clears the ID inherited from the previous record.putAPI withOption.VerifyPublication. Its documentation requires a unique publication ID in the serialized value and preservation of the ID, serialized bytes, and expected version across retries of the same write. Other metadata record types can use the same verification path.getDataso verification also works for valid records larger than the server’smultiReadresponse limit. Return the observedStat, including its session ownership information.Local verification passed the repository-wide
sanityCheckand all 47 tests inZKMetadataStoreTest,MetaStoreImplTest,ManagedCursorInfoMetadataTest, andManagedCursorPropertiesTest.Does this pull request potentially affect one of the following parts:
The metadata-store API gains the optional
VerifyPublicationwrite option. The persisted managed cursor protobuf gains an optional string field. Brokers can still read older cursor records that omit it.