From ccd84e729ef582a31da43ef7354f08b639d59705 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Mon, 25 Nov 2024 21:57:10 +0100 Subject: [PATCH] Use ops --- .../rockserver/core/impl/EmbeddedDB.java | 66 +++++++++++-------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/src/main/java/it/cavallium/rockserver/core/impl/EmbeddedDB.java b/src/main/java/it/cavallium/rockserver/core/impl/EmbeddedDB.java index eeecf8a..5e0de0d 100644 --- a/src/main/java/it/cavallium/rockserver/core/impl/EmbeddedDB.java +++ b/src/main/java/it/cavallium/rockserver/core/impl/EmbeddedDB.java @@ -173,21 +173,26 @@ public class EmbeddedDB implements RocksDBSyncAPI, InternalConnection, Closeable logger.debug("Cleaning expired transactions..."); var idsToRemove = new LongArrayList(); var startTime = System.currentTimeMillis(); - EmbeddedDB.this.txs.forEach(((txId, tx) -> { - if (startTime >= tx.expirationTimestamp()) { - idsToRemove.add((long) txId); - } - })); - idsToRemove.forEach(id -> { - var tx = EmbeddedDB.this.txs.remove(id); - if (tx != null) { - try { - tx.close(); - } catch (Throwable ex) { - logger.error("Failed to close a transaction", ex); + ops.beginOp(); + try { + EmbeddedDB.this.txs.forEach(((txId, tx) -> { + if (startTime >= tx.expirationTimestamp()) { + idsToRemove.add((long) txId); } - } - }); + })); + idsToRemove.forEach(id -> { + var tx = EmbeddedDB.this.txs.remove(id); + if (tx != null) { + try { + tx.close(); + } catch (Throwable ex) { + logger.error("Failed to close a transaction", ex); + } + } + }); + } finally { + ops.endOp(); + } var endTime = System.currentTimeMillis(); var removedCount = idsToRemove.size(); if (removedCount > 2) { @@ -202,21 +207,26 @@ public class EmbeddedDB implements RocksDBSyncAPI, InternalConnection, Closeable logger.debug("Cleaning expired iterators..."); var idsToRemove = new LongArrayList(); var startTime = System.currentTimeMillis(); - EmbeddedDB.this.its.forEach(((itId, entry) -> { - if (entry.expirationTimestamp() != null && startTime >= entry.expirationTimestamp()) { - idsToRemove.add((long) itId); - } - })); - idsToRemove.forEach(id -> { - var it = EmbeddedDB.this.its.remove(id); - if (it != null) { - try { - it.close(); - } catch (Throwable ex) { - logger.error("Failed to close an iteration", ex); + ops.beginOp(); + try { + EmbeddedDB.this.its.forEach(((itId, entry) -> { + if (entry.expirationTimestamp() != null && startTime >= entry.expirationTimestamp()) { + idsToRemove.add((long) itId); } - } - }); + })); + idsToRemove.forEach(id -> { + var it = EmbeddedDB.this.its.remove(id); + if (it != null) { + try { + it.close(); + } catch (Throwable ex) { + logger.error("Failed to close an iteration", ex); + } + } + }); + } finally { + ops.endOp(); + } var endTime = System.currentTimeMillis(); var removedCount = idsToRemove.size(); if (removedCount > 2) {