Status
Current state: Under Discussion
Discussion thread: here
JIRA:
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 using TaskId here, 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.
Public Interfaces
New interface added to the public API:
package org.apache.kafka.streams.processor; /** * A basic wrapper class for task metadata */ public interface TaskId { /** * @return The ID of the topic group, ie the subtopology that this task executes */ int topicGroupId(); /** * @return The ID number of the partition. */ int partition(); }
"New" class that implements the public interface but is itself internal:
package org.apache.streams.processor.internals; class TaskId implements o.a.k.streams.processor.TaskId { // This is just the existing TaskId class & implementation, but // moved to the internals package }
class TaskMetadata { private final TaskId taskId; @Deprecated public String taskId() { return taskId.toString(); } // New API public o.a.k.streams.processor.TaskId id() { return taskId; } }
Proposed Changes
To migrate from the String to TaskId, we'll need to deprecate the existing getter method and add a new one. It's a bit unfortunate that we now can't use the name `taskId()` for this method, but oh well. We can just call it `id()` instead.
Since the actual existing TaskId class is not really a public API, and currently has a handful of public utility methods, we don't want to explicitly pull this into into the public API. Instead, we'll introduce a new TaskId interface in the public API that's implemented by the current TaskId class, and move the TaskId class to an internal package to clarify that it's not a public.
Compatibility, Deprecation, and Migration Plan
The TaskMetadata#taskId() method will be deprecated and removed in a future release.
Rejected Alternatives
N/A