Search in sources :

Example 6 with KeyCacheKey

use of org.apache.cassandra.cache.KeyCacheKey in project eiger by wlloyd.

the class StatusLogger method log.

public static void log() {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    // everything from o.a.c.concurrent
    logger.info(String.format("%-25s%10s%10s%10s", "Pool Name", "Active", "Pending", "Blocked"));
    Set<ObjectName> request, internal;
    try {
        request = server.queryNames(new ObjectName("org.apache.cassandra.request:type=*"), null);
        internal = server.queryNames(new ObjectName("org.apache.cassandra.internal:type=*"), null);
    } catch (MalformedObjectNameException e) {
        throw new RuntimeException(e);
    }
    for (ObjectName objectName : Iterables.concat(request, internal)) {
        String poolName = objectName.getKeyProperty("type");
        JMXEnabledThreadPoolExecutorMBean threadPoolProxy = JMX.newMBeanProxy(server, objectName, JMXEnabledThreadPoolExecutorMBean.class);
        logger.info(String.format("%-25s%10s%10s%10s", poolName, threadPoolProxy.getActiveCount(), threadPoolProxy.getPendingTasks(), threadPoolProxy.getCurrentlyBlockedTasks()));
    }
    // one offs
    logger.info(String.format("%-25s%10s%10s", "CompactionManager", "n/a", CompactionManager.instance.getPendingTasks()));
    int pendingCommands = 0;
    for (int n : MessagingService.instance().getCommandPendingTasks().values()) {
        pendingCommands += n;
    }
    int pendingResponses = 0;
    for (int n : MessagingService.instance().getResponsePendingTasks().values()) {
        pendingResponses += n;
    }
    logger.info(String.format("%-25s%10s%10s", "MessagingService", "n/a", pendingCommands + "," + pendingResponses));
    // Global key/row cache information
    AutoSavingCache<KeyCacheKey, Long> keyCache = CacheService.instance.keyCache;
    AutoSavingCache<RowCacheKey, ColumnFamily> rowCache = CacheService.instance.rowCache;
    int keyCacheKeysToSave = DatabaseDescriptor.getKeyCacheKeysToSave();
    int rowCacheKeysToSave = DatabaseDescriptor.getRowCacheKeysToSave();
    logger.info(String.format("%-25s%10s%25s%25s%65s", "Cache Type", "Size", "Capacity", "KeysToSave", "Provider"));
    logger.info(String.format("%-25s%10s%25s%25s%65s", "KeyCache", keyCache.weightedSize(), keyCache.getCapacity(), keyCacheKeysToSave == Integer.MAX_VALUE ? "all" : keyCacheKeysToSave, ""));
    logger.info(String.format("%-25s%10s%25s%25s%65s", "RowCache", rowCache.weightedSize(), rowCache.getCapacity(), rowCacheKeysToSave == Integer.MAX_VALUE ? "all" : rowCacheKeysToSave, DatabaseDescriptor.getRowCacheProvider().getClass().getName()));
    // per-CF stats
    logger.info(String.format("%-25s%20s", "ColumnFamily", "Memtable ops,data"));
    for (ColumnFamilyStore cfs : ColumnFamilyStore.all()) {
        logger.info(String.format("%-25s%20s", cfs.table.name + "." + cfs.columnFamily, cfs.getMemtableColumnsCount() + "," + cfs.getMemtableDataSize()));
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) JMXEnabledThreadPoolExecutorMBean(org.apache.cassandra.concurrent.JMXEnabledThreadPoolExecutorMBean) KeyCacheKey(org.apache.cassandra.cache.KeyCacheKey) ObjectName(javax.management.ObjectName) ColumnFamily(org.apache.cassandra.db.ColumnFamily) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RowCacheKey(org.apache.cassandra.cache.RowCacheKey) MBeanServer(javax.management.MBeanServer)

Example 7 with KeyCacheKey

use of org.apache.cassandra.cache.KeyCacheKey in project eiger by wlloyd.

the class KeyCacheTest method testKeyCacheLoad.

@Test
public void testKeyCacheLoad() throws Exception {
    CompactionManager.instance.disableAutoCompaction();
    ColumnFamilyStore store = Table.open(TABLE1).getColumnFamilyStore(COLUMN_FAMILY2);
    // empty the cache
    CacheService.instance.invalidateKeyCache();
    assert CacheService.instance.keyCache.size() == 0;
    // insert data and force to disk
    insertData(TABLE1, COLUMN_FAMILY2, 0, 100);
    store.forceBlockingFlush();
    // populate the cache
    readData(TABLE1, COLUMN_FAMILY2, 0, 100);
    assertEquals(100, CacheService.instance.keyCache.size());
    // really? our caches don't implement the map interface? (hence no .addAll)
    Map<KeyCacheKey, Long> savedMap = new HashMap<KeyCacheKey, Long>();
    for (KeyCacheKey k : CacheService.instance.keyCache.getKeySet()) {
        savedMap.put(k, CacheService.instance.keyCache.get(k));
    }
    // force the cache to disk
    CacheService.instance.keyCache.submitWrite(Integer.MAX_VALUE).get();
    CacheService.instance.invalidateKeyCache();
    assert CacheService.instance.keyCache.size() == 0;
}
Also used : HashMap(java.util.HashMap) KeyCacheKey(org.apache.cassandra.cache.KeyCacheKey) Test(org.junit.Test)

Example 8 with KeyCacheKey

use of org.apache.cassandra.cache.KeyCacheKey in project eiger by wlloyd.

the class SSTableReader method getPosition.

/**
     * @param key The key to apply as the rhs to the given Operator. A 'fake' key is allowed to
     * allow key selection by token bounds but only if op != * EQ
     * @param op The Operator defining matching keys: the nearest key to the target matching the operator wins.
     * @return The position in the data file to find the key, or -1 if the key is not present
     */
public long getPosition(RowPosition key, Operator op) {
    // first, check bloom filter
    if (op == Operator.EQ) {
        // EQ only make sense if the key is a valid row key
        assert key instanceof DecoratedKey;
        if (!bf.isPresent(((DecoratedKey) key).key))
            return -1;
    }
    // next, the key cache (only make sense for valid row key)
    if ((op == Operator.EQ || op == Operator.GE) && (key instanceof DecoratedKey)) {
        DecoratedKey decoratedKey = (DecoratedKey) key;
        Long cachedPosition = getCachedPosition(new KeyCacheKey(descriptor, decoratedKey.key), true);
        if (cachedPosition != null)
            return cachedPosition;
    }
    // next, see if the sampled index says it's impossible for the key to be present
    IndexSummary.KeyPosition sampledPosition = getIndexScanPosition(key);
    if (sampledPosition == null) {
        if (op == Operator.EQ)
            bloomFilterTracker.addFalsePositive();
        // we matched the -1th position: if the operator might match forward, return the 0th position
        return op.apply(1) >= 0 ? 0 : -1;
    }
    // scan the on-disk index, starting at the nearest sampled position
    Iterator<FileDataInput> segments = ifile.iterator(sampledPosition.indexPosition, INDEX_FILE_BUFFER_BYTES);
    while (segments.hasNext()) {
        FileDataInput input = segments.next();
        try {
            while (!input.isEOF()) {
                // read key & data position from index entry
                DecoratedKey indexDecoratedKey = decodeKey(partitioner, descriptor, ByteBufferUtil.readWithShortLength(input));
                long dataPosition = input.readLong();
                int comparison = indexDecoratedKey.compareTo(key);
                int v = op.apply(comparison);
                if (v == 0) {
                    if (comparison == 0 && keyCache != null && keyCache.getCapacity() > 0) {
                        // key can be == to the index key only if it's a true row key
                        assert key instanceof DecoratedKey;
                        DecoratedKey decoratedKey = (DecoratedKey) key;
                        // store exact match for the key
                        cacheKey(decoratedKey, dataPosition);
                    }
                    if (op == Operator.EQ)
                        bloomFilterTracker.addTruePositive();
                    return dataPosition;
                }
                if (v < 0) {
                    if (op == Operator.EQ)
                        bloomFilterTracker.addFalsePositive();
                    return -1;
                }
            }
        } catch (IOException e) {
            throw new IOError(e);
        } finally {
            FileUtils.closeQuietly(input);
        }
    }
    if (op == Operator.EQ)
        bloomFilterTracker.addFalsePositive();
    return -1;
}
Also used : KeyCacheKey(org.apache.cassandra.cache.KeyCacheKey)

Example 9 with KeyCacheKey

use of org.apache.cassandra.cache.KeyCacheKey in project eiger by wlloyd.

the class SSTableReader method cacheKey.

public void cacheKey(DecoratedKey key, Long info) {
    CFMetaData.Caching caching = metadata.getCaching();
    if (keyCache == null || caching == CFMetaData.Caching.NONE || caching == CFMetaData.Caching.ROWS_ONLY)
        return;
    // avoid keeping a permanent reference to the original key buffer
    keyCache.put(new KeyCacheKey(descriptor, ByteBufferUtil.clone(key.key)), info);
}
Also used : CFMetaData(org.apache.cassandra.config.CFMetaData) KeyCacheKey(org.apache.cassandra.cache.KeyCacheKey)

Aggregations

KeyCacheKey (org.apache.cassandra.cache.KeyCacheKey)9 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ByteBuffer (java.nio.ByteBuffer)1 Map (java.util.Map)1 MBeanServer (javax.management.MBeanServer)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ObjectName (javax.management.ObjectName)1 RowCacheKey (org.apache.cassandra.cache.RowCacheKey)1 JMXEnabledThreadPoolExecutorMBean (org.apache.cassandra.concurrent.JMXEnabledThreadPoolExecutorMBean)1 CFMetaData (org.apache.cassandra.config.CFMetaData)1 ColumnFamily (org.apache.cassandra.db.ColumnFamily)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)1 FileDataInput (org.apache.cassandra.io.util.FileDataInput)1 CacheMetrics (org.apache.cassandra.metrics.CacheMetrics)1 CachingParams (org.apache.cassandra.schema.CachingParams)1 TableMetadataRef (org.apache.cassandra.schema.TableMetadataRef)1 Test (org.junit.Test)1