public Iterator<T> iterator() { return cacheMap.keys() ; }
@Override public Iterator<Key> keys() { return cache.keys(); }
@Override synchronized public Iterator<Key> keys() { return cache.keys(); }
public Iterator<T> iterator() { return cacheMap.keys() ; }
@Override public Iterator<Key> keys() { return cache.keys(); }
@Override public Iterator<Key> keys() { return cache.keys(); }
@Override synchronized public void resetAlloc(long boundary) { // On abort, need to clear the caches of inaccesible blocks. // An abort is rare (?). We do very carefully. // Could (probably) delete in the loop or use Iteator.remove on keys(). // (Check the Cache contract) List<Long> removals = new ArrayList<>() ; readCache.keys().forEachRemaining((x)->{ if ( x >= boundary ) removals.add(x) ; }) ; removals.forEach(readCache::remove) ; removals.clear() ; writeCache.keys().forEachRemaining((x)->{ if ( x >= boundary ) removals.add(x) ; }) ; removals.forEach(writeCache::remove) ; super.resetAlloc(boundary); }
@Override synchronized public void resetAlloc(long boundary) { // On abort, need to clear the caches of inaccesible blocks. // An abort is rare (?). We do very carefully. // Could (probably) delete in the loop or use Iteator.remove on keys(). // (Check the Cache contract) List<Long> removals = new ArrayList<>() ; readCache.keys().forEachRemaining((x)->{ if ( x >= boundary ) removals.add(x) ; }) ; removals.forEach(readCache::remove) ; removals.clear() ; writeCache.keys().forEachRemaining((x)->{ if ( x >= boundary ) removals.add(x) ; }) ; removals.forEach(writeCache::remove) ; super.resetAlloc(boundary); }
private boolean syncFlush() { if ( writeCache == null ) return false ; boolean didSync = false ; log("Flush (write cache)") ; long N = writeCache.size() ; Long[] ids = new Long[(int)N] ; // Single writer (sync is a write operation MRSW) // Iterating is safe. Iterator<Long> iter = writeCache.keys() ; if ( iter.hasNext() ) didSync = true ; // Need to get all then delete else concurrent modification exception. for ( int i = 0 ; iter.hasNext() ; i++ ) ids[i] = iter.next() ; for ( int i = 0 ; i < N ; i++ ) { Long id = ids[i] ; expelEntry(id) ; } if ( didSync ) super.sync() ; return didSync ; }
private boolean syncFlush() { if ( writeCache == null ) return false ; boolean didSync = false ; log("Flush (write cache)") ; long N = writeCache.size() ; Long[] ids = new Long[(int)N] ; // Single writer (sync is a write operation MRSW) // Iterating is safe. Iterator<Long> iter = writeCache.keys() ; if ( iter.hasNext() ) didSync = true ; // Need to get all then delete else concurrent modification exception. for ( int i = 0 ; iter.hasNext() ; i++ ) ids[i] = iter.next() ; for ( int i = 0 ; i < N ; i++ ) { Long id = ids[i] ; expelEntry(id) ; } if ( didSync ) super.sync() ; return didSync ; }
private boolean syncFlush() { if ( writeCache == null ) return false ; boolean didSync = false ; log("Flush (write cache)") ; long N = writeCache.size() ; Long[] ids = new Long[(int)N] ; // Single writer (sync is a write operation MRSW) // Iterating is safe. Iterator<Long> iter = writeCache.keys() ; if ( iter.hasNext() ) didSync = true ; // Need to get all then delete else concurrent modification exception. for ( int i = 0 ; iter.hasNext() ; i++ ) ids[i] = iter.next() ; for ( int i = 0 ; i < N ; i++ ) { Long id = ids[i] ; expelEntry(id) ; } if ( didSync ) super.sync() ; return didSync ; }
private void testForConsistency() { Iterator<Node> iter1 = Iter.toList(node2id_Cache.keys()).iterator() ; for ( ; iter1.hasNext() ; ) { Node n = iter1.next() ; NodeId nId = node2id_Cache.getIfPresent(n) ; if ( !id2node_Cache.containsKey(nId) ) throw new TDBException("Inconsistent: " + n + " => " + nId) ; if ( notPresent.contains(n) ) throw new TDBException("Inconsistent: " + n + " in notPresent cache (1)") ; } Iterator<NodeId> iter2 = Iter.toList(id2node_Cache.keys()).iterator() ; for ( ; iter2.hasNext() ; ) { NodeId nId = iter2.next() ; Node n = id2node_Cache.getIfPresent(nId) ; if ( !node2id_Cache.containsKey(n) ) throw new TDBException("Inconsistent: " + nId + " => " + n) ; if ( notPresent.contains(n) ) throw new TDBException("Inconsistent: " + n + " in notPresent cache (2)") ; } }
private void testForConsistency() { Iterator<Node> iter1 = Iter.toList(node2id_Cache.keys()).iterator() ; for ( ; iter1.hasNext() ; ) { Node n = iter1.next() ; NodeId nId = node2id_Cache.getIfPresent(n) ; if ( !id2node_Cache.containsKey(nId) ) throw new TDBException("Inconsistent: "+n+" => "+nId) ; if ( notPresent.contains(n) ) throw new TDBException("Inconsistent: "+n+" in notPresent cache (1)") ; } Iterator<NodeId> iter2 = Iter.toList(id2node_Cache.keys()).iterator() ; for ( ; iter2.hasNext() ; ) { NodeId nId = iter2.next() ; Node n = id2node_Cache.getIfPresent(nId) ; if ( !node2id_Cache.containsKey(n) ) throw new TDBException("Inconsistent: "+nId+" => "+n) ; if ( notPresent.contains(n) ) throw new TDBException("Inconsistent: "+n+" in notPresent cache (2)") ; } }
@Test public void cache_04() { cache.clear() ; cache.put(7, 77) ; List<Integer> x = Iter.toList(cache.keys()) ; assertEquals(1, x.size()) ; assertEquals(Integer.valueOf(7), x.get(0)) ; }