Skip to content

Commit

Permalink
OAK-5787: BlobStore should be AutoCloseable
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1871267 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
reschke committed Dec 12, 2019
1 parent 6335586 commit a8bcdeb
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,11 @@ public Iterator<String> resolveChunks(String blobId) throws IOException {
public boolean deleteChunks(List<String> chunkIds, long maxLastModifiedTime) throws Exception {
return (chunkIds.size() == countDeleteChunks(chunkIds, maxLastModifiedTime));
}


@Override
public void close() throws Exception {
}

/**
* A block id. Blocks are small enough to fit in memory, so they can be
* cached.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* An interface to store and read large binary objects.
*/
public interface BlobStore {
public interface BlobStore extends AutoCloseable {

/**
* Write a blob from an input stream.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,26 @@ private BlobStore chooseBlobStoreByBlobId(String blobId) throws IOException {
public String toString() {
return String.format("SplitBlobStore[old=%s, new=%s]", oldBlobStore, newBlobStore);
}

@Override
public void close() throws Exception {
Exception thrown = null;
try {
oldBlobStore.close();
} catch (Exception ex) {
thrown = ex;
}
try {
newBlobStore.close();
} catch (Exception ex) {
if (thrown != null) {
thrown.addSuppressed(ex);
} else {
thrown = ex;
}
}
if (thrown != null) {
throw thrown;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ public boolean isMigrated(String blobId) throws IOException {
return getSplitBlobStore().isMigrated(blobId);
}

@Override
public void close() throws Exception {
getSplitBlobStore().close();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,8 @@ class CountingBlobStore implements GarbageCollectableBlobStore, BlobTrackingStor
}
return Type.DEFAULT;
}

@Override public void close() throws Exception {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ public Iterator<String> resolveChunks(String blobId) throws IOException {
return Iterators.forArray(blobId + "-1", blobId + "-2");
}

@Override
public void close() throws Exception {
}

private void resetLists() {
deletedChunkIds.clear();
failWithDSEForChunkIds.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ public String getBlobId(@NotNull String reference) {
public String getReference(@NotNull String blobId) {
return blobId;
}

@Override
public void close() throws Exception {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public String getReference(@NotNull String s) {
return bs.getBlobId(mapId(s));
}

@Override
public void close() throws Exception {
bs.close();
}

private String mapId(String in) {
String out = ids.get(in);
if (out == null) {
Expand All @@ -95,7 +100,6 @@ private String mapId(String in) {
}

protected abstract String generateId();

}

private static class ShortIdMappingBlobStore extends IdMappingBlobStore {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ public String getBlobId(@NotNull String reference) {
public String getReference(@NotNull String blobId) {
return blobId;
}

@Override
public void close() throws Exception {
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,13 +827,12 @@ public void headOfQueue(@NotNull Revision revision) {

store.dispose();

if (blobStore instanceof Closeable) {
try {
((Closeable) blobStore).close();
} catch (IOException e) {
LOG.debug("Error closing blob store " + blobStore, e);
}
try {
blobStore.close();
} catch (Exception e) {
LOG.debug("Error closing blob store " + blobStore, e);
}

if (persistentCache != null) {
persistentCache.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,8 @@ public String getBlobId(@NotNull String reference) {
public String getReference(@NotNull String blobId) {
return checkNotNull(blobId);
}

@Override
public void close() throws Exception {
}
}

0 comments on commit a8bcdeb

Please sign in to comment.