private AbstractShard getReadMap(byte[] hash) throws IOException { Lock l = gcLock.readLock(); l.lock(); // long v = ct.incrementAndGet(); try { if (!runningGC && !lbf.mightContain(hash)) { // SDFSLogger.getLog().info("not in bloom filter"); return null; } } finally { l.unlock(); } Iterator<ProgressiveFileByteArrayLongMap> iter = activeReadMaps.iterator(); while (iter.hasNext()) { ProgressiveFileByteArrayLongMap _m = iter.next(); if (_m.containsKey(hash)) return _m; } iter = maps.iterator(); while (iter.hasNext()) { ProgressiveFileByteArrayLongMap _m = iter.next(); if (!activeReadMaps.contains(_m) && _m.containsKey(hash)) { al.lock(); try { // SDFSLogger.getLog().info("adding active " + // _m.toString()); if (activeReadMaps.remainingCapacity() == 0) { ProgressiveFileByteArrayLongMap obf = activeReadMaps.poll(); // SDFSLogger.getLog().info("removed active " + // obf.toString()); if (obf != null) obf.stopRun(); } /* * if(activeReadMaps.offer(_m)) * SDFSLogger.getLog().info("added active " + * _m.toString()); else * SDFSLogger.getLog().info("unable to add active " + * _m.toString()); */ try { loadCacheExecutor.execute(_m); } catch (Exception e) { if (SDFSLogger.isDebug()) SDFSLogger.getLog().debug("unable to cache " + _m, e); } } finally { al.unlock(); } return _m; } } /* if(!runningGC) { long mv = mt.incrementAndGet(); double pc = (double)mv/(double)v; SDFSLogger.getLog().info("might be in bloom filter " + runningGC + " pc=" + pc); } */ return null; }
private long getPos(byte[] hash) throws IOException { long pos = -1; Lock l = gcLock.readLock(); l.lock(); try { if (!runningGC && !lbf.mightContain(hash)) return pos; } finally { l.unlock(); } Iterator<ProgressiveFileByteArrayLongMap> iter = activeReadMaps.iterator(); while (iter.hasNext()) { ProgressiveFileByteArrayLongMap m = iter.next(); pos = m.get(hash); if (pos != -1) { return pos; } } if (pos == -1) { iter = maps.iterator(); while (iter.hasNext()) { ProgressiveFileByteArrayLongMap m = iter.next(); pos = m.get(hash); if (pos != -1) { al.lock(); try { if (!activeReadMaps.contains(m)) { if (SDFSLogger.isDebug()) SDFSLogger.getLog().debug("adding active " + m.toString()); if (activeReadMaps.remainingCapacity() == 0) { ProgressiveFileByteArrayLongMap obf = activeReadMaps.poll(); if (obf != null) obf.stopRun(); } activeReadMaps.offer(m); try { loadCacheExecutor.execute(m); } catch (Exception e) { SDFSLogger.getLog().debug("unable to cache " + m, e); } } } finally { al.unlock(); } return pos; } } } return pos; }