DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
| Table of Contents |
|---|
Status
Current state: Under DiscussionAccepted
Discussion thread: Thread
JIRA:
| Jira | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).
...
| Code Block | ||||||||
|---|---|---|---|---|---|---|---|---|
| ||||||||
/** * Determines if this StateStore manages its own offsets. * <p> * If this method returns {@code true}, then offsets provided to {@link #commit(Map)} will be retrievable using * {@link #committedOffset(TopicPartition)}. * <p> * If this method returns {@code false}, offsets provided to {@link #commit(Map)} will be ignored, and {@link * #committedOffset(TopicPartition)} will be expected to always return {@code null}. * <p> * This method is provided to enable custom StateStores to opt-in to managing their own offsets. This is highlyrequired, * recommended, if possible, to to ensure that custom StateStores provide the consistency guarantees that Kafka Streams expects when operating * expects when operating* under thean {@code exactly-once} {@code processing.modeguarantee}. * <p> * @deprecated New implementations should always are required to implement this method and return {@code true} and manage their own offsets. In the future,Existing implementations * should upgrade to managing their own offsets as soon as possible, this method will be removed and itas the legacy offset management is deprecated * and will be assumedremoved toin alwaysa return {@code true}future version. * @return Whether this StateStore manages its* own@deprecated offsets. New implementations should always return */ @Deprecated default boolean managesOffsets() {{@code true} and manage their own offsets. In the future, * return false; } /** this method will be *removed Flushand anyit cachedwill data be assumed to always return *{@code true}. * @return @deprecatedWhether Usethis {@link org.apache.kafka.streams.processor.api.ProcessingContext#commit() ProcessorContext#commit()} * StateStore manages its own offsets. instead. */ @Deprecated default voidboolean flushmanagesOffsets() { // no-opreturn false; } /** * CommitFlush allany written records to this StateStore.cached data * <p> * This method <b>CANNOT<b> be called by users from @deprecated Use {@link org.apache.kafka.streams.processor.api.ProcessorProcessingContext#commit() ProcessorContext#commit()} * processors}. Doing so will throw an {@link java.lang.UnsupportedOperationException}. * <p> instead. */ @Deprecated default * Instead, users should call {@link org.apache.kafka.streams.processor.api.ProcessingContext#commit() void flush() { * ProcessorContext#commit()} to request a Task commit. // no-op } /** <p> * IfCommit {@link #managesOffsets()} returns {@code true}, the given {@code changelogOffsets} will be guaranteed to be * persisted to disk along with the written records.all written records to this StateStore. * <p> * This method <b>CANNOT<b> be called by users from {@link org.apache.kafka.streams.processor.api.Processor * <p> processors}. Doing so will throw *an {@code changelogOffsets} will usually contain a single partition, in the case of a regular StateStore. However,@link java.lang.UnsupportedOperationException}. * <p> * Instead, users should call {@link org.apache.kafka.streams.processor.api.ProcessingContext#commit() * they may contain multiple partitions in the case of a Global StateStore with multiple partitions. All provided * partitions <em>MUST</em> be persisted to disk. * <p>ProcessorContext#commit()} to request a Task commit. * <p> * If {@link #managesOffsets()} returns {@code true}, the given {@code changelogOffsets} will be guaranteed to be * Implementations <em>SHOULD</em> ensure that {@code changelogOffsets} are committed persisted to disk atomicallyalong with the *written records they represent, if possible. * <p> * @param{@code changelogOffsets} will usually Thecontain changelog offset(s) corresponding toa single partition, in the mostcase recentlyof a writtenregular recordsStateStore. However, */ they may contain defaultmultiple voidpartitions commit(final Map<TopicPartition, Long> changelogOffsets) { flush();in the case of a Global StateStore with multiple partitions. All provided } * partitions <em>MUST</** em> be persisted to disk. * Returns<p> the most recently {@link #commit(Map) committed} offset for the given {@link TopicPartition}. * <p> * Implementations <em>SHOULD</em> ensure that {@code changelogOffsets} are committed to disk atomically with the * Ifrecords {@link #managesOffsets()} and {@link #persistent()} both return {@code true}, this method will return the * offset that corresponds to the changelog recordthey represent, if possible. * * @param changelogOffsets The changelog offset(s) corresponding to the most recently written to this store, for the given {@coderecords. * partition}./ default * void commit(final Map<TopicPartition, Long> changelogOffsets) { * @param partitionflush(); The partition to get} the committed offset for./** * Returns @returnthe Themost lastrecently {@link #commit(Map) committed} offset for the given {@code@link partitionTopicPartition};. or {@code null} if no* offset<p> * If {@link #managesOffsets()} has been committed for the partition, or if either and {@link #persistent()} both orreturn {@link@code #managesOffsets()true} , this method will return *the * offset that corresponds returnto {@code false}. */ default Long committedOffset(final TopicPartition partition) { return null; } |
Metrics
the changelog record most recently written to this store, for the given {@code
* partition}.
*
* @param partition The partition to get the committed offset for.
* @return The last {@link #commit(Map) committed} offset for the {@code partition}; or {@code null} if no offset
* has been committed for the partition, or if either {@link #persistent()} or {@link #managesOffsets()}
* return {@code false}.
*/
default Long committedOffset(final TopicPartition partition) {
return null;
}
|
Metrics
NewNew
Each added metric will be on store-level and have the following tags:
...
| Name | RecordingLevel | Metric Type | Description |
|---|---|---|---|
commit-rate | DEBUG | Rate | The average number of calls to StateStore#commit(Map).commit per second |
commit-latency-avg | DEBUG | Avg | The average time taken to call StateStore#commit(Map).latency of calls to commit |
commit-latency-max | DEBUG | Max | The maximum time taken to call StateStore#commit(Map).latency of calls to commit |
Deprecated
stream-state-metricsflush-rateflush-latency-avgflush-latency-max
...
- On start-up, we will construct and initialize state stores for every corresponding Task store directory we find on-disk, and call
committedOffsetto determine their stored offset(s). We will then cache these offsets in-memory andclose()these stores. This cache will be shared among allStreamThreads, and will therefore be thread-safe. - On rebalance, we will consult this cache to compute our Task offset lags.
- After state restore completes for an assigned Task, we will update the offset cache to
Task.LATEST_OFFSET, to indicate that the Task now has the currently latest offset. - When closing a StateStore, we will update the offset cache with the current changelog offset for the store.
- This will ensure that when a
Taskis reassigned to another instance, the Task lag for the local state matches what's on-disk, instead of using the sentinel valueTask.LATEST_OFFSET, which is only valid for Tasks currently assigned to a thread on the local instance.
- This will ensure that when a
We will conduct performance testing for this strategy, and if we find that initializing and closing many on-disk stores on startup is prohibitively expensive, we will parallelize this process by forking a new thread for each Task directory.
Compatibility, Deprecation, and Migration Plan
- only valid for Tasks currently assigned to a thread on the local instance.
Compatibility, Deprecation, and Migration Plan
Kafka Streams will automatically migrate offsets found in an existing .checkpoint file, and/or an existing .position file, to store those offsets directly in the StateStore, if managesOffsets returns true. Users of the in-built store types will not need to make any changes. See Upgrading.
Because checkpointed offsets are now stored inside the state stores, the state stores must be opened during KafkaStreams#start() to read the offsets, what implies that #start() might fail with new types of errors. This change is not a backward incompatible change because #start() already declares that StreamsException might be thrown, and thus existing code which is prepared for error handling would not be impactedKafka Streams will automatically migrate offsets found in an existing .checkpoint file, and/or an existing .position file, to store those offsets directly in the StateStore, if managesOffsets returns true. Users of the in-built store types will not need to make any changes. See Upgrading.
flush deprecation
All internal usage of the StateStore#flush method has been removed/replaced. Therefore, the main concern is with end-users calling StateStore#flush directly from custom Processors. Obviously, users cannot safely call StateStore#commit, because they do not know the changelog offsets that correspond to the locally written state. Forcibly flushing/fsyncing recently written records to disk may also violate any transactional guarantees that StateStores are providing. Therefore, the default implementation of flush has been updated to a no-op. Users are now advised (via JavaDoc) that should instead request an early commit via. ProcessingContext#commit().
...
The newly introduced StateStore#managesOffsets method will be immediately deprecated, to allow for its removal in the next major release of Kafka Streamsa future release. It is being introduced as a transitional mechanism, to ensure that existing custom StateStores continue to work as expected without managing their own offsets. However, to encourage maintainers of custom stores to add support for offset management, we will emit a WARN level log message when initializing any StateStore that is persistent, but does not manage its own offsets.
...