接口 ManagedLedger
- 所有已知实现类:
ManagedLedgerImpl,ReadOnlyManagedLedgerImpl
@LimitedPrivate
@Stable
public interface ManagedLedger
A ManagedLedger it's a superset of a BookKeeper ledger concept.
It mimics the concept of an appender log that:
- has a unique name (chosen by clients) by which it can be created/opened/deleted
- is always writable: if a writer process crashes, a new writer can re-open the ManagedLedger and continue writing into it
- has multiple persisted consumers (see
ManagedCursor), each of them with an associated position - when all the consumers have processed all the entries contained in a Bookkeeper ledger, the ledger is deleted
- A single ManagedLedger can only be open once at any time. Implementation can protect double access from the same VM, but accesses from different machines to the same ManagedLedger need to be avoided through an external source of coordination.
-
方法概要
修饰符和类型方法说明addEntry(byte[] data) Append a new entry to the end of a managed ledger.addEntry(byte[] data, int numberOfMessages) Append a new entry to the end of a managed ledger.addEntry(byte[] data, int offset, int length) Append a new entry to the end of a managed ledger.addEntry(byte[] data, int numberOfMessages, int offset, int length) Append a new entry to the end of a managed ledger.voidasyncAddEntry(byte[] data, int numberOfMessages, int offset, int length, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.voidasyncAddEntry(byte[] data, int offset, int length, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.voidasyncAddEntry(byte[] data, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.voidasyncAddEntry(io.netty.buffer.ByteBuf buffer, int numberOfMessages, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.voidasyncAddEntry(io.netty.buffer.ByteBuf buffer, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.voidasyncClose(AsyncCallbacks.CloseCallback callback, Object ctx) Close the ManagedLedger asynchronously.voidasyncDelete(AsyncCallbacks.DeleteLedgerCallback callback, Object ctx) Async delete a ledger.voidasyncDeleteCursor(String name, AsyncCallbacks.DeleteCursorCallback callback, Object ctx) Delete a ManagedCursor asynchronously.voidasyncDeleteProperty(String key, AsyncCallbacks.UpdatePropertiesCallback callback, Object ctx) Async delete the property by key.asyncFindPosition(com.google.common.base.Predicate<Entry> predicate) Find position by sequenceId.voidasyncOffloadPrefix(Position pos, AsyncCallbacks.OffloadCallback callback, Object ctx) Offload as many entries before position as possible to longterm storage.voidasyncOpenCursor(String name, AsyncCallbacks.OpenCursorCallback callback, Object ctx) Open a ManagedCursor asynchronously.voidasyncOpenCursor(String name, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, Map<String, Long> properties, Map<String, String> cursorProperties, AsyncCallbacks.OpenCursorCallback callback, Object ctx) Open a ManagedCursor asynchronously.voidasyncOpenCursor(String name, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, AsyncCallbacks.OpenCursorCallback callback, Object ctx) Open a ManagedCursor asynchronously.voidasyncSetProperties(Map<String, String> properties, AsyncCallbacks.UpdatePropertiesCallback callback, Object ctx) Async update managed-ledger's properties.voidasyncSetProperty(String key, String value, AsyncCallbacks.UpdatePropertiesCallback callback, Object ctx) Async add key-value to propertiesMap.voidasyncTerminate(AsyncCallbacks.TerminateCallback callback, Object ctx) Truncate ledgers The truncate operation will move all cursors to the end of the topic and delete all inactive ledgers.voidCheck current inactive ledger (based onManagedLedgerConfig.getInactiveLedgerRollOverTimeMs()and roll over that ledger if inactive.voidclose()Close the ManagedLedger.voiddelete()Delete the ManagedLedger.voiddeleteCursor(String name) Remove a ManagedCursor from this ManagedLedger.voiddeleteProperty(String key) Delete the property by key.Get a list of all the active cursors reading from this ManagedLedger.Returns managed-ledger config.Get a list of all the cursors reading from this ManagedLedger.Get the publishing time of the oldest message in the backlog.longGet estimated total unconsumed or backlog size in bytes for the managed ledger, without accounting for replicas.Gets last confirmed entry of the managed ledger.longGet last failed offloaded timestamp.longGet last offloaded ledgerId.longGet last suceessful offloaded timestamp.getLedgerInfo(long ledgerId) Get basic ledger summary.Get the ManagedLedgerInterceptor for ManagedLedger.CompletableFuture<org.apache.pulsar.common.policies.data.ManagedLedgerInternalStats>getManagedLedgerInternalStats(boolean includeLedgerMetadata) Get managed ledger internal stats.getName()longGet the total number of active entries for this managed ledger.longGet the total number of entries for this managed ledger.longReturn the size of all ledgers offloaded to 2nd tier storage.getOptionalLedgerInfo(long ledgerId) Get basic ledger summary.Returns managed-ledger's properties.Get the slowest consumer.getStats()longGet the total sizes in bytes of the managed ledger, without accounting for replicas.booleanReturns whether the managed ledger was terminated.newNonDurableCursor(Position startCursorPosition) Creates a new cursor whose metadata is not backed by durable storage.newNonDurableCursor(Position startPosition, String subscriptionName) newNonDurableCursor(Position startPosition, String subscriptionName, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, boolean isReadCompacted) offloadPrefix(Position pos) Offload as many entries before position as possible to longterm storage.openCursor(String name) Open a ManagedCursor in this ManagedLedger.openCursor(String name, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition) Open a ManagedCursor in this ManagedLedger.openCursor(String name, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, Map<String, Long> properties, Map<String, String> cursorProperties) Open a ManagedCursor in this ManagedLedger.voidSignaling managed ledger that we can resume after BK write failure.voidremoveWaitingCursor(ManagedCursor cursor) Remove a ManagedCursor from this ManagedLedger's waitingCursors.void已过时。voidsetConfig(ManagedLedgerConfig config) Updates managed-ledger config.voidsetProperties(Map<String, String> properties) Update managed-ledger's properties.voidsetProperty(String key, String value) Add key-value to propertiesMap.Terminate the managed ledger and return the last committed entry.voidtrimConsumedLedgersInBackground(CompletableFuture<?> promise) Trim consumed ledgers in background.
-
方法详细资料
-
getName
String getName()- 返回:
- the unique name of this ManagedLedger
-
addEntry
Append a new entry to the end of a managed ledger.- 参数:
data- data entry to be persisted- 返回:
- the Position at which the entry has been inserted
- 抛出:
ManagedLedgerExceptionInterruptedException
-
addEntry
Position addEntry(byte[] data, int numberOfMessages) throws InterruptedException, ManagedLedgerException Append a new entry to the end of a managed ledger.- 参数:
data- data entry to be persistednumberOfMessages- numberOfMessages of entry- 返回:
- the Position at which the entry has been inserted
- 抛出:
ManagedLedgerExceptionInterruptedException
-
asyncAddEntry
Append a new entry asynchronously.- 参数:
data- data entry to be persistedcallback- callback objectctx- opaque context- 另请参阅:
-
addEntry
Position addEntry(byte[] data, int offset, int length) throws InterruptedException, ManagedLedgerException Append a new entry to the end of a managed ledger.- 参数:
data- data entry to be persistedoffset- offset in the data arraylength- number of bytes- 返回:
- the Position at which the entry has been inserted
- 抛出:
ManagedLedgerExceptionInterruptedException
-
addEntry
Position addEntry(byte[] data, int numberOfMessages, int offset, int length) throws InterruptedException, ManagedLedgerException Append a new entry to the end of a managed ledger.- 参数:
data- data entry to be persistednumberOfMessages- numberOfMessages of entryoffset- offset in the data arraylength- number of bytes- 返回:
- the Position at which the entry has been inserted
- 抛出:
ManagedLedgerExceptionInterruptedException
-
asyncAddEntry
void asyncAddEntry(byte[] data, int offset, int length, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.- 参数:
data- data entry to be persistedoffset- offset in the data arraylength- number of bytescallback- callback objectctx- opaque context- 另请参阅:
-
asyncAddEntry
void asyncAddEntry(byte[] data, int numberOfMessages, int offset, int length, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.- 参数:
data- data entry to be persistednumberOfMessages- numberOfMessages of entryoffset- offset in the data arraylength- number of bytescallback- callback objectctx- opaque context- 另请参阅:
-
asyncAddEntry
void asyncAddEntry(io.netty.buffer.ByteBuf buffer, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.- 参数:
buffer- buffer with the data entrycallback- callback objectctx- opaque context- 另请参阅:
-
asyncAddEntry
void asyncAddEntry(io.netty.buffer.ByteBuf buffer, int numberOfMessages, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.- 参数:
buffer- buffer with the data entrynumberOfMessages- numberOfMessages for data entrycallback- callback objectctx- opaque context- 另请参阅:
-
openCursor
Open a ManagedCursor in this ManagedLedger. If the cursors doesn't exist, a new one will be created and its position will be at the end of the ManagedLedger.- 参数:
name- the name associated with the ManagedCursor- 返回:
- the ManagedCursor
- 抛出:
ManagedLedgerExceptionInterruptedException
-
openCursor
ManagedCursor openCursor(String name, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition) throws InterruptedException, ManagedLedgerException Open a ManagedCursor in this ManagedLedger.If the cursors doesn't exist, a new one will be created and its position will be at the end of the ManagedLedger.
- 参数:
name- the name associated with the ManagedCursorinitialPosition- if null, the cursor will be set at latest position when first created- 返回:
- the ManagedCursor
- 抛出:
ManagedLedgerExceptionInterruptedException
-
openCursor
ManagedCursor openCursor(String name, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, Map<String, Long> properties, Map<String, throws InterruptedException, ManagedLedgerExceptionString> cursorProperties) Open a ManagedCursor in this ManagedLedger.If the cursors doesn't exist, a new one will be created and its position will be at the end of the ManagedLedger.
- 参数:
name- the name associated with the ManagedCursorinitialPosition- if null, the cursor will be set at latest position when first createdproperties- user defined properties that will be attached to the first position of the cursor, if the open operation will trigger the creation of the cursor.cursorProperties- the properties for the Cursor- 返回:
- the ManagedCursor
- 抛出:
ManagedLedgerExceptionInterruptedException
-
newNonDurableCursor
Creates a new cursor whose metadata is not backed by durable storage. A caller can treat the non-durable cursor exactly like a normal cursor, with the only difference in that after restart it will not remember which entries were deleted. Also it does not prevent data from being deleted. The cursor is anonymous and can be positioned on an arbitrary position. This method is not-blocking.- 参数:
startCursorPosition- the position where the cursor should be initialized, or null to start from the current latest entry. When starting on a particular cursor position, the first entry to be returned will be the entry next to the specified position- 返回:
- the new NonDurableCursor
- 抛出:
ManagedLedgerException
-
newNonDurableCursor
ManagedCursor newNonDurableCursor(Position startPosition, String subscriptionName) throws ManagedLedgerException -
newNonDurableCursor
ManagedCursor newNonDurableCursor(Position startPosition, String subscriptionName, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, boolean isReadCompacted) throws ManagedLedgerException -
asyncDeleteCursor
Delete a ManagedCursor asynchronously.- 参数:
name- the name associated with the ManagedCursorcallback- callback objectctx- opaque context- 另请参阅:
-
deleteCursor
Remove a ManagedCursor from this ManagedLedger. If the cursor doesn't exist, the operation will still succeed.- 参数:
name- the name associated with the ManagedCursor- 抛出:
ManagedLedgerExceptionInterruptedException
-
removeWaitingCursor
Remove a ManagedCursor from this ManagedLedger's waitingCursors.- 参数:
cursor- the ManagedCursor
-
asyncOpenCursor
Open a ManagedCursor asynchronously.- 参数:
name- the name associated with the ManagedCursorcallback- callback objectctx- opaque context- 另请参阅:
-
asyncOpenCursor
void asyncOpenCursor(String name, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, AsyncCallbacks.OpenCursorCallback callback, Object ctx) Open a ManagedCursor asynchronously.- 参数:
name- the name associated with the ManagedCursorinitialPosition- if null, the cursor will be set at latest position when first createdcallback- callback objectctx- opaque context- 另请参阅:
-
asyncOpenCursor
void asyncOpenCursor(String name, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, Map<String, Long> properties, Map<String, String> cursorProperties, AsyncCallbacks.OpenCursorCallback callback, Object ctx) Open a ManagedCursor asynchronously.- 参数:
name- the name associated with the ManagedCursorinitialPosition- if null, the cursor will be set at latest position when first createdcursorProperties- the properties for the Cursorcallback- callback objectctx- opaque context- 另请参阅:
-
getCursors
Iterable<ManagedCursor> getCursors()Get a list of all the cursors reading from this ManagedLedger.- 返回:
- a list of cursors
-
getActiveCursors
Iterable<ManagedCursor> getActiveCursors()Get a list of all the active cursors reading from this ManagedLedger.- 返回:
- a list of cursors
-
getNumberOfEntries
long getNumberOfEntries()Get the total number of entries for this managed ledger. This is defined by the number of entries in all the BookKeeper ledgers that are being maintained by this ManagedLedger. This method is non-blocking.- 返回:
- the number of entries
-
getNumberOfActiveEntries
long getNumberOfActiveEntries()Get the total number of active entries for this managed ledger. This is defined by the number of non consumed entries in all the BookKeeper ledgers that are being maintained by this ManagedLedger. This method is non-blocking.- 返回:
- the number of entries
-
getTotalSize
long getTotalSize()Get the total sizes in bytes of the managed ledger, without accounting for replicas. This is defined by the sizes of all the BookKeeper ledgers that are being maintained by this ManagedLedger. This method is non-blocking.- 返回:
- total size in bytes
-
getEstimatedBacklogSize
long getEstimatedBacklogSize()Get estimated total unconsumed or backlog size in bytes for the managed ledger, without accounting for replicas.- 返回:
- estimated total backlog size
-
getEarliestMessagePublishTimeInBacklog
CompletableFuture<Long> getEarliestMessagePublishTimeInBacklog()Get the publishing time of the oldest message in the backlog.- 返回:
- the publishing time of the oldest message
-
getOffloadedSize
long getOffloadedSize()Return the size of all ledgers offloaded to 2nd tier storage. -
getLastOffloadedLedgerId
long getLastOffloadedLedgerId()Get last offloaded ledgerId. If no offloaded yet, it returns 0.- 返回:
- last offloaded ledgerId
-
getLastOffloadedSuccessTimestamp
long getLastOffloadedSuccessTimestamp()Get last suceessful offloaded timestamp. If no successful offload, it returns 0.- 返回:
- last successful offloaded timestamp
-
getLastOffloadedFailureTimestamp
long getLastOffloadedFailureTimestamp()Get last failed offloaded timestamp. If no failed offload, it returns 0.- 返回:
- last failed offloaded timestamp
-
asyncTerminate
-
terminate
Terminate the managed ledger and return the last committed entry. Once the managed ledger is terminated, it will not accept any more write -
close
Close the ManagedLedger. This will close all the underlying BookKeeper ledgers. All the ManagedCursors associated will be invalidated. -
asyncClose
Close the ManagedLedger asynchronously.- 参数:
callback- callback objectctx- opaque context- 另请参阅:
-
getStats
ManagedLedgerMXBean getStats()- 返回:
- the managed ledger stats MBean
-
delete
Delete the ManagedLedger. -
asyncDelete
Async delete a ledger.- 参数:
callback-ctx-- 抛出:
InterruptedExceptionManagedLedgerException
-
offloadPrefix
Offload as many entries before position as possible to longterm storage.- 参数:
pos- the position before which entries will be offloaded- 返回:
- the earliest position which was not offloaded
- 抛出:
InterruptedExceptionManagedLedgerException- 另请参阅:
-
asyncOffloadPrefix
Offload as many entries before position as possible to longterm storage. As internally, entries is stored in ledgers, and ledgers can only be operated on as a whole, it is likely not possible to offload every entry before the passed in position. Only complete ledgers will be offloaded. On completion a position will be passed to the callback. This position is the earliest entry which was not offloaded.- 参数:
pos- the position before which entries will be offloadedcallback- a callback which will be supplied with the earliest unoffloaded position on completionctx- a context object which will be passed to the callback on completion
-
getSlowestConsumer
ManagedCursor getSlowestConsumer()Get the slowest consumer.- 返回:
- the slowest consumer
-
isTerminated
boolean isTerminated()Returns whether the managed ledger was terminated. -
getConfig
ManagedLedgerConfig getConfig()Returns managed-ledger config. -
setConfig
Updates managed-ledger config.- 参数:
config-
-
getLastConfirmedEntry
Position getLastConfirmedEntry()Gets last confirmed entry of the managed ledger.- 返回:
- the last confirmed entry id
-
readyToCreateNewLedger
void readyToCreateNewLedger()Signaling managed ledger that we can resume after BK write failure. -
getProperties
Returns managed-ledger's properties.- 返回:
- key-values of properties
-
setProperty
Add key-value to propertiesMap.- 参数:
key- key of property to addvalue- value of property to add- 抛出:
InterruptedExceptionManagedLedgerException
-
asyncSetProperty
void asyncSetProperty(String key, String value, AsyncCallbacks.UpdatePropertiesCallback callback, Object ctx) Async add key-value to propertiesMap.- 参数:
key- key of property to addvalue- value of property to addcallback- a callback which will be supplied with the newest properties in managedLedger.ctx- a context object which will be passed to the callback on completion.
-
deleteProperty
Delete the property by key.- 参数:
key- key of property to delete- 抛出:
InterruptedExceptionManagedLedgerException
-
asyncDeleteProperty
Async delete the property by key.- 参数:
key- key of property to deletecallback- a callback which will be supplied with the newest properties in managedLedger.ctx- a context object which will be passed to the callback on completion.
-
setProperties
void setProperties(Map<String, String> properties) throws InterruptedException, ManagedLedgerExceptionUpdate managed-ledger's properties.- 参数:
properties- key-values of properties- 抛出:
InterruptedExceptionManagedLedgerException
-
asyncSetProperties
void asyncSetProperties(Map<String, String> properties, AsyncCallbacks.UpdatePropertiesCallback callback, Object ctx) Async update managed-ledger's properties.- 参数:
properties- key-values of properties.callback- a callback which will be supplied with the newest properties in managedLedger.ctx- a context object which will be passed to the callback on completion.
-
trimConsumedLedgersInBackground
Trim consumed ledgers in background.- 参数:
promise-
-
rollCurrentLedgerIfFull
已过时。Roll current ledger if it is full. -
asyncFindPosition
Find position by sequenceId. -
getManagedLedgerInterceptor
ManagedLedgerInterceptor getManagedLedgerInterceptor()Get the ManagedLedgerInterceptor for ManagedLedger. -
getLedgerInfo
Get basic ledger summary. will got null if corresponding ledger not exists. -
getOptionalLedgerInfo
Get basic ledger summary. will getOptional.empty()if corresponding ledger not exists. -
asyncTruncate
CompletableFuture<Void> asyncTruncate()Truncate ledgers The truncate operation will move all cursors to the end of the topic and delete all inactive ledgers. -
getManagedLedgerInternalStats
CompletableFuture<org.apache.pulsar.common.policies.data.ManagedLedgerInternalStats> getManagedLedgerInternalStats(boolean includeLedgerMetadata) Get managed ledger internal stats.- 参数:
includeLedgerMetadata- the flag to control managed ledger internal stats include ledger metadata- 返回:
- the future of managed ledger internal stats
-
checkInactiveLedgerAndRollOver
void checkInactiveLedgerAndRollOver()Check current inactive ledger (based onManagedLedgerConfig.getInactiveLedgerRollOverTimeMs()and roll over that ledger if inactive.
-