Merge branch 'stable-5.12'

* stable-5.12:
  LockFile: create OutputStream only when needed
  Remove ReftableNumbersNotIncreasingException

Change-Id: I9d85187d00771beef908f1136015d059024f4118
This commit is contained in:
Matthias Sohn 2021-05-11 01:00:31 +02:00
commit cf76a92e04
2 changed files with 12 additions and 49 deletions

View File

@ -131,33 +131,6 @@ CompactionStats getStats() {
return stats; return stats;
} }
/** Thrown if the update indices in the stack are not monotonic */
public static class ReftableNumbersNotIncreasingException
extends RuntimeException {
private static final long serialVersionUID = 1L;
String name;
long lastMax;
long min;
ReftableNumbersNotIncreasingException(String name, long lastMax,
long min) {
this.name = name;
this.lastMax = lastMax;
this.min = min;
}
@SuppressWarnings({ "nls", "boxing" })
@Override
public String toString() {
return String.format(
"ReftableNumbersNotIncreasingException %s: min %d, lastMax %d",
name, min, lastMax);
}
}
/** /**
* Reloads the stack, potentially reusing opened reftableReaders. * Reloads the stack, potentially reusing opened reftableReaders.
* *
@ -176,7 +149,6 @@ private void reloadOnce(List<String> names)
List<ReftableReader> newTables = new ArrayList<>(); List<ReftableReader> newTables = new ArrayList<>();
List<StackEntry> newStack = new ArrayList<>(stack.size() + 1); List<StackEntry> newStack = new ArrayList<>(stack.size() + 1);
try { try {
ReftableReader last = null;
for (String name : names) { for (String name : names) {
StackEntry entry = new StackEntry(); StackEntry entry = new StackEntry();
entry.name = name; entry.name = name;
@ -194,15 +166,6 @@ private void reloadOnce(List<String> names)
newTables.add(t); newTables.add(t);
} }
if (last != null) {
// TODO: move this to MergedReftable
if (last.maxUpdateIndex() >= t.minUpdateIndex()) {
throw new ReftableNumbersNotIncreasingException(name,
last.maxUpdateIndex(), t.minUpdateIndex());
}
}
last = t;
entry.reftableReader = t; entry.reftableReader = t;
newStack.add(entry); newStack.add(entry);
} }

View File

@ -218,14 +218,14 @@ public void copyCurrentContent() throws IOException {
int r; int r;
while ((r = fis.read(buf)) >= 0) { while ((r = fis.read(buf)) >= 0) {
out.write(buf, 0, r); out.write(buf, 0, r);
}
} }
} catch (FileNotFoundException fnfe) { }
if (ref.exists()) { } catch (FileNotFoundException fnfe) {
throw fnfe; if (ref.exists()) {
} throw fnfe;
// Don't worry about a file that doesn't exist yet, it }
// conceptually has no current content to copy. // Don't worry about a file that doesn't exist yet, it
// conceptually has no current content to copy.
} }
} catch (IOException | RuntimeException | Error ioe) { } catch (IOException | RuntimeException | Error ioe) {
unlock(); unlock();
@ -322,9 +322,9 @@ private OutputStream get() throws IOException {
if (out == null) { if (out == null) {
os = getStream(); os = getStream();
if (fsync) { if (fsync) {
out = Channels.newOutputStream(os.getChannel()); out = Channels.newOutputStream(os.getChannel());
} else { } else {
out = os; out = os;
} }
} }
return out; return out;
@ -359,10 +359,10 @@ public void close() throws IOException {
} }
if (out != null) { if (out != null) {
if (fsync) { if (fsync) {
os.getChannel().force(true); os.getChannel().force(true);
} }
out.close(); out.close();
os = null; os = null;
} }
written = true; written = true;
} catch (IOException | RuntimeException | Error ioe) { } catch (IOException | RuntimeException | Error ioe) {