Browse Source

reftable: support threshold based compaction

Transactions may wish to merge several tables together as part of an
operation.  Setting a byte limit allows the transaction to consider
only some recent tables, bounding the cost of the compaction.

Change-Id: If037f2cbdc174ff1a215d5917178b33cde4ddaba
stable-4.9
Shawn Pearce 8 years ago
parent
commit
195541dd30
  1. 41
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableCompactor.java
  2. 11
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java

41
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableCompactor.java

@ -71,6 +71,8 @@ public class ReftableCompactor {
private final ReftableWriter writer = new ReftableWriter();
private final ArrayDeque<Reftable> tables = new ArrayDeque<>();
private long compactBytesLimit;
private long bytesToCompact;
private boolean includeDeletes;
private long minUpdateIndex;
private long maxUpdateIndex;
@ -87,6 +89,16 @@ public class ReftableCompactor {
return this;
}
/**
* @param bytes
* limit on number of bytes from source tables to compact.
* @return {@code this}
*/
public ReftableCompactor setCompactBytesLimit(long bytes) {
compactBytesLimit = bytes;
return this;
}
/**
* @param deletes
* {@code true} to include deletions in the output, which may be
@ -139,6 +151,9 @@ public class ReftableCompactor {
/**
* Add all of the tables, in the specified order.
* <p>
* Unconditionally adds all tables, ignoring the
* {@link #setCompactBytesLimit(long)}.
*
* @param readers
* tables to compact. Tables should be ordered oldest first/most
@ -149,6 +164,32 @@ public class ReftableCompactor {
tables.addAll(readers);
}
/**
* Try to add this reader at the bottom of the stack.
* <p>
* A reader may be rejected by returning {@code false} if the compactor is
* already rewriting its {@link #setCompactBytesLimit(long)}. When this
* happens the caller should stop trying to add tables, and execute the
* compaction.
*
* @param reader
* the reader to insert at the bottom of the stack. Caller is
* responsible for closing the reader.
* @return {@code true} if the compactor accepted this table; {@code false}
* if the compactor has reached its limit.
* @throws IOException
* if size of {@code reader} cannot be read.
*/
public boolean tryAddFirst(ReftableReader reader) throws IOException {
long sz = reader.size();
if (compactBytesLimit > 0 && bytesToCompact + sz > compactBytesLimit) {
return false;
}
bytesToCompact += sz;
tables.addFirst(reader);
return true;
}
/**
* Write a compaction to {@code out}.
*

11
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java

@ -433,6 +433,17 @@ public class ReftableReader extends Reftable {
return end % blockSize == 0 ? blocks : (blocks + 1);
}
/**
* Get size of the reftable, in bytes.
*
* @return size of the reftable, in bytes.
* @throws IOException
* size cannot be obtained.
*/
public long size() throws IOException {
return src.size();
}
@Override
public void close() throws IOException {
src.close();

Loading…
Cancel
Save