Kafka Stream 0.10.2.0状态存储在存储值时获取异常

时间:2017-05-18 09:44:15

标签: apache-kafka-streams

我正在使用带有状态存储的低级处理器API,所以直到0.10.0.1它工作正常,但我已经升级了kafka流但是我得到了以下错误,所以在那之后我想出来这是由于对于更改日志,它正在查看记录上下文

java.lang.IllegalStateException: This should not happen as timestamp() should only be called while a record is processed
! at org.apache.kafka.streams.processor.internals.AbstractProcessorContext.timestamp(AbstractProcessorContext.java:150)
! at org.apache.kafka.streams.state.internals.StoreChangeLogger.logChange(StoreChangeLogger.java:60)
! at org.apache.kafka.streams.state.internals.ChangeLoggingKeyValueBytesStore.put(ChangeLoggingKeyValueBytesStore.java:47)
! at org.apache.kafka.streams.state.internals.ChangeLoggingKeyValueStore.put(ChangeLoggingKeyValueStore.java:66)
! at     org.apache.kafka.streams.state.internals.MeteredKeyValueStore$2.run(MeteredKeyValueStore.java:67)
@Override
    public void process(String arg0, List<Data> data {
        data.forEach((x) -> {
            String rawKey = x.getId();
            Data data = kvStore.get(rawKey);
            long bytesize = data == null ? 0 : data.getVolume();
            x.addVolume(bytesize);
            kvStore.put(rawKey, x);
        });
    }

public void start() {
        builder = new KStreamBuilder();
        storeSupplier =     Stores.create(getKVStoreName()).withKeys(getProcessorKeySerde()).withValues(getProcessorValueSerde()).persistent().build();
        builder.addStateStore(storeSupplier);
        stream = builder.stream(Serdes.String(), serde(),getTopicName());
        processStream(stream);
        streams = new KafkaStreams(builder, props);
        streams.cleanUp();
        streams.start();
    }

    @Override
    public void init(ProcessorContext context) {
        super.init(context);
        this.context = context;
        this.context.schedule(timeinterval);
        this.kvStore = (KeyValueStore) context.getStateStore(getKVStoreName());
    }

1 个答案:

答案 0 :(得分:6)

在多个流线程或分区中使用Processor相同实例时,可能会出现这种情况。

确保您将新实例返回到ProcessorSupplier

new ProcesorSupplier(() -> new Processor(...

这同样适用于TransformerTransformerSupplier