Enum TransactionOwnership

  • All Implemented Interfaces:
    Serializable, Comparable<TransactionOwnership>

    @Internal
    public enum TransactionOwnership
    extends Enum<TransactionOwnership>
    Describes the ownership model of transactional ids and with that ownership of the transactions.

    A subtask that owns a transactional id is responsible for committing and aborting the transactions having that id. Only that subtask may create new ids.

    Transactional ids have the form transactionalIdPrefix + "-" + subtaskId + "-" + counter . The prefix is given by the user, the subtask id is defined through the ownership model and the counter through the TransactionNamingStrategy.

    For all strategies ownership is extrapolated for subtask ids beyond the currently known subtasks. This is necessary to support cases of intermediate upscaling where no checkpoint has been taken. Consider an application that runs with 3 subtasks and checkpointed. Later, its upscaled to 5 but then a failure happens. We need to have at least 5 open transactions. If the application is finally resumed from the checkpoint with 3 subtasks again. These 3 subtasks need to assume ownership of the remaining 2.

    • Enum Constant Detail

      • IMPLICIT_BY_SUBTASK_ID

        public static final TransactionOwnership IMPLICIT_BY_SUBTASK_ID
        The ownership is determined by the current subtask ID. Ownership is extrapolated by extracting the original subtask id of the ongoing transactions and applying modulo on the current parallelism.
      • EXPLICIT_BY_WRITER_STATE

        public static final TransactionOwnership EXPLICIT_BY_WRITER_STATE
        The ownership is determined by the writer state that is recovered. Each writer may have multiple states each with a different subtask id (e.g. when downscaling).

        Additionally, the maximum parallelism that has been observed is stored in the state and used to extrapolate ownership.

        This ownership model has two assumption of the state assignment:

        • State is assigned first to lower subtask ids and then to higher ones. In the upscaling case, from oldP to newP, only tasks [0; oldP) are assigned. [oldP; newP) are not assigned any state.
        • State is uniformly assigned. In the upscaling case, none of the tasks have more than 1 state assigned.

        Hence, the state is consecutively assigned to the subtasks from low to high.

        With these assumption, this ownership model is able to recover from writer states with subtask id + max parallelism:

        • If there is state, we can extract the owned subtask ids and the max parallelism from the state.
        • If there is no state, we can use the current subtask id and the max parallelism from the current parallelism. The current subtask id cannot possibly be owned already. The max parallelism in any state must be lower than the current max parallelism.
        • Hence, no subtask id is owned by more than one task and all tasks have the same max parallelism.
        • Since all tasks have shared knowledge, we can exclusively assign all transactional ids.
        • Since each subtask owns at least one transactional id, we can safely create new transactional ids while other subtasks are still aborting their transactions.
    • Method Detail

      • values

        public static TransactionOwnership[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (TransactionOwnership c : TransactionOwnership.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static TransactionOwnership valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • getOwnedSubtaskIds

        public abstract int[] getOwnedSubtaskIds​(int currentSubtaskId,
                                                 int currentParallelism,
                                                 Collection<KafkaWriterState> recoveredStates)
        Returns the owned subtask ids for this subtask.
      • getTotalNumberOfOwnedSubtasks

        public abstract int getTotalNumberOfOwnedSubtasks​(int currentSubtaskId,
                                                          int currentParallelism,
                                                          Collection<KafkaWriterState> recoveredStates)
        Returns the total number of owned subtasks across all subtasks.