From e035aa6971edee8cf6dd58925713cfe148bd9050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sat, 19 Dec 2020 03:02:28 +0100 Subject: [PATCH] Apply deletes in blob storage immediately. We can already go out of sync with world saves anyway, because we need to write persistent data to disk when unloading devices due to computers shutting down, so just go all in here. Makes it much less likely to have zombie blobs, too. --- .../cil/oc2/common/serialization/BlobStorage.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main/java/li/cil/oc2/common/serialization/BlobStorage.java b/src/main/java/li/cil/oc2/common/serialization/BlobStorage.java index 3ea5f564..a8c9a1d1 100644 --- a/src/main/java/li/cil/oc2/common/serialization/BlobStorage.java +++ b/src/main/java/li/cil/oc2/common/serialization/BlobStorage.java @@ -36,7 +36,6 @@ public final class BlobStorage { private static final HashMultimap> WRITE_HANDLES = HashMultimap.create(); private static final HashMultimap> READ_HANDLES = HashMultimap.create(); - private static final HashSet DELETED_HANDLES = new HashSet<>(); private static final ExecutorService WORKERS = Executors.newCachedThreadPool(r -> { final Thread thread = new Thread(r, "OC2 BlobStorage Thread"); thread.setDaemon(false); @@ -134,10 +133,6 @@ public final class BlobStorage { public static void synchronize() { awaitCompletion(READ_HANDLES); awaitCompletion(WRITE_HANDLES); - for (final UUID handle : DELETED_HANDLES) { - delete(handle); - } - DELETED_HANDLES.clear(); } /** @@ -166,7 +161,10 @@ public final class BlobStorage { */ public static void freeHandle(@Nullable final UUID handle) { if (handle != null) { - DELETED_HANDLES.add(handle); + awaitCompletion(READ_HANDLES, handle); + awaitCompletion(WRITE_HANDLES, handle); + + submitJob(WRITE_HANDLES, handle, () -> delete(handle)); } } @@ -180,7 +178,6 @@ public final class BlobStorage { if (handle == null || (handle.getMostSignificantBits() == 0 && handle.getLeastSignificantBits() == 0)) { return allocateHandle(); } else { - DELETED_HANDLES.remove(handle); return handle; } } @@ -205,8 +202,6 @@ public final class BlobStorage { awaitCompletion(READ_HANDLES, handle); awaitCompletion(WRITE_HANDLES, handle); - DELETED_HANDLES.remove(handle); - return submitJob(WRITE_HANDLES, handle, () -> save(handle, dataAccess)); } @@ -229,8 +224,6 @@ public final class BlobStorage { // Multiple jobs may read from a handle at a time but none may write to it when reading from it. awaitCompletion(WRITE_HANDLES, handle); - DELETED_HANDLES.remove(handle); - return submitJob(READ_HANDLES, handle, () -> load(handle, dataAccess)); }