@Override public ReftableConfig getReftableConfig() { ReftableConfig cfg = new ReftableConfig(); cfg.setAlignBlocks(false); cfg.setIndexObjects(false); cfg.fromConfig(getRepository().getConfig()); return cfg; }
refBlockSize = config.getRefBlockSize(); logBlockSize = config.getLogBlockSize(); restartInterval = config.getRestartInterval(); maxIndexLevels = config.getMaxIndexLevels(); alignBlocks = config.isAlignBlocks(); indexObjects = config.isIndexObjects();
static ReftableConfig configureReftable(ReftableConfig cfg, DfsOutputStream out) { int bs = out.blockSize(); if (bs > 0) { cfg = new ReftableConfig(cfg); cfg.setRefBlockSize(bs); cfg.setAlignBlocks(true); } return cfg; }
/** * 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); } }
/** * Set configuration for the writer. * * @param cfg * configuration for the writer. * @return {@code this} */ public ReftableWriter setConfig(ReftableConfig cfg) { this.config = cfg != null ? cfg : new ReftableConfig(); return this; }
/** * Create a configuration honoring settings in a * {@link org.eclipse.jgit.lib.Config}. * * @param cfg * the source to read settings from. The source is not retained * by the new configuration, instead its settings are copied * during the constructor. */ public ReftableConfig(Config cfg) { fromConfig(cfg); }
private boolean canCompactTopOfStack(ReftableConfig cfg) throws IOException { ReftableStack stack = refdb.stack(); List<Reftable> readers = stack.readers(); if (readers.isEmpty()) { return false; } int lastIdx = readers.size() - 1; DfsReftable last = stack.files().get(lastIdx); DfsPackDescription desc = last.getPackDescription(); if (desc.getPackSource() != PackSource.INSERT || !packOnlyContainsReftable(desc)) { return false; } Reftable table = readers.get(lastIdx); int bs = cfg.getRefBlockSize(); return table instanceof ReftableReader && ((ReftableReader) table).size() <= 3 * bs; }
static ReftableConfig configureReftable(ReftableConfig cfg, DfsOutputStream out) { int bs = out.blockSize(); if (bs > 0) { cfg = new ReftableConfig(cfg); cfg.setRefBlockSize(bs); cfg.setAlignBlocks(true); } return cfg; }
/** * 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); } }
/** * Initialize a writer with a default configuration. */ public ReftableWriter() { this(new ReftableConfig()); }
/** * Create a configuration honoring the repository's settings. * * @param db * the repository to read settings from. The repository is not * retained by the new configuration, instead its settings are * copied during the constructor. */ public ReftableConfig(Repository db) { fromConfig(db.getConfig()); }
private void applyUpdates(RevWalk rw, List<ReceiveCommand> pending) throws IOException { List<Ref> newRefs = toNewRefs(rw, pending); long updateIndex = nextUpdateIndex(); Set<DfsPackDescription> prune = Collections.emptySet(); DfsPackDescription pack = odb.newPack(PackSource.INSERT); try (DfsOutputStream out = odb.writeFile(pack, REFTABLE)) { ReftableConfig cfg = DfsPackCompactor .configureReftable(reftableConfig, out); ReftableWriter.Stats stats; if (refdb.compactDuringCommit() && newRefs.size() * AVG_BYTES <= cfg.getRefBlockSize() && canCompactTopOfStack(cfg)) { ByteArrayOutputStream tmp = new ByteArrayOutputStream(); write(tmp, cfg, updateIndex, newRefs, pending); stats = compactTopOfStack(out, cfg, tmp.toByteArray()); prune = toPruneTopOfStack(); } else { stats = write(out, cfg, updateIndex, newRefs, pending); } pack.addFileExt(REFTABLE); pack.setReftableStats(stats); } odb.commitPack(Collections.singleton(pack), prune); odb.addReftable(pack, prune); refdb.clearCache(); }
refBlockSize = config.getRefBlockSize(); logBlockSize = config.getLogBlockSize(); restartInterval = config.getRestartInterval(); maxIndexLevels = config.getMaxIndexLevels(); alignBlocks = config.isAlignBlocks(); indexObjects = config.isIndexObjects();
@Override public ReftableConfig getReftableConfig() { ReftableConfig cfg = new ReftableConfig(); cfg.setAlignBlocks(false); cfg.setIndexObjects(false); cfg.fromConfig(getRepository().getConfig()); return cfg; }
/** * Get configuration to write new reftables with. * * @return configuration to write new reftables with. */ public ReftableConfig getReftableConfig() { return new ReftableConfig(getRepository().getConfig()); }
/** * Create a configuration honoring settings in a * {@link org.eclipse.jgit.lib.Config}. * * @param cfg * the source to read settings from. The source is not retained * by the new configuration, instead its settings are copied * during the constructor. */ public ReftableConfig(Config cfg) { fromConfig(cfg); }
private boolean canCompactTopOfStack(ReftableConfig cfg) throws IOException { ReftableStack stack = refdb.stack(); List<Reftable> readers = stack.readers(); if (readers.isEmpty()) { return false; } int lastIdx = readers.size() - 1; DfsReftable last = stack.files().get(lastIdx); DfsPackDescription desc = last.getPackDescription(); if (desc.getPackSource() != PackSource.INSERT || !packOnlyContainsReftable(desc)) { return false; } Reftable table = readers.get(lastIdx); int bs = cfg.getRefBlockSize(); return table instanceof ReftableReader && ((ReftableReader) table).size() <= 3 * bs; }
/** * Set configuration for the writer. * * @param cfg * configuration for the writer. * @return {@code this} */ public ReftableWriter setConfig(ReftableConfig cfg) { this.config = cfg != null ? cfg : new ReftableConfig(); return this; }
/** * Create a configuration honoring the repository's settings. * * @param db * the repository to read settings from. The repository is not * retained by the new configuration, instead its settings are * copied during the constructor. */ public ReftableConfig(Repository db) { fromConfig(db.getConfig()); }
private void applyUpdates(RevWalk rw, List<ReceiveCommand> pending) throws IOException { List<Ref> newRefs = toNewRefs(rw, pending); long updateIndex = nextUpdateIndex(); Set<DfsPackDescription> prune = Collections.emptySet(); DfsPackDescription pack = odb.newPack(PackSource.INSERT); try (DfsOutputStream out = odb.writeFile(pack, REFTABLE)) { ReftableConfig cfg = DfsPackCompactor .configureReftable(reftableConfig, out); ReftableWriter.Stats stats; if (refdb.compactDuringCommit() && newRefs.size() * AVG_BYTES <= cfg.getRefBlockSize() && canCompactTopOfStack(cfg)) { ByteArrayOutputStream tmp = new ByteArrayOutputStream(); write(tmp, cfg, updateIndex, newRefs, pending); stats = compactTopOfStack(out, cfg, tmp.toByteArray()); prune = toPruneTopOfStack(); } else { stats = write(out, cfg, updateIndex, newRefs, pending); } pack.addFileExt(REFTABLE); pack.setReftableStats(stats); } odb.commitPack(Collections.singleton(pack), prune); odb.addReftable(pack, prune); refdb.clearCache(); }