Status
Current state: Under Discussion Accepted
Discussion thread: http://mail-archives.apache.org/mod_mbox/samza-dev/201703.mbox/browser
JIRA: SAMZA-1126
Released: 0.13.0
Problem
In Samza 0.12, we introduced the StreamProcessor API to support Samza as a Library model. That introduced "processorId" that is synonymous to the logical "containerId" that Samza assigns in a fixed-set container model.
However, having an "int" processorId is insufficient to uniquely identify a processor in various runtime environment(s). This proposal is to define proper semantics to processorId and how it will be used in the samza tech stack.
...
Proposed Changes
- Introduces a ProcessorIdentifier configurable ProcessorIdGenerator interface that can be used the users of StreamProcessor API by JobCoordinator to generate a unique processorId for each processor
- Job Coordinator has the responsibility of generating a unique processorId within the runtime environment. Hence, this needs to be a pluggable component. (For more details, see SAMZA-881)
- "processorId" is a String, contrasting to "containerId" that is an integer
Note: With the introduction of ApplicationRunner in SAMZA-1067, ApplicationRunner will be the Samza user-api, instead of StreamProcessor.
...
Code Block | ||||
---|---|---|---|---|
| ||||
public interface JobCoordinator { ... default ProcessorIdGenerator getProcessorIdGeneratorFromConfig(Config config) { // Static helper to load ProcessorIdGenerator class from config } // Before // int getProcessorId(); String getProcessorId(); ... } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
/**
* To be used by the JobCoordinator to generator ProcessorId
* It can be configured by using a configuration - app.processor-id-generator.class
*/
public interface ProcessorIdGenerator {
/**
* Generates a String representation to identify the processor instance
* This value can be representative of its current executing environment. It can also be custom-managed by the user.
* **Note**: processorId has to be unique among the processors within a job
* @return String , identifier for the processor
*/
String generateProcessorId();
}
// Default (after 0.13+)
public class UUIDGenerator implements ProcessorIdGenerator {
String generateProcessorId() {
return UUID.randomUUID();
}
} |
...
processor.id - In the absence of app.processor-id-generator.class configuration, we expect a processor.id configuration to be set in the config. This config is purely for the sake of backward compatibility with existing users of StreamProcessor API. It ONLY applies for Stream application(s) which is composed of a single job.
In the absence of either of processor.id or app.processor.idGenerator.class, Samza should throw an Exception for unknown processorId.
...
Existing users of StreamProcessor API should also set the processor.id config to the value previously assigned in the constructor.
Note: In case of more than one StreamProcessor within the same JVM, it is still required to use unique processorId for each StreamProcessor instance. The custom ProcessorIdGenerator, then, can contain a static counter which is incremented for each call to generateProcessorId and the counter value can be appended to the identifier.
processor.id - to be deprecated in Samza 0.14.
Rejected Alternatives
None so far