Search in sources :

Example 1 with ReadOptions

use of org.iq80.leveldb.ReadOptions in project hadoop by apache.

the class RollingLevelDBTimelineStore method evictOldStartTimes.

@VisibleForTesting
long evictOldStartTimes(long minStartTime) throws IOException {
    LOG.info("Searching for start times to evict earlier than " + minStartTime);
    long batchSize = 0;
    long totalCount = 0;
    long startTimesCount = 0;
    WriteBatch writeBatch = null;
    DBIterator iterator = null;
    try {
        writeBatch = starttimedb.createWriteBatch();
        ReadOptions readOptions = new ReadOptions();
        readOptions.fillCache(false);
        iterator = starttimedb.iterator(readOptions);
        // seek to the first start time entry
        iterator.seekToFirst();
        // evaluate each start time entry to see if it needs to be evicted or not
        while (iterator.hasNext()) {
            Map.Entry<byte[], byte[]> current = iterator.next();
            byte[] entityKey = current.getKey();
            byte[] entityValue = current.getValue();
            long startTime = readReverseOrderedLong(entityValue, 0);
            if (startTime < minStartTime) {
                ++batchSize;
                ++startTimesCount;
                writeBatch.delete(entityKey);
                // a large delete will hold the lock for too long
                if (batchSize >= writeBatchSize) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Preparing to delete a batch of " + batchSize + " old start times");
                    }
                    starttimedb.write(writeBatch);
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Deleted batch of " + batchSize + ". Total start times deleted so far this cycle: " + startTimesCount);
                    }
                    IOUtils.cleanup(LOG, writeBatch);
                    writeBatch = starttimedb.createWriteBatch();
                    batchSize = 0;
                }
            }
            ++totalCount;
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Preparing to delete a batch of " + batchSize + " old start times");
        }
        starttimedb.write(writeBatch);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Deleted batch of " + batchSize + ". Total start times deleted so far this cycle: " + startTimesCount);
        }
        LOG.info("Deleted " + startTimesCount + "/" + totalCount + " start time entities earlier than " + minStartTime);
    } finally {
        IOUtils.cleanup(LOG, writeBatch);
        IOUtils.cleanup(LOG, iterator);
    }
    return startTimesCount;
}
Also used : DBIterator(org.iq80.leveldb.DBIterator) ReadOptions(org.iq80.leveldb.ReadOptions) RollingWriteBatch(org.apache.hadoop.yarn.server.timeline.RollingLevelDB.RollingWriteBatch) WriteBatch(org.iq80.leveldb.WriteBatch) Map(java.util.Map) TreeMap(java.util.TreeMap) LRUMap(org.apache.commons.collections.map.LRUMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 LRUMap (org.apache.commons.collections.map.LRUMap)1 RollingWriteBatch (org.apache.hadoop.yarn.server.timeline.RollingLevelDB.RollingWriteBatch)1 DBIterator (org.iq80.leveldb.DBIterator)1 ReadOptions (org.iq80.leveldb.ReadOptions)1 WriteBatch (org.iq80.leveldb.WriteBatch)1