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