simplify Store#close by grandinj · Pull Request #4168 · h2database/h2database
Expand Up
@@ -342,32 +342,10 @@ public void close(int allowedCompactionTime) {
try {
FileStore<?> fileStore = mvStore.getFileStore();
if (!mvStore.isClosed() && fileStore != null) {
boolean compactFully = allowedCompactionTime == -1;
if (fileStore.isReadOnly()) {
compactFully = false;
} else {
if (!fileStore.isReadOnly()) {
transactionStore.close();
}
if (compactFully) {
allowedCompactionTime = 0;
}
String fileName = null; FileStore<?> targetFileStore = null; if (compactFully) { fileName = fileStore.getFileName(); String tempName = fileName + Constants.SUFFIX_MV_STORE_TEMP_FILE; FileUtils.delete(tempName); targetFileStore = fileStore.open(tempName, false); }
mvStore.close(allowedCompactionTime);
if (compactFully && FileUtils.exists(fileName)) { // the file could have been deleted concurrently, // so only compact if the file still exists compact(fileName, targetFileStore); } } } catch (MVStoreException e) { mvStore.closeImmediately(); Expand All @@ -376,19 +354,6 @@ public void close(int allowedCompactionTime) { }
private static void compact(String sourceFilename, FileStore<?> targetFileStore) { MVStore.Builder targetBuilder = new MVStore.Builder().compress().adoptFileStore(targetFileStore); try (MVStore targetMVStore = targetBuilder.open()) { FileStore<?> sourceFileStore = targetFileStore.open(sourceFilename, true); MVStore.Builder sourceBuilder = new MVStore.Builder(); sourceBuilder.readOnly().adoptFileStore(sourceFileStore); try (MVStore sourceMVStore = sourceBuilder.open()) { MVStoreTool.compact(sourceMVStore, targetMVStore); } } MVStoreTool.moveAtomicReplace(targetFileStore.getFileName(), sourceFilename); }
/** * Start collecting statistics. */ Expand Down
String fileName = null; FileStore<?> targetFileStore = null; if (compactFully) { fileName = fileStore.getFileName(); String tempName = fileName + Constants.SUFFIX_MV_STORE_TEMP_FILE; FileUtils.delete(tempName); targetFileStore = fileStore.open(tempName, false); }
mvStore.close(allowedCompactionTime);
if (compactFully && FileUtils.exists(fileName)) { // the file could have been deleted concurrently, // so only compact if the file still exists compact(fileName, targetFileStore); } } } catch (MVStoreException e) { mvStore.closeImmediately(); Expand All @@ -376,19 +354,6 @@ public void close(int allowedCompactionTime) { }
private static void compact(String sourceFilename, FileStore<?> targetFileStore) { MVStore.Builder targetBuilder = new MVStore.Builder().compress().adoptFileStore(targetFileStore); try (MVStore targetMVStore = targetBuilder.open()) { FileStore<?> sourceFileStore = targetFileStore.open(sourceFilename, true); MVStore.Builder sourceBuilder = new MVStore.Builder(); sourceBuilder.readOnly().adoptFileStore(sourceFileStore); try (MVStore sourceMVStore = sourceBuilder.open()) { MVStoreTool.compact(sourceMVStore, targetMVStore); } } MVStoreTool.moveAtomicReplace(targetFileStore.getFileName(), sourceFilename); }
/** * Start collecting statistics. */ Expand Down