/** * Open reader on the reftable. * <p> * The returned reader is not thread safe. * * @param ctx * reader to access the DFS storage. * @return cursor to read the table; caller must close. * @throws java.io.IOException * table cannot be opened. */ public ReftableReader open(DfsReader ctx) throws IOException { return new ReftableReader(new CacheSource(this, cache, ctx)); }
private ReftableWriter.Stats compactTopOfStack(OutputStream out, ReftableConfig cfg, byte[] newTable) throws IOException { List<Reftable> stack = refdb.stack().readers(); Reftable last = stack.get(stack.size() - 1); List<Reftable> tables = new ArrayList<>(2); tables.add(last); tables.add(new ReftableReader(BlockSource.from(newTable))); ReftableCompactor compactor = new ReftableCompactor(); compactor.setConfig(cfg); compactor.setIncludeDeletes(true); compactor.addAll(tables); compactor.compact(out); return compactor.getStats(); }
/** * References to convert into a reftable * * @param refs * references to convert into a reftable; may be empty. * @return a reader for the supplied references. */ public static Reftable from(Collection<Ref> refs) { try { ReftableConfig cfg = new ReftableConfig(); cfg.setIndexObjects(false); cfg.setAlignBlocks(false); ByteArrayOutputStream buf = new ByteArrayOutputStream(); new ReftableWriter() .setConfig(cfg) .begin(buf) .sortAndWriteRefs(refs) .finish(); return new ReftableReader(BlockSource.from(buf.toByteArray())); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Open reader on the reftable. * <p> * The returned reader is not thread safe. * * @param ctx * reader to access the DFS storage. * @return cursor to read the table; caller must close. * @throws java.io.IOException * table cannot be opened. */ public ReftableReader open(DfsReader ctx) throws IOException { return new ReftableReader(new CacheSource(this, cache, ctx)); }
private ReftableWriter.Stats compactTopOfStack(OutputStream out, ReftableConfig cfg, byte[] newTable) throws IOException { List<Reftable> stack = refdb.stack().readers(); Reftable last = stack.get(stack.size() - 1); List<Reftable> tables = new ArrayList<>(2); tables.add(last); tables.add(new ReftableReader(BlockSource.from(newTable))); ReftableCompactor compactor = new ReftableCompactor(); compactor.setConfig(cfg); compactor.setIncludeDeletes(true); compactor.addAll(tables); compactor.compact(out); return compactor.getStats(); }
/** * References to convert into a reftable * * @param refs * references to convert into a reftable; may be empty. * @return a reader for the supplied references. */ public static Reftable from(Collection<Ref> refs) { try { ReftableConfig cfg = new ReftableConfig(); cfg.setIndexObjects(false); cfg.setAlignBlocks(false); ByteArrayOutputStream buf = new ByteArrayOutputStream(); new ReftableWriter() .setConfig(cfg) .begin(buf) .sortAndWriteRefs(refs) .finish(); return new ReftableReader(BlockSource.from(buf.toByteArray())); } catch (IOException e) { throw new RuntimeException(e); } }