mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
perf(dynamodb): retain the live item map in memory mode instead of copying the table (#6915)
Keep memory item storage current by retaining the concurrent live map. Preserve snapshots for durable backends and cover writes, reloads, restore, and account-scoped storage. Refs #1292
This commit is contained in:
1 parent
479595e6ec
commit
5f89a70095
4 files changed
+87
-4
No files matched your search
@@ -449,6 +449,11 @@ public class AccountAwareStorageBackend<V> implements StorageBackend<String, V>
|
||||
delegate.deleteAllAtomically(rawKeys);
|
||||
}
|
||||
|
||||
/** Whether the delegate only retains values in memory, without persistence or serialization. */
|
||||
public boolean isInMemory() {
|
||||
return delegate instanceof InMemoryStorage<?, ?>;
|
||||
}
|
||||
|
||||
// --- Entry writes, for map-valued stores whose backend persists one entry at a time ---
|
||||
|
||||
/** Whether the backend persists one map entry at a time; the entry methods require it. */
|
||||
|
||||
@@ -408,11 +408,20 @@ public class DynamoDbService {
|
||||
return rekeyedItems;
|
||||
}
|
||||
|
||||
private Map<String, JsonNode> itemsForStorage(Map<String, JsonNode> items) {
|
||||
// Memory storage can retain the live concurrent map; durable stores still need a snapshot.
|
||||
if (itemStore instanceof InMemoryStorage<?, ?>
|
||||
|| itemStore instanceof AccountAwareStorageBackend<?> aware && aware.isInMemory()) {
|
||||
return items;
|
||||
}
|
||||
return new HashMap<>(items);
|
||||
}
|
||||
|
||||
private void persistItems(String storageKey) {
|
||||
if (itemStore == null) return;
|
||||
ConcurrentSkipListMap<String, JsonNode> items = currentItems(storageKey, false);
|
||||
if (items != null) {
|
||||
itemStore.put(storageKey, new HashMap<>(items));
|
||||
itemStore.put(storageKey, itemsForStorage(items));
|
||||
} else {
|
||||
itemStore.delete(storageKey);
|
||||
}
|
||||
@@ -3212,9 +3221,9 @@ public class DynamoDbService {
|
||||
private void persistItemsForAccount(String accountId, String storageKey, Map<String, JsonNode> items) {
|
||||
if (itemStore == null) return;
|
||||
if (accountId != null && itemStore instanceof AccountAwareStorageBackend<Map<String, JsonNode>> aware) {
|
||||
aware.putForAccount(accountId, storageKey, new HashMap<>(items));
|
||||
aware.putForAccount(accountId, storageKey, itemsForStorage(items));
|
||||
} else {
|
||||
itemStore.put(storageKey, new HashMap<>(items));
|
||||
itemStore.put(storageKey, itemsForStorage(items));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user