Ben Chambers created BEAM-3806:

             Summary: DirectRunner hangs if multiple timers set in the same 
                 Key: BEAM-3806
             Project: Beam
          Issue Type: Bug
          Components: runner-direct
            Reporter: Ben Chambers
            Assignee: Thomas Groh

See the repro below:
package com.simbly.beam.cassandra;

import org.apache.beam.sdk.coders.KvCoder;
import org.apache.beam.sdk.coders.StringUtf8Coder;
import org.apache.beam.sdk.state.TimeDomain;
import org.apache.beam.sdk.state.Timer;
import org.apache.beam.sdk.state.TimerSpec;
import org.apache.beam.sdk.state.TimerSpecs;
import org.apache.beam.sdk.testing.PAssert;
import org.apache.beam.sdk.testing.TestPipeline;
import org.apache.beam.sdk.testing.TestStream;
import org.apache.beam.sdk.transforms.DoFn;
import org.apache.beam.sdk.transforms.ParDo;
import org.apache.beam.sdk.values.KV;
import org.apache.beam.sdk.values.PCollection;
import org.joda.time.Duration;
import org.junit.Rule;
import org.junit.Test;

public class DirectRunnerTest {

  public TestPipeline pipeline = TestPipeline.create();

  public void badTimerBehavior() {
    TestStream<KV<String, String>> stream = TestStream
        .create(KvCoder.of(StringUtf8Coder.of(), StringUtf8Coder.of()))
        .addElements(KV.of("key1", "v1"))

    PCollection<String> result = pipeline
        .apply(ParDo.of(new TestDoFn()));
    PAssert.that(result).containsInAnyOrder("It works");;

  private static class TestDoFn extends DoFn<KV<String, String>, String> {
    private final TimerSpec timer = TimerSpecs.timer(TimeDomain.EVENT_TIME);

    public void process(ProcessContext c,
        @TimerId("timer") Timer timer) {

    public void onTimer(OnTimerContext c, @TimerId("timer") Timer timer) {
      c.output("It works");
>From inspection, this seems to be caused by the logic in 
> which does the following if there are multiple timers for akey:
 # Adds the first timer to the `pendingTimers`, `keyTimers`, and 
 # Removes the first timer from `keyTimers`
 # Adds the second timer to `keyTimers` and `existingTimersForKey`.

This leads to inconsistencies since pendingTimers has only the first timer, 
keyTimers only the second, and existingTimers has both. This becomes more 
problematic since one of these lists is used for *firing* (and thus releasing 
holds) and the other is used for holds.

This message was sent by Atlassian JIRA

Reply via email to