Search in sources :

Example 1 with StateStore

use of org.apache.kafka.streams.processor.StateStore in project kafka by apache.

the class AbstractTask method initializeStateStores.

protected void initializeStateStores() {
    // set initial offset limits
    initializeOffsetLimits();
    for (StateStore store : this.topology.stateStores()) {
        log.trace("task [{}] Initializing store {}", id(), store.name());
        store.init(this.processorContext, store);
    }
}
Also used : StateStore(org.apache.kafka.streams.processor.StateStore)

Example 2 with StateStore

use of org.apache.kafka.streams.processor.StateStore in project kafka by apache.

the class GlobalStateManagerImpl method flush.

public void flush(final InternalProcessorContext context) {
    log.debug("Flushing all global stores registered in the state manager");
    for (StateStore store : this.stores.values()) {
        try {
            log.trace("Flushing global store={}", store.name());
            store.flush();
        } catch (Exception e) {
            throw new ProcessorStateException(String.format("Failed to flush global state store %s", store.name()), e);
        }
    }
}
Also used : StateStore(org.apache.kafka.streams.processor.StateStore) ProcessorStateException(org.apache.kafka.streams.errors.ProcessorStateException) ProcessorStateException(org.apache.kafka.streams.errors.ProcessorStateException) IOException(java.io.IOException) StreamsException(org.apache.kafka.streams.errors.StreamsException) LockException(org.apache.kafka.streams.errors.LockException)

Example 3 with StateStore

use of org.apache.kafka.streams.processor.StateStore in project kafka by apache.

the class KStreamBuilderTest method shouldAddGlobalTablesToEachGroup.

@Test
public void shouldAddGlobalTablesToEachGroup() throws Exception {
    final String one = "globalTable";
    final String two = "globalTable2";
    final GlobalKTable<String, String> globalTable = builder.globalTable("table", one);
    final GlobalKTable<String, String> globalTable2 = builder.globalTable("table2", two);
    builder.table("not-global", "not-global");
    final KeyValueMapper<String, String, String> kvMapper = new KeyValueMapper<String, String, String>() {

        @Override
        public String apply(final String key, final String value) {
            return value;
        }
    };
    final KStream<String, String> stream = builder.stream("t1");
    stream.leftJoin(globalTable, kvMapper, MockValueJoiner.TOSTRING_JOINER);
    final KStream<String, String> stream2 = builder.stream("t2");
    stream2.leftJoin(globalTable2, kvMapper, MockValueJoiner.TOSTRING_JOINER);
    final Map<Integer, Set<String>> nodeGroups = builder.nodeGroups();
    for (Integer groupId : nodeGroups.keySet()) {
        final ProcessorTopology topology = builder.build(groupId);
        final List<StateStore> stateStores = topology.globalStateStores();
        final Set<String> names = new HashSet<>();
        for (StateStore stateStore : stateStores) {
            names.add(stateStore.name());
        }
        assertEquals(2, stateStores.size());
        assertTrue(names.contains(one));
        assertTrue(names.contains(two));
    }
}
Also used : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) Set(java.util.Set) HashSet(java.util.HashSet) StateStore(org.apache.kafka.streams.processor.StateStore) MockKeyValueMapper(org.apache.kafka.test.MockKeyValueMapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with StateStore

use of org.apache.kafka.streams.processor.StateStore in project kafka by apache.

the class KStreamBuilderTest method shouldBuildGlobalTopologyWithAllGlobalTables.

@Test
public void shouldBuildGlobalTopologyWithAllGlobalTables() throws Exception {
    builder.globalTable("table", "globalTable");
    builder.globalTable("table2", "globalTable2");
    final ProcessorTopology topology = builder.buildGlobalStateTopology();
    final List<StateStore> stateStores = topology.globalStateStores();
    final Set<String> sourceTopics = topology.sourceTopics();
    assertEquals(Utils.mkSet("table", "table2"), sourceTopics);
    assertEquals(2, stateStores.size());
}
Also used : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) StateStore(org.apache.kafka.streams.processor.StateStore) Test(org.junit.Test)

Example 5 with StateStore

use of org.apache.kafka.streams.processor.StateStore in project kafka by apache.

the class KStreamBuilderTest method shouldBuildSimpleGlobalTableTopology.

@Test
public void shouldBuildSimpleGlobalTableTopology() throws Exception {
    builder.globalTable("table", "globalTable");
    final ProcessorTopology topology = builder.buildGlobalStateTopology();
    final List<StateStore> stateStores = topology.globalStateStores();
    assertEquals(1, stateStores.size());
    assertEquals("globalTable", stateStores.get(0).name());
}
Also used : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) StateStore(org.apache.kafka.streams.processor.StateStore) Test(org.junit.Test)

Aggregations

StateStore (org.apache.kafka.streams.processor.StateStore)12 Test (org.junit.Test)5 IOException (java.io.IOException)3 LockException (org.apache.kafka.streams.errors.LockException)3 StreamsException (org.apache.kafka.streams.errors.StreamsException)3 ProcessorTopology (org.apache.kafka.streams.processor.internals.ProcessorTopology)3 File (java.io.File)2 MockTime (org.apache.kafka.common.utils.MockTime)2 ProcessorStateException (org.apache.kafka.streams.errors.ProcessorStateException)2 NoOpProcessorContext (org.apache.kafka.test.NoOpProcessorContext)2 NoOpRecordCollector (org.apache.kafka.test.NoOpRecordCollector)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 PartitionInfo (org.apache.kafka.common.PartitionInfo)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 Metrics (org.apache.kafka.common.metrics.Metrics)1 StreamsConfig (org.apache.kafka.streams.StreamsConfig)1 StreamsMetrics (org.apache.kafka.streams.StreamsMetrics)1 GlobalKTableImpl (org.apache.kafka.streams.kstream.internals.GlobalKTableImpl)1