target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void shouldCreatePersistenStoreSupplierWithLoggedConfig() throws Exception { final StateStoreSupplier supplier = Stores.create("store") .withKeys(Serdes.String()) .withValues(Serdes.String()) .persistent() .enableLogging(Collections.singletonMap("retention.ms", "1000")) .build(); final Map<String, String> config = supplier.logConfig(); assertTrue(supplier.loggingEnabled()); assertEquals("1000", config.get("retention.ms")); }
public static StoreFactory create(final String name) { return new StoreFactory() { @Override public <K> ValueFactory<K> withKeys(final Serde<K> keySerde) { return new ValueFactory<K>() { @Override public <V> KeyValueFactory<K, V> withValues(final Serde<V> valueSerde) { return new KeyValueFactory<K, V>() { @Override public InMemoryKeyValueFactory<K, V> inMemory() { return new InMemoryKeyValueFactory<K, V>() { private int capacity = Integer.MAX_VALUE; private final Map<String, String> logConfig = new HashMap<>(); private boolean logged = true; @Override public InMemoryKeyValueFactory<K, V> maxEntries(int capacity) { if (capacity < 1) throw new IllegalArgumentException("The capacity must be positive"); this.capacity = capacity; return this; } @Override public InMemoryKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public InMemoryKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public StateStoreSupplier build() { log.trace("Creating InMemory Store name={} capacity={} logged={}", name, capacity, logged); if (capacity < Integer.MAX_VALUE) { return new InMemoryLRUCacheStoreSupplier<>(name, capacity, keySerde, valueSerde, logged, logConfig); } return new InMemoryKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig); } }; } @Override public PersistentKeyValueFactory<K, V> persistent() { return new PersistentKeyValueFactory<K, V>() { public boolean cachingEnabled; private long windowSize; private final Map<String, String> logConfig = new HashMap<>(); private int numSegments = 0; private long retentionPeriod = 0L; private boolean retainDuplicates = false; private boolean sessionWindows; private boolean logged = true; @Override public PersistentKeyValueFactory<K, V> windowed(final long windowSize, final long retentionPeriod, final int numSegments, final boolean retainDuplicates) { this.windowSize = windowSize; this.numSegments = numSegments; this.retentionPeriod = retentionPeriod; this.retainDuplicates = retainDuplicates; this.sessionWindows = false; return this; } @Override public PersistentKeyValueFactory<K, V> sessionWindowed(final long retentionPeriod) { this.sessionWindows = true; this.retentionPeriod = retentionPeriod; return this; } @Override public PersistentKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public PersistentKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public PersistentKeyValueFactory<K, V> enableCaching() { cachingEnabled = true; return this; } @Override public StateStoreSupplier build() { log.trace("Creating RocksDb Store name={} numSegments={} logged={}", name, numSegments, logged); if (sessionWindows) { return new RocksDBSessionStoreSupplier<>(name, retentionPeriod, keySerde, valueSerde, logged, logConfig, cachingEnabled); } else if (numSegments > 0) { return new RocksDBWindowStoreSupplier<>(name, retentionPeriod, numSegments, retainDuplicates, keySerde, valueSerde, windowSize, logged, logConfig, cachingEnabled); } return new RocksDBKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig, cachingEnabled); } }; } }; } }; } }; }
Stores { public static StoreFactory create(final String name) { return new StoreFactory() { @Override public <K> ValueFactory<K> withKeys(final Serde<K> keySerde) { return new ValueFactory<K>() { @Override public <V> KeyValueFactory<K, V> withValues(final Serde<V> valueSerde) { return new KeyValueFactory<K, V>() { @Override public InMemoryKeyValueFactory<K, V> inMemory() { return new InMemoryKeyValueFactory<K, V>() { private int capacity = Integer.MAX_VALUE; private final Map<String, String> logConfig = new HashMap<>(); private boolean logged = true; @Override public InMemoryKeyValueFactory<K, V> maxEntries(int capacity) { if (capacity < 1) throw new IllegalArgumentException("The capacity must be positive"); this.capacity = capacity; return this; } @Override public InMemoryKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public InMemoryKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public StateStoreSupplier build() { log.trace("Creating InMemory Store name={} capacity={} logged={}", name, capacity, logged); if (capacity < Integer.MAX_VALUE) { return new InMemoryLRUCacheStoreSupplier<>(name, capacity, keySerde, valueSerde, logged, logConfig); } return new InMemoryKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig); } }; } @Override public PersistentKeyValueFactory<K, V> persistent() { return new PersistentKeyValueFactory<K, V>() { public boolean cachingEnabled; private long windowSize; private final Map<String, String> logConfig = new HashMap<>(); private int numSegments = 0; private long retentionPeriod = 0L; private boolean retainDuplicates = false; private boolean sessionWindows; private boolean logged = true; @Override public PersistentKeyValueFactory<K, V> windowed(final long windowSize, final long retentionPeriod, final int numSegments, final boolean retainDuplicates) { this.windowSize = windowSize; this.numSegments = numSegments; this.retentionPeriod = retentionPeriod; this.retainDuplicates = retainDuplicates; this.sessionWindows = false; return this; } @Override public PersistentKeyValueFactory<K, V> sessionWindowed(final long retentionPeriod) { this.sessionWindows = true; this.retentionPeriod = retentionPeriod; return this; } @Override public PersistentKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public PersistentKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public PersistentKeyValueFactory<K, V> enableCaching() { cachingEnabled = true; return this; } @Override public StateStoreSupplier build() { log.trace("Creating RocksDb Store name={} numSegments={} logged={}", name, numSegments, logged); if (sessionWindows) { return new RocksDBSessionStoreSupplier<>(name, retentionPeriod, keySerde, valueSerde, logged, logConfig, cachingEnabled); } else if (numSegments > 0) { return new RocksDBWindowStoreSupplier<>(name, retentionPeriod, numSegments, retainDuplicates, keySerde, valueSerde, windowSize, logged, logConfig, cachingEnabled); } return new RocksDBKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig, cachingEnabled); } }; } }; } }; } }; } }
Stores { public static StoreFactory create(final String name) { return new StoreFactory() { @Override public <K> ValueFactory<K> withKeys(final Serde<K> keySerde) { return new ValueFactory<K>() { @Override public <V> KeyValueFactory<K, V> withValues(final Serde<V> valueSerde) { return new KeyValueFactory<K, V>() { @Override public InMemoryKeyValueFactory<K, V> inMemory() { return new InMemoryKeyValueFactory<K, V>() { private int capacity = Integer.MAX_VALUE; private final Map<String, String> logConfig = new HashMap<>(); private boolean logged = true; @Override public InMemoryKeyValueFactory<K, V> maxEntries(int capacity) { if (capacity < 1) throw new IllegalArgumentException("The capacity must be positive"); this.capacity = capacity; return this; } @Override public InMemoryKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public InMemoryKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public StateStoreSupplier build() { log.trace("Creating InMemory Store name={} capacity={} logged={}", name, capacity, logged); if (capacity < Integer.MAX_VALUE) { return new InMemoryLRUCacheStoreSupplier<>(name, capacity, keySerde, valueSerde, logged, logConfig); } return new InMemoryKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig); } }; } @Override public PersistentKeyValueFactory<K, V> persistent() { return new PersistentKeyValueFactory<K, V>() { public boolean cachingEnabled; private long windowSize; private final Map<String, String> logConfig = new HashMap<>(); private int numSegments = 0; private long retentionPeriod = 0L; private boolean retainDuplicates = false; private boolean sessionWindows; private boolean logged = true; @Override public PersistentKeyValueFactory<K, V> windowed(final long windowSize, final long retentionPeriod, final int numSegments, final boolean retainDuplicates) { this.windowSize = windowSize; this.numSegments = numSegments; this.retentionPeriod = retentionPeriod; this.retainDuplicates = retainDuplicates; this.sessionWindows = false; return this; } @Override public PersistentKeyValueFactory<K, V> sessionWindowed(final long retentionPeriod) { this.sessionWindows = true; this.retentionPeriod = retentionPeriod; return this; } @Override public PersistentKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public PersistentKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public PersistentKeyValueFactory<K, V> enableCaching() { cachingEnabled = true; return this; } @Override public StateStoreSupplier build() { log.trace("Creating RocksDb Store name={} numSegments={} logged={}", name, numSegments, logged); if (sessionWindows) { return new RocksDBSessionStoreSupplier<>(name, retentionPeriod, keySerde, valueSerde, logged, logConfig, cachingEnabled); } else if (numSegments > 0) { return new RocksDBWindowStoreSupplier<>(name, retentionPeriod, numSegments, retainDuplicates, keySerde, valueSerde, windowSize, logged, logConfig, cachingEnabled); } return new RocksDBKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig, cachingEnabled); } }; } }; } }; } }; } }
Stores { public static StoreFactory create(final String name) { return new StoreFactory() { @Override public <K> ValueFactory<K> withKeys(final Serde<K> keySerde) { return new ValueFactory<K>() { @Override public <V> KeyValueFactory<K, V> withValues(final Serde<V> valueSerde) { return new KeyValueFactory<K, V>() { @Override public InMemoryKeyValueFactory<K, V> inMemory() { return new InMemoryKeyValueFactory<K, V>() { private int capacity = Integer.MAX_VALUE; private final Map<String, String> logConfig = new HashMap<>(); private boolean logged = true; @Override public InMemoryKeyValueFactory<K, V> maxEntries(int capacity) { if (capacity < 1) throw new IllegalArgumentException("The capacity must be positive"); this.capacity = capacity; return this; } @Override public InMemoryKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public InMemoryKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public StateStoreSupplier build() { log.trace("Creating InMemory Store name={} capacity={} logged={}", name, capacity, logged); if (capacity < Integer.MAX_VALUE) { return new InMemoryLRUCacheStoreSupplier<>(name, capacity, keySerde, valueSerde, logged, logConfig); } return new InMemoryKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig); } }; } @Override public PersistentKeyValueFactory<K, V> persistent() { return new PersistentKeyValueFactory<K, V>() { public boolean cachingEnabled; private long windowSize; private final Map<String, String> logConfig = new HashMap<>(); private int numSegments = 0; private long retentionPeriod = 0L; private boolean retainDuplicates = false; private boolean sessionWindows; private boolean logged = true; @Override public PersistentKeyValueFactory<K, V> windowed(final long windowSize, final long retentionPeriod, final int numSegments, final boolean retainDuplicates) { this.windowSize = windowSize; this.numSegments = numSegments; this.retentionPeriod = retentionPeriod; this.retainDuplicates = retainDuplicates; this.sessionWindows = false; return this; } @Override public PersistentKeyValueFactory<K, V> sessionWindowed(final long retentionPeriod) { this.sessionWindows = true; this.retentionPeriod = retentionPeriod; return this; } @Override public PersistentKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public PersistentKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public PersistentKeyValueFactory<K, V> enableCaching() { cachingEnabled = true; return this; } @Override public StateStoreSupplier build() { log.trace("Creating RocksDb Store name={} numSegments={} logged={}", name, numSegments, logged); if (sessionWindows) { return new RocksDBSessionStoreSupplier<>(name, retentionPeriod, keySerde, valueSerde, logged, logConfig, cachingEnabled); } else if (numSegments > 0) { return new RocksDBWindowStoreSupplier<>(name, retentionPeriod, numSegments, retainDuplicates, keySerde, valueSerde, windowSize, logged, logConfig, cachingEnabled); } return new RocksDBKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig, cachingEnabled); } }; } }; } }; } }; } static StoreFactory create(final String name); }
Stores { public static StoreFactory create(final String name) { return new StoreFactory() { @Override public <K> ValueFactory<K> withKeys(final Serde<K> keySerde) { return new ValueFactory<K>() { @Override public <V> KeyValueFactory<K, V> withValues(final Serde<V> valueSerde) { return new KeyValueFactory<K, V>() { @Override public InMemoryKeyValueFactory<K, V> inMemory() { return new InMemoryKeyValueFactory<K, V>() { private int capacity = Integer.MAX_VALUE; private final Map<String, String> logConfig = new HashMap<>(); private boolean logged = true; @Override public InMemoryKeyValueFactory<K, V> maxEntries(int capacity) { if (capacity < 1) throw new IllegalArgumentException("The capacity must be positive"); this.capacity = capacity; return this; } @Override public InMemoryKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public InMemoryKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public StateStoreSupplier build() { log.trace("Creating InMemory Store name={} capacity={} logged={}", name, capacity, logged); if (capacity < Integer.MAX_VALUE) { return new InMemoryLRUCacheStoreSupplier<>(name, capacity, keySerde, valueSerde, logged, logConfig); } return new InMemoryKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig); } }; } @Override public PersistentKeyValueFactory<K, V> persistent() { return new PersistentKeyValueFactory<K, V>() { public boolean cachingEnabled; private long windowSize; private final Map<String, String> logConfig = new HashMap<>(); private int numSegments = 0; private long retentionPeriod = 0L; private boolean retainDuplicates = false; private boolean sessionWindows; private boolean logged = true; @Override public PersistentKeyValueFactory<K, V> windowed(final long windowSize, final long retentionPeriod, final int numSegments, final boolean retainDuplicates) { this.windowSize = windowSize; this.numSegments = numSegments; this.retentionPeriod = retentionPeriod; this.retainDuplicates = retainDuplicates; this.sessionWindows = false; return this; } @Override public PersistentKeyValueFactory<K, V> sessionWindowed(final long retentionPeriod) { this.sessionWindows = true; this.retentionPeriod = retentionPeriod; return this; } @Override public PersistentKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public PersistentKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public PersistentKeyValueFactory<K, V> enableCaching() { cachingEnabled = true; return this; } @Override public StateStoreSupplier build() { log.trace("Creating RocksDb Store name={} numSegments={} logged={}", name, numSegments, logged); if (sessionWindows) { return new RocksDBSessionStoreSupplier<>(name, retentionPeriod, keySerde, valueSerde, logged, logConfig, cachingEnabled); } else if (numSegments > 0) { return new RocksDBWindowStoreSupplier<>(name, retentionPeriod, numSegments, retainDuplicates, keySerde, valueSerde, windowSize, logged, logConfig, cachingEnabled); } return new RocksDBKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig, cachingEnabled); } }; } }; } }; } }; } static StoreFactory create(final String name); }
@Test public void shouldCreatePersistenStoreSupplierNotLogged() throws Exception { final StateStoreSupplier supplier = Stores.create("store") .withKeys(Serdes.String()) .withValues(Serdes.String()) .persistent() .disableLogging() .build(); assertFalse(supplier.loggingEnabled()); }
public static StoreFactory create(final String name) { return new StoreFactory() { @Override public <K> ValueFactory<K> withKeys(final Serde<K> keySerde) { return new ValueFactory<K>() { @Override public <V> KeyValueFactory<K, V> withValues(final Serde<V> valueSerde) { return new KeyValueFactory<K, V>() { @Override public InMemoryKeyValueFactory<K, V> inMemory() { return new InMemoryKeyValueFactory<K, V>() { private int capacity = Integer.MAX_VALUE; private final Map<String, String> logConfig = new HashMap<>(); private boolean logged = true; @Override public InMemoryKeyValueFactory<K, V> maxEntries(int capacity) { if (capacity < 1) throw new IllegalArgumentException("The capacity must be positive"); this.capacity = capacity; return this; } @Override public InMemoryKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public InMemoryKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public StateStoreSupplier build() { log.trace("Creating InMemory Store name={} capacity={} logged={}", name, capacity, logged); if (capacity < Integer.MAX_VALUE) { return new InMemoryLRUCacheStoreSupplier<>(name, capacity, keySerde, valueSerde, logged, logConfig); } return new InMemoryKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig); } }; } @Override public PersistentKeyValueFactory<K, V> persistent() { return new PersistentKeyValueFactory<K, V>() { public boolean cachingEnabled; private long windowSize; private final Map<String, String> logConfig = new HashMap<>(); private int numSegments = 0; private long retentionPeriod = 0L; private boolean retainDuplicates = false; private boolean sessionWindows; private boolean logged = true; @Override public PersistentKeyValueFactory<K, V> windowed(final long windowSize, final long retentionPeriod, final int numSegments, final boolean retainDuplicates) { this.windowSize = windowSize; this.numSegments = numSegments; this.retentionPeriod = retentionPeriod; this.retainDuplicates = retainDuplicates; this.sessionWindows = false; return this; } @Override public PersistentKeyValueFactory<K, V> sessionWindowed(final long retentionPeriod) { this.sessionWindows = true; this.retentionPeriod = retentionPeriod; return this; } @Override public PersistentKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public PersistentKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public PersistentKeyValueFactory<K, V> enableCaching() { cachingEnabled = true; return this; } @Override public StateStoreSupplier build() { log.trace("Creating RocksDb Store name={} numSegments={} logged={}", name, numSegments, logged); if (sessionWindows) { return new RocksDBSessionStoreSupplier<>(name, retentionPeriod, keySerde, valueSerde, logged, logConfig, cachingEnabled); } else if (numSegments > 0) { return new RocksDBWindowStoreSupplier<>(name, retentionPeriod, numSegments, retainDuplicates, keySerde, valueSerde, windowSize, logged, logConfig, cachingEnabled); } return new RocksDBKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig, cachingEnabled); } }; } }; } }; } }; }
Stores { public static StoreFactory create(final String name) { return new StoreFactory() { @Override public <K> ValueFactory<K> withKeys(final Serde<K> keySerde) { return new ValueFactory<K>() { @Override public <V> KeyValueFactory<K, V> withValues(final Serde<V> valueSerde) { return new KeyValueFactory<K, V>() { @Override public InMemoryKeyValueFactory<K, V> inMemory() { return new InMemoryKeyValueFactory<K, V>() { private int capacity = Integer.MAX_VALUE; private final Map<String, String> logConfig = new HashMap<>(); private boolean logged = true; @Override public InMemoryKeyValueFactory<K, V> maxEntries(int capacity) { if (capacity < 1) throw new IllegalArgumentException("The capacity must be positive"); this.capacity = capacity; return this; } @Override public InMemoryKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public InMemoryKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public StateStoreSupplier build() { log.trace("Creating InMemory Store name={} capacity={} logged={}", name, capacity, logged); if (capacity < Integer.MAX_VALUE) { return new InMemoryLRUCacheStoreSupplier<>(name, capacity, keySerde, valueSerde, logged, logConfig); } return new InMemoryKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig); } }; } @Override public PersistentKeyValueFactory<K, V> persistent() { return new PersistentKeyValueFactory<K, V>() { public boolean cachingEnabled; private long windowSize; private final Map<String, String> logConfig = new HashMap<>(); private int numSegments = 0; private long retentionPeriod = 0L; private boolean retainDuplicates = false; private boolean sessionWindows; private boolean logged = true; @Override public PersistentKeyValueFactory<K, V> windowed(final long windowSize, final long retentionPeriod, final int numSegments, final boolean retainDuplicates) { this.windowSize = windowSize; this.numSegments = numSegments; this.retentionPeriod = retentionPeriod; this.retainDuplicates = retainDuplicates; this.sessionWindows = false; return this; } @Override public PersistentKeyValueFactory<K, V> sessionWindowed(final long retentionPeriod) { this.sessionWindows = true; this.retentionPeriod = retentionPeriod; return this; } @Override public PersistentKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public PersistentKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public PersistentKeyValueFactory<K, V> enableCaching() { cachingEnabled = true; return this; } @Override public StateStoreSupplier build() { log.trace("Creating RocksDb Store name={} numSegments={} logged={}", name, numSegments, logged); if (sessionWindows) { return new RocksDBSessionStoreSupplier<>(name, retentionPeriod, keySerde, valueSerde, logged, logConfig, cachingEnabled); } else if (numSegments > 0) { return new RocksDBWindowStoreSupplier<>(name, retentionPeriod, numSegments, retainDuplicates, keySerde, valueSerde, windowSize, logged, logConfig, cachingEnabled); } return new RocksDBKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig, cachingEnabled); } }; } }; } }; } }; } }
Stores { public static StoreFactory create(final String name) { return new StoreFactory() { @Override public <K> ValueFactory<K> withKeys(final Serde<K> keySerde) { return new ValueFactory<K>() { @Override public <V> KeyValueFactory<K, V> withValues(final Serde<V> valueSerde) { return new KeyValueFactory<K, V>() { @Override public InMemoryKeyValueFactory<K, V> inMemory() { return new InMemoryKeyValueFactory<K, V>() { private int capacity = Integer.MAX_VALUE; private final Map<String, String> logConfig = new HashMap<>(); private boolean logged = true; @Override public InMemoryKeyValueFactory<K, V> maxEntries(int capacity) { if (capacity < 1) throw new IllegalArgumentException("The capacity must be positive"); this.capacity = capacity; return this; } @Override public InMemoryKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public InMemoryKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public StateStoreSupplier build() { log.trace("Creating InMemory Store name={} capacity={} logged={}", name, capacity, logged); if (capacity < Integer.MAX_VALUE) { return new InMemoryLRUCacheStoreSupplier<>(name, capacity, keySerde, valueSerde, logged, logConfig); } return new InMemoryKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig); } }; } @Override public PersistentKeyValueFactory<K, V> persistent() { return new PersistentKeyValueFactory<K, V>() { public boolean cachingEnabled; private long windowSize; private final Map<String, String> logConfig = new HashMap<>(); private int numSegments = 0; private long retentionPeriod = 0L; private boolean retainDuplicates = false; private boolean sessionWindows; private boolean logged = true; @Override public PersistentKeyValueFactory<K, V> windowed(final long windowSize, final long retentionPeriod, final int numSegments, final boolean retainDuplicates) { this.windowSize = windowSize; this.numSegments = numSegments; this.retentionPeriod = retentionPeriod; this.retainDuplicates = retainDuplicates; this.sessionWindows = false; return this; } @Override public PersistentKeyValueFactory<K, V> sessionWindowed(final long retentionPeriod) { this.sessionWindows = true; this.retentionPeriod = retentionPeriod; return this; } @Override public PersistentKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public PersistentKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public PersistentKeyValueFactory<K, V> enableCaching() { cachingEnabled = true; return this; } @Override public StateStoreSupplier build() { log.trace("Creating RocksDb Store name={} numSegments={} logged={}", name, numSegments, logged); if (sessionWindows) { return new RocksDBSessionStoreSupplier<>(name, retentionPeriod, keySerde, valueSerde, logged, logConfig, cachingEnabled); } else if (numSegments > 0) { return new RocksDBWindowStoreSupplier<>(name, retentionPeriod, numSegments, retainDuplicates, keySerde, valueSerde, windowSize, logged, logConfig, cachingEnabled); } return new RocksDBKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig, cachingEnabled); } }; } }; } }; } }; } }
Stores { public static StoreFactory create(final String name) { return new StoreFactory() { @Override public <K> ValueFactory<K> withKeys(final Serde<K> keySerde) { return new ValueFactory<K>() { @Override public <V> KeyValueFactory<K, V> withValues(final Serde<V> valueSerde) { return new KeyValueFactory<K, V>() { @Override public InMemoryKeyValueFactory<K, V> inMemory() { return new InMemoryKeyValueFactory<K, V>() { private int capacity = Integer.MAX_VALUE; private final Map<String, String> logConfig = new HashMap<>(); private boolean logged = true; @Override public InMemoryKeyValueFactory<K, V> maxEntries(int capacity) { if (capacity < 1) throw new IllegalArgumentException("The capacity must be positive"); this.capacity = capacity; return this; } @Override public InMemoryKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public InMemoryKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public StateStoreSupplier build() { log.trace("Creating InMemory Store name={} capacity={} logged={}", name, capacity, logged); if (capacity < Integer.MAX_VALUE) { return new InMemoryLRUCacheStoreSupplier<>(name, capacity, keySerde, valueSerde, logged, logConfig); } return new InMemoryKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig); } }; } @Override public PersistentKeyValueFactory<K, V> persistent() { return new PersistentKeyValueFactory<K, V>() { public boolean cachingEnabled; private long windowSize; private final Map<String, String> logConfig = new HashMap<>(); private int numSegments = 0; private long retentionPeriod = 0L; private boolean retainDuplicates = false; private boolean sessionWindows; private boolean logged = true; @Override public PersistentKeyValueFactory<K, V> windowed(final long windowSize, final long retentionPeriod, final int numSegments, final boolean retainDuplicates) { this.windowSize = windowSize; this.numSegments = numSegments; this.retentionPeriod = retentionPeriod; this.retainDuplicates = retainDuplicates; this.sessionWindows = false; return this; } @Override public PersistentKeyValueFactory<K, V> sessionWindowed(final long retentionPeriod) { this.sessionWindows = true; this.retentionPeriod = retentionPeriod; return this; } @Override public PersistentKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public PersistentKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public PersistentKeyValueFactory<K, V> enableCaching() { cachingEnabled = true; return this; } @Override public StateStoreSupplier build() { log.trace("Creating RocksDb Store name={} numSegments={} logged={}", name, numSegments, logged); if (sessionWindows) { return new RocksDBSessionStoreSupplier<>(name, retentionPeriod, keySerde, valueSerde, logged, logConfig, cachingEnabled); } else if (numSegments > 0) { return new RocksDBWindowStoreSupplier<>(name, retentionPeriod, numSegments, retainDuplicates, keySerde, valueSerde, windowSize, logged, logConfig, cachingEnabled); } return new RocksDBKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig, cachingEnabled); } }; } }; } }; } }; } static StoreFactory create(final String name); }
Stores { public static StoreFactory create(final String name) { return new StoreFactory() { @Override public <K> ValueFactory<K> withKeys(final Serde<K> keySerde) { return new ValueFactory<K>() { @Override public <V> KeyValueFactory<K, V> withValues(final Serde<V> valueSerde) { return new KeyValueFactory<K, V>() { @Override public InMemoryKeyValueFactory<K, V> inMemory() { return new InMemoryKeyValueFactory<K, V>() { private int capacity = Integer.MAX_VALUE; private final Map<String, String> logConfig = new HashMap<>(); private boolean logged = true; @Override public InMemoryKeyValueFactory<K, V> maxEntries(int capacity) { if (capacity < 1) throw new IllegalArgumentException("The capacity must be positive"); this.capacity = capacity; return this; } @Override public InMemoryKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public InMemoryKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public StateStoreSupplier build() { log.trace("Creating InMemory Store name={} capacity={} logged={}", name, capacity, logged); if (capacity < Integer.MAX_VALUE) { return new InMemoryLRUCacheStoreSupplier<>(name, capacity, keySerde, valueSerde, logged, logConfig); } return new InMemoryKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig); } }; } @Override public PersistentKeyValueFactory<K, V> persistent() { return new PersistentKeyValueFactory<K, V>() { public boolean cachingEnabled; private long windowSize; private final Map<String, String> logConfig = new HashMap<>(); private int numSegments = 0; private long retentionPeriod = 0L; private boolean retainDuplicates = false; private boolean sessionWindows; private boolean logged = true; @Override public PersistentKeyValueFactory<K, V> windowed(final long windowSize, final long retentionPeriod, final int numSegments, final boolean retainDuplicates) { this.windowSize = windowSize; this.numSegments = numSegments; this.retentionPeriod = retentionPeriod; this.retainDuplicates = retainDuplicates; this.sessionWindows = false; return this; } @Override public PersistentKeyValueFactory<K, V> sessionWindowed(final long retentionPeriod) { this.sessionWindows = true; this.retentionPeriod = retentionPeriod; return this; } @Override public PersistentKeyValueFactory<K, V> enableLogging(final Map<String, String> config) { logged = true; logConfig.putAll(config); return this; } @Override public PersistentKeyValueFactory<K, V> disableLogging() { logged = false; logConfig.clear(); return this; } @Override public PersistentKeyValueFactory<K, V> enableCaching() { cachingEnabled = true; return this; } @Override public StateStoreSupplier build() { log.trace("Creating RocksDb Store name={} numSegments={} logged={}", name, numSegments, logged); if (sessionWindows) { return new RocksDBSessionStoreSupplier<>(name, retentionPeriod, keySerde, valueSerde, logged, logConfig, cachingEnabled); } else if (numSegments > 0) { return new RocksDBWindowStoreSupplier<>(name, retentionPeriod, numSegments, retainDuplicates, keySerde, valueSerde, windowSize, logged, logConfig, cachingEnabled); } return new RocksDBKeyValueStoreSupplier<>(name, keySerde, valueSerde, logged, logConfig, cachingEnabled); } }; } }; } }; } }; } static StoreFactory create(final String name); }
@Test public void shouldReturnNextValueWhenItExists() throws Exception { assertThat(serializedKeyValueIterator.next(), equalTo(KeyValue.pair("hi", "there"))); assertThat(serializedKeyValueIterator.next(), equalTo(KeyValue.pair("hello", "world"))); }
@Override public KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<Bytes, byte[]> next = bytesIterator.next(); return KeyValue.pair(serdes.keyFrom(next.key.get()), serdes.valueFrom(next.value)); }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<Bytes, byte[]> next = bytesIterator.next(); return KeyValue.pair(serdes.keyFrom(next.key.get()), serdes.valueFrom(next.value)); } }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<Bytes, byte[]> next = bytesIterator.next(); return KeyValue.pair(serdes.keyFrom(next.key.get()), serdes.valueFrom(next.value)); } SerializedKeyValueIterator(final KeyValueIterator<Bytes, byte[]> bytesIterator, final StateSerdes<K, V> serdes); }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<Bytes, byte[]> next = bytesIterator.next(); return KeyValue.pair(serdes.keyFrom(next.key.get()), serdes.valueFrom(next.value)); } SerializedKeyValueIterator(final KeyValueIterator<Bytes, byte[]> bytesIterator, final StateSerdes<K, V> serdes); @Override void close(); @Override K peekNextKey(); @Override boolean hasNext(); @Override KeyValue<K, V> next(); @Override void remove(); }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<Bytes, byte[]> next = bytesIterator.next(); return KeyValue.pair(serdes.keyFrom(next.key.get()), serdes.valueFrom(next.value)); } SerializedKeyValueIterator(final KeyValueIterator<Bytes, byte[]> bytesIterator, final StateSerdes<K, V> serdes); @Override void close(); @Override K peekNextKey(); @Override boolean hasNext(); @Override KeyValue<K, V> next(); @Override void remove(); }
@Test public void shouldReturnFalseOnHasNextWhenNoMoreResults() throws Exception { advanceIteratorToEnd(); assertFalse(serializedKeyValueIterator.hasNext()); }
@Override public boolean hasNext() { return bytesIterator.hasNext(); }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public boolean hasNext() { return bytesIterator.hasNext(); } }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public boolean hasNext() { return bytesIterator.hasNext(); } SerializedKeyValueIterator(final KeyValueIterator<Bytes, byte[]> bytesIterator, final StateSerdes<K, V> serdes); }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public boolean hasNext() { return bytesIterator.hasNext(); } SerializedKeyValueIterator(final KeyValueIterator<Bytes, byte[]> bytesIterator, final StateSerdes<K, V> serdes); @Override void close(); @Override K peekNextKey(); @Override boolean hasNext(); @Override KeyValue<K, V> next(); @Override void remove(); }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public boolean hasNext() { return bytesIterator.hasNext(); } SerializedKeyValueIterator(final KeyValueIterator<Bytes, byte[]> bytesIterator, final StateSerdes<K, V> serdes); @Override void close(); @Override K peekNextKey(); @Override boolean hasNext(); @Override KeyValue<K, V> next(); @Override void remove(); }
@Test public void shouldThrowNoSuchElementOnNextWhenIteratorExhausted() throws Exception { advanceIteratorToEnd(); try { serializedKeyValueIterator.next(); fail("Expected NoSuchElementException on exhausted iterator"); } catch (final NoSuchElementException nse) { } }
@Override public KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<Bytes, byte[]> next = bytesIterator.next(); return KeyValue.pair(serdes.keyFrom(next.key.get()), serdes.valueFrom(next.value)); }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<Bytes, byte[]> next = bytesIterator.next(); return KeyValue.pair(serdes.keyFrom(next.key.get()), serdes.valueFrom(next.value)); } }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<Bytes, byte[]> next = bytesIterator.next(); return KeyValue.pair(serdes.keyFrom(next.key.get()), serdes.valueFrom(next.value)); } SerializedKeyValueIterator(final KeyValueIterator<Bytes, byte[]> bytesIterator, final StateSerdes<K, V> serdes); }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<Bytes, byte[]> next = bytesIterator.next(); return KeyValue.pair(serdes.keyFrom(next.key.get()), serdes.valueFrom(next.value)); } SerializedKeyValueIterator(final KeyValueIterator<Bytes, byte[]> bytesIterator, final StateSerdes<K, V> serdes); @Override void close(); @Override K peekNextKey(); @Override boolean hasNext(); @Override KeyValue<K, V> next(); @Override void remove(); }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<Bytes, byte[]> next = bytesIterator.next(); return KeyValue.pair(serdes.keyFrom(next.key.get()), serdes.valueFrom(next.value)); } SerializedKeyValueIterator(final KeyValueIterator<Bytes, byte[]> bytesIterator, final StateSerdes<K, V> serdes); @Override void close(); @Override K peekNextKey(); @Override boolean hasNext(); @Override KeyValue<K, V> next(); @Override void remove(); }
@Test(expected = UnsupportedOperationException.class) public void shouldThrowUnsupportedOperationOnRemove() throws Exception { serializedKeyValueIterator.remove(); }
@Override public void remove() { throw new UnsupportedOperationException("remove() is not supported in " + getClass().getName()); }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public void remove() { throw new UnsupportedOperationException("remove() is not supported in " + getClass().getName()); } }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public void remove() { throw new UnsupportedOperationException("remove() is not supported in " + getClass().getName()); } SerializedKeyValueIterator(final KeyValueIterator<Bytes, byte[]> bytesIterator, final StateSerdes<K, V> serdes); }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public void remove() { throw new UnsupportedOperationException("remove() is not supported in " + getClass().getName()); } SerializedKeyValueIterator(final KeyValueIterator<Bytes, byte[]> bytesIterator, final StateSerdes<K, V> serdes); @Override void close(); @Override K peekNextKey(); @Override boolean hasNext(); @Override KeyValue<K, V> next(); @Override void remove(); }
SerializedKeyValueIterator implements KeyValueIterator<K, V> { @Override public void remove() { throw new UnsupportedOperationException("remove() is not supported in " + getClass().getName()); } SerializedKeyValueIterator(final KeyValueIterator<Bytes, byte[]> bytesIterator, final StateSerdes<K, V> serdes); @Override void close(); @Override K peekNextKey(); @Override boolean hasNext(); @Override KeyValue<K, V> next(); @Override void remove(); }
@Test public void shouldFetchExactKeysSkippingLongerKeys() throws Exception { final Bytes key = Bytes.wrap(new byte[]{0}); final List<Integer> result = getValues(sessionKeySchema.hasNextCondition(key, key, 0, Long.MAX_VALUE)); assertThat(result, equalTo(Arrays.asList(2, 4))); }
@Override public HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to) { return new HasNextCondition() { @Override public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) { while (iterator.hasNext()) { final Bytes bytes = iterator.peekNextKey(); final Windowed<Bytes> windowedKey = SessionKeySerde.fromBytes(bytes); if (windowedKey.key().compareTo(binaryKeyFrom) >= 0 && windowedKey.key().compareTo(binaryKeyTo) <= 0 && windowedKey.window().end() >= from && windowedKey.window().start() <= to) { return true; } iterator.next(); } return false; } }; }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to) { return new HasNextCondition() { @Override public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) { while (iterator.hasNext()) { final Bytes bytes = iterator.peekNextKey(); final Windowed<Bytes> windowedKey = SessionKeySerde.fromBytes(bytes); if (windowedKey.key().compareTo(binaryKeyFrom) >= 0 && windowedKey.key().compareTo(binaryKeyTo) <= 0 && windowedKey.window().end() >= from && windowedKey.window().start() <= to) { return true; } iterator.next(); } return false; } }; } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to) { return new HasNextCondition() { @Override public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) { while (iterator.hasNext()) { final Bytes bytes = iterator.peekNextKey(); final Windowed<Bytes> windowedKey = SessionKeySerde.fromBytes(bytes); if (windowedKey.key().compareTo(binaryKeyFrom) >= 0 && windowedKey.key().compareTo(binaryKeyTo) <= 0 && windowedKey.window().end() >= from && windowedKey.window().start() <= to) { return true; } iterator.next(); } return false; } }; } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to) { return new HasNextCondition() { @Override public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) { while (iterator.hasNext()) { final Bytes bytes = iterator.peekNextKey(); final Windowed<Bytes> windowedKey = SessionKeySerde.fromBytes(bytes); if (windowedKey.key().compareTo(binaryKeyFrom) >= 0 && windowedKey.key().compareTo(binaryKeyTo) <= 0 && windowedKey.window().end() >= from && windowedKey.window().start() <= to) { return true; } iterator.next(); } return false; } }; } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to) { return new HasNextCondition() { @Override public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) { while (iterator.hasNext()) { final Bytes bytes = iterator.peekNextKey(); final Windowed<Bytes> windowedKey = SessionKeySerde.fromBytes(bytes); if (windowedKey.key().compareTo(binaryKeyFrom) >= 0 && windowedKey.key().compareTo(binaryKeyTo) <= 0 && windowedKey.window().end() >= from && windowedKey.window().start() <= to) { return true; } iterator.next(); } return false; } }; } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test public void shouldFetchExactKeySkippingShorterKeys() throws Exception { final Bytes key = Bytes.wrap(new byte[]{0, 0}); final HasNextCondition hasNextCondition = sessionKeySchema.hasNextCondition(key, key, 0, Long.MAX_VALUE); final List<Integer> results = getValues(hasNextCondition); assertThat(results, equalTo(Arrays.asList(1, 5))); }
@Override public HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to) { return new HasNextCondition() { @Override public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) { while (iterator.hasNext()) { final Bytes bytes = iterator.peekNextKey(); final Windowed<Bytes> windowedKey = SessionKeySerde.fromBytes(bytes); if (windowedKey.key().compareTo(binaryKeyFrom) >= 0 && windowedKey.key().compareTo(binaryKeyTo) <= 0 && windowedKey.window().end() >= from && windowedKey.window().start() <= to) { return true; } iterator.next(); } return false; } }; }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to) { return new HasNextCondition() { @Override public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) { while (iterator.hasNext()) { final Bytes bytes = iterator.peekNextKey(); final Windowed<Bytes> windowedKey = SessionKeySerde.fromBytes(bytes); if (windowedKey.key().compareTo(binaryKeyFrom) >= 0 && windowedKey.key().compareTo(binaryKeyTo) <= 0 && windowedKey.window().end() >= from && windowedKey.window().start() <= to) { return true; } iterator.next(); } return false; } }; } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to) { return new HasNextCondition() { @Override public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) { while (iterator.hasNext()) { final Bytes bytes = iterator.peekNextKey(); final Windowed<Bytes> windowedKey = SessionKeySerde.fromBytes(bytes); if (windowedKey.key().compareTo(binaryKeyFrom) >= 0 && windowedKey.key().compareTo(binaryKeyTo) <= 0 && windowedKey.window().end() >= from && windowedKey.window().start() <= to) { return true; } iterator.next(); } return false; } }; } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to) { return new HasNextCondition() { @Override public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) { while (iterator.hasNext()) { final Bytes bytes = iterator.peekNextKey(); final Windowed<Bytes> windowedKey = SessionKeySerde.fromBytes(bytes); if (windowedKey.key().compareTo(binaryKeyFrom) >= 0 && windowedKey.key().compareTo(binaryKeyTo) <= 0 && windowedKey.window().end() >= from && windowedKey.window().start() <= to) { return true; } iterator.next(); } return false; } }; } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to) { return new HasNextCondition() { @Override public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) { while (iterator.hasNext()) { final Bytes bytes = iterator.peekNextKey(); final Windowed<Bytes> windowedKey = SessionKeySerde.fromBytes(bytes); if (windowedKey.key().compareTo(binaryKeyFrom) >= 0 && windowedKey.key().compareTo(binaryKeyTo) <= 0 && windowedKey.window().end() >= from && windowedKey.window().start() <= to) { return true; } iterator.next(); } return false; } }; } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test public void testUpperBoundWithLargeTimestamps() throws Exception { Bytes upper = sessionKeySchema.upperRange(Bytes.wrap(new byte[]{0xA, 0xB, 0xC}), Long.MAX_VALUE); assertThat( "shorter key with max timestamp should be in range", upper.compareTo( SessionKeySerde.bytesToBinary( new Windowed<>( Bytes.wrap(new byte[]{0xA}), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE)) ) ) >= 0 ); assertThat( "shorter key with max timestamp should be in range", upper.compareTo( SessionKeySerde.bytesToBinary( new Windowed<>( Bytes.wrap(new byte[]{0xA, 0xB}), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE)) ) ) >= 0 ); assertThat(upper, equalTo(SessionKeySerde.bytesToBinary( new Windowed<>(Bytes.wrap(new byte[]{0xA}), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE)))) ); }
@Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test public void testUpperBoundWithKeyBytesLargerThanFirstTimestampByte() throws Exception { Bytes upper = sessionKeySchema.upperRange(Bytes.wrap(new byte[]{0xA, (byte) 0x8F, (byte) 0x9F}), Long.MAX_VALUE); assertThat( "shorter key with max timestamp should be in range", upper.compareTo( SessionKeySerde.bytesToBinary( new Windowed<>( Bytes.wrap(new byte[]{0xA, (byte) 0x8F}), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE)) ) ) >= 0 ); assertThat(upper, equalTo(SessionKeySerde.bytesToBinary( new Windowed<>(Bytes.wrap(new byte[]{0xA, (byte) 0x8F, (byte) 0x9F}), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE)))) ); }
@Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test public void testUpperBoundWithZeroTimestamp() throws Exception { Bytes upper = sessionKeySchema.upperRange(Bytes.wrap(new byte[]{0xA, 0xB, 0xC}), 0); assertThat(upper, equalTo(SessionKeySerde.bytesToBinary( new Windowed<>(Bytes.wrap(new byte[]{0xA, 0xB, 0xC}), new SessionWindow(0, 0)))) ); }
@Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes upperRange(Bytes key, long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putLong(to) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test public void testLowerBoundWithZeroTimestamp() throws Exception { Bytes lower = sessionKeySchema.lowerRange(Bytes.wrap(new byte[]{0xA, 0xB, 0xC}), 0); assertThat(lower, equalTo(SessionKeySerde.bytesToBinary(new Windowed<>(Bytes.wrap(new byte[]{0xA, 0xB, 0xC}), new SessionWindow(0, 0))))); }
@Override public Bytes lowerRange(Bytes key, long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(Bytes key, long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(Bytes key, long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(Bytes key, long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(Bytes key, long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test public void testLowerBoundMatchesTrailingZeros() throws Exception { Bytes lower = sessionKeySchema.lowerRange(Bytes.wrap(new byte[]{0xA, 0xB, 0xC}), Long.MAX_VALUE); assertThat( "appending zeros to key should still be in range", lower.compareTo( SessionKeySerde.bytesToBinary( new Windowed<>( Bytes.wrap(new byte[]{0xA, 0xB, 0xC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE)) ) ) < 0 ); assertThat(lower, equalTo(SessionKeySerde.bytesToBinary(new Windowed<>(Bytes.wrap(new byte[]{0xA, 0xB, 0xC}), new SessionWindow(0, 0))))); }
@Override public Bytes lowerRange(Bytes key, long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(Bytes key, long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(Bytes key, long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(Bytes key, long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
SessionKeySchema implements SegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(Bytes key, long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } @Override void init(final String topic); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRange(Bytes key, long to); @Override Bytes lowerRange(Bytes key, long from); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test public void shouldFetchResulstFromUnderlyingSessionStore() throws Exception { underlyingSessionStore.put(new Windowed<>("a", new SessionWindow(0, 0)), 1L); underlyingSessionStore.put(new Windowed<>("a", new SessionWindow(10, 10)), 2L); final List<KeyValue<Windowed<String>, Long>> results = toList(sessionStore.fetch("a")); assertEquals(Arrays.asList(KeyValue.pair(new Windowed<>("a", new SessionWindow(0, 0)), 1L), KeyValue.pair(new Windowed<>("a", new SessionWindow(10, 10)), 2L)), results); }
private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); @Override KeyValueIterator<Windowed<K>, V> fetch(final K key); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); @Override KeyValueIterator<Windowed<K>, V> fetch(final K key); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to); }
@Test public void longToConnect() { assertEquals(new SchemaAndValue(Schema.INT64_SCHEMA, 12L), converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"int64\" }, \"payload\": 12 }".getBytes())); assertEquals(new SchemaAndValue(Schema.INT64_SCHEMA, 4398046511104L), converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"int64\" }, \"payload\": 4398046511104 }".getBytes())); }
@Override public SchemaAndValue toConnectData(String topic, byte[] value) { JsonNode jsonValue; try { jsonValue = deserializer.deserialize(topic, value); } catch (SerializationException e) { throw new DataException("Converting byte[] to Kafka Connect data failed due to serialization error: ", e); } if (enableSchemas && (jsonValue == null || !jsonValue.isObject() || jsonValue.size() != 2 || !jsonValue.has("schema") || !jsonValue.has("payload"))) throw new DataException("JsonConverter with schemas.enable requires \"schema\" and \"payload\" fields and may not contain additional fields." + " If you are trying to deserialize plain JSON data, set schemas.enable=false in your converter configuration."); if (!enableSchemas) { ObjectNode envelope = JsonNodeFactory.instance.objectNode(); envelope.set("schema", null); envelope.set("payload", jsonValue); jsonValue = envelope; } return jsonToConnect(jsonValue); }
JsonConverter implements Converter { @Override public SchemaAndValue toConnectData(String topic, byte[] value) { JsonNode jsonValue; try { jsonValue = deserializer.deserialize(topic, value); } catch (SerializationException e) { throw new DataException("Converting byte[] to Kafka Connect data failed due to serialization error: ", e); } if (enableSchemas && (jsonValue == null || !jsonValue.isObject() || jsonValue.size() != 2 || !jsonValue.has("schema") || !jsonValue.has("payload"))) throw new DataException("JsonConverter with schemas.enable requires \"schema\" and \"payload\" fields and may not contain additional fields." + " If you are trying to deserialize plain JSON data, set schemas.enable=false in your converter configuration."); if (!enableSchemas) { ObjectNode envelope = JsonNodeFactory.instance.objectNode(); envelope.set("schema", null); envelope.set("payload", jsonValue); jsonValue = envelope; } return jsonToConnect(jsonValue); } }
JsonConverter implements Converter { @Override public SchemaAndValue toConnectData(String topic, byte[] value) { JsonNode jsonValue; try { jsonValue = deserializer.deserialize(topic, value); } catch (SerializationException e) { throw new DataException("Converting byte[] to Kafka Connect data failed due to serialization error: ", e); } if (enableSchemas && (jsonValue == null || !jsonValue.isObject() || jsonValue.size() != 2 || !jsonValue.has("schema") || !jsonValue.has("payload"))) throw new DataException("JsonConverter with schemas.enable requires \"schema\" and \"payload\" fields and may not contain additional fields." + " If you are trying to deserialize plain JSON data, set schemas.enable=false in your converter configuration."); if (!enableSchemas) { ObjectNode envelope = JsonNodeFactory.instance.objectNode(); envelope.set("schema", null); envelope.set("payload", jsonValue); jsonValue = envelope; } return jsonToConnect(jsonValue); } }
JsonConverter implements Converter { @Override public SchemaAndValue toConnectData(String topic, byte[] value) { JsonNode jsonValue; try { jsonValue = deserializer.deserialize(topic, value); } catch (SerializationException e) { throw new DataException("Converting byte[] to Kafka Connect data failed due to serialization error: ", e); } if (enableSchemas && (jsonValue == null || !jsonValue.isObject() || jsonValue.size() != 2 || !jsonValue.has("schema") || !jsonValue.has("payload"))) throw new DataException("JsonConverter with schemas.enable requires \"schema\" and \"payload\" fields and may not contain additional fields." + " If you are trying to deserialize plain JSON data, set schemas.enable=false in your converter configuration."); if (!enableSchemas) { ObjectNode envelope = JsonNodeFactory.instance.objectNode(); envelope.set("schema", null); envelope.set("payload", jsonValue); jsonValue = envelope; } return jsonToConnect(jsonValue); } @Override void configure(Map<String, ?> configs, boolean isKey); @Override byte[] fromConnectData(String topic, Schema schema, Object value); @Override SchemaAndValue toConnectData(String topic, byte[] value); ObjectNode asJsonSchema(Schema schema); Schema asConnectSchema(JsonNode jsonSchema); }
JsonConverter implements Converter { @Override public SchemaAndValue toConnectData(String topic, byte[] value) { JsonNode jsonValue; try { jsonValue = deserializer.deserialize(topic, value); } catch (SerializationException e) { throw new DataException("Converting byte[] to Kafka Connect data failed due to serialization error: ", e); } if (enableSchemas && (jsonValue == null || !jsonValue.isObject() || jsonValue.size() != 2 || !jsonValue.has("schema") || !jsonValue.has("payload"))) throw new DataException("JsonConverter with schemas.enable requires \"schema\" and \"payload\" fields and may not contain additional fields." + " If you are trying to deserialize plain JSON data, set schemas.enable=false in your converter configuration."); if (!enableSchemas) { ObjectNode envelope = JsonNodeFactory.instance.objectNode(); envelope.set("schema", null); envelope.set("payload", jsonValue); jsonValue = envelope; } return jsonToConnect(jsonValue); } @Override void configure(Map<String, ?> configs, boolean isKey); @Override byte[] fromConnectData(String topic, Schema schema, Object value); @Override SchemaAndValue toConnectData(String topic, byte[] value); ObjectNode asJsonSchema(Schema schema); Schema asConnectSchema(JsonNode jsonSchema); }
@Test public void shouldReturnEmptyIteratorIfNoData() throws Exception { final KeyValueIterator<Windowed<String>, Long> result = sessionStore.fetch("b"); assertFalse(result.hasNext()); }
private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); @Override KeyValueIterator<Windowed<K>, V> fetch(final K key); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); @Override KeyValueIterator<Windowed<K>, V> fetch(final K key); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to); }
@Test public void shouldFindValueForKeyWhenMultiStores() throws Exception { final ReadOnlySessionStoreStub<String, Long> secondUnderlying = new ReadOnlySessionStoreStub<>(); stubProviderTwo.addStore(storeName, secondUnderlying); final Windowed<String> keyOne = new Windowed<>("key-one", new SessionWindow(0, 0)); final Windowed<String> keyTwo = new Windowed<>("key-two", new SessionWindow(0, 0)); underlyingSessionStore.put(keyOne, 0L); secondUnderlying.put(keyTwo, 10L); final List<KeyValue<Windowed<String>, Long>> keyOneResults = toList(sessionStore.fetch("key-one")); final List<KeyValue<Windowed<String>, Long>> keyTwoResults = toList(sessionStore.fetch("key-two")); assertEquals(Collections.singletonList(KeyValue.pair(keyOne, 0L)), keyOneResults); assertEquals(Collections.singletonList(KeyValue.pair(keyTwo, 10L)), keyTwoResults); }
private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); @Override KeyValueIterator<Windowed<K>, V> fetch(final K key); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); @Override KeyValueIterator<Windowed<K>, V> fetch(final K key); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to); }
@Test public void shouldNotGetValueFromOtherStores() throws Exception { final Windowed<String> expectedKey = new Windowed<>("foo", new SessionWindow(0, 0)); otherUnderlyingStore.put(new Windowed<>("foo", new SessionWindow(10, 10)), 10L); underlyingSessionStore.put(expectedKey, 1L); final KeyValueIterator<Windowed<String>, Long> result = sessionStore.fetch("foo"); assertEquals(KeyValue.pair(expectedKey, 1L), result.next()); assertFalse(result.hasNext()); }
private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); @Override KeyValueIterator<Windowed<K>, V> fetch(final K key); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); @Override KeyValueIterator<Windowed<K>, V> fetch(final K key); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to); }
@Test(expected = InvalidStateStoreException.class) public void shouldThrowInvalidStateStoreExceptionOnRebalance() throws Exception { final CompositeReadOnlySessionStore<String, String> store = new CompositeReadOnlySessionStore<>(new StateStoreProviderStub(true), QueryableStoreTypes.<String, String>sessionStore(), "whateva"); store.fetch("a"); }
private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); @Override KeyValueIterator<Windowed<K>, V> fetch(final K key); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); @Override KeyValueIterator<Windowed<K>, V> fetch(final K key); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to); }
@Test(expected = InvalidStateStoreException.class) public void shouldThrowInvalidStateStoreExceptionIfFetchThrows() throws Exception { underlyingSessionStore.setOpen(false); underlyingSessionStore.fetch("key"); }
private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); @Override KeyValueIterator<Windowed<K>, V> fetch(final K key); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to); }
CompositeReadOnlySessionStore implements ReadOnlySessionStore<K, V> { private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) { final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType); for (final ReadOnlySessionStore<K, V> store : stores) { try { final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final InvalidStateStoreException ise) { throw new InvalidStateStoreException("State store [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return KeyValueIterators.emptyIterator(); } CompositeReadOnlySessionStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlySessionStore<K, V>> queryableStoreType, final String storeName); @Override KeyValueIterator<Windowed<K>, V> fetch(final K key); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to); }
@Test public void shouldNotThrowNullPointerWhenCacheIsEmptyAndEvictionCalled() throws Exception { cache.evict(); }
synchronized void evict() { if (tail == null) { return; } final LRUNode eldest = tail; currentSizeBytes -= eldest.size(); remove(eldest); cache.remove(eldest.key); if (eldest.entry.isDirty()) { flush(eldest); } }
NamedCache { synchronized void evict() { if (tail == null) { return; } final LRUNode eldest = tail; currentSizeBytes -= eldest.size(); remove(eldest); cache.remove(eldest.key); if (eldest.entry.isDirty()) { flush(eldest); } } }
NamedCache { synchronized void evict() { if (tail == null) { return; } final LRUNode eldest = tail; currentSizeBytes -= eldest.size(); remove(eldest); cache.remove(eldest.key); if (eldest.entry.isDirty()) { flush(eldest); } } NamedCache(final String name, final StreamsMetrics metrics); }
NamedCache { synchronized void evict() { if (tail == null) { return; } final LRUNode eldest = tail; currentSizeBytes -= eldest.size(); remove(eldest); cache.remove(eldest.key); if (eldest.entry.isDirty()) { flush(eldest); } } NamedCache(final String name, final StreamsMetrics metrics); long size(); }
NamedCache { synchronized void evict() { if (tail == null) { return; } final LRUNode eldest = tail; currentSizeBytes -= eldest.size(); remove(eldest); cache.remove(eldest.key); if (eldest.entry.isDirty()) { flush(eldest); } } NamedCache(final String name, final StreamsMetrics metrics); long size(); }
@Test(expected = IllegalStateException.class) public void shouldThrowIllegalStateExceptionWhenTryingToOverwriteDirtyEntryWithCleanEntry() throws Exception { cache.put(Bytes.wrap(new byte[]{0}), new LRUCacheEntry(new byte[]{10}, true, 0, 0, 0, "")); cache.put(Bytes.wrap(new byte[]{0}), new LRUCacheEntry(new byte[]{10}, false, 0, 0, 0, "")); }
synchronized void put(final Bytes key, final LRUCacheEntry value) { if (!value.isDirty() && dirtyKeys.contains(key)) { throw new IllegalStateException(String.format("Attempting to put a clean entry for key [%s] " + "into NamedCache [%s] when it already contains " + "a dirty entry for the same key", key, name)); } LRUNode node = cache.get(key); if (node != null) { numOverwrites++; currentSizeBytes -= node.size(); node.update(value); updateLRU(node); } else { node = new LRUNode(key, value); putHead(node); cache.put(key, node); } if (value.isDirty()) { dirtyKeys.remove(key); dirtyKeys.add(key); } currentSizeBytes += node.size(); }
NamedCache { synchronized void put(final Bytes key, final LRUCacheEntry value) { if (!value.isDirty() && dirtyKeys.contains(key)) { throw new IllegalStateException(String.format("Attempting to put a clean entry for key [%s] " + "into NamedCache [%s] when it already contains " + "a dirty entry for the same key", key, name)); } LRUNode node = cache.get(key); if (node != null) { numOverwrites++; currentSizeBytes -= node.size(); node.update(value); updateLRU(node); } else { node = new LRUNode(key, value); putHead(node); cache.put(key, node); } if (value.isDirty()) { dirtyKeys.remove(key); dirtyKeys.add(key); } currentSizeBytes += node.size(); } }
NamedCache { synchronized void put(final Bytes key, final LRUCacheEntry value) { if (!value.isDirty() && dirtyKeys.contains(key)) { throw new IllegalStateException(String.format("Attempting to put a clean entry for key [%s] " + "into NamedCache [%s] when it already contains " + "a dirty entry for the same key", key, name)); } LRUNode node = cache.get(key); if (node != null) { numOverwrites++; currentSizeBytes -= node.size(); node.update(value); updateLRU(node); } else { node = new LRUNode(key, value); putHead(node); cache.put(key, node); } if (value.isDirty()) { dirtyKeys.remove(key); dirtyKeys.add(key); } currentSizeBytes += node.size(); } NamedCache(final String name, final StreamsMetrics metrics); }
NamedCache { synchronized void put(final Bytes key, final LRUCacheEntry value) { if (!value.isDirty() && dirtyKeys.contains(key)) { throw new IllegalStateException(String.format("Attempting to put a clean entry for key [%s] " + "into NamedCache [%s] when it already contains " + "a dirty entry for the same key", key, name)); } LRUNode node = cache.get(key); if (node != null) { numOverwrites++; currentSizeBytes -= node.size(); node.update(value); updateLRU(node); } else { node = new LRUNode(key, value); putHead(node); cache.put(key, node); } if (value.isDirty()) { dirtyKeys.remove(key); dirtyKeys.add(key); } currentSizeBytes += node.size(); } NamedCache(final String name, final StreamsMetrics metrics); long size(); }
NamedCache { synchronized void put(final Bytes key, final LRUCacheEntry value) { if (!value.isDirty() && dirtyKeys.contains(key)) { throw new IllegalStateException(String.format("Attempting to put a clean entry for key [%s] " + "into NamedCache [%s] when it already contains " + "a dirty entry for the same key", key, name)); } LRUNode node = cache.get(key); if (node != null) { numOverwrites++; currentSizeBytes -= node.size(); node.update(value); updateLRU(node); } else { node = new LRUNode(key, value); putHead(node); cache.put(key, node); } if (value.isDirty()) { dirtyKeys.remove(key); dirtyKeys.add(key); } currentSizeBytes += node.size(); } NamedCache(final String name, final StreamsMetrics metrics); long size(); }
@Test public void shouldReturnNullIfKeyIsNull() throws Exception { assertNull(cache.get(null)); }
synchronized LRUCacheEntry get(final Bytes key) { if (key == null) { return null; } final LRUNode node = getInternal(key); if (node == null) { return null; } updateLRU(node); return node.entry; }
NamedCache { synchronized LRUCacheEntry get(final Bytes key) { if (key == null) { return null; } final LRUNode node = getInternal(key); if (node == null) { return null; } updateLRU(node); return node.entry; } }
NamedCache { synchronized LRUCacheEntry get(final Bytes key) { if (key == null) { return null; } final LRUNode node = getInternal(key); if (node == null) { return null; } updateLRU(node); return node.entry; } NamedCache(final String name, final StreamsMetrics metrics); }
NamedCache { synchronized LRUCacheEntry get(final Bytes key) { if (key == null) { return null; } final LRUNode node = getInternal(key); if (node == null) { return null; } updateLRU(node); return node.entry; } NamedCache(final String name, final StreamsMetrics metrics); long size(); }
NamedCache { synchronized LRUCacheEntry get(final Bytes key) { if (key == null) { return null; } final LRUNode node = getInternal(key); if (node == null) { return null; } updateLRU(node); return node.entry; } NamedCache(final String name, final StreamsMetrics metrics); long size(); }
@Test public void shouldFlushEvictedItemsIntoUnderlyingStore() throws Exception { int added = addItemsToCache(); final KeyValueIterator<Bytes, byte[]> iter = underlying.fetch(Bytes.wrap("0".getBytes()), DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP); final KeyValue<Bytes, byte[]> next = iter.next(); assertEquals(DEFAULT_TIMESTAMP, keySchema.segmentTimestamp(next.key)); assertArrayEquals("0".getBytes(), next.value); assertFalse(iter.hasNext()); assertEquals(added - 1, cache.size()); }
@Override public synchronized WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo) { validateStoreOpen(); final Bytes keyBytes = Bytes.wrap(serdes.rawKey(key)); final WindowStoreIterator<byte[]> underlyingIterator = underlying.fetch(keyBytes, timeFrom, timeTo); final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRangeFixedSize(keyBytes, timeFrom)); final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRangeFixedSize(keyBytes, timeTo)); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(name, cacheKeyFrom, cacheKeyTo); final HasNextCondition hasNextCondition = keySchema.hasNextCondition(keyBytes, keyBytes, timeFrom, timeTo); final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator( cacheIterator, hasNextCondition, cacheFunction ); return new MergedSortedCacheWindowStoreIterator<>(filteredCacheIterator, underlyingIterator, new StateSerdes<>(serdes.topic(), Serdes.Long(), serdes.valueSerde())); }
CachingWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V>, CachedStateStore<Windowed<K>, V> { @Override public synchronized WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo) { validateStoreOpen(); final Bytes keyBytes = Bytes.wrap(serdes.rawKey(key)); final WindowStoreIterator<byte[]> underlyingIterator = underlying.fetch(keyBytes, timeFrom, timeTo); final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRangeFixedSize(keyBytes, timeFrom)); final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRangeFixedSize(keyBytes, timeTo)); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(name, cacheKeyFrom, cacheKeyTo); final HasNextCondition hasNextCondition = keySchema.hasNextCondition(keyBytes, keyBytes, timeFrom, timeTo); final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator( cacheIterator, hasNextCondition, cacheFunction ); return new MergedSortedCacheWindowStoreIterator<>(filteredCacheIterator, underlyingIterator, new StateSerdes<>(serdes.topic(), Serdes.Long(), serdes.valueSerde())); } }
CachingWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V>, CachedStateStore<Windowed<K>, V> { @Override public synchronized WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo) { validateStoreOpen(); final Bytes keyBytes = Bytes.wrap(serdes.rawKey(key)); final WindowStoreIterator<byte[]> underlyingIterator = underlying.fetch(keyBytes, timeFrom, timeTo); final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRangeFixedSize(keyBytes, timeFrom)); final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRangeFixedSize(keyBytes, timeTo)); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(name, cacheKeyFrom, cacheKeyTo); final HasNextCondition hasNextCondition = keySchema.hasNextCondition(keyBytes, keyBytes, timeFrom, timeTo); final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator( cacheIterator, hasNextCondition, cacheFunction ); return new MergedSortedCacheWindowStoreIterator<>(filteredCacheIterator, underlyingIterator, new StateSerdes<>(serdes.topic(), Serdes.Long(), serdes.valueSerde())); } CachingWindowStore(final WindowStore<Bytes, byte[]> underlying, final Serde<K> keySerde, final Serde<V> valueSerde, final long windowSize, final long segmentInterval); }
CachingWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V>, CachedStateStore<Windowed<K>, V> { @Override public synchronized WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo) { validateStoreOpen(); final Bytes keyBytes = Bytes.wrap(serdes.rawKey(key)); final WindowStoreIterator<byte[]> underlyingIterator = underlying.fetch(keyBytes, timeFrom, timeTo); final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRangeFixedSize(keyBytes, timeFrom)); final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRangeFixedSize(keyBytes, timeTo)); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(name, cacheKeyFrom, cacheKeyTo); final HasNextCondition hasNextCondition = keySchema.hasNextCondition(keyBytes, keyBytes, timeFrom, timeTo); final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator( cacheIterator, hasNextCondition, cacheFunction ); return new MergedSortedCacheWindowStoreIterator<>(filteredCacheIterator, underlyingIterator, new StateSerdes<>(serdes.topic(), Serdes.Long(), serdes.valueSerde())); } CachingWindowStore(final WindowStore<Bytes, byte[]> underlying, final Serde<K> keySerde, final Serde<V> valueSerde, final long windowSize, final long segmentInterval); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); void setFlushListener(CacheFlushListener<Windowed<K>, V> flushListener); @Override synchronized void flush(); @Override void close(); @Override synchronized void put(final K key, final V value); @Override synchronized void put(final K key, final V value, final long timestamp); @Override synchronized WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
CachingWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V>, CachedStateStore<Windowed<K>, V> { @Override public synchronized WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo) { validateStoreOpen(); final Bytes keyBytes = Bytes.wrap(serdes.rawKey(key)); final WindowStoreIterator<byte[]> underlyingIterator = underlying.fetch(keyBytes, timeFrom, timeTo); final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRangeFixedSize(keyBytes, timeFrom)); final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRangeFixedSize(keyBytes, timeTo)); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(name, cacheKeyFrom, cacheKeyTo); final HasNextCondition hasNextCondition = keySchema.hasNextCondition(keyBytes, keyBytes, timeFrom, timeTo); final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator( cacheIterator, hasNextCondition, cacheFunction ); return new MergedSortedCacheWindowStoreIterator<>(filteredCacheIterator, underlyingIterator, new StateSerdes<>(serdes.topic(), Serdes.Long(), serdes.valueSerde())); } CachingWindowStore(final WindowStore<Bytes, byte[]> underlying, final Serde<K> keySerde, final Serde<V> valueSerde, final long windowSize, final long segmentInterval); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); void setFlushListener(CacheFlushListener<Windowed<K>, V> flushListener); @Override synchronized void flush(); @Override void close(); @Override synchronized void put(final K key, final V value); @Override synchronized void put(final K key, final V value, final long timestamp); @Override synchronized WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
@Test public void shouldFlushItemsToStoreOnEviction() throws Exception { final List<KeyValue<Windowed<String>, Long>> added = addSessionsUntilOverflow("a", "b", "c", "d"); assertEquals(added.size() - 1, cache.size()); final KeyValueIterator<Bytes, byte[]> iterator = underlying.fetch(Bytes.wrap(added.get(0).key.key().getBytes()), 0, 0); final KeyValue<Bytes, byte[]> next = iterator.next(); assertEquals(added.get(0).key, SessionKeySerde.from(next.key.get(), Serdes.String().deserializer(), "dummy")); assertArrayEquals(serdes.rawValue(added.get(0).value), next.value); }
@Override public KeyValueIterator<Windowed<K>, AGG> fetch(final K key) { return findSessions(key, 0, Long.MAX_VALUE); }
CachingSessionStore extends WrappedStateStore.AbstractStateStore implements SessionStore<K, AGG>, CachedStateStore<Windowed<K>, AGG> { @Override public KeyValueIterator<Windowed<K>, AGG> fetch(final K key) { return findSessions(key, 0, Long.MAX_VALUE); } }
CachingSessionStore extends WrappedStateStore.AbstractStateStore implements SessionStore<K, AGG>, CachedStateStore<Windowed<K>, AGG> { @Override public KeyValueIterator<Windowed<K>, AGG> fetch(final K key) { return findSessions(key, 0, Long.MAX_VALUE); } CachingSessionStore(final SessionStore<Bytes, byte[]> bytesStore, final Serde<K> keySerde, final Serde<AGG> aggSerde, final long segmentInterval); }
CachingSessionStore extends WrappedStateStore.AbstractStateStore implements SessionStore<K, AGG>, CachedStateStore<Windowed<K>, AGG> { @Override public KeyValueIterator<Windowed<K>, AGG> fetch(final K key) { return findSessions(key, 0, Long.MAX_VALUE); } CachingSessionStore(final SessionStore<Bytes, byte[]> bytesStore, final Serde<K> keySerde, final Serde<AGG> aggSerde, final long segmentInterval); void init(final ProcessorContext context, final StateStore root); KeyValueIterator<Windowed<K>, AGG> findSessions(final K key, final long earliestSessionEndTime, final long latestSessionStartTime); @Override KeyValueIterator<Windowed<K>, AGG> findSessions(K keyFrom, K keyTo, long earliestSessionEndTime, long latestSessionStartTime); @Override void remove(final Windowed<K> sessionKey); @Override void put(final Windowed<K> key, AGG value); @Override KeyValueIterator<Windowed<K>, AGG> fetch(final K key); @Override KeyValueIterator<Windowed<K>, AGG> fetch(K from, K to); void flush(); void close(); void setFlushListener(CacheFlushListener<Windowed<K>, AGG> flushListener); }
CachingSessionStore extends WrappedStateStore.AbstractStateStore implements SessionStore<K, AGG>, CachedStateStore<Windowed<K>, AGG> { @Override public KeyValueIterator<Windowed<K>, AGG> fetch(final K key) { return findSessions(key, 0, Long.MAX_VALUE); } CachingSessionStore(final SessionStore<Bytes, byte[]> bytesStore, final Serde<K> keySerde, final Serde<AGG> aggSerde, final long segmentInterval); void init(final ProcessorContext context, final StateStore root); KeyValueIterator<Windowed<K>, AGG> findSessions(final K key, final long earliestSessionEndTime, final long latestSessionStartTime); @Override KeyValueIterator<Windowed<K>, AGG> findSessions(K keyFrom, K keyTo, long earliestSessionEndTime, long latestSessionStartTime); @Override void remove(final Windowed<K> sessionKey); @Override void put(final Windowed<K> key, AGG value); @Override KeyValueIterator<Windowed<K>, AGG> fetch(final K key); @Override KeyValueIterator<Windowed<K>, AGG> fetch(K from, K to); void flush(); void close(); void setFlushListener(CacheFlushListener<Windowed<K>, AGG> flushListener); }
@Test public void shouldQueryItemsInCacheAndStore() throws Exception { final List<KeyValue<Windowed<String>, Long>> added = addSessionsUntilOverflow("a"); final KeyValueIterator<Windowed<String>, Long> iterator = cachingStore.findSessions("a", 0, added.size() * 10); final List<KeyValue<Windowed<String>, Long>> actual = toList(iterator); assertEquals(added, actual); }
public KeyValueIterator<Windowed<K>, AGG> findSessions(final K key, final long earliestSessionEndTime, final long latestSessionStartTime) { validateStoreOpen(); final Bytes binarySessionId = Bytes.wrap(serdes.rawKey(key)); final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRangeFixedSize(binarySessionId, earliestSessionEndTime)); final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRangeFixedSize(binarySessionId, latestSessionStartTime)); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, cacheKeyFrom, cacheKeyTo); final KeyValueIterator<Windowed<Bytes>, byte[]> storeIterator = bytesStore.findSessions( binarySessionId, earliestSessionEndTime, latestSessionStartTime ); final HasNextCondition hasNextCondition = keySchema.hasNextCondition(binarySessionId, binarySessionId, earliestSessionEndTime, latestSessionStartTime); final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator(cacheIterator, hasNextCondition, cacheFunction); return new MergedSortedCacheSessionStoreIterator<>(filteredCacheIterator, storeIterator, serdes, cacheFunction); }
CachingSessionStore extends WrappedStateStore.AbstractStateStore implements SessionStore<K, AGG>, CachedStateStore<Windowed<K>, AGG> { public KeyValueIterator<Windowed<K>, AGG> findSessions(final K key, final long earliestSessionEndTime, final long latestSessionStartTime) { validateStoreOpen(); final Bytes binarySessionId = Bytes.wrap(serdes.rawKey(key)); final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRangeFixedSize(binarySessionId, earliestSessionEndTime)); final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRangeFixedSize(binarySessionId, latestSessionStartTime)); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, cacheKeyFrom, cacheKeyTo); final KeyValueIterator<Windowed<Bytes>, byte[]> storeIterator = bytesStore.findSessions( binarySessionId, earliestSessionEndTime, latestSessionStartTime ); final HasNextCondition hasNextCondition = keySchema.hasNextCondition(binarySessionId, binarySessionId, earliestSessionEndTime, latestSessionStartTime); final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator(cacheIterator, hasNextCondition, cacheFunction); return new MergedSortedCacheSessionStoreIterator<>(filteredCacheIterator, storeIterator, serdes, cacheFunction); } }
CachingSessionStore extends WrappedStateStore.AbstractStateStore implements SessionStore<K, AGG>, CachedStateStore<Windowed<K>, AGG> { public KeyValueIterator<Windowed<K>, AGG> findSessions(final K key, final long earliestSessionEndTime, final long latestSessionStartTime) { validateStoreOpen(); final Bytes binarySessionId = Bytes.wrap(serdes.rawKey(key)); final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRangeFixedSize(binarySessionId, earliestSessionEndTime)); final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRangeFixedSize(binarySessionId, latestSessionStartTime)); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, cacheKeyFrom, cacheKeyTo); final KeyValueIterator<Windowed<Bytes>, byte[]> storeIterator = bytesStore.findSessions( binarySessionId, earliestSessionEndTime, latestSessionStartTime ); final HasNextCondition hasNextCondition = keySchema.hasNextCondition(binarySessionId, binarySessionId, earliestSessionEndTime, latestSessionStartTime); final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator(cacheIterator, hasNextCondition, cacheFunction); return new MergedSortedCacheSessionStoreIterator<>(filteredCacheIterator, storeIterator, serdes, cacheFunction); } CachingSessionStore(final SessionStore<Bytes, byte[]> bytesStore, final Serde<K> keySerde, final Serde<AGG> aggSerde, final long segmentInterval); }
CachingSessionStore extends WrappedStateStore.AbstractStateStore implements SessionStore<K, AGG>, CachedStateStore<Windowed<K>, AGG> { public KeyValueIterator<Windowed<K>, AGG> findSessions(final K key, final long earliestSessionEndTime, final long latestSessionStartTime) { validateStoreOpen(); final Bytes binarySessionId = Bytes.wrap(serdes.rawKey(key)); final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRangeFixedSize(binarySessionId, earliestSessionEndTime)); final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRangeFixedSize(binarySessionId, latestSessionStartTime)); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, cacheKeyFrom, cacheKeyTo); final KeyValueIterator<Windowed<Bytes>, byte[]> storeIterator = bytesStore.findSessions( binarySessionId, earliestSessionEndTime, latestSessionStartTime ); final HasNextCondition hasNextCondition = keySchema.hasNextCondition(binarySessionId, binarySessionId, earliestSessionEndTime, latestSessionStartTime); final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator(cacheIterator, hasNextCondition, cacheFunction); return new MergedSortedCacheSessionStoreIterator<>(filteredCacheIterator, storeIterator, serdes, cacheFunction); } CachingSessionStore(final SessionStore<Bytes, byte[]> bytesStore, final Serde<K> keySerde, final Serde<AGG> aggSerde, final long segmentInterval); void init(final ProcessorContext context, final StateStore root); KeyValueIterator<Windowed<K>, AGG> findSessions(final K key, final long earliestSessionEndTime, final long latestSessionStartTime); @Override KeyValueIterator<Windowed<K>, AGG> findSessions(K keyFrom, K keyTo, long earliestSessionEndTime, long latestSessionStartTime); @Override void remove(final Windowed<K> sessionKey); @Override void put(final Windowed<K> key, AGG value); @Override KeyValueIterator<Windowed<K>, AGG> fetch(final K key); @Override KeyValueIterator<Windowed<K>, AGG> fetch(K from, K to); void flush(); void close(); void setFlushListener(CacheFlushListener<Windowed<K>, AGG> flushListener); }
CachingSessionStore extends WrappedStateStore.AbstractStateStore implements SessionStore<K, AGG>, CachedStateStore<Windowed<K>, AGG> { public KeyValueIterator<Windowed<K>, AGG> findSessions(final K key, final long earliestSessionEndTime, final long latestSessionStartTime) { validateStoreOpen(); final Bytes binarySessionId = Bytes.wrap(serdes.rawKey(key)); final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRangeFixedSize(binarySessionId, earliestSessionEndTime)); final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRangeFixedSize(binarySessionId, latestSessionStartTime)); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, cacheKeyFrom, cacheKeyTo); final KeyValueIterator<Windowed<Bytes>, byte[]> storeIterator = bytesStore.findSessions( binarySessionId, earliestSessionEndTime, latestSessionStartTime ); final HasNextCondition hasNextCondition = keySchema.hasNextCondition(binarySessionId, binarySessionId, earliestSessionEndTime, latestSessionStartTime); final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator(cacheIterator, hasNextCondition, cacheFunction); return new MergedSortedCacheSessionStoreIterator<>(filteredCacheIterator, storeIterator, serdes, cacheFunction); } CachingSessionStore(final SessionStore<Bytes, byte[]> bytesStore, final Serde<K> keySerde, final Serde<AGG> aggSerde, final long segmentInterval); void init(final ProcessorContext context, final StateStore root); KeyValueIterator<Windowed<K>, AGG> findSessions(final K key, final long earliestSessionEndTime, final long latestSessionStartTime); @Override KeyValueIterator<Windowed<K>, AGG> findSessions(K keyFrom, K keyTo, long earliestSessionEndTime, long latestSessionStartTime); @Override void remove(final Windowed<K> sessionKey); @Override void put(final Windowed<K> key, AGG value); @Override KeyValueIterator<Windowed<K>, AGG> fetch(final K key); @Override KeyValueIterator<Windowed<K>, AGG> fetch(K from, K to); void flush(); void close(); void setFlushListener(CacheFlushListener<Windowed<K>, AGG> flushListener); }
@Test public void key() throws Exception { assertThat( cacheFunction.key(THE_CACHE_KEY), equalTo(THE_KEY) ); }
@Override public Bytes key(Bytes cacheKey) { return Bytes.wrap(bytesFromCacheKey(cacheKey)); }
SegmentedCacheFunction implements CacheFunction { @Override public Bytes key(Bytes cacheKey) { return Bytes.wrap(bytesFromCacheKey(cacheKey)); } }
SegmentedCacheFunction implements CacheFunction { @Override public Bytes key(Bytes cacheKey) { return Bytes.wrap(bytesFromCacheKey(cacheKey)); } SegmentedCacheFunction(KeySchema keySchema, long segmentInterval); }
SegmentedCacheFunction implements CacheFunction { @Override public Bytes key(Bytes cacheKey) { return Bytes.wrap(bytesFromCacheKey(cacheKey)); } SegmentedCacheFunction(KeySchema keySchema, long segmentInterval); @Override Bytes key(Bytes cacheKey); @Override Bytes cacheKey(Bytes key); long segmentId(Bytes key); }
SegmentedCacheFunction implements CacheFunction { @Override public Bytes key(Bytes cacheKey) { return Bytes.wrap(bytesFromCacheKey(cacheKey)); } SegmentedCacheFunction(KeySchema keySchema, long segmentInterval); @Override Bytes key(Bytes cacheKey); @Override Bytes cacheKey(Bytes key); long segmentId(Bytes key); }
@Test public void cacheKey() throws Exception { final long segmentId = TIMESTAMP / SEGMENT_INTERVAL; final Bytes actualCacheKey = cacheFunction.cacheKey(THE_KEY); final ByteBuffer buffer = ByteBuffer.wrap(actualCacheKey.get()); assertThat(buffer.getLong(), equalTo(segmentId)); byte[] actualKey = new byte[buffer.remaining()]; buffer.get(actualKey); assertThat(Bytes.wrap(actualKey), equalTo(THE_KEY)); }
@Override public Bytes cacheKey(Bytes key) { final byte[] keyBytes = key.get(); ByteBuffer buf = ByteBuffer.allocate(SEGMENT_ID_BYTES + keyBytes.length); buf.putLong(segmentId(key)).put(keyBytes); return Bytes.wrap(buf.array()); }
SegmentedCacheFunction implements CacheFunction { @Override public Bytes cacheKey(Bytes key) { final byte[] keyBytes = key.get(); ByteBuffer buf = ByteBuffer.allocate(SEGMENT_ID_BYTES + keyBytes.length); buf.putLong(segmentId(key)).put(keyBytes); return Bytes.wrap(buf.array()); } }
SegmentedCacheFunction implements CacheFunction { @Override public Bytes cacheKey(Bytes key) { final byte[] keyBytes = key.get(); ByteBuffer buf = ByteBuffer.allocate(SEGMENT_ID_BYTES + keyBytes.length); buf.putLong(segmentId(key)).put(keyBytes); return Bytes.wrap(buf.array()); } SegmentedCacheFunction(KeySchema keySchema, long segmentInterval); }
SegmentedCacheFunction implements CacheFunction { @Override public Bytes cacheKey(Bytes key) { final byte[] keyBytes = key.get(); ByteBuffer buf = ByteBuffer.allocate(SEGMENT_ID_BYTES + keyBytes.length); buf.putLong(segmentId(key)).put(keyBytes); return Bytes.wrap(buf.array()); } SegmentedCacheFunction(KeySchema keySchema, long segmentInterval); @Override Bytes key(Bytes cacheKey); @Override Bytes cacheKey(Bytes key); long segmentId(Bytes key); }
SegmentedCacheFunction implements CacheFunction { @Override public Bytes cacheKey(Bytes key) { final byte[] keyBytes = key.get(); ByteBuffer buf = ByteBuffer.allocate(SEGMENT_ID_BYTES + keyBytes.length); buf.putLong(segmentId(key)).put(keyBytes); return Bytes.wrap(buf.array()); } SegmentedCacheFunction(KeySchema keySchema, long segmentInterval); @Override Bytes key(Bytes cacheKey); @Override Bytes cacheKey(Bytes key); long segmentId(Bytes key); }
@Test public void compareSegmentedKeys() throws Exception { assertThat( "same key in same segment should be ranked the same", cacheFunction.compareSegmentedKeys( cacheFunction.cacheKey(THE_KEY), THE_KEY ) == 0 ); final Bytes sameKeyInPriorSegment = WindowStoreUtils.toBinaryKey(new byte[]{0xA, 0xB, 0xC}, 1234, 42); assertThat( "same keys in different segments should be ordered according to segment", cacheFunction.compareSegmentedKeys( cacheFunction.cacheKey(sameKeyInPriorSegment), THE_KEY ) < 0 ); assertThat( "same keys in different segments should be ordered according to segment", cacheFunction.compareSegmentedKeys( cacheFunction.cacheKey(THE_KEY), sameKeyInPriorSegment ) > 0 ); final Bytes lowerKeyInSameSegment = WindowStoreUtils.toBinaryKey(new byte[]{0xA, 0xB, 0xB}, TIMESTAMP - 1, 0); assertThat( "different keys in same segments should be ordered according to key", cacheFunction.compareSegmentedKeys( cacheFunction.cacheKey(THE_KEY), lowerKeyInSameSegment ) > 0 ); assertThat( "different keys in same segments should be ordered according to key", cacheFunction.compareSegmentedKeys( cacheFunction.cacheKey(lowerKeyInSameSegment), THE_KEY ) < 0 ); }
int compareSegmentedKeys(Bytes cacheKey, Bytes storeKey) { long storeSegmentId = segmentId(storeKey); long cacheSegmentId = ByteBuffer.wrap(cacheKey.get()).getLong(); final int segmentCompare = Long.compare(cacheSegmentId, storeSegmentId); if (segmentCompare == 0) { byte[] cacheKeyBytes = cacheKey.get(); byte[] storeKeyBytes = storeKey.get(); return Bytes.BYTES_LEXICO_COMPARATOR.compare( cacheKeyBytes, SEGMENT_ID_BYTES, cacheKeyBytes.length - SEGMENT_ID_BYTES, storeKeyBytes, 0, storeKeyBytes.length ); } else { return segmentCompare; } }
SegmentedCacheFunction implements CacheFunction { int compareSegmentedKeys(Bytes cacheKey, Bytes storeKey) { long storeSegmentId = segmentId(storeKey); long cacheSegmentId = ByteBuffer.wrap(cacheKey.get()).getLong(); final int segmentCompare = Long.compare(cacheSegmentId, storeSegmentId); if (segmentCompare == 0) { byte[] cacheKeyBytes = cacheKey.get(); byte[] storeKeyBytes = storeKey.get(); return Bytes.BYTES_LEXICO_COMPARATOR.compare( cacheKeyBytes, SEGMENT_ID_BYTES, cacheKeyBytes.length - SEGMENT_ID_BYTES, storeKeyBytes, 0, storeKeyBytes.length ); } else { return segmentCompare; } } }
SegmentedCacheFunction implements CacheFunction { int compareSegmentedKeys(Bytes cacheKey, Bytes storeKey) { long storeSegmentId = segmentId(storeKey); long cacheSegmentId = ByteBuffer.wrap(cacheKey.get()).getLong(); final int segmentCompare = Long.compare(cacheSegmentId, storeSegmentId); if (segmentCompare == 0) { byte[] cacheKeyBytes = cacheKey.get(); byte[] storeKeyBytes = storeKey.get(); return Bytes.BYTES_LEXICO_COMPARATOR.compare( cacheKeyBytes, SEGMENT_ID_BYTES, cacheKeyBytes.length - SEGMENT_ID_BYTES, storeKeyBytes, 0, storeKeyBytes.length ); } else { return segmentCompare; } } SegmentedCacheFunction(KeySchema keySchema, long segmentInterval); }
SegmentedCacheFunction implements CacheFunction { int compareSegmentedKeys(Bytes cacheKey, Bytes storeKey) { long storeSegmentId = segmentId(storeKey); long cacheSegmentId = ByteBuffer.wrap(cacheKey.get()).getLong(); final int segmentCompare = Long.compare(cacheSegmentId, storeSegmentId); if (segmentCompare == 0) { byte[] cacheKeyBytes = cacheKey.get(); byte[] storeKeyBytes = storeKey.get(); return Bytes.BYTES_LEXICO_COMPARATOR.compare( cacheKeyBytes, SEGMENT_ID_BYTES, cacheKeyBytes.length - SEGMENT_ID_BYTES, storeKeyBytes, 0, storeKeyBytes.length ); } else { return segmentCompare; } } SegmentedCacheFunction(KeySchema keySchema, long segmentInterval); @Override Bytes key(Bytes cacheKey); @Override Bytes cacheKey(Bytes key); long segmentId(Bytes key); }
SegmentedCacheFunction implements CacheFunction { int compareSegmentedKeys(Bytes cacheKey, Bytes storeKey) { long storeSegmentId = segmentId(storeKey); long cacheSegmentId = ByteBuffer.wrap(cacheKey.get()).getLong(); final int segmentCompare = Long.compare(cacheSegmentId, storeSegmentId); if (segmentCompare == 0) { byte[] cacheKeyBytes = cacheKey.get(); byte[] storeKeyBytes = storeKey.get(); return Bytes.BYTES_LEXICO_COMPARATOR.compare( cacheKeyBytes, SEGMENT_ID_BYTES, cacheKeyBytes.length - SEGMENT_ID_BYTES, storeKeyBytes, 0, storeKeyBytes.length ); } else { return segmentCompare; } } SegmentedCacheFunction(KeySchema keySchema, long segmentInterval); @Override Bytes key(Bytes cacheKey); @Override Bytes cacheKey(Bytes key); long segmentId(Bytes key); }
@Test public void shouldNotBlowUpOnNonExistentNamespaceWhenDeleting() throws Exception { final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics())); assertNull(cache.delete("name", Bytes.wrap(new byte[]{1}))); }
public LRUCacheEntry delete(final String namespace, final Bytes key) { final NamedCache cache = getCache(namespace); if (cache == null) { return null; } return cache.delete(key); }
ThreadCache { public LRUCacheEntry delete(final String namespace, final Bytes key) { final NamedCache cache = getCache(namespace); if (cache == null) { return null; } return cache.delete(key); } }
ThreadCache { public LRUCacheEntry delete(final String namespace, final Bytes key) { final NamedCache cache = getCache(namespace); if (cache == null) { return null; } return cache.delete(key); } ThreadCache(final String name, long maxCacheSizeBytes, final StreamsMetrics metrics); }
ThreadCache { public LRUCacheEntry delete(final String namespace, final Bytes key) { final NamedCache cache = getCache(namespace); if (cache == null) { return null; } return cache.delete(key); } ThreadCache(final String name, long maxCacheSizeBytes, final StreamsMetrics metrics); long puts(); long gets(); long evicts(); long flushes(); void addDirtyEntryFlushListener(final String namespace, DirtyEntryFlushListener listener); void flush(final String namespace); LRUCacheEntry get(final String namespace, Bytes key); void put(final String namespace, Bytes key, LRUCacheEntry value); LRUCacheEntry putIfAbsent(final String namespace, Bytes key, LRUCacheEntry value); void putAll(final String namespace, final List<KeyValue<Bytes, LRUCacheEntry>> entries); LRUCacheEntry delete(final String namespace, final Bytes key); MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to); MemoryLRUCacheBytesIterator all(final String namespace); long size(); }
ThreadCache { public LRUCacheEntry delete(final String namespace, final Bytes key) { final NamedCache cache = getCache(namespace); if (cache == null) { return null; } return cache.delete(key); } ThreadCache(final String name, long maxCacheSizeBytes, final StreamsMetrics metrics); long puts(); long gets(); long evicts(); long flushes(); void addDirtyEntryFlushListener(final String namespace, DirtyEntryFlushListener listener); void flush(final String namespace); LRUCacheEntry get(final String namespace, Bytes key); void put(final String namespace, Bytes key, LRUCacheEntry value); LRUCacheEntry putIfAbsent(final String namespace, Bytes key, LRUCacheEntry value); void putAll(final String namespace, final List<KeyValue<Bytes, LRUCacheEntry>> entries); LRUCacheEntry delete(final String namespace, final Bytes key); MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to); MemoryLRUCacheBytesIterator all(final String namespace); long size(); }
@Test(expected = NoSuchElementException.class) public void shouldThrowIfNoPeekNextKey() throws Exception { final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics())); final ThreadCache.MemoryLRUCacheBytesIterator iterator = cache.range("", Bytes.wrap(new byte[]{0}), Bytes.wrap(new byte[]{1})); iterator.peekNextKey(); }
public MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to) { final NamedCache cache = getCache(namespace); if (cache == null) { return new MemoryLRUCacheBytesIterator(Collections.<Bytes>emptyIterator(), new NamedCache(namespace, this.metrics)); } return new MemoryLRUCacheBytesIterator(cache.keyRange(from, to), cache); }
ThreadCache { public MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to) { final NamedCache cache = getCache(namespace); if (cache == null) { return new MemoryLRUCacheBytesIterator(Collections.<Bytes>emptyIterator(), new NamedCache(namespace, this.metrics)); } return new MemoryLRUCacheBytesIterator(cache.keyRange(from, to), cache); } }
ThreadCache { public MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to) { final NamedCache cache = getCache(namespace); if (cache == null) { return new MemoryLRUCacheBytesIterator(Collections.<Bytes>emptyIterator(), new NamedCache(namespace, this.metrics)); } return new MemoryLRUCacheBytesIterator(cache.keyRange(from, to), cache); } ThreadCache(final String name, long maxCacheSizeBytes, final StreamsMetrics metrics); }
ThreadCache { public MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to) { final NamedCache cache = getCache(namespace); if (cache == null) { return new MemoryLRUCacheBytesIterator(Collections.<Bytes>emptyIterator(), new NamedCache(namespace, this.metrics)); } return new MemoryLRUCacheBytesIterator(cache.keyRange(from, to), cache); } ThreadCache(final String name, long maxCacheSizeBytes, final StreamsMetrics metrics); long puts(); long gets(); long evicts(); long flushes(); void addDirtyEntryFlushListener(final String namespace, DirtyEntryFlushListener listener); void flush(final String namespace); LRUCacheEntry get(final String namespace, Bytes key); void put(final String namespace, Bytes key, LRUCacheEntry value); LRUCacheEntry putIfAbsent(final String namespace, Bytes key, LRUCacheEntry value); void putAll(final String namespace, final List<KeyValue<Bytes, LRUCacheEntry>> entries); LRUCacheEntry delete(final String namespace, final Bytes key); MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to); MemoryLRUCacheBytesIterator all(final String namespace); long size(); }
ThreadCache { public MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to) { final NamedCache cache = getCache(namespace); if (cache == null) { return new MemoryLRUCacheBytesIterator(Collections.<Bytes>emptyIterator(), new NamedCache(namespace, this.metrics)); } return new MemoryLRUCacheBytesIterator(cache.keyRange(from, to), cache); } ThreadCache(final String name, long maxCacheSizeBytes, final StreamsMetrics metrics); long puts(); long gets(); long evicts(); long flushes(); void addDirtyEntryFlushListener(final String namespace, DirtyEntryFlushListener listener); void flush(final String namespace); LRUCacheEntry get(final String namespace, Bytes key); void put(final String namespace, Bytes key, LRUCacheEntry value); LRUCacheEntry putIfAbsent(final String namespace, Bytes key, LRUCacheEntry value); void putAll(final String namespace, final List<KeyValue<Bytes, LRUCacheEntry>> entries); LRUCacheEntry delete(final String namespace, final Bytes key); MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to); MemoryLRUCacheBytesIterator all(final String namespace); long size(); }
@Test public void shouldReturnFalseIfNoNextKey() throws Exception { final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics())); final ThreadCache.MemoryLRUCacheBytesIterator iterator = cache.range("", Bytes.wrap(new byte[]{0}), Bytes.wrap(new byte[]{1})); assertFalse(iterator.hasNext()); }
public MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to) { final NamedCache cache = getCache(namespace); if (cache == null) { return new MemoryLRUCacheBytesIterator(Collections.<Bytes>emptyIterator(), new NamedCache(namespace, this.metrics)); } return new MemoryLRUCacheBytesIterator(cache.keyRange(from, to), cache); }
ThreadCache { public MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to) { final NamedCache cache = getCache(namespace); if (cache == null) { return new MemoryLRUCacheBytesIterator(Collections.<Bytes>emptyIterator(), new NamedCache(namespace, this.metrics)); } return new MemoryLRUCacheBytesIterator(cache.keyRange(from, to), cache); } }
ThreadCache { public MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to) { final NamedCache cache = getCache(namespace); if (cache == null) { return new MemoryLRUCacheBytesIterator(Collections.<Bytes>emptyIterator(), new NamedCache(namespace, this.metrics)); } return new MemoryLRUCacheBytesIterator(cache.keyRange(from, to), cache); } ThreadCache(final String name, long maxCacheSizeBytes, final StreamsMetrics metrics); }
ThreadCache { public MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to) { final NamedCache cache = getCache(namespace); if (cache == null) { return new MemoryLRUCacheBytesIterator(Collections.<Bytes>emptyIterator(), new NamedCache(namespace, this.metrics)); } return new MemoryLRUCacheBytesIterator(cache.keyRange(from, to), cache); } ThreadCache(final String name, long maxCacheSizeBytes, final StreamsMetrics metrics); long puts(); long gets(); long evicts(); long flushes(); void addDirtyEntryFlushListener(final String namespace, DirtyEntryFlushListener listener); void flush(final String namespace); LRUCacheEntry get(final String namespace, Bytes key); void put(final String namespace, Bytes key, LRUCacheEntry value); LRUCacheEntry putIfAbsent(final String namespace, Bytes key, LRUCacheEntry value); void putAll(final String namespace, final List<KeyValue<Bytes, LRUCacheEntry>> entries); LRUCacheEntry delete(final String namespace, final Bytes key); MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to); MemoryLRUCacheBytesIterator all(final String namespace); long size(); }
ThreadCache { public MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to) { final NamedCache cache = getCache(namespace); if (cache == null) { return new MemoryLRUCacheBytesIterator(Collections.<Bytes>emptyIterator(), new NamedCache(namespace, this.metrics)); } return new MemoryLRUCacheBytesIterator(cache.keyRange(from, to), cache); } ThreadCache(final String name, long maxCacheSizeBytes, final StreamsMetrics metrics); long puts(); long gets(); long evicts(); long flushes(); void addDirtyEntryFlushListener(final String namespace, DirtyEntryFlushListener listener); void flush(final String namespace); LRUCacheEntry get(final String namespace, Bytes key); void put(final String namespace, Bytes key, LRUCacheEntry value); LRUCacheEntry putIfAbsent(final String namespace, Bytes key, LRUCacheEntry value); void putAll(final String namespace, final List<KeyValue<Bytes, LRUCacheEntry>> entries); LRUCacheEntry delete(final String namespace, final Bytes key); MemoryLRUCacheBytesIterator range(final String namespace, final Bytes from, final Bytes to); MemoryLRUCacheBytesIterator all(final String namespace); long size(); }
@Test public void shouldGetSegmentIdsFromTimestamp() throws Exception { assertEquals(0, segments.segmentId(0)); assertEquals(1, segments.segmentId(60000)); assertEquals(2, segments.segmentId(120000)); assertEquals(3, segments.segmentId(180000)); }
long segmentId(long timestamp) { return timestamp / segmentInterval; }
Segments { long segmentId(long timestamp) { return timestamp / segmentInterval; } }
Segments { long segmentId(long timestamp) { return timestamp / segmentInterval; } Segments(final String name, final long retentionPeriod, final int numSegments); }
Segments { long segmentId(long timestamp) { return timestamp / segmentInterval; } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
Segments { long segmentId(long timestamp) { return timestamp / segmentInterval; } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
@Test public void shouldBaseSegmentIntervalOnRetentionAndNumSegments() throws Exception { final Segments segments = new Segments("test", 8 * 60 * 1000, 5); assertEquals(0, segments.segmentId(0)); assertEquals(0, segments.segmentId(60000)); assertEquals(1, segments.segmentId(120000)); }
long segmentId(long timestamp) { return timestamp / segmentInterval; }
Segments { long segmentId(long timestamp) { return timestamp / segmentInterval; } }
Segments { long segmentId(long timestamp) { return timestamp / segmentInterval; } Segments(final String name, final long retentionPeriod, final int numSegments); }
Segments { long segmentId(long timestamp) { return timestamp / segmentInterval; } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
Segments { long segmentId(long timestamp) { return timestamp / segmentInterval; } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
@Test public void shouldGetSegmentNameFromId() throws Exception { assertEquals("test-197001010000", segments.segmentName(0)); assertEquals("test-197001010001", segments.segmentName(1)); assertEquals("test-197001010002", segments.segmentName(2)); }
String segmentName(long segmentId) { return name + "-" + formatter.format(new Date(segmentId * segmentInterval)); }
Segments { String segmentName(long segmentId) { return name + "-" + formatter.format(new Date(segmentId * segmentInterval)); } }
Segments { String segmentName(long segmentId) { return name + "-" + formatter.format(new Date(segmentId * segmentInterval)); } Segments(final String name, final long retentionPeriod, final int numSegments); }
Segments { String segmentName(long segmentId) { return name + "-" + formatter.format(new Date(segmentId * segmentInterval)); } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
Segments { String segmentName(long segmentId) { return name + "-" + formatter.format(new Date(segmentId * segmentInterval)); } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
@Test public void shouldCreateSegments() throws Exception { final Segment segment1 = segments.getOrCreateSegment(0, context); final Segment segment2 = segments.getOrCreateSegment(1, context); final Segment segment3 = segments.getOrCreateSegment(2, context); assertTrue(new File(context.stateDir(), "test/test-197001010000").isDirectory()); assertTrue(new File(context.stateDir(), "test/test-197001010001").isDirectory()); assertTrue(new File(context.stateDir(), "test/test-197001010002").isDirectory()); assertEquals(true, segment1.isOpen()); assertEquals(true, segment2.isOpen()); assertEquals(true, segment3.isOpen()); }
Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } Segments(final String name, final long retentionPeriod, final int numSegments); }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
@Test public void shouldNotCreateSegmentThatIsAlreadyExpired() throws Exception { segments.getOrCreateSegment(7, context); assertNull(segments.getOrCreateSegment(0, context)); assertFalse(new File(context.stateDir(), "test/test-197001010000").exists()); }
Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } Segments(final String name, final long retentionPeriod, final int numSegments); }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
@Test public void shouldCleanupSegmentsThatHaveExpired() throws Exception { final Segment segment1 = segments.getOrCreateSegment(0, context); final Segment segment2 = segments.getOrCreateSegment(0, context); final Segment segment3 = segments.getOrCreateSegment(7, context); assertFalse(segment1.isOpen()); assertFalse(segment2.isOpen()); assertTrue(segment3.isOpen()); assertFalse(new File(context.stateDir(), "test/test-197001010000").exists()); assertFalse(new File(context.stateDir(), "test/test-197001010001").exists()); assertTrue(new File(context.stateDir(), "test/test-197001010007").exists()); }
Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } Segments(final String name, final long retentionPeriod, final int numSegments); }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
@Test public void shouldRollSegments() throws Exception { segments.getOrCreateSegment(0, context); verifyCorrectSegments(0, 1); segments.getOrCreateSegment(1, context); verifyCorrectSegments(0, 2); segments.getOrCreateSegment(2, context); verifyCorrectSegments(0, 3); segments.getOrCreateSegment(3, context); verifyCorrectSegments(0, 4); segments.getOrCreateSegment(4, context); verifyCorrectSegments(0, 5); segments.getOrCreateSegment(5, context); verifyCorrectSegments(1, 5); segments.getOrCreateSegment(6, context); verifyCorrectSegments(2, 5); }
Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } Segments(final String name, final long retentionPeriod, final int numSegments); }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
Segments { Segment getOrCreateSegment(final long segmentId, final ProcessorContext context) { if (segmentId > maxSegmentId - numSegments) { final long key = segmentId % numSegments; final Segment segment = segments.get(key); if (!isSegment(segment, segmentId)) { cleanup(segmentId); } Segment newSegment = new Segment(segmentName(segmentId), name, segmentId); Segment previousSegment = segments.putIfAbsent(key, newSegment); if (previousSegment == null) { newSegment.openDB(context); maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId; if (minSegmentId == Long.MAX_VALUE) { minSegmentId = maxSegmentId; } } return previousSegment == null ? newSegment : previousSegment; } else { return null; } } Segments(final String name, final long retentionPeriod, final int numSegments); void close(); }
@Test public void shouldIterateAllStoredItems() throws Exception { int items = addItemsToCache(); final KeyValueIterator<String, String> all = store.all(); final List<String> results = new ArrayList<>(); while (all.hasNext()) { results.add(all.next().key); } assertEquals(items, results.size()); }
@Override public KeyValueIterator<K, V> all() { validateStoreOpen(); final KeyValueIterator<Bytes, byte[]> storeIterator = new DelegatingPeekingKeyValueIterator<>(this.name(), underlying.all()); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.all(cacheName); return new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes); }
CachingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V>, CachedStateStore<K, V> { @Override public KeyValueIterator<K, V> all() { validateStoreOpen(); final KeyValueIterator<Bytes, byte[]> storeIterator = new DelegatingPeekingKeyValueIterator<>(this.name(), underlying.all()); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.all(cacheName); return new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes); } }
CachingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V>, CachedStateStore<K, V> { @Override public KeyValueIterator<K, V> all() { validateStoreOpen(); final KeyValueIterator<Bytes, byte[]> storeIterator = new DelegatingPeekingKeyValueIterator<>(this.name(), underlying.all()); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.all(cacheName); return new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes); } CachingKeyValueStore(final KeyValueStore<Bytes, byte[]> underlying, final Serde<K> keySerde, final Serde<V> valueSerde); }
CachingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V>, CachedStateStore<K, V> { @Override public KeyValueIterator<K, V> all() { validateStoreOpen(); final KeyValueIterator<Bytes, byte[]> storeIterator = new DelegatingPeekingKeyValueIterator<>(this.name(), underlying.all()); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.all(cacheName); return new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes); } CachingKeyValueStore(final KeyValueStore<Bytes, byte[]> underlying, final Serde<K> keySerde, final Serde<V> valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); void setFlushListener(final CacheFlushListener<K, V> flushListener); @Override synchronized void flush(); @Override void close(); @Override boolean persistent(); @Override boolean isOpen(); @Override synchronized V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override synchronized long approximateNumEntries(); @Override synchronized void put(final K key, final V value); @Override synchronized V putIfAbsent(final K key, final V value); @Override synchronized void putAll(final List<KeyValue<K, V>> entries); @Override synchronized V delete(final K key); @Override StateStore inner(); }
CachingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V>, CachedStateStore<K, V> { @Override public KeyValueIterator<K, V> all() { validateStoreOpen(); final KeyValueIterator<Bytes, byte[]> storeIterator = new DelegatingPeekingKeyValueIterator<>(this.name(), underlying.all()); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.all(cacheName); return new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes); } CachingKeyValueStore(final KeyValueStore<Bytes, byte[]> underlying, final Serde<K> keySerde, final Serde<V> valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); void setFlushListener(final CacheFlushListener<K, V> flushListener); @Override synchronized void flush(); @Override void close(); @Override boolean persistent(); @Override boolean isOpen(); @Override synchronized V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override synchronized long approximateNumEntries(); @Override synchronized void put(final K key, final V value); @Override synchronized V putIfAbsent(final K key, final V value); @Override synchronized void putAll(final List<KeyValue<K, V>> entries); @Override synchronized V delete(final K key); @Override StateStore inner(); }
@Test public void shouldIterateOverRange() throws Exception { int items = addItemsToCache(); final KeyValueIterator<String, String> range = store.range(String.valueOf(0), String.valueOf(items)); final List<String> results = new ArrayList<>(); while (range.hasNext()) { results.add(range.next().key); } assertEquals(items, results.size()); }
@Override public KeyValueIterator<K, V> range(final K from, final K to) { validateStoreOpen(); final Bytes origFrom = Bytes.wrap(serdes.rawKey(from)); final Bytes origTo = Bytes.wrap(serdes.rawKey(to)); final KeyValueIterator<Bytes, byte[]> storeIterator = underlying.range(origFrom, origTo); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, origFrom, origTo); return new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes); }
CachingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V>, CachedStateStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { validateStoreOpen(); final Bytes origFrom = Bytes.wrap(serdes.rawKey(from)); final Bytes origTo = Bytes.wrap(serdes.rawKey(to)); final KeyValueIterator<Bytes, byte[]> storeIterator = underlying.range(origFrom, origTo); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, origFrom, origTo); return new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes); } }
CachingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V>, CachedStateStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { validateStoreOpen(); final Bytes origFrom = Bytes.wrap(serdes.rawKey(from)); final Bytes origTo = Bytes.wrap(serdes.rawKey(to)); final KeyValueIterator<Bytes, byte[]> storeIterator = underlying.range(origFrom, origTo); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, origFrom, origTo); return new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes); } CachingKeyValueStore(final KeyValueStore<Bytes, byte[]> underlying, final Serde<K> keySerde, final Serde<V> valueSerde); }
CachingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V>, CachedStateStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { validateStoreOpen(); final Bytes origFrom = Bytes.wrap(serdes.rawKey(from)); final Bytes origTo = Bytes.wrap(serdes.rawKey(to)); final KeyValueIterator<Bytes, byte[]> storeIterator = underlying.range(origFrom, origTo); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, origFrom, origTo); return new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes); } CachingKeyValueStore(final KeyValueStore<Bytes, byte[]> underlying, final Serde<K> keySerde, final Serde<V> valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); void setFlushListener(final CacheFlushListener<K, V> flushListener); @Override synchronized void flush(); @Override void close(); @Override boolean persistent(); @Override boolean isOpen(); @Override synchronized V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override synchronized long approximateNumEntries(); @Override synchronized void put(final K key, final V value); @Override synchronized V putIfAbsent(final K key, final V value); @Override synchronized void putAll(final List<KeyValue<K, V>> entries); @Override synchronized V delete(final K key); @Override StateStore inner(); }
CachingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V>, CachedStateStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { validateStoreOpen(); final Bytes origFrom = Bytes.wrap(serdes.rawKey(from)); final Bytes origTo = Bytes.wrap(serdes.rawKey(to)); final KeyValueIterator<Bytes, byte[]> storeIterator = underlying.range(origFrom, origTo); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, origFrom, origTo); return new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes); } CachingKeyValueStore(final KeyValueStore<Bytes, byte[]> underlying, final Serde<K> keySerde, final Serde<V> valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); void setFlushListener(final CacheFlushListener<K, V> flushListener); @Override synchronized void flush(); @Override void close(); @Override boolean persistent(); @Override boolean isOpen(); @Override synchronized V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override synchronized long approximateNumEntries(); @Override synchronized void put(final K key, final V value); @Override synchronized V putIfAbsent(final K key, final V value); @Override synchronized void putAll(final List<KeyValue<K, V>> entries); @Override synchronized V delete(final K key); @Override StateStore inner(); }
@Test public void shouldReturnNullIfKeyIsNull() throws Exception { assertNull(store.get(null)); }
@Override public synchronized V get(final K key) { validateStoreOpen(); if (key == null) { return null; } final byte[] rawKey = serdes.rawKey(key); return get(rawKey); }
CachingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V>, CachedStateStore<K, V> { @Override public synchronized V get(final K key) { validateStoreOpen(); if (key == null) { return null; } final byte[] rawKey = serdes.rawKey(key); return get(rawKey); } }
CachingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V>, CachedStateStore<K, V> { @Override public synchronized V get(final K key) { validateStoreOpen(); if (key == null) { return null; } final byte[] rawKey = serdes.rawKey(key); return get(rawKey); } CachingKeyValueStore(final KeyValueStore<Bytes, byte[]> underlying, final Serde<K> keySerde, final Serde<V> valueSerde); }
CachingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V>, CachedStateStore<K, V> { @Override public synchronized V get(final K key) { validateStoreOpen(); if (key == null) { return null; } final byte[] rawKey = serdes.rawKey(key); return get(rawKey); } CachingKeyValueStore(final KeyValueStore<Bytes, byte[]> underlying, final Serde<K> keySerde, final Serde<V> valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); void setFlushListener(final CacheFlushListener<K, V> flushListener); @Override synchronized void flush(); @Override void close(); @Override boolean persistent(); @Override boolean isOpen(); @Override synchronized V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override synchronized long approximateNumEntries(); @Override synchronized void put(final K key, final V value); @Override synchronized V putIfAbsent(final K key, final V value); @Override synchronized void putAll(final List<KeyValue<K, V>> entries); @Override synchronized V delete(final K key); @Override StateStore inner(); }
CachingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V>, CachedStateStore<K, V> { @Override public synchronized V get(final K key) { validateStoreOpen(); if (key == null) { return null; } final byte[] rawKey = serdes.rawKey(key); return get(rawKey); } CachingKeyValueStore(final KeyValueStore<Bytes, byte[]> underlying, final Serde<K> keySerde, final Serde<V> valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); void setFlushListener(final CacheFlushListener<K, V> flushListener); @Override synchronized void flush(); @Override void close(); @Override boolean persistent(); @Override boolean isOpen(); @Override synchronized V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override synchronized long approximateNumEntries(); @Override synchronized void put(final K key, final V value); @Override synchronized V putIfAbsent(final K key, final V value); @Override synchronized void putAll(final List<KeyValue<K, V>> entries); @Override synchronized V delete(final K key); @Override StateStore inner(); }
@Test(expected = NoSuchElementException.class) public void shouldThrowNoSuchElementOnPeekNextKeyIfNoNext() throws Exception { iterator = new SegmentIterator(Arrays.asList(segmentOne, segmentTwo).iterator(), hasNextCondition, Bytes.wrap("f".getBytes()), Bytes.wrap("h".getBytes())); iterator.peekNextKey(); }
@Override public Bytes peekNextKey() { if (!hasNext()) { throw new NoSuchElementException(); } return currentIterator.peekNextKey(); }
SegmentIterator implements KeyValueIterator<Bytes, byte[]> { @Override public Bytes peekNextKey() { if (!hasNext()) { throw new NoSuchElementException(); } return currentIterator.peekNextKey(); } }
SegmentIterator implements KeyValueIterator<Bytes, byte[]> { @Override public Bytes peekNextKey() { if (!hasNext()) { throw new NoSuchElementException(); } return currentIterator.peekNextKey(); } SegmentIterator(final Iterator<Segment> segments, final HasNextCondition hasNextCondition, final Bytes from, final Bytes to); }
SegmentIterator implements KeyValueIterator<Bytes, byte[]> { @Override public Bytes peekNextKey() { if (!hasNext()) { throw new NoSuchElementException(); } return currentIterator.peekNextKey(); } SegmentIterator(final Iterator<Segment> segments, final HasNextCondition hasNextCondition, final Bytes from, final Bytes to); void close(); @Override Bytes peekNextKey(); @Override boolean hasNext(); KeyValue<Bytes, byte[]> next(); void remove(); }
SegmentIterator implements KeyValueIterator<Bytes, byte[]> { @Override public Bytes peekNextKey() { if (!hasNext()) { throw new NoSuchElementException(); } return currentIterator.peekNextKey(); } SegmentIterator(final Iterator<Segment> segments, final HasNextCondition hasNextCondition, final Bytes from, final Bytes to); void close(); @Override Bytes peekNextKey(); @Override boolean hasNext(); KeyValue<Bytes, byte[]> next(); void remove(); }
@Test(expected = NoSuchElementException.class) public void shouldThrowNoSuchElementOnNextIfNoNext() throws Exception { iterator = new SegmentIterator(Arrays.asList(segmentOne, segmentTwo).iterator(), hasNextCondition, Bytes.wrap("f".getBytes()), Bytes.wrap("h".getBytes())); iterator.next(); }
public KeyValue<Bytes, byte[]> next() { if (!hasNext()) { throw new NoSuchElementException(); } return currentIterator.next(); }
SegmentIterator implements KeyValueIterator<Bytes, byte[]> { public KeyValue<Bytes, byte[]> next() { if (!hasNext()) { throw new NoSuchElementException(); } return currentIterator.next(); } }
SegmentIterator implements KeyValueIterator<Bytes, byte[]> { public KeyValue<Bytes, byte[]> next() { if (!hasNext()) { throw new NoSuchElementException(); } return currentIterator.next(); } SegmentIterator(final Iterator<Segment> segments, final HasNextCondition hasNextCondition, final Bytes from, final Bytes to); }
SegmentIterator implements KeyValueIterator<Bytes, byte[]> { public KeyValue<Bytes, byte[]> next() { if (!hasNext()) { throw new NoSuchElementException(); } return currentIterator.next(); } SegmentIterator(final Iterator<Segment> segments, final HasNextCondition hasNextCondition, final Bytes from, final Bytes to); void close(); @Override Bytes peekNextKey(); @Override boolean hasNext(); KeyValue<Bytes, byte[]> next(); void remove(); }
SegmentIterator implements KeyValueIterator<Bytes, byte[]> { public KeyValue<Bytes, byte[]> next() { if (!hasNext()) { throw new NoSuchElementException(); } return currentIterator.next(); } SegmentIterator(final Iterator<Segment> segments, final HasNextCondition hasNextCondition, final Bytes from, final Bytes to); void close(); @Override Bytes peekNextKey(); @Override boolean hasNext(); KeyValue<Bytes, byte[]> next(); void remove(); }
@Test public void shouldFetchValuesFromWindowStore() throws Exception { underlyingWindowStore.put("my-key", "my-value", 0L); underlyingWindowStore.put("my-key", "my-later-value", 10L); final WindowStoreIterator<String> iterator = windowStore.fetch("my-key", 0L, 25L); final List<KeyValue<Long, String>> results = StreamsTestUtils.toList(iterator); assertEquals(asList(new KeyValue<>(0L, "my-value"), new KeyValue<>(10L, "my-later-value")), results); }
public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
@Test public void shouldReturnEmptyIteratorIfNoData() throws Exception { final WindowStoreIterator<String> iterator = windowStore.fetch("my-key", 0L, 25L); assertEquals(false, iterator.hasNext()); }
public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
@Test public void shouldFindValueForKeyWhenMultiStores() throws Exception { final ReadOnlyWindowStoreStub<String, String> secondUnderlying = new ReadOnlyWindowStoreStub<>(WINDOW_SIZE); stubProviderTwo.addStore(storeName, secondUnderlying); underlyingWindowStore.put("key-one", "value-one", 0L); secondUnderlying.put("key-two", "value-two", 10L); final List<KeyValue<Long, String>> keyOneResults = StreamsTestUtils.toList(windowStore.fetch("key-one", 0L, 1L)); final List<KeyValue<Long, String>> keyTwoResults = StreamsTestUtils.toList(windowStore.fetch("key-two", 10L, 11L)); assertEquals(Collections.singletonList(KeyValue.pair(0L, "value-one")), keyOneResults); assertEquals(Collections.singletonList(KeyValue.pair(10L, "value-two")), keyTwoResults); }
public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
@Test public void shouldNotGetValuesFromOtherStores() throws Exception { otherUnderlyingStore.put("some-key", "some-value", 0L); underlyingWindowStore.put("some-key", "my-value", 1L); final List<KeyValue<Long, String>> results = StreamsTestUtils.toList(windowStore.fetch("some-key", 0L, 2L)); assertEquals(Collections.singletonList(new KeyValue<>(1L, "my-value")), results); }
public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
@Test(expected = InvalidStateStoreException.class) public void shouldThrowInvalidStateStoreExceptionOnRebalance() throws Exception { final CompositeReadOnlyWindowStore<Object, Object> store = new CompositeReadOnlyWindowStore<>(new StateStoreProviderStub(true), QueryableStoreTypes.windowStore(), "foo"); store.fetch("key", 1, 10); }
public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
@Test public void shouldThrowInvalidStateStoreExceptionIfFetchThrows() throws Exception { underlyingWindowStore.setOpen(false); final CompositeReadOnlyWindowStore<Object, Object> store = new CompositeReadOnlyWindowStore<>(stubProviderOne, QueryableStoreTypes.windowStore(), "window-store"); try { store.fetch("key", 1, 10); Assert.fail("InvalidStateStoreException was expected"); } catch (InvalidStateStoreException e) { Assert.assertEquals("State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata.", e.getMessage()); } }
public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
@Test public void emptyIteratorAlwaysReturnsFalse() throws Exception { final CompositeReadOnlyWindowStore<Object, Object> store = new CompositeReadOnlyWindowStore<>(new StateStoreProviderStub(false), QueryableStoreTypes.windowStore(), "foo"); final WindowStoreIterator<Object> windowStoreIterator = store.fetch("key", 1, 10); Assert.assertFalse(windowStoreIterator.hasNext()); }
public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
@Test public void emptyIteratorPeekNextKeyShouldThrowNoSuchElementException() throws Exception { final CompositeReadOnlyWindowStore<Object, Object> store = new CompositeReadOnlyWindowStore<>(new StateStoreProviderStub(false), QueryableStoreTypes.windowStore(), "foo"); final WindowStoreIterator<Object> windowStoreIterator = store.fetch("key", 1, 10); windowStoreIteratorException.expect(NoSuchElementException.class); windowStoreIterator.peekNextKey(); }
public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
@Test public void emptyIteratorNextShouldThrowNoSuchElementException() throws Exception { final CompositeReadOnlyWindowStore<Object, Object> store = new CompositeReadOnlyWindowStore<>(new StateStoreProviderStub(false), QueryableStoreTypes.windowStore(), "foo"); final WindowStoreIterator<Object> windowStoreIterator = store.fetch("key", 1, 10); windowStoreIteratorException.expect(NoSuchElementException.class); windowStoreIterator.next(); }
public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
CompositeReadOnlyWindowStore implements ReadOnlyWindowStore<K, V> { public <IteratorType extends KeyValueIterator<?, V>> IteratorType fetch(Fetcher<K, V, IteratorType> fetcher) { final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (ReadOnlyWindowStore<K, V> windowStore : stores) { try { final IteratorType result = fetcher.fetch(windowStore); if (!result.hasNext()) { result.close(); } else { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException( "State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata."); } } return fetcher.empty(); } CompositeReadOnlyWindowStore(final StateStoreProvider provider, final QueryableStoreType<ReadOnlyWindowStore<K, V>> windowStoreType, final String storeName); IteratorType fetch(Fetcher<K, V, IteratorType> fetcher); @Override WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo); }
@Test(expected = UnsupportedOperationException.class) public void shouldThrowUnsupportedOperationExeceptionOnRemove() throws Exception { allIterator.remove(); }
@Override public void remove() { throw new UnsupportedOperationException(); }
FilteredCacheIterator implements PeekingKeyValueIterator<Bytes, LRUCacheEntry> { @Override public void remove() { throw new UnsupportedOperationException(); } }
FilteredCacheIterator implements PeekingKeyValueIterator<Bytes, LRUCacheEntry> { @Override public void remove() { throw new UnsupportedOperationException(); } FilteredCacheIterator(final PeekingKeyValueIterator<Bytes, LRUCacheEntry> cacheIterator, final HasNextCondition hasNextCondition, final CacheFunction cacheFunction); }
FilteredCacheIterator implements PeekingKeyValueIterator<Bytes, LRUCacheEntry> { @Override public void remove() { throw new UnsupportedOperationException(); } FilteredCacheIterator(final PeekingKeyValueIterator<Bytes, LRUCacheEntry> cacheIterator, final HasNextCondition hasNextCondition, final CacheFunction cacheFunction); @Override void close(); @Override Bytes peekNextKey(); @Override boolean hasNext(); @Override KeyValue<Bytes, LRUCacheEntry> next(); @Override void remove(); @Override KeyValue<Bytes, LRUCacheEntry> peekNext(); }
FilteredCacheIterator implements PeekingKeyValueIterator<Bytes, LRUCacheEntry> { @Override public void remove() { throw new UnsupportedOperationException(); } FilteredCacheIterator(final PeekingKeyValueIterator<Bytes, LRUCacheEntry> cacheIterator, final HasNextCondition hasNextCondition, final CacheFunction cacheFunction); @Override void close(); @Override Bytes peekNextKey(); @Override boolean hasNext(); @Override KeyValue<Bytes, LRUCacheEntry> next(); @Override void remove(); @Override KeyValue<Bytes, LRUCacheEntry> peekNext(); }
@SuppressWarnings("unchecked") @Test public void testPutAndFetch() throws IOException { windowStore = createWindowStore(context, false, true); long startTime = segmentSize - 4L; putFirstBatch(windowStore, startTime, context); assertEquals(Utils.mkList("zero"), toList(windowStore.fetch(0, startTime + 0L - WINDOW_SIZE, startTime + 0L + WINDOW_SIZE))); assertEquals(Utils.mkList("one"), toList(windowStore.fetch(1, startTime + 1L - WINDOW_SIZE, startTime + 1L + WINDOW_SIZE))); assertEquals(Utils.mkList("two"), toList(windowStore.fetch(2, startTime + 2L - WINDOW_SIZE, startTime + 2L + WINDOW_SIZE))); assertEquals(Utils.mkList(), toList(windowStore.fetch(3, startTime + 3L - WINDOW_SIZE, startTime + 3L + WINDOW_SIZE))); assertEquals(Utils.mkList("four"), toList(windowStore.fetch(4, startTime + 4L - WINDOW_SIZE, startTime + 4L + WINDOW_SIZE))); assertEquals(Utils.mkList("five"), toList(windowStore.fetch(5, startTime + 5L - WINDOW_SIZE, startTime + 5L + WINDOW_SIZE))); putSecondBatch(windowStore, startTime, context); assertEquals(Utils.mkList(), toList(windowStore.fetch(2, startTime - 2L - WINDOW_SIZE, startTime - 2L + WINDOW_SIZE))); assertEquals(Utils.mkList("two"), toList(windowStore.fetch(2, startTime - 1L - WINDOW_SIZE, startTime - 1L + WINDOW_SIZE))); assertEquals(Utils.mkList("two", "two+1"), toList(windowStore.fetch(2, startTime - WINDOW_SIZE, startTime + WINDOW_SIZE))); assertEquals(Utils.mkList("two", "two+1", "two+2"), toList(windowStore.fetch(2, startTime + 1L - WINDOW_SIZE, startTime + 1L + WINDOW_SIZE))); assertEquals(Utils.mkList("two", "two+1", "two+2", "two+3"), toList(windowStore.fetch(2, startTime + 2L - WINDOW_SIZE, startTime + 2L + WINDOW_SIZE))); assertEquals(Utils.mkList("two", "two+1", "two+2", "two+3", "two+4"), toList(windowStore.fetch(2, startTime + 3L - WINDOW_SIZE, startTime + 3L + WINDOW_SIZE))); assertEquals(Utils.mkList("two", "two+1", "two+2", "two+3", "two+4", "two+5"), toList(windowStore.fetch(2, startTime + 4L - WINDOW_SIZE, startTime + 4L + WINDOW_SIZE))); assertEquals(Utils.mkList("two", "two+1", "two+2", "two+3", "two+4", "two+5", "two+6"), toList(windowStore.fetch(2, startTime + 5L - WINDOW_SIZE, startTime + 5L + WINDOW_SIZE))); assertEquals(Utils.mkList("two+1", "two+2", "two+3", "two+4", "two+5", "two+6"), toList(windowStore.fetch(2, startTime + 6L - WINDOW_SIZE, startTime + 6L + WINDOW_SIZE))); assertEquals(Utils.mkList("two+2", "two+3", "two+4", "two+5", "two+6"), toList(windowStore.fetch(2, startTime + 7L - WINDOW_SIZE, startTime + 7L + WINDOW_SIZE))); assertEquals(Utils.mkList("two+3", "two+4", "two+5", "two+6"), toList(windowStore.fetch(2, startTime + 8L - WINDOW_SIZE, startTime + 8L + WINDOW_SIZE))); assertEquals(Utils.mkList("two+4", "two+5", "two+6"), toList(windowStore.fetch(2, startTime + 9L - WINDOW_SIZE, startTime + 9L + WINDOW_SIZE))); assertEquals(Utils.mkList("two+5", "two+6"), toList(windowStore.fetch(2, startTime + 10L - WINDOW_SIZE, startTime + 10L + WINDOW_SIZE))); assertEquals(Utils.mkList("two+6"), toList(windowStore.fetch(2, startTime + 11L - WINDOW_SIZE, startTime + 11L + WINDOW_SIZE))); assertEquals(Utils.mkList(), toList(windowStore.fetch(2, startTime + 12L - WINDOW_SIZE, startTime + 12L + WINDOW_SIZE))); windowStore.flush(); Map<Integer, Set<String>> entriesByKey = entriesByKey(changeLog, startTime); assertEquals(Utils.mkSet("zero@0"), entriesByKey.get(0)); assertEquals(Utils.mkSet("one@1"), entriesByKey.get(1)); assertEquals(Utils.mkSet("two@2", "two+1@3", "two+2@4", "two+3@5", "two+4@6", "two+5@7", "two+6@8"), entriesByKey.get(2)); assertNull(entriesByKey.get(3)); assertEquals(Utils.mkSet("four@4"), entriesByKey.get(4)); assertEquals(Utils.mkSet("five@5"), entriesByKey.get(5)); assertNull(entriesByKey.get(6)); }
@Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); @Override @SuppressWarnings("unchecked") void init(final ProcessorContext context, final StateStore root); @Override void put(K key, V value); @Override void put(K key, V value, long timestamp); @Override WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(K from, K to, long timeFrom, long timeTo); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); @Override @SuppressWarnings("unchecked") void init(final ProcessorContext context, final StateStore root); @Override void put(K key, V value); @Override void put(K key, V value, long timestamp); @Override WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(K from, K to, long timeFrom, long timeTo); }
@SuppressWarnings("unchecked") @Test public void testFetchRange() throws IOException { windowStore = createWindowStore(context, false, true); long startTime = segmentSize - 4L; putFirstBatch(windowStore, startTime, context); final KeyValue<Windowed<Integer>, String> zero = windowedPair(0, "zero", startTime + 0); final KeyValue<Windowed<Integer>, String> one = windowedPair(1, "one", startTime + 1); final KeyValue<Windowed<Integer>, String> two = windowedPair(2, "two", startTime + 2); final KeyValue<Windowed<Integer>, String> four = windowedPair(4, "four", startTime + 4); final KeyValue<Windowed<Integer>, String> five = windowedPair(5, "five", startTime + 5); assertEquals( Utils.mkList(zero, one), StreamsTestUtils.toList(windowStore.fetch(0, 1, startTime + 0L - WINDOW_SIZE, startTime + 0L + WINDOW_SIZE)) ); assertEquals( Utils.mkList(one), StreamsTestUtils.toList(windowStore.fetch(1, 1, startTime + 0L - WINDOW_SIZE, startTime + 0L + WINDOW_SIZE)) ); assertEquals( Utils.mkList(one, two), StreamsTestUtils.toList(windowStore.fetch(1, 3, startTime + 0L - WINDOW_SIZE, startTime + 0L + WINDOW_SIZE)) ); assertEquals( Utils.mkList(zero, one, two), StreamsTestUtils.toList(windowStore.fetch(0, 5, startTime + 0L - WINDOW_SIZE, startTime + 0L + WINDOW_SIZE)) ); assertEquals( Utils.mkList(zero, one, two, four, five), StreamsTestUtils.toList(windowStore.fetch(0, 5, startTime + 0L - WINDOW_SIZE, startTime + 0L + WINDOW_SIZE + 5L)) ); assertEquals( Utils.mkList(two, four, five), StreamsTestUtils.toList(windowStore.fetch(0, 5, startTime + 2L, startTime + 0L + WINDOW_SIZE + 5L)) ); assertEquals( Utils.mkList(), StreamsTestUtils.toList(windowStore.fetch(4, 5, startTime + 2L, startTime + WINDOW_SIZE)) ); assertEquals( Utils.mkList(), StreamsTestUtils.toList(windowStore.fetch(0, 3, startTime + 3L, startTime + WINDOW_SIZE + 5)) ); }
@Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); @Override @SuppressWarnings("unchecked") void init(final ProcessorContext context, final StateStore root); @Override void put(K key, V value); @Override void put(K key, V value, long timestamp); @Override WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(K from, K to, long timeFrom, long timeTo); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); @Override @SuppressWarnings("unchecked") void init(final ProcessorContext context, final StateStore root); @Override void put(K key, V value); @Override void put(K key, V value, long timestamp); @Override WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(K from, K to, long timeFrom, long timeTo); }
@SuppressWarnings("unchecked") @Test public void testPutAndFetchBefore() throws IOException { windowStore = createWindowStore(context, false, true); long startTime = segmentSize - 4L; putFirstBatch(windowStore, startTime, context); assertEquals(Utils.mkList("zero"), toList(windowStore.fetch(0, startTime + 0L - WINDOW_SIZE, startTime + 0L))); assertEquals(Utils.mkList("one"), toList(windowStore.fetch(1, startTime + 1L - WINDOW_SIZE, startTime + 1L))); assertEquals(Utils.mkList("two"), toList(windowStore.fetch(2, startTime + 2L - WINDOW_SIZE, startTime + 2L))); assertEquals(Utils.mkList(), toList(windowStore.fetch(3, startTime + 3L - WINDOW_SIZE, startTime + 3L))); assertEquals(Utils.mkList("four"), toList(windowStore.fetch(4, startTime + 4L - WINDOW_SIZE, startTime + 4L))); assertEquals(Utils.mkList("five"), toList(windowStore.fetch(5, startTime + 5L - WINDOW_SIZE, startTime + 5L))); putSecondBatch(windowStore, startTime, context); assertEquals(Utils.mkList(), toList(windowStore.fetch(2, startTime - 1L - WINDOW_SIZE, startTime - 1L))); assertEquals(Utils.mkList(), toList(windowStore.fetch(2, startTime + 0L - WINDOW_SIZE, startTime + 0L))); assertEquals(Utils.mkList(), toList(windowStore.fetch(2, startTime + 1L - WINDOW_SIZE, startTime + 1L))); assertEquals(Utils.mkList("two"), toList(windowStore.fetch(2, startTime + 2L - WINDOW_SIZE, startTime + 2L))); assertEquals(Utils.mkList("two", "two+1"), toList(windowStore.fetch(2, startTime + 3L - WINDOW_SIZE, startTime + 3L))); assertEquals(Utils.mkList("two", "two+1", "two+2"), toList(windowStore.fetch(2, startTime + 4L - WINDOW_SIZE, startTime + 4L))); assertEquals(Utils.mkList("two", "two+1", "two+2", "two+3"), toList(windowStore.fetch(2, startTime + 5L - WINDOW_SIZE, startTime + 5L))); assertEquals(Utils.mkList("two+1", "two+2", "two+3", "two+4"), toList(windowStore.fetch(2, startTime + 6L - WINDOW_SIZE, startTime + 6L))); assertEquals(Utils.mkList("two+2", "two+3", "two+4", "two+5"), toList(windowStore.fetch(2, startTime + 7L - WINDOW_SIZE, startTime + 7L))); assertEquals(Utils.mkList("two+3", "two+4", "two+5", "two+6"), toList(windowStore.fetch(2, startTime + 8L - WINDOW_SIZE, startTime + 8L))); assertEquals(Utils.mkList("two+4", "two+5", "two+6"), toList(windowStore.fetch(2, startTime + 9L - WINDOW_SIZE, startTime + 9L))); assertEquals(Utils.mkList("two+5", "two+6"), toList(windowStore.fetch(2, startTime + 10L - WINDOW_SIZE, startTime + 10L))); assertEquals(Utils.mkList("two+6"), toList(windowStore.fetch(2, startTime + 11L - WINDOW_SIZE, startTime + 11L))); assertEquals(Utils.mkList(), toList(windowStore.fetch(2, startTime + 12L - WINDOW_SIZE, startTime + 12L))); assertEquals(Utils.mkList(), toList(windowStore.fetch(2, startTime + 13L - WINDOW_SIZE, startTime + 13L))); windowStore.flush(); Map<Integer, Set<String>> entriesByKey = entriesByKey(changeLog, startTime); assertEquals(Utils.mkSet("zero@0"), entriesByKey.get(0)); assertEquals(Utils.mkSet("one@1"), entriesByKey.get(1)); assertEquals(Utils.mkSet("two@2", "two+1@3", "two+2@4", "two+3@5", "two+4@6", "two+5@7", "two+6@8"), entriesByKey.get(2)); assertNull(entriesByKey.get(3)); assertEquals(Utils.mkSet("four@4"), entriesByKey.get(4)); assertEquals(Utils.mkSet("five@5"), entriesByKey.get(5)); assertNull(entriesByKey.get(6)); }
@Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); @Override @SuppressWarnings("unchecked") void init(final ProcessorContext context, final StateStore root); @Override void put(K key, V value); @Override void put(K key, V value, long timestamp); @Override WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(K from, K to, long timeFrom, long timeTo); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); @Override @SuppressWarnings("unchecked") void init(final ProcessorContext context, final StateStore root); @Override void put(K key, V value); @Override void put(K key, V value, long timestamp); @Override WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(K from, K to, long timeFrom, long timeTo); }
@SuppressWarnings("unchecked") @Test public void testPutAndFetchAfter() throws IOException { windowStore = createWindowStore(context, false, true); long startTime = segmentSize - 4L; putFirstBatch(windowStore, startTime, context); assertEquals(Utils.mkList("zero"), toList(windowStore.fetch(0, startTime + 0L, startTime + 0L + WINDOW_SIZE))); assertEquals(Utils.mkList("one"), toList(windowStore.fetch(1, startTime + 1L, startTime + 1L + WINDOW_SIZE))); assertEquals(Utils.mkList("two"), toList(windowStore.fetch(2, startTime + 2L, startTime + 2L + WINDOW_SIZE))); assertEquals(Utils.mkList(), toList(windowStore.fetch(3, startTime + 3L, startTime + 3L + WINDOW_SIZE))); assertEquals(Utils.mkList("four"), toList(windowStore.fetch(4, startTime + 4L, startTime + 4L + WINDOW_SIZE))); assertEquals(Utils.mkList("five"), toList(windowStore.fetch(5, startTime + 5L, startTime + 5L + WINDOW_SIZE))); putSecondBatch(windowStore, startTime, context); assertEquals(Utils.mkList(), toList(windowStore.fetch(2, startTime - 2L, startTime - 2L + WINDOW_SIZE))); assertEquals(Utils.mkList("two"), toList(windowStore.fetch(2, startTime - 1L, startTime - 1L + WINDOW_SIZE))); assertEquals(Utils.mkList("two", "two+1"), toList(windowStore.fetch(2, startTime, startTime + WINDOW_SIZE))); assertEquals(Utils.mkList("two", "two+1", "two+2"), toList(windowStore.fetch(2, startTime + 1L, startTime + 1L + WINDOW_SIZE))); assertEquals(Utils.mkList("two", "two+1", "two+2", "two+3"), toList(windowStore.fetch(2, startTime + 2L, startTime + 2L + WINDOW_SIZE))); assertEquals(Utils.mkList("two+1", "two+2", "two+3", "two+4"), toList(windowStore.fetch(2, startTime + 3L, startTime + 3L + WINDOW_SIZE))); assertEquals(Utils.mkList("two+2", "two+3", "two+4", "two+5"), toList(windowStore.fetch(2, startTime + 4L, startTime + 4L + WINDOW_SIZE))); assertEquals(Utils.mkList("two+3", "two+4", "two+5", "two+6"), toList(windowStore.fetch(2, startTime + 5L, startTime + 5L + WINDOW_SIZE))); assertEquals(Utils.mkList("two+4", "two+5", "two+6"), toList(windowStore.fetch(2, startTime + 6L, startTime + 6L + WINDOW_SIZE))); assertEquals(Utils.mkList("two+5", "two+6"), toList(windowStore.fetch(2, startTime + 7L, startTime + 7L + WINDOW_SIZE))); assertEquals(Utils.mkList("two+6"), toList(windowStore.fetch(2, startTime + 8L, startTime + 8L + WINDOW_SIZE))); assertEquals(Utils.mkList(), toList(windowStore.fetch(2, startTime + 9L, startTime + 9L + WINDOW_SIZE))); assertEquals(Utils.mkList(), toList(windowStore.fetch(2, startTime + 10L, startTime + 10L + WINDOW_SIZE))); assertEquals(Utils.mkList(), toList(windowStore.fetch(2, startTime + 11L, startTime + 11L + WINDOW_SIZE))); assertEquals(Utils.mkList(), toList(windowStore.fetch(2, startTime + 12L, startTime + 12L + WINDOW_SIZE))); windowStore.flush(); Map<Integer, Set<String>> entriesByKey = entriesByKey(changeLog, startTime); assertEquals(Utils.mkSet("zero@0"), entriesByKey.get(0)); assertEquals(Utils.mkSet("one@1"), entriesByKey.get(1)); assertEquals(Utils.mkSet("two@2", "two+1@3", "two+2@4", "two+3@5", "two+4@6", "two+5@7", "two+6@8"), entriesByKey.get(2)); assertNull(entriesByKey.get(3)); assertEquals(Utils.mkSet("four@4"), entriesByKey.get(4)); assertEquals(Utils.mkSet("five@5"), entriesByKey.get(5)); assertNull(entriesByKey.get(6)); }
@Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); @Override @SuppressWarnings("unchecked") void init(final ProcessorContext context, final StateStore root); @Override void put(K key, V value); @Override void put(K key, V value, long timestamp); @Override WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(K from, K to, long timeFrom, long timeTo); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); @Override @SuppressWarnings("unchecked") void init(final ProcessorContext context, final StateStore root); @Override void put(K key, V value); @Override void put(K key, V value, long timestamp); @Override WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(K from, K to, long timeFrom, long timeTo); }
@SuppressWarnings("unchecked") @Test public void testInitialLoading() throws IOException { File storeDir = new File(baseDir, windowName); windowStore = createWindowStore(context, false, true); new File(storeDir, segments.segmentName(0L)).mkdir(); new File(storeDir, segments.segmentName(1L)).mkdir(); new File(storeDir, segments.segmentName(2L)).mkdir(); new File(storeDir, segments.segmentName(3L)).mkdir(); new File(storeDir, segments.segmentName(4L)).mkdir(); new File(storeDir, segments.segmentName(5L)).mkdir(); new File(storeDir, segments.segmentName(6L)).mkdir(); windowStore.close(); windowStore = createWindowStore(context, false, true); assertEquals( Utils.mkSet(segments.segmentName(4L), segments.segmentName(5L), segments.segmentName(6L)), segmentDirs(baseDir) ); try (WindowStoreIterator iter = windowStore.fetch(0, 0L, 1000000L)) { while (iter.hasNext()) { iter.next(); } } assertEquals( Utils.mkSet(segments.segmentName(4L), segments.segmentName(5L), segments.segmentName(6L)), segmentDirs(baseDir) ); }
@Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); @Override @SuppressWarnings("unchecked") void init(final ProcessorContext context, final StateStore root); @Override void put(K key, V value); @Override void put(K key, V value, long timestamp); @Override WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(K from, K to, long timeFrom, long timeTo); }
RocksDBWindowStore extends WrappedStateStore.AbstractStateStore implements WindowStore<K, V> { @Override public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo) { final KeyValueIterator<Bytes, byte[]> bytesIterator = bytesStore.fetch(Bytes.wrap(serdes.rawKey(key)), timeFrom, timeTo); return new WindowStoreIteratorWrapper<>(bytesIterator, serdes, windowSize).valuesIterator(); } RocksDBWindowStore(final SegmentedBytesStore bytesStore, final Serde<K> keySerde, final Serde<V> valueSerde, final boolean retainDuplicates, final long windowSize); @Override @SuppressWarnings("unchecked") void init(final ProcessorContext context, final StateStore root); @Override void put(K key, V value); @Override void put(K key, V value, long timestamp); @Override WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo); @Override KeyValueIterator<Windowed<K>, V> fetch(K from, K to, long timeFrom, long timeTo); }
@Test public void shouldDelegateToUnderlyingStoreWhenFetching() throws Exception { store.fetch(Bytes.wrap(new byte[0]), 1, 1); assertTrue(bytesStore.fetchCalled); }
@Override public KeyValueIterator<Bytes, byte[]> fetch(final Bytes key, final long from, final long to) { return bytesStore.fetch(key, from, to); }
ChangeLoggingSegmentedBytesStore extends WrappedStateStore.AbstractStateStore implements SegmentedBytesStore { @Override public KeyValueIterator<Bytes, byte[]> fetch(final Bytes key, final long from, final long to) { return bytesStore.fetch(key, from, to); } }
ChangeLoggingSegmentedBytesStore extends WrappedStateStore.AbstractStateStore implements SegmentedBytesStore { @Override public KeyValueIterator<Bytes, byte[]> fetch(final Bytes key, final long from, final long to) { return bytesStore.fetch(key, from, to); } ChangeLoggingSegmentedBytesStore(final SegmentedBytesStore bytesStore); }
ChangeLoggingSegmentedBytesStore extends WrappedStateStore.AbstractStateStore implements SegmentedBytesStore { @Override public KeyValueIterator<Bytes, byte[]> fetch(final Bytes key, final long from, final long to) { return bytesStore.fetch(key, from, to); } ChangeLoggingSegmentedBytesStore(final SegmentedBytesStore bytesStore); @Override KeyValueIterator<Bytes, byte[]> fetch(final Bytes key, final long from, final long to); @Override KeyValueIterator<Bytes, byte[]> fetch(Bytes keyFrom, Bytes keyTo, long from, long to); @Override void remove(final Bytes key); @Override void put(final Bytes key, final byte[] value); @Override byte[] get(final Bytes key); @Override @SuppressWarnings("unchecked") void init(final ProcessorContext context, final StateStore root); }
ChangeLoggingSegmentedBytesStore extends WrappedStateStore.AbstractStateStore implements SegmentedBytesStore { @Override public KeyValueIterator<Bytes, byte[]> fetch(final Bytes key, final long from, final long to) { return bytesStore.fetch(key, from, to); } ChangeLoggingSegmentedBytesStore(final SegmentedBytesStore bytesStore); @Override KeyValueIterator<Bytes, byte[]> fetch(final Bytes key, final long from, final long to); @Override KeyValueIterator<Bytes, byte[]> fetch(Bytes keyFrom, Bytes keyTo, long from, long to); @Override void remove(final Bytes key); @Override void put(final Bytes key, final byte[] value); @Override byte[] get(final Bytes key); @Override @SuppressWarnings("unchecked") void init(final ProcessorContext context, final StateStore root); }
@Test public void shouldFindKeyValueStores() throws Exception { List<ReadOnlyKeyValueStore<String, String>> results = wrappingStoreProvider.stores("kv", QueryableStoreTypes.<String, String>keyValueStore()); assertEquals(2, results.size()); }
public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; }
WrappingStoreProvider implements StateStoreProvider { public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; } }
WrappingStoreProvider implements StateStoreProvider { public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; } WrappingStoreProvider(final List<StateStoreProvider> storeProviders); }
WrappingStoreProvider implements StateStoreProvider { public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; } WrappingStoreProvider(final List<StateStoreProvider> storeProviders); List<T> stores(final String storeName, QueryableStoreType<T> type); }
WrappingStoreProvider implements StateStoreProvider { public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; } WrappingStoreProvider(final List<StateStoreProvider> storeProviders); List<T> stores(final String storeName, QueryableStoreType<T> type); }
@Test public void shouldFindWindowStores() throws Exception { final List<ReadOnlyWindowStore<Object, Object>> windowStores = wrappingStoreProvider.stores("window", windowStore()); assertEquals(2, windowStores.size()); }
public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; }
WrappingStoreProvider implements StateStoreProvider { public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; } }
WrappingStoreProvider implements StateStoreProvider { public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; } WrappingStoreProvider(final List<StateStoreProvider> storeProviders); }
WrappingStoreProvider implements StateStoreProvider { public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; } WrappingStoreProvider(final List<StateStoreProvider> storeProviders); List<T> stores(final String storeName, QueryableStoreType<T> type); }
WrappingStoreProvider implements StateStoreProvider { public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; } WrappingStoreProvider(final List<StateStoreProvider> storeProviders); List<T> stores(final String storeName, QueryableStoreType<T> type); }
@Test(expected = InvalidStateStoreException.class) public void shouldThrowInvalidStoreExceptionIfNoStoreOfTypeFound() throws Exception { wrappingStoreProvider.stores("doesn't exist", QueryableStoreTypes.keyValueStore()); }
public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; }
WrappingStoreProvider implements StateStoreProvider { public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; } }
WrappingStoreProvider implements StateStoreProvider { public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; } WrappingStoreProvider(final List<StateStoreProvider> storeProviders); }
WrappingStoreProvider implements StateStoreProvider { public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; } WrappingStoreProvider(final List<StateStoreProvider> storeProviders); List<T> stores(final String storeName, QueryableStoreType<T> type); }
WrappingStoreProvider implements StateStoreProvider { public <T> List<T> stores(final String storeName, QueryableStoreType<T> type) { final List<T> allStores = new ArrayList<>(); for (StateStoreProvider provider : storeProviders) { final List<T> stores = provider.stores(storeName, type); allStores.addAll(stores); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return allStores; } WrappingStoreProvider(final List<StateStoreProvider> storeProviders); List<T> stores(final String storeName, QueryableStoreType<T> type); }
@Test public void shouldReturnNullOnPutIfAbsentWhenNoPreviousValue() throws Exception { assertThat(store.putIfAbsent(hi, there), is(nullValue())); }
@Override public byte[] putIfAbsent(final Bytes key, final byte[] value) { final byte[] previous = get(key); if (previous == null) { put(key, value); } return previous; }
ChangeLoggingKeyValueBytesStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<Bytes, byte[]> { @Override public byte[] putIfAbsent(final Bytes key, final byte[] value) { final byte[] previous = get(key); if (previous == null) { put(key, value); } return previous; } }
ChangeLoggingKeyValueBytesStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<Bytes, byte[]> { @Override public byte[] putIfAbsent(final Bytes key, final byte[] value) { final byte[] previous = get(key); if (previous == null) { put(key, value); } return previous; } ChangeLoggingKeyValueBytesStore(final KeyValueStore<Bytes, byte[]> inner); }
ChangeLoggingKeyValueBytesStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<Bytes, byte[]> { @Override public byte[] putIfAbsent(final Bytes key, final byte[] value) { final byte[] previous = get(key); if (previous == null) { put(key, value); } return previous; } ChangeLoggingKeyValueBytesStore(final KeyValueStore<Bytes, byte[]> inner); @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final Bytes key, final byte[] value); @Override byte[] putIfAbsent(final Bytes key, final byte[] value); @Override void putAll(final List<KeyValue<Bytes, byte[]>> entries); @Override byte[] delete(final Bytes key); @Override byte[] get(final Bytes key); @Override KeyValueIterator<Bytes, byte[]> range(final Bytes from, final Bytes to); @Override KeyValueIterator<Bytes, byte[]> all(); }
ChangeLoggingKeyValueBytesStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<Bytes, byte[]> { @Override public byte[] putIfAbsent(final Bytes key, final byte[] value) { final byte[] previous = get(key); if (previous == null) { put(key, value); } return previous; } ChangeLoggingKeyValueBytesStore(final KeyValueStore<Bytes, byte[]> inner); @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final Bytes key, final byte[] value); @Override byte[] putIfAbsent(final Bytes key, final byte[] value); @Override void putAll(final List<KeyValue<Bytes, byte[]>> entries); @Override byte[] delete(final Bytes key); @Override byte[] get(final Bytes key); @Override KeyValueIterator<Bytes, byte[]> range(final Bytes from, final Bytes to); @Override KeyValueIterator<Bytes, byte[]> all(); }
@Test public void shouldReturnNullOnGetWhenDoesntExist() throws Exception { assertThat(store.get(hello), is(nullValue())); }
@Override public byte[] get(final Bytes key) { return inner.get(key); }
ChangeLoggingKeyValueBytesStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<Bytes, byte[]> { @Override public byte[] get(final Bytes key) { return inner.get(key); } }
ChangeLoggingKeyValueBytesStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<Bytes, byte[]> { @Override public byte[] get(final Bytes key) { return inner.get(key); } ChangeLoggingKeyValueBytesStore(final KeyValueStore<Bytes, byte[]> inner); }
ChangeLoggingKeyValueBytesStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<Bytes, byte[]> { @Override public byte[] get(final Bytes key) { return inner.get(key); } ChangeLoggingKeyValueBytesStore(final KeyValueStore<Bytes, byte[]> inner); @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final Bytes key, final byte[] value); @Override byte[] putIfAbsent(final Bytes key, final byte[] value); @Override void putAll(final List<KeyValue<Bytes, byte[]>> entries); @Override byte[] delete(final Bytes key); @Override byte[] get(final Bytes key); @Override KeyValueIterator<Bytes, byte[]> range(final Bytes from, final Bytes to); @Override KeyValueIterator<Bytes, byte[]> all(); }
ChangeLoggingKeyValueBytesStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<Bytes, byte[]> { @Override public byte[] get(final Bytes key) { return inner.get(key); } ChangeLoggingKeyValueBytesStore(final KeyValueStore<Bytes, byte[]> inner); @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final Bytes key, final byte[] value); @Override byte[] putIfAbsent(final Bytes key, final byte[] value); @Override void putAll(final List<KeyValue<Bytes, byte[]>> entries); @Override byte[] delete(final Bytes key); @Override byte[] get(final Bytes key); @Override KeyValueIterator<Bytes, byte[]> range(final Bytes from, final Bytes to); @Override KeyValueIterator<Bytes, byte[]> all(); }
@Test public void testUpperBoundWithLargeTimestamps() throws Exception { Bytes upper = windowKeySchema.upperRange(Bytes.wrap(new byte[]{0xA, 0xB, 0xC}), Long.MAX_VALUE); assertThat( "shorter key with max timestamp should be in range", upper.compareTo( WindowStoreUtils.toBinaryKey( new byte[]{0xA}, Long.MAX_VALUE, Integer.MAX_VALUE ) ) >= 0 ); assertThat( "shorter key with max timestamp should be in range", upper.compareTo( WindowStoreUtils.toBinaryKey( new byte[]{0xA, 0xB}, Long.MAX_VALUE, Integer.MAX_VALUE ) ) >= 0 ); assertThat(upper, equalTo(WindowStoreUtils.toBinaryKey(new byte[]{0xA}, Long.MAX_VALUE, Integer.MAX_VALUE))); }
@Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test public void testUpperBoundWithKeyBytesLargerThanFirstTimestampByte() throws Exception { Bytes upper = windowKeySchema.upperRange(Bytes.wrap(new byte[]{0xA, (byte) 0x8F, (byte) 0x9F}), Long.MAX_VALUE); assertThat( "shorter key with max timestamp should be in range", upper.compareTo( WindowStoreUtils.toBinaryKey( new byte[]{0xA, (byte) 0x8F}, Long.MAX_VALUE, Integer.MAX_VALUE ) ) >= 0 ); assertThat(upper, equalTo(WindowStoreUtils.toBinaryKey(new byte[]{0xA, (byte) 0x8F, (byte) 0x9F}, Long.MAX_VALUE, Integer.MAX_VALUE))); }
@Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test public void testUpperBoundWithKeyBytesLargerAndSmallerThanFirstTimestampByte() throws Exception { Bytes upper = windowKeySchema.upperRange(Bytes.wrap(new byte[]{0xC, 0xC, 0x9}), 0x0AffffffffffffffL); assertThat( "shorter key with max timestamp should be in range", upper.compareTo( WindowStoreUtils.toBinaryKey( new byte[]{0xC, 0xC}, 0x0AffffffffffffffL, Integer.MAX_VALUE ) ) >= 0 ); assertThat(upper, equalTo(WindowStoreUtils.toBinaryKey(new byte[]{0xC, 0xC}, 0x0AffffffffffffffL, Integer.MAX_VALUE))); }
@Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test public void testUpperBoundWithZeroTimestamp() throws Exception { Bytes upper = windowKeySchema.upperRange(Bytes.wrap(new byte[]{0xA, 0xB, 0xC}), 0); assertThat(upper, equalTo(WindowStoreUtils.toBinaryKey(new byte[]{0xA, 0xB, 0xC}, 0, Integer.MAX_VALUE))); }
@Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes upperRange(final Bytes key, final long to) { final byte[] maxSuffix = ByteBuffer.allocate(SUFFIX_SIZE) .putLong(to) .putInt(Integer.MAX_VALUE) .array(); return OrderedBytes.upperRange(key, maxSuffix); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test public void testLowerBoundWithZeroTimestamp() throws Exception { Bytes lower = windowKeySchema.lowerRange(Bytes.wrap(new byte[]{0xA, 0xB, 0xC}), 0); assertThat(lower, equalTo(WindowStoreUtils.toBinaryKey(new byte[]{0xA, 0xB, 0xC}, 0, 0))); }
@Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test public void testLowerBoundWithMonZeroTimestamp() throws Exception { Bytes lower = windowKeySchema.lowerRange(Bytes.wrap(new byte[]{0xA, 0xB, 0xC}), 42); assertThat(lower, equalTo(WindowStoreUtils.toBinaryKey(new byte[]{0xA, 0xB, 0xC}, 0, 0))); }
@Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test public void testLowerBoundMatchesTrailingZeros() throws Exception { Bytes lower = windowKeySchema.lowerRange(Bytes.wrap(new byte[]{0xA, 0xB, 0xC}), Long.MAX_VALUE - 1); assertThat( "appending zeros to key should still be in range", lower.compareTo( WindowStoreUtils.toBinaryKey( new byte[]{0xA, 0xB, 0xC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Long.MAX_VALUE - 1, 0 ) ) < 0 ); assertThat(lower, equalTo(WindowStoreUtils.toBinaryKey(new byte[]{0xA, 0xB, 0xC}, 0, 0))); }
@Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
WindowKeySchema implements RocksDBSegmentedBytesStore.KeySchema { @Override public Bytes lowerRange(final Bytes key, final long from) { return OrderedBytes.lowerRange(key, MIN_SUFFIX); } @Override void init(final String topic); @Override Bytes upperRange(final Bytes key, final long to); @Override Bytes lowerRange(final Bytes key, final long from); @Override Bytes lowerRangeFixedSize(final Bytes key, final long from); @Override Bytes upperRangeFixedSize(final Bytes key, final long to); @Override long segmentTimestamp(final Bytes key); @Override HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to); @Override List<Segment> segmentsToSearch(final Segments segments, final long from, final long to); }
@Test(expected = NoSuchElementException.class) public void shouldThrowNoSuchElementWhenNoMoreItemsLeftAndNextCalled() throws Exception { final DelegatingPeekingKeyValueIterator<String, String> peekingIterator = new DelegatingPeekingKeyValueIterator<>(name, store.all()); peekingIterator.next(); }
@Override public synchronized KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<K, V> result = next; next = null; return result; }
DelegatingPeekingKeyValueIterator implements KeyValueIterator<K, V>, PeekingKeyValueIterator<K, V> { @Override public synchronized KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<K, V> result = next; next = null; return result; } }
DelegatingPeekingKeyValueIterator implements KeyValueIterator<K, V>, PeekingKeyValueIterator<K, V> { @Override public synchronized KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<K, V> result = next; next = null; return result; } DelegatingPeekingKeyValueIterator(final String storeName, final KeyValueIterator<K, V> underlying); }
DelegatingPeekingKeyValueIterator implements KeyValueIterator<K, V>, PeekingKeyValueIterator<K, V> { @Override public synchronized KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<K, V> result = next; next = null; return result; } DelegatingPeekingKeyValueIterator(final String storeName, final KeyValueIterator<K, V> underlying); @Override synchronized K peekNextKey(); @Override synchronized void close(); @Override synchronized boolean hasNext(); @Override synchronized KeyValue<K, V> next(); @Override void remove(); @Override KeyValue<K, V> peekNext(); }
DelegatingPeekingKeyValueIterator implements KeyValueIterator<K, V>, PeekingKeyValueIterator<K, V> { @Override public synchronized KeyValue<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } final KeyValue<K, V> result = next; next = null; return result; } DelegatingPeekingKeyValueIterator(final String storeName, final KeyValueIterator<K, V> underlying); @Override synchronized K peekNextKey(); @Override synchronized void close(); @Override synchronized boolean hasNext(); @Override synchronized KeyValue<K, V> next(); @Override void remove(); @Override KeyValue<K, V> peekNext(); }
@Test(expected = NoSuchElementException.class) public void shouldThrowNoSuchElementWhenNoMoreItemsLeftAndPeekNextCalled() throws Exception { final DelegatingPeekingKeyValueIterator<String, String> peekingIterator = new DelegatingPeekingKeyValueIterator<>(name, store.all()); peekingIterator.peekNextKey(); }
@Override public synchronized K peekNextKey() { if (!hasNext()) { throw new NoSuchElementException(); } return next.key; }
DelegatingPeekingKeyValueIterator implements KeyValueIterator<K, V>, PeekingKeyValueIterator<K, V> { @Override public synchronized K peekNextKey() { if (!hasNext()) { throw new NoSuchElementException(); } return next.key; } }
DelegatingPeekingKeyValueIterator implements KeyValueIterator<K, V>, PeekingKeyValueIterator<K, V> { @Override public synchronized K peekNextKey() { if (!hasNext()) { throw new NoSuchElementException(); } return next.key; } DelegatingPeekingKeyValueIterator(final String storeName, final KeyValueIterator<K, V> underlying); }
DelegatingPeekingKeyValueIterator implements KeyValueIterator<K, V>, PeekingKeyValueIterator<K, V> { @Override public synchronized K peekNextKey() { if (!hasNext()) { throw new NoSuchElementException(); } return next.key; } DelegatingPeekingKeyValueIterator(final String storeName, final KeyValueIterator<K, V> underlying); @Override synchronized K peekNextKey(); @Override synchronized void close(); @Override synchronized boolean hasNext(); @Override synchronized KeyValue<K, V> next(); @Override void remove(); @Override KeyValue<K, V> peekNext(); }
DelegatingPeekingKeyValueIterator implements KeyValueIterator<K, V>, PeekingKeyValueIterator<K, V> { @Override public synchronized K peekNextKey() { if (!hasNext()) { throw new NoSuchElementException(); } return next.key; } DelegatingPeekingKeyValueIterator(final String storeName, final KeyValueIterator<K, V> underlying); @Override synchronized K peekNextKey(); @Override synchronized void close(); @Override synchronized boolean hasNext(); @Override synchronized KeyValue<K, V> next(); @Override void remove(); @Override KeyValue<K, V> peekNext(); }
@Test public void shouldReturnNullIfKeyDoesntExist() throws Exception { assertNull(theStore.get("whatever")); }
@Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
@Test public void shouldReturnValueIfExists() throws Exception { stubOneUnderlying.put("key", "value"); assertEquals("value", theStore.get("key")); }
@Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
@Test public void shouldNotGetValuesFromOtherStores() throws Exception { otherUnderlyingStore.put("otherKey", "otherValue"); assertNull(theStore.get("otherKey")); }
@Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
@SuppressWarnings("unchecked") @Test public void shouldFindValueForKeyWhenMultiStores() throws Exception { final KeyValueStore<String, String> cache = newStoreInstance(); stubProviderTwo.addStore(storeName, cache); cache.put("key-two", "key-two-value"); stubOneUnderlying.put("key-one", "key-one-value"); assertEquals("key-two-value", theStore.get("key-two")); assertEquals("key-one-value", theStore.get("key-one")); }
@Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
@Test public void shouldSupportRange() throws Exception { stubOneUnderlying.put("a", "a"); stubOneUnderlying.put("b", "b"); stubOneUnderlying.put("c", "c"); final List<KeyValue<String, String>> results = toList(theStore.range("a", "b")); assertTrue(results.contains(new KeyValue<>("a", "a"))); assertTrue(results.contains(new KeyValue<>("b", "b"))); assertEquals(2, results.size()); }
@Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
@SuppressWarnings("unchecked") @Test public void shouldSupportRangeAcrossMultipleKVStores() throws Exception { final KeyValueStore<String, String> cache = newStoreInstance(); stubProviderTwo.addStore(storeName, cache); stubOneUnderlying.put("a", "a"); stubOneUnderlying.put("b", "b"); stubOneUnderlying.put("z", "z"); cache.put("c", "c"); cache.put("d", "d"); cache.put("x", "x"); final List<KeyValue<String, String>> results = toList(theStore.range("a", "e")); assertTrue(results.contains(new KeyValue<>("a", "a"))); assertTrue(results.contains(new KeyValue<>("b", "b"))); assertTrue(results.contains(new KeyValue<>("c", "c"))); assertTrue(results.contains(new KeyValue<>("d", "d"))); assertEquals(4, results.size()); }
@Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
@Test public void shouldSupportAllAcrossMultipleStores() throws Exception { final KeyValueStore<String, String> cache = newStoreInstance(); stubProviderTwo.addStore(storeName, cache); stubOneUnderlying.put("a", "a"); stubOneUnderlying.put("b", "b"); stubOneUnderlying.put("z", "z"); cache.put("c", "c"); cache.put("d", "d"); cache.put("x", "x"); final List<KeyValue<String, String>> results = toList(theStore.all()); assertTrue(results.contains(new KeyValue<>("a", "a"))); assertTrue(results.contains(new KeyValue<>("b", "b"))); assertTrue(results.contains(new KeyValue<>("c", "c"))); assertTrue(results.contains(new KeyValue<>("d", "d"))); assertTrue(results.contains(new KeyValue<>("x", "x"))); assertTrue(results.contains(new KeyValue<>("z", "z"))); assertEquals(6, results.size()); }
@Override public KeyValueIterator<K, V> all() { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.all(); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> all() { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.all(); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> all() { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.all(); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> all() { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.all(); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> all() { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.all(); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
@Test(expected = InvalidStateStoreException.class) public void shouldThrowInvalidStoreExceptionDuringRebalance() throws Exception { rebalancing().get("anything"); }
@Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
@Test(expected = InvalidStateStoreException.class) public void shouldThrowInvalidStoreExceptionOnRangeDuringRebalance() throws Exception { rebalancing().range("anything", "something"); }
@Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> range(final K from, final K to) { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.range(from, to); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
@Test(expected = InvalidStateStoreException.class) public void shouldThrowInvalidStoreExceptionOnAllDuringRebalance() throws Exception { rebalancing().all(); }
@Override public KeyValueIterator<K, V> all() { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.all(); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> all() { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.all(); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> all() { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.all(); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> all() { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.all(); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public KeyValueIterator<K, V> all() { final NextIteratorFunction<K, V> nextIteratorFunction = new NextIteratorFunction<K, V>() { @Override public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) { try { return store.all(); } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } }; final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator(stores.iterator(), nextIteratorFunction)); } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
@Test public void shouldGetApproximateEntriesAcrossAllStores() throws Exception { final KeyValueStore<String, String> cache = newStoreInstance(); stubProviderTwo.addStore(storeName, cache); stubOneUnderlying.put("a", "a"); stubOneUnderlying.put("b", "b"); stubOneUnderlying.put("z", "z"); cache.put("c", "c"); cache.put("d", "d"); cache.put("x", "x"); assertEquals(6, theStore.approximateNumEntries()); }
@Override public long approximateNumEntries() { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); long total = 0; for (ReadOnlyKeyValueStore<K, V> store : stores) { total += store.approximateNumEntries(); } return total < 0 ? Long.MAX_VALUE : total; }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public long approximateNumEntries() { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); long total = 0; for (ReadOnlyKeyValueStore<K, V> store : stores) { total += store.approximateNumEntries(); } return total < 0 ? Long.MAX_VALUE : total; } }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public long approximateNumEntries() { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); long total = 0; for (ReadOnlyKeyValueStore<K, V> store : stores) { total += store.approximateNumEntries(); } return total < 0 ? Long.MAX_VALUE : total; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public long approximateNumEntries() { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); long total = 0; for (ReadOnlyKeyValueStore<K, V> store : stores) { total += store.approximateNumEntries(); } return total < 0 ? Long.MAX_VALUE : total; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public long approximateNumEntries() { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); long total = 0; for (ReadOnlyKeyValueStore<K, V> store : stores) { total += store.approximateNumEntries(); } return total < 0 ? Long.MAX_VALUE : total; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
@Test public void shouldReturnLongMaxValueOnOverflow() throws Exception { stubProviderTwo.addStore(storeName, new NoOpReadOnlyStore<Object, Object>() { @Override public long approximateNumEntries() { return Long.MAX_VALUE; } }); stubOneUnderlying.put("overflow", "me"); assertEquals(Long.MAX_VALUE, theStore.approximateNumEntries()); }
@Override public long approximateNumEntries() { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); long total = 0; for (ReadOnlyKeyValueStore<K, V> store : stores) { total += store.approximateNumEntries(); } return total < 0 ? Long.MAX_VALUE : total; }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public long approximateNumEntries() { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); long total = 0; for (ReadOnlyKeyValueStore<K, V> store : stores) { total += store.approximateNumEntries(); } return total < 0 ? Long.MAX_VALUE : total; } }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public long approximateNumEntries() { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); long total = 0; for (ReadOnlyKeyValueStore<K, V> store : stores) { total += store.approximateNumEntries(); } return total < 0 ? Long.MAX_VALUE : total; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public long approximateNumEntries() { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); long total = 0; for (ReadOnlyKeyValueStore<K, V> store : stores) { total += store.approximateNumEntries(); } return total < 0 ? Long.MAX_VALUE : total; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public long approximateNumEntries() { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); long total = 0; for (ReadOnlyKeyValueStore<K, V> store : stores) { total += store.approximateNumEntries(); } return total < 0 ? Long.MAX_VALUE : total; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider, final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType, final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries(); }
@Test public void shouldWriteKeyValueBytesToInnerStoreOnPut() throws Exception { store.put(hi, there); assertThat(deserializedValueFromInner(hi), equalTo(there)); }
@Override public void put(final K key, final V value) { final Bytes bytesKey = Bytes.wrap(serdes.rawKey(key)); final byte[] bytesValue = serdes.rawValue(value); innerBytes.put(bytesKey, bytesValue); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public void put(final K key, final V value) { final Bytes bytesKey = Bytes.wrap(serdes.rawKey(key)); final byte[] bytesValue = serdes.rawValue(value); innerBytes.put(bytesKey, bytesValue); } }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public void put(final K key, final V value) { final Bytes bytesKey = Bytes.wrap(serdes.rawKey(key)); final byte[] bytesValue = serdes.rawValue(value); innerBytes.put(bytesKey, bytesValue); } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public void put(final K key, final V value) { final Bytes bytesKey = Bytes.wrap(serdes.rawKey(key)); final byte[] bytesValue = serdes.rawValue(value); innerBytes.put(bytesKey, bytesValue); } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final K key, final V value); @Override V putIfAbsent(final K key, final V value); @Override void putAll(final List<KeyValue<K, V>> entries); @Override V delete(final K key); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public void put(final K key, final V value) { final Bytes bytesKey = Bytes.wrap(serdes.rawKey(key)); final byte[] bytesValue = serdes.rawValue(value); innerBytes.put(bytesKey, bytesValue); } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final K key, final V value); @Override V putIfAbsent(final K key, final V value); @Override void putAll(final List<KeyValue<K, V>> entries); @Override V delete(final K key); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); }
@Test public void shouldWriteAllKeyValueToInnerStoreOnPutAll() throws Exception { store.putAll(Arrays.asList(KeyValue.pair(hello, world), KeyValue.pair(hi, there))); assertThat(deserializedValueFromInner(hello), equalTo(world)); assertThat(deserializedValueFromInner(hi), equalTo(there)); }
@Override public void putAll(final List<KeyValue<K, V>> entries) { final List<KeyValue<Bytes, byte[]>> keyValues = new ArrayList<>(); for (final KeyValue<K, V> entry : entries) { keyValues.add(KeyValue.pair(Bytes.wrap(serdes.rawKey(entry.key)), serdes.rawValue(entry.value))); } innerBytes.putAll(keyValues); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public void putAll(final List<KeyValue<K, V>> entries) { final List<KeyValue<Bytes, byte[]>> keyValues = new ArrayList<>(); for (final KeyValue<K, V> entry : entries) { keyValues.add(KeyValue.pair(Bytes.wrap(serdes.rawKey(entry.key)), serdes.rawValue(entry.value))); } innerBytes.putAll(keyValues); } }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public void putAll(final List<KeyValue<K, V>> entries) { final List<KeyValue<Bytes, byte[]>> keyValues = new ArrayList<>(); for (final KeyValue<K, V> entry : entries) { keyValues.add(KeyValue.pair(Bytes.wrap(serdes.rawKey(entry.key)), serdes.rawValue(entry.value))); } innerBytes.putAll(keyValues); } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public void putAll(final List<KeyValue<K, V>> entries) { final List<KeyValue<Bytes, byte[]>> keyValues = new ArrayList<>(); for (final KeyValue<K, V> entry : entries) { keyValues.add(KeyValue.pair(Bytes.wrap(serdes.rawKey(entry.key)), serdes.rawValue(entry.value))); } innerBytes.putAll(keyValues); } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final K key, final V value); @Override V putIfAbsent(final K key, final V value); @Override void putAll(final List<KeyValue<K, V>> entries); @Override V delete(final K key); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public void putAll(final List<KeyValue<K, V>> entries) { final List<KeyValue<Bytes, byte[]>> keyValues = new ArrayList<>(); for (final KeyValue<K, V> entry : entries) { keyValues.add(KeyValue.pair(Bytes.wrap(serdes.rawKey(entry.key)), serdes.rawValue(entry.value))); } innerBytes.putAll(keyValues); } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final K key, final V value); @Override V putIfAbsent(final K key, final V value); @Override void putAll(final List<KeyValue<K, V>> entries); @Override V delete(final K key); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); }
@Test public void shouldReturnNullOnDeleteIfNoOldValue() throws Exception { assertThat(store.delete(hi), is(nullValue())); }
@Override public V delete(final K key) { final byte[] oldValue = innerBytes.delete(Bytes.wrap(serdes.rawKey(key))); if (oldValue == null) { return null; } return serdes.valueFrom(oldValue); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public V delete(final K key) { final byte[] oldValue = innerBytes.delete(Bytes.wrap(serdes.rawKey(key))); if (oldValue == null) { return null; } return serdes.valueFrom(oldValue); } }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public V delete(final K key) { final byte[] oldValue = innerBytes.delete(Bytes.wrap(serdes.rawKey(key))); if (oldValue == null) { return null; } return serdes.valueFrom(oldValue); } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public V delete(final K key) { final byte[] oldValue = innerBytes.delete(Bytes.wrap(serdes.rawKey(key))); if (oldValue == null) { return null; } return serdes.valueFrom(oldValue); } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final K key, final V value); @Override V putIfAbsent(final K key, final V value); @Override void putAll(final List<KeyValue<K, V>> entries); @Override V delete(final K key); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public V delete(final K key) { final byte[] oldValue = innerBytes.delete(Bytes.wrap(serdes.rawKey(key))); if (oldValue == null) { return null; } return serdes.valueFrom(oldValue); } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final K key, final V value); @Override V putIfAbsent(final K key, final V value); @Override void putAll(final List<KeyValue<K, V>> entries); @Override V delete(final K key); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); }
@Test public void shouldReturnNullOnPutIfAbsentWhenNoPreviousValue() throws Exception { assertThat(store.putIfAbsent(hi, there), is(nullValue())); }
@Override public V putIfAbsent(final K key, final V value) { final V v = get(key); if (v == null) { put(key, value); } return v; }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public V putIfAbsent(final K key, final V value) { final V v = get(key); if (v == null) { put(key, value); } return v; } }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public V putIfAbsent(final K key, final V value) { final V v = get(key); if (v == null) { put(key, value); } return v; } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public V putIfAbsent(final K key, final V value) { final V v = get(key); if (v == null) { put(key, value); } return v; } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final K key, final V value); @Override V putIfAbsent(final K key, final V value); @Override void putAll(final List<KeyValue<K, V>> entries); @Override V delete(final K key); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public V putIfAbsent(final K key, final V value) { final V v = get(key); if (v == null) { put(key, value); } return v; } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final K key, final V value); @Override V putIfAbsent(final K key, final V value); @Override void putAll(final List<KeyValue<K, V>> entries); @Override V delete(final K key); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); }
@Test(expected = ConfigException.class) public void testConfigNoTargetType() { TimestampConverter<SourceRecord> xform = new TimestampConverter.Value<>(); xform.configure(Collections.<String, String>emptyMap()); }
@Override public void configure(Map<String, ?> configs) { final SimpleConfig simpleConfig = new SimpleConfig(CONFIG_DEF, configs); final String field = simpleConfig.getString(FIELD_CONFIG); final String type = simpleConfig.getString(TARGET_TYPE_CONFIG); String formatPattern = simpleConfig.getString(FORMAT_CONFIG); schemaUpdateCache = new SynchronizedCache<>(new LRUCache<Schema, Schema>(16)); if (!VALID_TYPES.contains(type)) { throw new ConfigException("Unknown timestamp type in TimestampConverter: " + type + ". Valid values are " + Utils.join(VALID_TYPES, ", ") + "."); } if (type.equals(TYPE_STRING) && formatPattern.trim().isEmpty()) { throw new ConfigException("TimestampConverter requires format option to be specified when using string timestamps"); } SimpleDateFormat format = null; if (formatPattern != null && !formatPattern.trim().isEmpty()) { try { format = new SimpleDateFormat(formatPattern); format.setTimeZone(UTC); } catch (IllegalArgumentException e) { throw new ConfigException("TimestampConverter requires a SimpleDateFormat-compatible pattern for string timestamps: " + formatPattern, e); } } config = new Config(field, type, format); }
TimestampConverter implements Transformation<R> { @Override public void configure(Map<String, ?> configs) { final SimpleConfig simpleConfig = new SimpleConfig(CONFIG_DEF, configs); final String field = simpleConfig.getString(FIELD_CONFIG); final String type = simpleConfig.getString(TARGET_TYPE_CONFIG); String formatPattern = simpleConfig.getString(FORMAT_CONFIG); schemaUpdateCache = new SynchronizedCache<>(new LRUCache<Schema, Schema>(16)); if (!VALID_TYPES.contains(type)) { throw new ConfigException("Unknown timestamp type in TimestampConverter: " + type + ". Valid values are " + Utils.join(VALID_TYPES, ", ") + "."); } if (type.equals(TYPE_STRING) && formatPattern.trim().isEmpty()) { throw new ConfigException("TimestampConverter requires format option to be specified when using string timestamps"); } SimpleDateFormat format = null; if (formatPattern != null && !formatPattern.trim().isEmpty()) { try { format = new SimpleDateFormat(formatPattern); format.setTimeZone(UTC); } catch (IllegalArgumentException e) { throw new ConfigException("TimestampConverter requires a SimpleDateFormat-compatible pattern for string timestamps: " + formatPattern, e); } } config = new Config(field, type, format); } }
TimestampConverter implements Transformation<R> { @Override public void configure(Map<String, ?> configs) { final SimpleConfig simpleConfig = new SimpleConfig(CONFIG_DEF, configs); final String field = simpleConfig.getString(FIELD_CONFIG); final String type = simpleConfig.getString(TARGET_TYPE_CONFIG); String formatPattern = simpleConfig.getString(FORMAT_CONFIG); schemaUpdateCache = new SynchronizedCache<>(new LRUCache<Schema, Schema>(16)); if (!VALID_TYPES.contains(type)) { throw new ConfigException("Unknown timestamp type in TimestampConverter: " + type + ". Valid values are " + Utils.join(VALID_TYPES, ", ") + "."); } if (type.equals(TYPE_STRING) && formatPattern.trim().isEmpty()) { throw new ConfigException("TimestampConverter requires format option to be specified when using string timestamps"); } SimpleDateFormat format = null; if (formatPattern != null && !formatPattern.trim().isEmpty()) { try { format = new SimpleDateFormat(formatPattern); format.setTimeZone(UTC); } catch (IllegalArgumentException e) { throw new ConfigException("TimestampConverter requires a SimpleDateFormat-compatible pattern for string timestamps: " + formatPattern, e); } } config = new Config(field, type, format); } }
TimestampConverter implements Transformation<R> { @Override public void configure(Map<String, ?> configs) { final SimpleConfig simpleConfig = new SimpleConfig(CONFIG_DEF, configs); final String field = simpleConfig.getString(FIELD_CONFIG); final String type = simpleConfig.getString(TARGET_TYPE_CONFIG); String formatPattern = simpleConfig.getString(FORMAT_CONFIG); schemaUpdateCache = new SynchronizedCache<>(new LRUCache<Schema, Schema>(16)); if (!VALID_TYPES.contains(type)) { throw new ConfigException("Unknown timestamp type in TimestampConverter: " + type + ". Valid values are " + Utils.join(VALID_TYPES, ", ") + "."); } if (type.equals(TYPE_STRING) && formatPattern.trim().isEmpty()) { throw new ConfigException("TimestampConverter requires format option to be specified when using string timestamps"); } SimpleDateFormat format = null; if (formatPattern != null && !formatPattern.trim().isEmpty()) { try { format = new SimpleDateFormat(formatPattern); format.setTimeZone(UTC); } catch (IllegalArgumentException e) { throw new ConfigException("TimestampConverter requires a SimpleDateFormat-compatible pattern for string timestamps: " + formatPattern, e); } } config = new Config(field, type, format); } @Override void configure(Map<String, ?> configs); @Override R apply(R record); @Override ConfigDef config(); @Override void close(); }
TimestampConverter implements Transformation<R> { @Override public void configure(Map<String, ?> configs) { final SimpleConfig simpleConfig = new SimpleConfig(CONFIG_DEF, configs); final String field = simpleConfig.getString(FIELD_CONFIG); final String type = simpleConfig.getString(TARGET_TYPE_CONFIG); String formatPattern = simpleConfig.getString(FORMAT_CONFIG); schemaUpdateCache = new SynchronizedCache<>(new LRUCache<Schema, Schema>(16)); if (!VALID_TYPES.contains(type)) { throw new ConfigException("Unknown timestamp type in TimestampConverter: " + type + ". Valid values are " + Utils.join(VALID_TYPES, ", ") + "."); } if (type.equals(TYPE_STRING) && formatPattern.trim().isEmpty()) { throw new ConfigException("TimestampConverter requires format option to be specified when using string timestamps"); } SimpleDateFormat format = null; if (formatPattern != null && !formatPattern.trim().isEmpty()) { try { format = new SimpleDateFormat(formatPattern); format.setTimeZone(UTC); } catch (IllegalArgumentException e) { throw new ConfigException("TimestampConverter requires a SimpleDateFormat-compatible pattern for string timestamps: " + formatPattern, e); } } config = new Config(field, type, format); } @Override void configure(Map<String, ?> configs); @Override R apply(R record); @Override ConfigDef config(); @Override void close(); static final String OVERVIEW_DOC; static final String FIELD_CONFIG; static final String TARGET_TYPE_CONFIG; static final String FORMAT_CONFIG; static final ConfigDef CONFIG_DEF; }
@Test public void shouldReturnNullOnGetWhenDoesntExist() throws Exception { assertThat(store.get(hello), is(nullValue())); }
@Override public V get(final K key) { final byte[] rawValue = innerBytes.get(Bytes.wrap(serdes.rawKey(key))); if (rawValue == null) { return null; } return serdes.valueFrom(rawValue); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public V get(final K key) { final byte[] rawValue = innerBytes.get(Bytes.wrap(serdes.rawKey(key))); if (rawValue == null) { return null; } return serdes.valueFrom(rawValue); } }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public V get(final K key) { final byte[] rawValue = innerBytes.get(Bytes.wrap(serdes.rawKey(key))); if (rawValue == null) { return null; } return serdes.valueFrom(rawValue); } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public V get(final K key) { final byte[] rawValue = innerBytes.get(Bytes.wrap(serdes.rawKey(key))); if (rawValue == null) { return null; } return serdes.valueFrom(rawValue); } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final K key, final V value); @Override V putIfAbsent(final K key, final V value); @Override void putAll(final List<KeyValue<K, V>> entries); @Override V delete(final K key); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); }
ChangeLoggingKeyValueStore extends WrappedStateStore.AbstractStateStore implements KeyValueStore<K, V> { @Override public V get(final K key) { final byte[] rawValue = innerBytes.get(Bytes.wrap(serdes.rawKey(key))); if (rawValue == null) { return null; } return serdes.valueFrom(rawValue); } ChangeLoggingKeyValueStore(final KeyValueStore<Bytes, byte[]> bytesStore, final Serde keySerde, final Serde valueSerde); private ChangeLoggingKeyValueStore(final ChangeLoggingKeyValueBytesStore bytesStore, final Serde keySerde, final Serde valueSerde); @SuppressWarnings("unchecked") @Override void init(final ProcessorContext context, final StateStore root); @Override long approximateNumEntries(); @Override void put(final K key, final V value); @Override V putIfAbsent(final K key, final V value); @Override void putAll(final List<KeyValue<K, V>> entries); @Override V delete(final K key); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); }
@Test(expected = InvalidStateStoreException.class) public void shouldThrowExceptionIfKVStoreDoesntExist() throws Exception { storeProvider.getStore("not-a-store", QueryableStoreTypes.keyValueStore()); }
public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
@Test(expected = InvalidStateStoreException.class) public void shouldThrowExceptionIfWindowStoreDoesntExist() throws Exception { storeProvider.getStore("not-a-store", QueryableStoreTypes.windowStore()); }
public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
@Test public void shouldReturnKVStoreWhenItExists() throws Exception { assertNotNull(storeProvider.getStore(keyValueStore, QueryableStoreTypes.keyValueStore())); }
public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
@Test public void shouldReturnWindowStoreWhenItExists() throws Exception { assertNotNull(storeProvider.getStore(windowStore, QueryableStoreTypes.windowStore())); }
public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
@Test(expected = InvalidStateStoreException.class) public void shouldThrowExceptionWhenLookingForWindowStoreWithDifferentType() throws Exception { storeProvider.getStore(windowStore, QueryableStoreTypes.keyValueStore()); }
public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
@Test(expected = InvalidStateStoreException.class) public void shouldThrowExceptionWhenLookingForKVStoreWithDifferentType() throws Exception { storeProvider.getStore(keyValueStore, QueryableStoreTypes.windowStore()); }
public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
@Test public void shouldFindGlobalStores() throws Exception { globalStateStores.put("global", new NoOpReadOnlyStore<>()); assertNotNull(storeProvider.getStore("global", QueryableStoreTypes.keyValueStore())); }
public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
QueryableStoreProvider { public <T> T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType) { final List<T> globalStore = globalStoreProvider.stores(storeName, queryableStoreType); if (!globalStore.isEmpty()) { return queryableStoreType.create(new WrappingStoreProvider(Collections.<StateStoreProvider>singletonList(globalStoreProvider)), storeName); } final List<T> allStores = new ArrayList<>(); for (StateStoreProvider storeProvider : storeProviders) { allStores.addAll(storeProvider.stores(storeName, queryableStoreType)); } if (allStores.isEmpty()) { throw new InvalidStateStoreException("the state store, " + storeName + ", may have migrated to another instance."); } return queryableStoreType.create( new WrappingStoreProvider(storeProviders), storeName); } QueryableStoreProvider(final List<StateStoreProvider> storeProviders, final GlobalStateStoreProvider globalStateStoreProvider); T getStore(final String storeName, final QueryableStoreType<T> queryableStoreType); }
@SuppressWarnings("unchecked") @Test public void testAddRemove() throws Exception { context.setTime(1); changeLogger.logChange(0, "zero"); changeLogger.logChange(1, "one"); changeLogger.logChange(2, "two"); assertEquals("zero", logged.get(0)); assertEquals("one", logged.get(1)); assertEquals("two", logged.get(2)); changeLogger.logChange(0, null); assertNull(logged.get(0)); }
void logChange(final K key, final V value) { if (collector != null) { final Serializer<K> keySerializer = serialization.keySerializer(); final Serializer<V> valueSerializer = serialization.valueSerializer(); collector.send(this.topic, key, value, this.partition, context.timestamp(), keySerializer, valueSerializer); } }
StoreChangeLogger { void logChange(final K key, final V value) { if (collector != null) { final Serializer<K> keySerializer = serialization.keySerializer(); final Serializer<V> valueSerializer = serialization.valueSerializer(); collector.send(this.topic, key, value, this.partition, context.timestamp(), keySerializer, valueSerializer); } } }
StoreChangeLogger { void logChange(final K key, final V value) { if (collector != null) { final Serializer<K> keySerializer = serialization.keySerializer(); final Serializer<V> valueSerializer = serialization.valueSerializer(); collector.send(this.topic, key, value, this.partition, context.timestamp(), keySerializer, valueSerializer); } } StoreChangeLogger(String storeName, ProcessorContext context, StateSerdes<K, V> serialization); private StoreChangeLogger(String storeName, ProcessorContext context, int partition, StateSerdes<K, V> serialization); }
StoreChangeLogger { void logChange(final K key, final V value) { if (collector != null) { final Serializer<K> keySerializer = serialization.keySerializer(); final Serializer<V> valueSerializer = serialization.valueSerializer(); collector.send(this.topic, key, value, this.partition, context.timestamp(), keySerializer, valueSerializer); } } StoreChangeLogger(String storeName, ProcessorContext context, StateSerdes<K, V> serialization); private StoreChangeLogger(String storeName, ProcessorContext context, int partition, StateSerdes<K, V> serialization); }
StoreChangeLogger { void logChange(final K key, final V value) { if (collector != null) { final Serializer<K> keySerializer = serialization.keySerializer(); final Serializer<V> valueSerializer = serialization.valueSerializer(); collector.send(this.topic, key, value, this.partition, context.timestamp(), keySerializer, valueSerializer); } } StoreChangeLogger(String storeName, ProcessorContext context, StateSerdes<K, V> serialization); private StoreChangeLogger(String storeName, ProcessorContext context, int partition, StateSerdes<K, V> serialization); }