final boolean isGarbage() { return desc.getPackSource() == UNREACHABLE_GARBAGE; }
private boolean hasGcReftable() { for (DfsReftable table : reftablesBefore) { if (table.getPackDescription().getPackSource() == GC) { return true; } } return false; }
private boolean packIsExpiredGarbage(DfsPackDescription d, long now) { // Consider the garbage pack as expired when it's older than // garbagePackTtl. This check gives concurrent inserter threads // sufficient time to identify an object is not in the graph and should // have a new copy written, rather than relying on something from an // UNREACHABLE_GARBAGE pack. return d.getPackSource() == UNREACHABLE_GARBAGE && garbageTtlMillis > 0 && now - d.getLastModified() >= garbageTtlMillis; }
/** {@inheritDoc} */ @Override public boolean wasDeltaAttempted() { switch (pack.getPackDescription().getPackSource()) { case GC: case GC_REST: case GC_TXN: return true; default: return false; } } }
private List<DfsPackFile> garbagePacksForSelectRepresentation() throws IOException { DfsPackFile[] packs = db.getPacks(); List<DfsPackFile> garbage = new ArrayList<>(packs.length); for (DfsPackFile p : packs) { if (p.getPackDescription().getPackSource() == UNREACHABLE_GARBAGE) { garbage.add(p); } } return garbage; }
private List<DfsPackFile> sortPacksForSelectRepresentation() throws IOException { DfsPackFile[] packs = db.getPacks(); List<DfsPackFile> sorted = new ArrayList<>(packs.length); for (DfsPackFile p : packs) { if (p.getPackDescription().getPackSource() != UNREACHABLE_GARBAGE) { sorted.add(p); } } Collections.sort(sorted, PACK_SORT_FOR_REUSE); return sorted; }
private long estimateGcPackSize(PackSource first, PackSource... rest) { EnumSet<PackSource> sourceSet = EnumSet.of(first, rest); // Every pack file contains 12 bytes of header and 20 bytes of trailer. // Include the final pack file header and trailer size here and ignore // the same from individual pack files. long size = 32; for (DfsPackDescription pack : getSourcePacks()) { if (sourceSet.contains(pack.getPackSource())) { size += pack.getFileSize(PACK) - 32; } } return size; }
static Comparator<DfsPackDescription> reuseComparator() { return (a, b) -> { PackSource as = a.getPackSource(); PackSource bs = b.getPackSource(); if (as == bs && DfsPackDescription.isGC(as)) { // Push smaller GC files last; these likely have higher quality // delta compression and the contained representation should be // favored over other files. return Long.signum(b.getFileSize(PACK) - a.getFileSize(PACK)); } // DfsPackDescription.compareTo already did a reasonable sort. // Rely on Arrays.sort being stable, leaving equal elements. return 0; }; }
static Comparator<DfsPackDescription> reftableComparator() { return (a, b) -> { // GC, COMPACT reftables first by reversing default order. int c = PackSource.DEFAULT_COMPARATOR.reversed() .compare(a.getPackSource(), b.getPackSource()); if (c != 0) { return c; } // Lower maxUpdateIndex first. c = Long.signum(a.getMaxUpdateIndex() - b.getMaxUpdateIndex()); if (c != 0) { return c; } // Older reftable first. return Long.signum(a.getLastModified() - b.getLastModified()); }; }
private void readPacksBefore() throws IOException { DfsPackFile[] packs = objdb.getPacks(); packsBefore = new ArrayList<>(packs.length); expiredGarbagePacks = new ArrayList<>(packs.length); long now = SystemReader.getInstance().getCurrentTime(); for (DfsPackFile p : packs) { DfsPackDescription d = p.getPackDescription(); if (d.getPackSource() != UNREACHABLE_GARBAGE) { packsBefore.add(p); } else if (packIsExpiredGarbage(d, now)) { expiredGarbagePacks.add(p); } else if (packIsCoalesceableGarbage(d, now)) { packsBefore.add(p); } } }
DfsPackDescription::getPackSource, packSourceComparator) .thenComparing((a, b) -> { PackSource as = a.getPackSource(); PackSource bs = b.getPackSource();
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; }
if (d.getPackSource() != UNREACHABLE_GARBAGE || d.getFileSize(PackExt.PACK) >= coalesceGarbageLimit) { return false;
private void checkPacks(ProgressMonitor pm, FsckError errors) throws IOException, FileNotFoundException { try (DfsReader ctx = objdb.newReader()) { for (DfsPackFile pack : objdb.getPacks()) { DfsPackDescription packDesc = pack.getPackDescription(); if (packDesc.getPackSource() == PackSource.UNREACHABLE_GARBAGE) { continue; } try (ReadableChannel rc = objdb.openFile(packDesc, PACK)) { verifyPack(pm, errors, ctx, pack, rc); } catch (MissingObjectException e) { errors.getMissingObjects().add(e.getObjectId()); } catch (CorruptPackIndexException e) { errors.getCorruptIndices().add(new CorruptIndex( pack.getPackDescription().getFileName(INDEX), e.getErrorType())); } } } checkGitModules(pm, errors); }
/** * Automatically select pack and reftables to be included, and add them. * <p> * Packs are selected based on size, smaller packs get included while bigger * ones are omitted. * * @return {@code this} * @throws java.io.IOException * existing packs cannot be read. */ public DfsPackCompactor autoAdd() throws IOException { DfsObjDatabase objdb = repo.getObjectDatabase(); for (DfsPackFile pack : objdb.getPacks()) { DfsPackDescription d = pack.getPackDescription(); if (d.getFileSize(PACK) < autoAddSize) add(pack); else exclude(pack); } if (reftableConfig != null) { for (DfsReftable table : objdb.getReftables()) { DfsPackDescription d = table.getPackDescription(); if (d.getPackSource() != GC && d.getFileSize(REFTABLE) < autoAddSize) { add(table); } } } return this; }
/** {@inheritDoc} */ @Override public boolean wasDeltaAttempted() { switch (pack.getPackDescription().getPackSource()) { case GC: case GC_REST: case GC_TXN: return true; default: return false; } } }
@Override public boolean wasDeltaAttempted() { return pack.getPackDescription().getPackSource() == GC; } }
private static long mostRecentGC(DfsPackFile[] packs) { long r = 0; for (DfsPackFile p : packs) { DfsPackDescription d = p.getPackDescription(); if (d.getPackSource() == GC || d.getPackSource() == GC_REST) { r = Math.max(r, d.getLastModified()); } } return r; }
private boolean packIsExpiredGarbage(DfsPackDescription d, long now) { // Consider the garbage pack as expired when it's older than // garbagePackTtl. This check gives concurrent inserter threads // sufficient time to identify an object is not in the graph and should // have a new copy written, rather than relying on something from an // UNREACHABLE_GARBAGE pack. return d.getPackSource() == UNREACHABLE_GARBAGE && garbageTtlMillis > 0 && now - d.getLastModified() >= garbageTtlMillis; }
private boolean hasGcReftable() { for (DfsReftable table : reftablesBefore) { if (table.getPackDescription().getPackSource() == GC) { return true; } } return false; }