void put(AnyObjectId id, List<ObjectInfo> info) { infoCache.put(id.copy(), copyList(info)); }
private Iterable<T> lookInCache(Iterable<T> objects) { RecentInfoCache infoCache = reader.getRecentInfoCache(); List<T> missing = null; for (T obj : objects) { List<ObjectInfo> info = infoCache.get(obj); if (info != null) { onResult(obj, info); if (progress != null) progress.update(1); } else { if (missing == null) { if (objects instanceof List<?>) missing = new ArrayList<T>(((List<?>) objects).size()); else missing = new ArrayList<T>(); } missing.add(obj); } } if (missing != null) return missing; return Collections.emptyList(); }
private void processResults(Context context, Map<ObjectIndexKey, T> batch, Map<ObjectIndexKey, Collection<ObjectInfo>> objects) { for (T obj : batch.values()) { Collection<ObjectInfo> matches = objects.get(obj); if (matches == null || matches.isEmpty()) { if (retryMissingObjects && context == Context.FAST_MISSING_OK) retry.add(obj); continue; } tmp.clear(); tmp.addAll(matches); ObjectInfo.sort(tmp); if (cacheLoadedInfo) reader.getRecentInfoCache().put(obj, tmp); onResult(obj, tmp); } if (progress != null) progress.update(objects.size()); }
private List<ObjectInfo> find(AnyObjectId obj) throws DhtException { List<ObjectInfo> info = recentInfo.get(obj); if (info != null) return info; stats.cntObjectIndex_Load++; ObjectIndexKey idxKey = ObjectIndexKey.create(repo, obj); Context opt = Context.READ_REPAIR; Sync<Map<ObjectIndexKey, Collection<ObjectInfo>>> sync = Sync.create(); db.objectIndex().get(opt, Collections.singleton(idxKey), sync); try { Collection<ObjectInfo> m; m = sync.get(getOptions().getTimeout()).get(idxKey); if (m == null || m.isEmpty()) return Collections.emptyList(); info = new ArrayList<ObjectInfo>(m); ObjectInfo.sort(info); recentInfo.put(obj, info); return info; } catch (InterruptedException e) { throw new DhtTimeoutException(e); } catch (TimeoutException e) { throw new DhtTimeoutException(e); } }
DhtReader(DhtObjDatabase objdb) { this.repository = objdb.getRepository(); this.repo = objdb.getRepository().getRepositoryKey(); this.db = objdb.getDatabase(); this.readerOptions = objdb.getReaderOptions(); this.inserterOptions = objdb.getInserterOptions(); this.stats = new Statistics(); this.recentInfo = new RecentInfoCache(getOptions()); this.recentChunks = new RecentChunks(this); this.deltaBaseCache = new DeltaBaseCache(this); }
private List<ObjectInfo> find(AnyObjectId obj) throws DhtException { List<ObjectInfo> info = recentInfo.get(obj); if (info != null) return info; stats.cntObjectIndex_Load++; ObjectIndexKey idxKey = ObjectIndexKey.create(repo, obj); Context opt = Context.READ_REPAIR; Sync<Map<ObjectIndexKey, Collection<ObjectInfo>>> sync = Sync.create(); db.objectIndex().get(opt, Collections.singleton(idxKey), sync); try { Collection<ObjectInfo> m; m = sync.get(getOptions().getTimeout()).get(idxKey); if (m == null || m.isEmpty()) return Collections.emptyList(); info = new ArrayList<ObjectInfo>(m); ObjectInfo.sort(info); recentInfo.put(obj, info); return info; } catch (InterruptedException e) { throw new DhtTimeoutException(e); } catch (TimeoutException e) { throw new DhtTimeoutException(e); } }
DhtReader(DhtObjDatabase objdb) { this.repository = objdb.getRepository(); this.repo = objdb.getRepository().getRepositoryKey(); this.db = objdb.getDatabase(); this.readerOptions = objdb.getReaderOptions(); this.inserterOptions = objdb.getInserterOptions(); this.stats = new Statistics(); this.recentInfo = new RecentInfoCache(getOptions()); this.recentChunks = new RecentChunks(this); this.deltaBaseCache = new DeltaBaseCache(this); }
private void processResults(Context context, Map<ObjectIndexKey, T> batch, Map<ObjectIndexKey, Collection<ObjectInfo>> objects) { for (T obj : batch.values()) { Collection<ObjectInfo> matches = objects.get(obj); if (matches == null || matches.isEmpty()) { if (retryMissingObjects && context == Context.FAST_MISSING_OK) retry.add(obj); continue; } tmp.clear(); tmp.addAll(matches); ObjectInfo.sort(tmp); if (cacheLoadedInfo) reader.getRecentInfoCache().put(obj, tmp); onResult(obj, tmp); } if (progress != null) progress.update(objects.size()); }
private Iterable<T> lookInCache(Iterable<T> objects) { RecentInfoCache infoCache = reader.getRecentInfoCache(); List<T> missing = null; for (T obj : objects) { if (needChunkOnly && obj instanceof RefDataUtil.IdWithChunk) { push(obj, ((RefDataUtil.IdWithChunk) obj).getChunkKey()); continue; } List<ObjectInfo> info = infoCache.get(obj); if (info != null && !info.isEmpty()) { push(obj, info.get(0)); } else { if (missing == null) { if (objects instanceof List<?>) missing = new ArrayList<T>(((List<?>) objects).size()); else missing = new ArrayList<T>(); } missing.add(obj); } } if (missing != null) return missing; return Collections.emptyList(); }
void put(AnyObjectId id, List<ObjectInfo> info) { infoCache.put(id.copy(), copyList(info)); }
private synchronized void processResults(Context ctx, Map<ObjectIndexKey, T> batch, Map<ObjectIndexKey, Collection<ObjectInfo>> objects) { for (T obj : batch.values()) { Collection<ObjectInfo> matches = objects.get(obj); if (matches == null || matches.isEmpty()) { if (ctx == Context.FAST_MISSING_OK) toRetry.add(obj); else if (reportMissing) push(obj, (ChunkKey) null); continue; } tmp.clear(); tmp.addAll(matches); ObjectInfo.sort(tmp); if (cacheLoadedInfo) reader.getRecentInfoCache().put(obj, tmp); push(obj, tmp.get(0)); } runningBatches--; notify(); }
private Iterable<T> lookInCache(Iterable<T> objects) { RecentInfoCache infoCache = reader.getRecentInfoCache(); List<T> missing = null; for (T obj : objects) { if (needChunkOnly && obj instanceof RefDataUtil.IdWithChunk) { push(obj, ((RefDataUtil.IdWithChunk) obj).getChunkKey()); continue; } List<ObjectInfo> info = infoCache.get(obj); if (info != null && !info.isEmpty()) { push(obj, info.get(0)); } else { if (missing == null) { if (objects instanceof List<?>) missing = new ArrayList<T>(((List<?>) objects).size()); else missing = new ArrayList<T>(); } missing.add(obj); } } if (missing != null) return missing; return Collections.emptyList(); }
private synchronized void processResults(Context ctx, Map<ObjectIndexKey, T> batch, Map<ObjectIndexKey, Collection<ObjectInfo>> objects) { for (T obj : batch.values()) { Collection<ObjectInfo> matches = objects.get(obj); if (matches == null || matches.isEmpty()) { if (ctx == Context.FAST_MISSING_OK) toRetry.add(obj); else if (reportMissing) push(obj, (ChunkKey) null); continue; } tmp.clear(); tmp.addAll(matches); ObjectInfo.sort(tmp); if (cacheLoadedInfo) reader.getRecentInfoCache().put(obj, tmp); push(obj, tmp.get(0)); } runningBatches--; notify(); }
private Iterable<T> lookInCache(Iterable<T> objects) { RecentInfoCache infoCache = reader.getRecentInfoCache(); List<T> missing = null; for (T obj : objects) { List<ObjectInfo> info = infoCache.get(obj); if (info != null) { onResult(obj, info); if (progress != null) progress.update(1); } else { if (missing == null) { if (objects instanceof List<?>) missing = new ArrayList<T>(((List<?>) objects).size()); else missing = new ArrayList<T>(); } missing.add(obj); } } if (missing != null) return missing; return Collections.emptyList(); }