reftable: move AutoCloseable to ReftableReader
MergedReftable is not used as an AutoCloseable, because closing tables is currently handled by DfsReftableStack#close. Encode that a MergedReftable is a list of ReftableReaders. The previous code suggested that we could form nested trees of MergedReftables, which is not how we use reftables. Change-Id: Icbe2fee8a5a12373f45fc5f97d8b1a2b14231c96 Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
This commit is contained in:
parent
e7a48bce3f
commit
a358d0c53b
|
@ -414,7 +414,7 @@ public void versioningResolveRef() throws IOException {
|
|||
}
|
||||
|
||||
private static MergedReftable merge(byte[]... table) {
|
||||
List<Reftable> stack = new ArrayList<>(table.length);
|
||||
List<ReftableReader> stack = new ArrayList<>(table.length);
|
||||
for (byte[] b : table) {
|
||||
stack.add(read(b));
|
||||
}
|
||||
|
|
|
@ -48,11 +48,11 @@
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jgit.internal.storage.reftable.Reftable;
|
||||
import org.eclipse.jgit.internal.storage.reftable.ReftableReader;
|
||||
|
||||
/**
|
||||
* Tracks multiple open
|
||||
* {@link org.eclipse.jgit.internal.storage.reftable.Reftable} instances.
|
||||
* {@link org.eclipse.jgit.internal.storage.reftable.ReftableReader} instances.
|
||||
*/
|
||||
public class DfsReftableStack implements AutoCloseable {
|
||||
/**
|
||||
|
@ -86,7 +86,7 @@ public static DfsReftableStack open(DfsReader ctx, List<DfsReftable> files)
|
|||
}
|
||||
|
||||
private final List<DfsReftable> files;
|
||||
private final List<Reftable> tables;
|
||||
private final List<ReftableReader> tables;
|
||||
|
||||
private DfsReftableStack(int tableCnt) {
|
||||
this.files = new ArrayList<>(tableCnt);
|
||||
|
@ -109,14 +109,14 @@ public List<DfsReftable> files() {
|
|||
* @return unmodifiable list of tables, in the same order the files were
|
||||
* passed to {@link #open(DfsReader, List)}.
|
||||
*/
|
||||
public List<Reftable> readers() {
|
||||
public List<ReftableReader> readers() {
|
||||
return Collections.unmodifiableList(tables);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void close() {
|
||||
for (Reftable t : tables) {
|
||||
for (ReftableReader t : tables) {
|
||||
try {
|
||||
t.close();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -406,7 +406,7 @@ private long nextUpdateIndex() throws IOException {
|
|||
private boolean canCompactTopOfStack(ReftableConfig cfg)
|
||||
throws IOException {
|
||||
DfsReftableStack stack = refdb.stack();
|
||||
List<Reftable> readers = stack.readers();
|
||||
List<ReftableReader> readers = stack.readers();
|
||||
if (readers.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -427,10 +427,10 @@ private boolean canCompactTopOfStack(ReftableConfig cfg)
|
|||
|
||||
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<ReftableReader> stack = refdb.stack().readers();
|
||||
ReftableReader last = stack.get(stack.size() - 1);
|
||||
|
||||
List<Reftable> tables = new ArrayList<>(2);
|
||||
List<ReftableReader> tables = new ArrayList<>(2);
|
||||
tables.add(last);
|
||||
tables.add(new ReftableReader(BlockSource.from(newTable)));
|
||||
|
||||
|
|
|
@ -67,13 +67,11 @@
|
|||
* A {@code MergedReftable} is not thread-safe.
|
||||
*/
|
||||
public class MergedReftable extends Reftable {
|
||||
private final Reftable[] tables;
|
||||
private final ReftableReader[] tables;
|
||||
|
||||
/**
|
||||
* Initialize a merged table reader.
|
||||
* <p>
|
||||
* The tables in {@code tableStack} will be closed when this
|
||||
* {@code MergedReftable} is closed.
|
||||
*
|
||||
* @param tableStack
|
||||
* stack of tables to read from. The base of the stack is at
|
||||
|
@ -81,12 +79,12 @@ public class MergedReftable extends Reftable {
|
|||
* {@code tableStack.size() - 1}. The top of the stack (higher
|
||||
* index) shadows the base of the stack (lower index).
|
||||
*/
|
||||
public MergedReftable(List<Reftable> tableStack) {
|
||||
tables = tableStack.toArray(new Reftable[0]);
|
||||
public MergedReftable(List<ReftableReader> tableStack) {
|
||||
tables = tableStack.toArray(new ReftableReader[0]);
|
||||
|
||||
// Tables must expose deletes to this instance to correctly
|
||||
// shadow references from lower tables.
|
||||
for (Reftable t : tables) {
|
||||
for (ReftableReader t : tables) {
|
||||
t.setIncludeDeletes(true);
|
||||
}
|
||||
}
|
||||
|
@ -161,14 +159,6 @@ public LogCursor seekLog(String refName, long updateIdx)
|
|||
return m;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
for (Reftable t : tables) {
|
||||
t.close();
|
||||
}
|
||||
}
|
||||
|
||||
int queueSize() {
|
||||
return Math.max(1, tables.length);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
/**
|
||||
* Abstract table of references.
|
||||
*/
|
||||
public abstract class Reftable implements AutoCloseable {
|
||||
public abstract class Reftable {
|
||||
/**
|
||||
* References to convert into a reftable
|
||||
*
|
||||
|
@ -295,8 +295,4 @@ private Ref resolve(Ref ref, int depth) throws IOException {
|
|||
}
|
||||
return new SymbolicRef(ref.getName(), dst, ref.getUpdateIndex());
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public abstract void close() throws IOException;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
*/
|
||||
public class ReftableCompactor {
|
||||
private final ReftableWriter writer;
|
||||
private final ArrayDeque<Reftable> tables = new ArrayDeque<>();
|
||||
private final ArrayDeque<ReftableReader> tables = new ArrayDeque<>();
|
||||
|
||||
private long compactBytesLimit;
|
||||
private long bytesToCompact;
|
||||
|
@ -188,12 +188,10 @@ public ReftableCompactor setOldestReflogTimeMillis(long timeMillis) {
|
|||
* @throws java.io.IOException
|
||||
* update indexes of a reader cannot be accessed.
|
||||
*/
|
||||
public void addAll(List<? extends Reftable> readers) throws IOException {
|
||||
tables.addAll(readers);
|
||||
for (Reftable r : readers) {
|
||||
if (r instanceof ReftableReader) {
|
||||
adjustUpdateIndexes((ReftableReader) r);
|
||||
}
|
||||
public void addAll(List<ReftableReader> readers) throws IOException {
|
||||
for (ReftableReader r : readers) {
|
||||
tables.add(r);
|
||||
adjustUpdateIndexes(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
* {@code ReftableReader} is not thread-safe. Concurrent readers need their own
|
||||
* instance to read from the same file.
|
||||
*/
|
||||
public class ReftableReader extends Reftable {
|
||||
public class ReftableReader extends Reftable implements AutoCloseable {
|
||||
private final BlockSource src;
|
||||
|
||||
private int blockSize = -1;
|
||||
|
|
Loading…
Reference in New Issue