You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2022/03/01 12:50:54 UTC

[GitHub] [cassandra] pauloricardomg commented on a change in pull request #1454: CASSANDRA-17390 Expose streaming as a vtable

pauloricardomg commented on a change in pull request #1454:
URL: https://github.com/apache/cassandra/pull/1454#discussion_r816739317



##########
File path: src/java/org/apache/cassandra/streaming/StreamManager.java
##########
@@ -213,6 +226,96 @@ private static double calculateEffectiveRateInBytes(double throughput)
     private final Map<UUID, StreamResultFuture> initiatorStreams = new NonBlockingHashMap<>();
     private final Map<UUID, StreamResultFuture> followerStreams = new NonBlockingHashMap<>();
 
+    private final Map<UUID, StreamingState> states = new NonBlockingHashMap<>();
+    private final StreamListener listener = new StreamListener()
+    {
+        @Override
+        public void onRegister(StreamResultFuture result)
+        {
+            StreamingState state = new StreamingState(result);
+            StreamingState previous = states.putIfAbsent(state.id(), state);
+            if (previous == null)
+            {
+                state.phase.start();
+                result.addEventListener(state);
+            }
+            else
+            {
+                logger.warn("Duplicate streaming states detected for id {}", state.id());
+            }
+        }
+    };
+    private volatile ScheduledFuture<?> cleanup = null;
+
+    public void start()
+    {
+        addListener(listener);
+        this.cleanup = ScheduledExecutors.optionalTasks.scheduleWithFixedDelay(this::cleanup, 0,
+                                                                               DatabaseDescriptor.getStreamingStateCleanupInterval().toNanoseconds(),
+                                                                               TimeUnit.NANOSECONDS);
+    }
+
+    public void stop()
+    {
+        removeListener(listener);
+        ScheduledFuture<?> cleanup = this.cleanup;
+        if (cleanup != null)
+            cleanup.cancel(false);
+    }
+
+    public Collection<StreamingState> getStreamingStates()
+    {
+        return states.values();
+    }
+
+    public StreamingState getStreamingState(UUID id)
+    {
+        return states.get(id);
+    }
+
+    @VisibleForTesting
+    public void putStreamingState(StreamingState state)
+    {
+        StreamingState previous = states.putIfAbsent(state.id(), state);
+        if (previous != null)
+            throw new AssertionError("StreamPlan id " + state.id() + " already exists");
+    }
+
+    @VisibleForTesting
+    public void cleanup()

Review comment:
       Can you use an expiring cache (see `ActiveRepairService.repairStatusByCmd`) with an expiration of `streaming_state_expires`? I think this would be simpler then cleaning up entries periodically.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org