ObjectCache create(CacheIdentifier cacheId) { return new ObjectCache(() -> sharedCache(), cacheId); }
private int query(List<ObjectId> ids) { int hits = 0; for (ObjectId id : ids) { RevObject object = cache.getIfPresent(id); if (object != null) { hits++; } } return hits; }
void doRelease(ObjectCache cache) { cache.invalidateAll(); }
private RevObject getIfPresent(final ObjectId id, final @Nullable RevObject.TYPE type, DataSource ds) { RevObject cached = sharedCache.getIfPresent(id); if (cached != null) { return cached; sharedCache.put(obj); return obj;
private Stopwatch put(List<? extends RevObject> objects) { Stopwatch sw = Stopwatch.createStarted(); for (RevObject f : objects) { cache.put(f); } return sw.stop(); }
long notifyDeleted(int[] deleted, List<ObjectId> ids, BulkOpListener listener) { long count = 0; for (int i = 0; i < deleted.length; i++) { ObjectId id = ids.get(i); sharedCache.invalidate(id); if (deleted[i] > 0) { count++; listener.deleted(id); } else { listener.notFound(id); } } return count; }
@Override public boolean exists(final ObjectId id) { checkNotNull(id, "argument id is null"); checkState(isOpen(), "Database is closed"); config.checkRepositoryExists(); if (sharedCache.contains(id)) { return true; } final String sql = format( "SELECT TRUE WHERE EXISTS ( SELECT 1 FROM %s WHERE ((id).h1) = ? AND id = CAST(ROW(?,?,?) AS OBJECTID) )", objectsTable()); final PGId pgid = PGId.valueOf(id); try (Connection cx = PGStorage.newConnection(dataSource)) { try (PreparedStatement ps = cx.prepareStatement(log(sql, LOG, id))) { ps.setInt(1, pgid.hash1()); pgid.setArgs(ps, 2); try (ResultSet rs = ps.executeQuery()) { boolean exists = rs.next(); return exists; } } } catch (SQLException e) { throw new RuntimeException(e); } }
private RevObject getIfPresent(final ObjectId id, final @Nullable RevObject.TYPE type, DataSource ds) { RevObject cached = sharedCache.getIfPresent(id); if (cached != null) { return cached; sharedCache.put(obj); return obj;
private Stopwatch put(List<? extends RevObject> objects) { Stopwatch sw = Stopwatch.createStarted(); for (RevObject f : objects) { cache.put(f); } return sw.stop(); }
long notifyDeleted(int[] deleted, List<ObjectId> ids, BulkOpListener listener) { long count = 0; for (int i = 0; i < deleted.length; i++) { ObjectId id = ids.get(i); sharedCache.invalidate(id); if (deleted[i] > 0) { count++; listener.deleted(id); } else { listener.notFound(id); } } return count; }
@Override public boolean exists(final ObjectId id) { checkNotNull(id, "argument id is null"); checkState(isOpen(), "Database is closed"); config.checkRepositoryExists(); if (sharedCache.contains(id)) { return true; } final String sql = format( "SELECT TRUE WHERE EXISTS ( SELECT 1 FROM %s WHERE ((id).h1) = ? AND id = CAST(ROW(?,?,?) AS OBJECTID) )", objectsTable()); final PGId pgid = PGId.valueOf(id); try (Connection cx = PGStorage.newConnection(dataSource)) { try (PreparedStatement ps = cx.prepareStatement(log(sql, LOG, id))) { ps.setInt(1, pgid.hash1()); pgid.setArgs(ps, 2); try (ResultSet rs = ps.executeQuery()) { boolean exists = rs.next(); return exists; } } } catch (SQLException e) { throw propagate(e); } }
private int query(List<ObjectId> ids) { int hits = 0; for (ObjectId id : ids) { RevObject object = cache.getIfPresent(id); if (object != null) { hits++; } } return hits; }
void doRelease(ObjectCache cache) { cache.invalidateAll(); }
ObjectCache create(CacheIdentifier cacheId) { return new ObjectCache(() -> sharedCache(), cacheId); }
sharedCache.put(obj);
/** * Deletes the object with the specified id. * * @return Flag indicating if object was actually removed. */ private void delete(final ObjectId id, DataSource ds) { String sql = format("DELETE FROM %s WHERE id = CAST(ROW(?,?,?) AS OBJECTID)", objectsTable()); try (Connection cx = PGStorage.newConnection(ds)) { cx.setAutoCommit(true); try (PreparedStatement stmt = cx.prepareStatement(log(sql, LOG, id))) { PGId.valueOf(id).setArgs(stmt, 1); stmt.executeUpdate(); sharedCache.invalidate(id); } } catch (SQLException e) { throw new RuntimeException(e); } }
for (int i = 0; i < superPartitionBatchSize && ids.hasNext(); i++) { ObjectId id = ids.next(); RevObject cached = cache.getIfPresent(id); if (cached == null) { cacheMisses.add(id);
public List<TestResult> runTest(List<? extends RevObject> objects) { List<TestResult> results = new ArrayList<>(); for (RevObjectSerializer encoder : encoders) { cache.invalidateAll(); TestResult result = run(encoder, objects); results.add(result); } return results; }
public void setUp(Supplier<SharedCache> sharedCache) throws Exception { this.sharedCache = sharedCache.get(); cache = new ObjectCache(sharedCache, new CacheIdentifier(1)); Stopwatch sw = Stopwatch.createStarted(); Runtime runtime = Runtime.getRuntime(); long mem = runtime.totalMemory() - Runtime.getRuntime().freeMemory(); leafTrees = createLeafTrees(treeCount); long mem2 = runtime.totalMemory() - Runtime.getRuntime().freeMemory(); System.err.printf("leaf tree mem: %,d\n", mem2 - mem); bucketTrees = createBucketTrees(bucketTreeCount); features = createFeatures(featureCount); sw.stop(); System.err.printf("Created %,d features, %,d trees, %,d buckets in %s\n", featureCount, treeCount, treeCount, sw); }