From 5c50d572d010f21b227f37adccee13ea2a609b75 Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Mon, 31 Mar 2025 16:05:00 +0200 Subject: [PATCH] Server: no delay op sending --- .../dhfs/repository/invalidation/OpPusher.java | 2 +- .../utils/HashSetDelayedBlockingQueue.java | 18 ++++++++++++++++++ .../utils/HashSetDelayedBlockingQueueTest.java | 13 +++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dhfs-parent/server/src/main/java/com/usatiuk/dhfs/repository/invalidation/OpPusher.java b/dhfs-parent/server/src/main/java/com/usatiuk/dhfs/repository/invalidation/OpPusher.java index 517b582f..97713ccd 100644 --- a/dhfs-parent/server/src/main/java/com/usatiuk/dhfs/repository/invalidation/OpPusher.java +++ b/dhfs-parent/server/src/main/java/com/usatiuk/dhfs/repository/invalidation/OpPusher.java @@ -65,7 +65,7 @@ public class OpPusher { if (tree.hasPendingOpsForHost(entry.peer())) { doAgain.set(true); - invalidationQueueService.pushInvalidationToOne(entry.peer(), pd.key()); + invalidationQueueService.pushInvalidationToOneNoDelay(entry.peer(), pd.key()); } return ops; } diff --git a/dhfs-parent/utils/src/main/java/com/usatiuk/dhfs/utils/HashSetDelayedBlockingQueue.java b/dhfs-parent/utils/src/main/java/com/usatiuk/dhfs/utils/HashSetDelayedBlockingQueue.java index e37aa9ea..53c66af3 100644 --- a/dhfs-parent/utils/src/main/java/com/usatiuk/dhfs/utils/HashSetDelayedBlockingQueue.java +++ b/dhfs-parent/utils/src/main/java/com/usatiuk/dhfs/utils/HashSetDelayedBlockingQueue.java @@ -44,6 +44,24 @@ public class HashSetDelayedBlockingQueue { } } + + // Adds the object to the queue, if it exists re-adds it + // With no delay + // Returns the old object, or null + public T addNoDelay(T el) { + synchronized (this) { + if (_closed) throw new IllegalStateException("Adding to a queue that is closed!"); + + SetElement old = _set.putFirst(el, new SetElement<>(el, 0)); + this.notify(); + + if (old != null) + return old.el(); + else + return null; + } + } + // Adds the object to the queue, if it exists re-adds it with a new delay // Returns the old object, or null public T readd(T el) { diff --git a/dhfs-parent/utils/src/test/java/com/usatiuk/dhfs/utils/HashSetDelayedBlockingQueueTest.java b/dhfs-parent/utils/src/test/java/com/usatiuk/dhfs/utils/HashSetDelayedBlockingQueueTest.java index 06d104e9..8b2b255e 100644 --- a/dhfs-parent/utils/src/test/java/com/usatiuk/dhfs/utils/HashSetDelayedBlockingQueueTest.java +++ b/dhfs-parent/utils/src/test/java/com/usatiuk/dhfs/utils/HashSetDelayedBlockingQueueTest.java @@ -24,6 +24,19 @@ public class HashSetDelayedBlockingQueueTest { Assertions.assertTrue((gotTime - curTime) >= 1000); } + + @Test + void addNoDelay() throws InterruptedException { + var queue = new HashSetDelayedBlockingQueue<>(1000); + + var curTime = System.currentTimeMillis(); + queue.addNoDelay("hello!"); + var thing = queue.get(); + var gotTime = System.currentTimeMillis(); + Assertions.assertEquals("hello!", thing); + Assertions.assertTrue((gotTime - curTime) < 500); + } + @Test void GetImmediate() throws InterruptedException { var queue = new HashSetDelayedBlockingQueue<>(0);