Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Status

Current stateUnder Discussion

...

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation

The TaskMetadata class in KafkaStreams is used for encoding information about a particular task, such as its offsets, topic partitions, and taskId. For some reason, the taskId is stored and exposed as a String object, rather than using the actual TaskId class. We should move towards returning this as a TaskId object, since that's literally what it is, and because if/when we add additional fields to the TaskId it will become more and more unwieldy to parse the string encoding in order to extract the actual information about the task.

At the same time, the existing TaskId class is a bit awkward, as it's clearly intended to be a simple metadata class to expose the topicGroupId (subtopology) and partition number fields. Yet it has plenty of totally irrelevant (to a user) utility methods, such as de/serialization. It also has completely public fields, and no actual getters for them. We should take this opportunity to migrate to a new public interface with only the getters for the relevant fields, and move all the implementation details and utilities to an internal implementation class.

Public Interfaces

New TaskInfo interface added to the public API:

...

Code Block
languagejava
titleTaskMetadata
package org.apache.kafka.streams.processor;

class TaskMetadata {

    private final TaskId taskId;

    /**
     * @return the basic task metadata such as subtopology and partition id
     */
    public TaskInfo taskInfo() {
        return taskId;
    }

    /**
     * @return the basic task metadata such as subtopology and partition id
     * @deprecated please use {@link #taskInfo()} instead.
     */
    @Deprecated
    public String taskId() {
        return taskId.toString();
    }
}

Proposed Changes

To separate the implementation from the the public API, we'll deprecate the existing o.a.k.streams.processor.TaskId class and replace it with a public interface TaskInfo. The existing TaskId class implementation will be moved to a new o.a.k.streams.processor.internals.TaskId class, which will implement the TaskInfo interface.

To migrate from the String to TaskInfo in TaskMetadata, we'll need to deprecate the existing taskId() getter method and add a taskInfo() getter in its place. Similarly, we will need to deprecate the existing taskId() getters on the ProcessorContext and StateStoreContext interfaces, and replace them with taskInfo() getters that return the new public interface instead of the now-deprecated class.

Compatibility, Deprecation, and Migration Plan

The TaskMetadata#taskId(), ProcessorContext#taskId(), and StateStoreContext#taskId() methods will be deprecated and removed in a future release. The entire o.a.k.streams.processor.TaskId class will also be deprecated and later removed.

Rejected Alternatives

N/A