pip/pip-384.md
Apache Pulsar uses a component called ManagedLedger to handle persistent storage of messages.
The ManagedLedger interfaces and implementation were initially tightly coupled, making it difficult to introduce alternative implementations or improve the architecture. This PIP documents changes that have been made in the master branch for Pulsar 4.0. Pull Requests #22891 and #23311 have already been merged. This work happened after lazy consensus on the dev mailing list based on the discussion thread "Preparing for Pulsar 4.0: cleaning up the Managed Ledger interfaces". There is one remaining PR #23313 at the time of writing this document. The goal of this PIP is to document the changes in this area for later reference.
Key concepts:
ManagedLedgerFactory instance. ManagedLedgerStorage.java source codeThe current ManagedLedger implementation faces several challenges:
Tight coupling: The interfaces are tightly coupled with their implementation, making it difficult to introduce alternative implementations.
Limited flexibility: The current architecture doesn't allow for easy integration of different storage systems or optimizations.
Dependency on BookKeeper: The ManagedLedger implementation is closely tied to BookKeeper, limiting options for alternative storage solutions.
Complexity: The tight coupling increases the overall complexity of the system, making it harder to maintain, test and evolve.
Limited extensibility: Introducing new features or optimizations often requires changes to both interfaces and implementations.
Decouple interfaces from implementations:
Introduce ReadOnlyManagedLedger interface:
Decouple ManagedLedgerInterceptor:
Enable multiple ManagedLedgerFactory instances:
Decouple BookKeeper client:
Update ManagedLedger interface:
Update ManagedLedgerFactory interface:
Update ManagedCursor interface:
Introduce ReadOnlyManagedLedger interface:
Decouple ManagedLedgerInterceptor:
Update ManagedLedgerStorage interface:
Implement BookkeeperManagedLedgerStorageClass:
Update PulsarService and related classes:
Update ManagedLedgerStorage interface:
Implement BookkeeperManagedLedgerStorageClass:
Update relevant code:
managedLedgerStorageClassName to PersistencePolicies which can be used by a custom ManagedLedgerStorage to control the ManagedLedgerFactory instance that is used for a particular namespace or topic.The changes are internal and don't affect external APIs or behaviors. Backward compatibility is fully preserved in Apache Pulsar.
The decoupling of interfaces and implementation doesn't introduce new security concerns.