use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class AbstractMergedSortedCacheStoreIterator method next.
@Override
public KeyValue<K, V> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
final Bytes nextCacheKey = cacheIterator.hasNext() ? cacheIterator.peekNextKey() : null;
final KS nextStoreKey = storeIterator.hasNext() ? storeIterator.peekNextKey() : null;
if (nextCacheKey == null) {
return nextStoreValue(nextStoreKey);
}
if (nextStoreKey == null) {
return nextCacheValue(nextCacheKey);
}
final int comparison = compare(nextCacheKey, nextStoreKey);
if (comparison > 0) {
return nextStoreValue(nextStoreKey);
} else if (comparison < 0) {
return nextCacheValue(nextCacheKey);
} else {
// skip the same keyed element
storeIterator.next();
return nextCacheValue(nextCacheKey);
}
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class AbstractMergedSortedCacheStoreIterator method peekNextKey.
@Override
public K peekNextKey() {
if (!hasNext()) {
throw new NoSuchElementException();
}
final Bytes nextCacheKey = cacheIterator.hasNext() ? cacheIterator.peekNextKey() : null;
final KS nextStoreKey = storeIterator.hasNext() ? storeIterator.peekNextKey() : null;
if (nextCacheKey == null) {
return deserializeStoreKey(nextStoreKey);
}
if (nextStoreKey == null) {
return serdes.keyFrom(nextCacheKey.get());
}
final int comparison = compare(nextCacheKey, nextStoreKey);
if (comparison > 0) {
return deserializeStoreKey(nextStoreKey);
} else if (comparison < 0) {
return deserializeCacheKey(nextCacheKey);
} else {
// skip the same keyed element
storeIterator.next();
return deserializeCacheKey(nextCacheKey);
}
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class CachingKeyValueStore method delete.
@Override
public synchronized V delete(final K key) {
validateStoreOpen();
final byte[] rawKey = serdes.rawKey(key);
final Bytes bytesKey = Bytes.wrap(rawKey);
final V v = get(rawKey);
cache.delete(cacheName, bytesKey);
underlying.delete(bytesKey);
return v;
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class CachingKeyValueStore method get.
private V get(final byte[] rawKey) {
final Bytes key = Bytes.wrap(rawKey);
final LRUCacheEntry entry = cache.get(cacheName, key);
if (entry == null) {
final byte[] rawValue = underlying.get(key);
if (rawValue == null) {
return null;
}
// as we don't want other threads to trigger an eviction/flush
if (Thread.currentThread().equals(streamThread)) {
cache.put(cacheName, key, new LRUCacheEntry(rawValue));
}
return serdes.valueFrom(rawValue);
}
if (entry.value == null) {
return null;
}
return serdes.valueFrom(entry.value);
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class CachingSessionStore method findSessions.
public KeyValueIterator<Windowed<K>, AGG> findSessions(final K key, final long earliestSessionEndTime, final long latestSessionStartTime) {
validateStoreOpen();
final Bytes binarySessionId = Bytes.wrap(keySerde.serializer().serialize(this.name(), key));
final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, keySchema.lowerRange(binarySessionId, earliestSessionEndTime), keySchema.upperRange(binarySessionId, latestSessionStartTime));
final KeyValueIterator<Windowed<Bytes>, byte[]> storeIterator = bytesStore.findSessions(binarySessionId, earliestSessionEndTime, latestSessionStartTime);
final HasNextCondition hasNextCondition = keySchema.hasNextCondition(binarySessionId, earliestSessionEndTime, latestSessionStartTime);
final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator(cacheIterator, hasNextCondition);
return new MergedSortedCacheSessionStoreIterator<>(filteredCacheIterator, storeIterator, serdes);
}
Aggregations