@ -20,6 +20,7 @@ import org.apache.kafka.common.utils.Bytes;
@@ -20,6 +20,7 @@ import org.apache.kafka.common.utils.Bytes;
import org.apache.kafka.common.utils.LogContext ;
import org.apache.kafka.streams.KeyValue ;
import org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl ;
import org.apache.kafka.streams.state.internals.NamedCache.LRUNode ;
import org.slf4j.Logger ;
import java.util.Collections ;
@ -180,17 +181,17 @@ public class ThreadCache {
@@ -180,17 +181,17 @@ public class 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 ( Collections . emptyIterator ( ) ) ;
}
return new MemoryLRUCacheBytesIterator ( cache . keyRange ( from , to ) , cache ) ;
return new MemoryLRUCacheBytesIterator ( cache . subMapIterator ( from , to ) ) ;
}
public MemoryLRUCacheBytesIterator all ( final String namespace ) {
final NamedCache cache = getCache ( namespace ) ;
if ( cache = = null ) {
return new MemoryLRUCacheBytesIterator ( Collections . < Bytes > emptyIterator ( ) , new NamedCache ( namespace , this . metrics ) ) ;
return new MemoryLRUCacheBytesIterator ( Collections . emptyIterator ( ) ) ;
}
return new MemoryLRUCacheBytesIterator ( cache . allKeys ( ) , cache ) ;
return new MemoryLRUCacheBytesIterator ( cache . allIterator ( ) ) ;
}
public long size ( ) {
@ -260,13 +261,11 @@ public class ThreadCache {
@@ -260,13 +261,11 @@ public class ThreadCache {
}
static class MemoryLRUCacheBytesIterator implements PeekingKeyValueIterator < Bytes , LRUCacheEntry > {
private final Iterator < Bytes > keys ;
private final NamedCache cache ;
private final Iterator < Map . Entry < Bytes , LRUNode > > underlying ;
private KeyValue < Bytes , LRUCacheEntry > nextEntry ;
MemoryLRUCacheBytesIterator ( final Iterator < Bytes > keys , final NamedCache cache ) {
this . keys = keys ;
this . cache = cache ;
MemoryLRUCacheBytesIterator ( final Iterator < Map . Entry < Bytes , LRUNode > > underlying ) {
this . underlying = underlying ;
}
public Bytes peekNextKey ( ) {
@ -290,7 +289,7 @@ public class ThreadCache {
@@ -290,7 +289,7 @@ public class ThreadCache {
return true ;
}
while ( keys . hasNext ( ) & & nextEntry = = null ) {
while ( underlying . hasNext ( ) & & nextEntry = = null ) {
internalNext ( ) ;
}
@ -308,8 +307,9 @@ public class ThreadCache {
@@ -308,8 +307,9 @@ public class ThreadCache {
}
private void internalNext ( ) {
final Bytes cacheKey = keys . next ( ) ;
final LRUCacheEntry entry = cache . get ( cacheKey ) ;
final Map . Entry < Bytes , LRUNode > mapEntry = underlying . next ( ) ;
final Bytes cacheKey = mapEntry . getKey ( ) ;
final LRUCacheEntry entry = mapEntry . getValue ( ) . entry ( ) ;
if ( entry = = null ) {
return ;
}