private boolean isDuplicate(final E eventId) { long eventTime = context.timestamp(); WindowStoreIterator<Long> timeIterator = eventIdStore.fetch( eventId, eventTime - leftDurationMs, eventTime + rightDurationMs); boolean isDuplicate = timeIterator.hasNext(); timeIterator.close(); return isDuplicate; }
@Override public KeyValueIterator<Windowed<Bytes>, byte[]> fetch(final Bytes keyFrom, final Bytes keyTo, final long from, final long to) { return bytesStore.fetch(keyFrom, keyTo, from, to); }
@Override public byte[] fetch(final Bytes key, final long timestamp) { return bytesStore.fetch(key, timestamp); }
@Override public WindowStoreIterator<byte[]> fetch(final Bytes key, final long from, final long to) { return bytesStore.fetch(key, from, to); }
private V fetchPrevious(final Bytes key, final long timestamp) { final byte[] value = underlying.fetch(key, timestamp); if (value != null) { return serdes.valueFrom(value); } return null; }
@Override default WindowStoreIterator<V> fetch(final K key, final Instant from, final Instant to) { ApiUtils.validateMillisecondInstant(from, "from"); ApiUtils.validateMillisecondInstant(to, "to"); return fetch(key, from.toEpochMilli(), to.toEpochMilli()); }
@Override default KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final Instant fromTime, final Instant toTime) { ApiUtils.validateMillisecondInstant(fromTime, "fromTime"); ApiUtils.validateMillisecondInstant(toTime, "toTime"); return fetch(from, to, fromTime.toEpochMilli(), toTime.toEpochMilli()); }
@Override public WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo) { return new MeteredWindowStoreIterator<>(inner.fetch(keyBytes(key), timeFrom, timeTo), fetchTime, metrics, serdes, time); }
@Override public byte[] fetch(final Bytes key, final long timestamp) { validateStoreOpen(); final Bytes bytesKey = WindowKeySchema.toStoreKeyBinary(key, timestamp, 0); final Bytes cacheKey = cacheFunction.cacheKey(bytesKey); if (cache == null) { return underlying.fetch(key, timestamp); } final LRUCacheEntry entry = cache.get(name, cacheKey); if (entry == null) { return underlying.fetch(key, timestamp); } else { return entry.value(); } }
@Override public KeyValueIterator<Windowed<K>, V> fetch(final K from, final K to, final long timeFrom, final long timeTo) { return new MeteredWindowedKeyValueIterator<>(inner.fetch(keyBytes(from), keyBytes(to), timeFrom, timeTo), fetchTime, metrics, serdes, time); }
@Override public V fetch(final K key, final long timestamp) { final long startNs = time.nanoseconds(); try { final byte[] result = inner.fetch(keyBytes(key), timestamp); if (result == null) { return null; } return serdes.valueFrom(result); } finally { metrics.recordLatency(this.fetchTime, startNs, time.nanoseconds()); } }
@Override public synchronized WindowStoreIterator<byte[]> fetch(final Bytes key, final long timeFrom, final long timeTo) { // since this function may not access the underlying inner store, we need to validate // if store is open outside as well. validateStoreOpen(); final WindowStoreIterator<byte[]> underlyingIterator = underlying.fetch(key, timeFrom, timeTo); if (cache == null) { return underlyingIterator; } final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRangeFixedSize(key, timeFrom)); final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRangeFixedSize(key, timeTo)); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(name, cacheKeyFrom, cacheKeyTo); final HasNextCondition hasNextCondition = keySchema.hasNextCondition(key, key, timeFrom, timeTo); final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator( cacheIterator, hasNextCondition, cacheFunction ); return new MergedSortedCacheWindowStoreIterator(filteredCacheIterator, underlyingIterator); }
@Override public KeyValueIterator<Windowed<Bytes>, byte[]> fetch(final Bytes from, final Bytes to, final long timeFrom, final long timeTo) { // since this function may not access the underlying inner store, we need to validate // if store is open outside as well. validateStoreOpen(); final KeyValueIterator<Windowed<Bytes>, byte[]> underlyingIterator = underlying.fetch(from, to, timeFrom, timeTo); if (cache == null) { return underlyingIterator; } final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRange(from, timeFrom)); final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRange(to, timeTo)); final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(name, cacheKeyFrom, cacheKeyTo); final HasNextCondition hasNextCondition = keySchema.hasNextCondition(from, to, timeFrom, timeTo); final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator(cacheIterator, hasNextCondition, cacheFunction); return new MergedSortedCacheWindowStoreKeyValueIterator( filteredCacheIterator, underlyingIterator, bytesSerdes, windowSize, cacheFunction ); }