Simplify row cache invalidation code

patch by Jonathan Ellis; reviewed by Aleksey Yeschenko for
CASSANDRA-10396
This commit is contained in:
Jonathan Ellis 2015-09-24 13:24:57 -07:00 committed by Aleksey Yeschenko
parent b0def95b59
commit d867ac1f41
7 changed files with 9 additions and 21 deletions

View File

@ -1226,7 +1226,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
return String.format("%.2f/%.2f", onHeap, offHeap);
}
public void maybeUpdateRowCache(DecoratedKey key)
public void maybeInvalidateCachedRow(DecoratedKey key)
{
if (!isRowCacheEnabled())
return;
@ -1247,7 +1247,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
long start = System.nanoTime();
Memtable mt = data.getMemtableFor(opGroup, replayPosition);
final long timeDelta = mt.put(key, columnFamily, indexer, opGroup);
maybeUpdateRowCache(key);
maybeInvalidateCachedRow(key);
metric.samplers.get(Sampler.WRITES).addSample(key.getKey(), key.hashCode(), 1);
metric.writeLatency.addNano(System.nanoTime() - start);
if(timeDelta < Long.MAX_VALUE)
@ -2047,7 +2047,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
RowCacheKey key = keyIter.next();
DecoratedKey dk = partitioner.decorateKey(ByteBuffer.wrap(key.key));
if (key.ksAndCFName.equals(metadata.ksAndCFName) && !Range.isInRanges(dk.getToken(), ranges))
invalidateCachedRow(dk);
maybeInvalidateCachedRow(dk);
}
if (metadata.isCounter())
@ -2532,15 +2532,6 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
CacheService.instance.rowCache.remove(key);
}
public void invalidateCachedRow(DecoratedKey key)
{
UUID cfId = Schema.instance.getId(keyspace.getName(), this.name);
if (cfId == null)
return; // secondary index
invalidateCachedRow(new RowCacheKey(metadata.ksAndCFName, key));
}
public ClockAndCount getCachedCounter(ByteBuffer partitionKey, CellName cellName)
{
if (CacheService.instance.counterCache.getCapacity() == 0L) // counter cache disabled.

View File

@ -24,8 +24,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.cassandra.db.ColumnFamilyStore;
import org.apache.cassandra.db.lifecycle.SSTableIntervalTree;
import org.apache.cassandra.db.lifecycle.Tracker;
import org.apache.cassandra.db.DecoratedKey;
import org.apache.cassandra.db.RowPosition;
import org.apache.cassandra.utils.AlwaysPresentFilter;
@ -191,7 +189,7 @@ public class CompactionController implements AutoCloseable
public void invalidateCachedRow(DecoratedKey key)
{
cfs.invalidateCachedRow(key);
cfs.maybeInvalidateCachedRow(key);
}
public void close()

View File

@ -934,7 +934,7 @@ public class CompactionManager implements CompactionManagerMBean
if (Range.isInRanges(row.getKey().getToken(), ranges))
return row;
cfs.invalidateCachedRow(row.getKey());
cfs.maybeInvalidateCachedRow(row.getKey());
if (indexedColumnsInRow != null)
indexedColumnsInRow.clear();

View File

@ -20,7 +20,6 @@ package org.apache.cassandra.io.sstable;
import java.util.*;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.Runnables;
import org.apache.cassandra.cache.InstrumentingCache;
import org.apache.cassandra.cache.KeyCacheKey;
@ -119,7 +118,7 @@ public class SSTableRewriter extends Transactional.AbstractTransactional impleme
{
if (index == null)
{
cfs.invalidateCachedRow(row.key);
cfs.maybeInvalidateCachedRow(row.key);
}
else
{

View File

@ -171,6 +171,6 @@ public class StreamReader
{
DecoratedKey key = StorageService.getPartitioner().decorateKey(ByteBufferUtil.readWithShortLength(in));
writer.appendFromStream(key, cfs.metadata, in, inputVersion);
cfs.invalidateCachedRow(key);
cfs.maybeInvalidateCachedRow(key);
}
}

View File

@ -133,7 +133,7 @@ public class RowCacheTest
int keysLeft = 109;
for (int i = 109; i >= 10; i--)
{
cachedStore.invalidateCachedRow(Util.dk("key" + i));
cachedStore.maybeInvalidateCachedRow(Util.dk("key" + i));
assert CacheService.instance.rowCache.size() == keysLeft;
keysLeft--;
}

View File

@ -127,7 +127,7 @@ public class CompactionsPurgeTest
// major compact and test that all columns but the resurrected one is completely gone
FBUtilities.waitOnFutures(CompactionManager.instance.submitMaximal(cfs, Integer.MAX_VALUE, false));
cfs.invalidateCachedRow(key);
cfs.maybeInvalidateCachedRow(key);
ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, cfName, System.currentTimeMillis()));
assertColumns(cf, "5");
assertNotNull(cf.getColumn(cellname(String.valueOf(5))));