Versions Compared

Key

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

Table of Contents

Status

Current state: Under DiscussionAccepted

Discussion thread: here

JIRA: here

...

Code Block
titleJoined.java
linenumberstrue
public class Joined {
   /**
	* Set the grace period on the stream side of the join. Records will enter a buffer before being processed. Out of order records in the grace period will be processed in timestamp order. Late records, out of the grace period, will be executed right as they come in, if it is past the table history retention this could result in joins on the wrong version or a null join. Long gaps in stream side arriving records will cause records to be delayed in processing, even resulting in be dropped. processed out of the grace period window.
	*  
	*
	* @param gracePeriod the duration of the grace period. Must be Ifless zero,than nothe bufferjoining willtable's behistory usedretention. 
	* @return new {@code Joined} instance configured with the gracePeriod
	*/
	public Joined withGracePeriod(Duration gracePeriod);

   /**
     * Create an instance of {@code Joined} with key, value, and otherValue {@link Serde} instances.
     * {@code null} values are accepted and will be replaced by the default serdes as defined in
     * config.
     *
     * @param keySerde the key serde to use. If {@code null} the default key serde from config will be
     * used
     * @param valueSerde the value serde to use. If {@code null} the default value serde from config
     * will be used
     * @param otherValueSerde the otherValue serde to use. If {@code null} the default value serde
     * from config will be used
     * @param name the name used as the base for naming components of the join including any
     * repartition topics
	 * @param gracePeriod Duration of the stream side buffer
     * @param <K> key type
     * @param <V> value type
     * @param <VO> other value type
     * @return new {@code Joined} instance with the provided serdes
     */
    public static <K, V, VO> Joined<K, V, VO> with(final Serde<K> keySerde,
                                                   final Serde<V> valueSerde,
                                                   final Serde<VO> otherValueSerde,
                                                   final String name,
                                                   final Duration gracePeriod);

    public Duration gracePeriod() {
        return gracePeriod;
    }
}

...

If a grace period is not set the join will execute as before, using the same logic in the stream table join node. If a grace period of zero is set the join will drop all out of order records from the stream side operationsexecute as a normal join as each record comes it will try to join to the point of time in the versioned table. If the grace period is non zero, the record will enter a stream buffer and will dequeue when the record timestamp is greater lees than or equal to than stream time plus minus the grace period.  Late records, out of the grace period, will be executed right as they come in.

The buffer will be checked whenever stream time is advanced. Stream time will be advanced whenever a new record enters the node from the stream. From then the record records will be evicted and sent down to the next processor, the join node. The buffer will use an on disk implementation of TimeOrderedKeyValueBuffer.

Setting the grace period will only be allowed for already materialized tables with a table history retention that is greater than the stream buffer's grace period. All other configurations will result in an Exception.

When a failure occurs the buffer will try to recover from an OffsetCheckpoint if possible. If not it will reload the buffer from a compacted change-log topic.

Adding a buffer to the stream will increase the latency of the join by at least the grace period. It will also take the time to serialize and store the record as well as retrieve and deserialize.

Compatibility, Deprecation, and Migration Plan

...

Changing grace period might cause some capability issues. Decreasing the grace period would result in a lot of records being ejected. Increasing it might cause records to go past the retention time of the table and miss joins it should have made. When changing the grace period it makes sense to update the tables grace period and maybe reprocess data with the new grace period. To keep things simple for the zero duration buffer we will create a dummy store that will never have anything inserted.

Test Plan

The testing should be covered with unit test and integration test. The only other tests that would be necessary, would be benchmarking to assess the  performance impact on the stream buffer on the join.

Rejected Alternatives

  • Only allowing Allowing grace period to be set for non versioned tables. This would be unnecessarily restrictive especially if the table is not going to change and there is no need for the versioning. Or if the table is already materialized for another use that does not want versioningtabled. This maybe something we add later, but for now it is not clear if it is desired.
  • Auto materializing tables, choosing the table retention is a complicated process and is best controlled by the user.
  • Offset order buffer. It might make sense to do this, but it should be part of a follow up kip. The point of adding a buffer to the stream in joins is to process records based on timestamp rather the order they come out of the topic. Adding offset processing seems counterintuitive and out of scope.