Id Cache: Allow to configure if ids should be reused (memory wise) or not, default to false

closes #2605
This commit is contained in:
Shay Banon 2013-01-30 14:42:07 +01:00
parent bc20f068c9
commit 5c40c97e6e
1 changed files with 9 additions and 4 deletions

View File

@ -47,11 +47,13 @@ import java.util.concurrent.ConcurrentMap;
public class SimpleIdCache extends AbstractIndexComponent implements IdCache, SegmentReader.CoreClosedListener {
private final ConcurrentMap<Object, SimpleIdReaderCache> idReaders;
private final boolean reuse;
@Inject
public SimpleIdCache(Index index, @IndexSettings Settings indexSettings) {
super(index, indexSettings);
idReaders = ConcurrentCollections.newConcurrentMap();
this.reuse = componentSettings.getAsBoolean("reuse", false);
}
@Override
@ -207,12 +209,15 @@ public class SimpleIdCache extends AbstractIndexComponent implements IdCache, Se
private HashedBytesArray checkIfCanReuse(Map<Object, Map<String, TypeBuilder>> builders, HashedBytesArray idAsBytes) {
HashedBytesArray finalIdAsBytes;
// go over and see if we can reuse this id
for (SimpleIdReaderCache idReaderCache : idReaders.values()) {
finalIdAsBytes = idReaderCache.canReuse(idAsBytes);
if (finalIdAsBytes != null) {
return finalIdAsBytes;
if (reuse) {
for (SimpleIdReaderCache idReaderCache : idReaders.values()) {
finalIdAsBytes = idReaderCache.canReuse(idAsBytes);
if (finalIdAsBytes != null) {
return finalIdAsBytes;
}
}
}
// even if we don't enable reuse, at least check on the current "live" builders that we are handling
for (Map<String, TypeBuilder> map : builders.values()) {
for (TypeBuilder typeBuilder : map.values()) {
finalIdAsBytes = typeBuilder.canReuse(idAsBytes);