/** Shrinks queue to maximum allowed size. */ private void shrink() { long maxSize = this.maxSize; int maxBlocks = this.maxBlocks; int cnt = queue.sizex(); for (int i = 0; i < cnt && (maxBlocks > 0 && queue.sizex() > maxBlocks || maxSize > 0 && curSize.longValue() > maxSize); i++) { GridCacheEntry<GridGgfsBlockKey, byte[]> entry = queue.poll(); if (entry == null) break; // Queue is empty. byte[] val = entry.peek(); if (val != null) changeSize(-val.length); // Change current size as we polled entry from the queue. if (!entry.evict()) { // Reorder entries which we failed to evict. entry.removeMeta(META_NODE); touch(entry); } } }
@Test public void test() { Command<KVStore> initial = commands.remove(0); sm.applyFunction().apply(0L, initial); commands.forEach( c -> { final long index = la.longValue(); sm.applyFunction().apply(index, c); la.increment(); }); KVStore kvsm = (KVStore) sm; kvsm.getKvMap().forEach((k, v) -> System.out.println(k + " --> " + v)); assertTrue(kvsm.getKvMap().size() == 10); }
/** {@inheritDoc} */ @Override public long getCurrentSize() { return curSize.longValue(); }
public long getTicks() { return ticks.longValue(); }