public RocksdbDAGStore(Supplier<RocksDB> db) { this._dbSupplier = db; boolean overwriteKey = true; this.batchOptions = new DBOptions(); this.batch = new WriteBatchWithIndex(overwriteKey); }
/** * Fetch the underlying write batch that contains all pending changes to be * committed. * * Note: You should not write or delete anything from the batch directly and * should only use the functions in the {@link Transaction} class to * write to this transaction. * * @return The write batch */ public WriteBatchWithIndex getWriteBatch() { assert(isOwningHandle()); final WriteBatchWithIndex writeBatchWithIndex = new WriteBatchWithIndex(getWriteBatch(nativeHandle_)); return writeBatchWithIndex; }
/** * Atomically inserts the graph entries for all the provided commits. * * @param commits the commits to create the graph entries for (one entry for each commit/parent) * * @implNote uses a {@link WriteBatchWithIndex} to query uncommitted data through * {@link WriteBatchWithIndex#getFromBatchAndDB getFromBatchAndDB} */ public void putAll(Iterable<RevCommit> commits) { int count = 0; final Stopwatch sw = LOG.isTraceEnabled() ? Stopwatch.createStarted() : null; try (WriteBatchWithIndex batch = new WriteBatchWithIndex(); // RocksDBReference dbRef = dbhandle.getReference(); WriteOptions wo = new WriteOptions()) { wo.setSync(true); for (RevCommit c : commits) { ObjectId commitId = c.getId(); ImmutableList<ObjectId> parentIds = c.getParentIds(); put(dbRef, commitId, parentIds, batch); count++; } dbRef.db().write(wo, batch); } catch (Exception e) { throw Throwables.propagate(e); } if (LOG.isTraceEnabled()) { LOG.trace(String.format("Inserted %,d graph mappings in %s", count, sw.stop())); } }
/** * Atomically inserts the graph entries for all the provided commits. * * @param commits the commits to create the graph entries for (one entry for each commit/parent) * * @implNote uses a {@link WriteBatchWithIndex} to query uncommitted data through * {@link WriteBatchWithIndex#getFromBatchAndDB getFromBatchAndDB} */ public void putAll(Iterable<RevCommit> commits) { int count = 0; final Stopwatch sw = LOG.isTraceEnabled() ? Stopwatch.createStarted() : null; try (WriteBatchWithIndex batch = new WriteBatchWithIndex(); // RocksDBReference dbRef = dbhandle.getReference(); WriteOptions wo = new WriteOptions()) { wo.setSync(true); for (RevCommit c : commits) { ObjectId commitId = c.getId(); ImmutableList<ObjectId> parentIds = c.getParentIds(); put(dbRef, commitId, parentIds, batch); count++; } dbRef.db().write(wo, batch); } catch (RocksDBException e) { throw new RuntimeException(e); } if (LOG.isTraceEnabled()) { LOG.trace(String.format("Inserted %,d graph mappings in %s", count, sw.stop())); } }
@Override public boolean put(ObjectId commitId, ImmutableList<ObjectId> parentIds) { try (WriteBatchWithIndex batch = new WriteBatchWithIndex(); // RocksDBReference dbRef = dbhandle.getReference(); WriteOptions wo = new WriteOptions()) { wo.setSync(true); boolean updated = put(dbRef, commitId, parentIds, batch); dbRef.db().write(wo, batch); return updated; } catch (RocksDBException e) { throw new RuntimeException(e); } }
@Override public boolean put(ObjectId commitId, ImmutableList<ObjectId> parentIds) { try (WriteBatchWithIndex batch = new WriteBatchWithIndex(); // RocksDBReference dbRef = dbhandle.getReference(); WriteOptions wo = new WriteOptions()) { wo.setSync(true); boolean updated = put(dbRef, commitId, parentIds, batch); dbRef.db().write(wo, batch); return updated; } catch (Exception e) { throw Throwables.propagate(e); } }