From: Kai Moritz Date: Tue, 12 Mar 2024 08:54:00 +0000 (+0100) Subject: TMP:test:FIX X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=8300dcd98f681893a077051560151a8f1b94e38d;p=demos%2Fkafka%2Fchat TMP:test:FIX --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoomData.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoomData.java index ca33aca5..20c046d8 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoomData.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoomData.java @@ -24,7 +24,7 @@ public class ChatRoomData private final Clock clock; private final int historyLimit; private Sinks.Many sink; - private volatile boolean active = true; + private volatile boolean active = false; public ChatRoomData( @@ -114,6 +114,12 @@ public class ChatRoomData public void activate() { + if (active) + { + log.info("{} is already active!", service.getChatRoomId()); + return; + } + log.info("{} is being activated", service.getChatRoomId()); this.sink = createSink(); active = true; diff --git a/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/DataChannel.java b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/DataChannel.java index 32a57206..ae544e41 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/DataChannel.java +++ b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/DataChannel.java @@ -144,10 +144,6 @@ public class DataChannel implements Channel, ConsumerRebalanceListener isShardOwned[partition] = true; this.currentOffset[partition] = currentOffset; - chatRoomData[partition] - .values() - .forEach(chatRoomData -> chatRoomData.activate()); - log.info( "Partition assigned: {} - loading messages: next={} -> current={}", partition, @@ -223,6 +219,7 @@ public class DataChannel implements Channel, ConsumerRebalanceListener { log.info("Loading of messages completed! Pausing all owned partitions..."); pauseAllOwnedPartions(); + activateAllOwnedChatRooms(); log.info("Resuming normal operations..."); channelState = ChannelState.READY; } @@ -323,6 +320,16 @@ public class DataChannel implements Channel, ConsumerRebalanceListener .toList()); } + private void activateAllOwnedChatRooms() + { + IntStream + .range(0, numShards) + .filter(shard -> isShardOwned[shard]) + .forEach(shard -> chatRoomData[shard] + .values() + .forEach(chatRoomData -> chatRoomData.activate())); + } + int[] getOwnedShards() {