You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by tm...@apache.org on 2020/04/24 19:28:47 UTC
[sling-org-apache-sling-distribution-journal] branch master
updated: SLING-9396 - log at INFO level only when the set of subscribed
agents changes
This is an automated email from the ASF dual-hosted git repository.
tmaret pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git
The following commit(s) were added to refs/heads/master by this push:
new 8fa6554 SLING-9396 - log at INFO level only when the set of subscribed agents changes
8fa6554 is described below
commit 8fa65544305db5fbaa97ec0058e7841c6ebe134f
Author: tmaret <tm...@adobe.com>
AuthorDate: Fri Apr 24 21:28:32 2020 +0200
SLING-9396 - log at INFO level only when the set of subscribed agents changes
---
.../journal/impl/publisher/DiscoveryService.java | 11 +++++++--
.../impl/publisher/PackageDistributedNotifier.java | 3 +--
.../impl/publisher/TopologyChangeHandler.java | 5 ++--
.../journal/impl/publisher/TopologyViewDiff.java | 14 +++++++++++
.../publisher/PackageDistributedNotifierTest.java | 3 ++-
.../impl/publisher/TopologyViewDiffTest.java | 28 ++++++++++++++++++++++
6 files changed, 56 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DiscoveryService.java b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DiscoveryService.java
index af052a3..6c99368 100644
--- a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DiscoveryService.java
+++ b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DiscoveryService.java
@@ -18,6 +18,7 @@
*/
package org.apache.sling.distribution.journal.impl.publisher;
+import static java.lang.String.format;
import static org.apache.sling.distribution.journal.HandlerAdapter.create;
import static org.apache.sling.commons.scheduler.Scheduler.PROPERTY_SCHEDULER_CONCURRENT;
import static org.apache.sling.commons.scheduler.Scheduler.PROPERTY_SCHEDULER_PERIOD;
@@ -124,8 +125,14 @@ public class DiscoveryService implements Runnable {
TopologyView oldView = viewManager.updateView();
TopologyView newView = viewManager.getCurrentView();
if (! newView.equals(oldView)) {
- LOG.info("TopologyView changed from {} to {}", oldView, newView);
- topologyChangeHandler.changed(oldView, newView);
+ String msg = format("TopologyView changed from %s to %s", oldView, newView);
+ TopologyViewDiff diffView = new TopologyViewDiff(oldView, newView);
+ if (diffView.subscribedAgentsChanged()) {
+ LOG.info(msg);
+ } else {
+ LOG.debug(msg);
+ }
+ topologyChangeHandler.changed(diffView);
}
}
diff --git a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/PackageDistributedNotifier.java b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/PackageDistributedNotifier.java
index 591a0cf..75326e8 100644
--- a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/PackageDistributedNotifier.java
+++ b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/PackageDistributedNotifier.java
@@ -79,8 +79,7 @@ public class PackageDistributedNotifier implements TopologyChangeHandler {
}
@Override
- public void changed(TopologyView oldView, TopologyView newView) {
- TopologyViewDiff diffView = new TopologyViewDiff(oldView, newView);
+ public void changed(TopologyViewDiff diffView) {
diffView.getProcessedOffsets().forEach(this::processOffsets);
}
diff --git a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/TopologyChangeHandler.java b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/TopologyChangeHandler.java
index 88b5ff2..aeb70c7 100644
--- a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/TopologyChangeHandler.java
+++ b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/TopologyChangeHandler.java
@@ -26,9 +26,8 @@ public interface TopologyChangeHandler {
/**
* Invoked by the framework when the TopologyView has changed.
*
- * @param oldView the topology view before the change
- * @param newView the topology view after the change
+ * @param diffView the diff between the old and new topology views
*/
- void changed(TopologyView oldView, TopologyView newView);
+ void changed(TopologyViewDiff diffView);
}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/TopologyViewDiff.java b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/TopologyViewDiff.java
index 019b3e9..235982c 100644
--- a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/TopologyViewDiff.java
+++ b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/TopologyViewDiff.java
@@ -20,6 +20,7 @@ package org.apache.sling.distribution.journal.impl.publisher;
import java.util.HashSet;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@@ -36,14 +37,19 @@ import static java.util.function.Function.identity;
public class TopologyViewDiff {
private final Map<String, Long> oldOffsets;
+
private final Map<String, Long> newOffsets;
+ private final boolean subAgentChanged;
+
public TopologyViewDiff(TopologyView oldView, TopologyView newView) {
oldOffsets = unmodifiableMap(oldView
.getMinOffsetByPubAgentName());
newOffsets = unmodifiableMap(newView
.getMinOffsetByPubAgentName());
+ subAgentChanged = ! Objects.equals(oldView.getSubscribedAgentIds(),
+ newView.getSubscribedAgentIds());
}
/**
@@ -57,6 +63,14 @@ public class TopologyViewDiff {
.collect(Collectors.toMap(identity(), this::offsetRange));
}
+ /**
+ * @return {@code true} if the set of subscribed agent changed between the old and new view ;
+ * {@code false} otherwise.
+ */
+ public boolean subscribedAgentsChanged() {
+ return subAgentChanged;
+ }
+
private boolean newOffsetIsHigher(String pubAgentName) {
return newOffsets.get(pubAgentName) > oldOffsets.get(pubAgentName);
}
diff --git a/src/test/java/org/apache/sling/distribution/journal/impl/publisher/PackageDistributedNotifierTest.java b/src/test/java/org/apache/sling/distribution/journal/impl/publisher/PackageDistributedNotifierTest.java
index acc91b0..afc6830 100644
--- a/src/test/java/org/apache/sling/distribution/journal/impl/publisher/PackageDistributedNotifierTest.java
+++ b/src/test/java/org/apache/sling/distribution/journal/impl/publisher/PackageDistributedNotifierTest.java
@@ -78,9 +78,10 @@ public class PackageDistributedNotifierTest {
setInternalState(notifier, "messagingProvider", messagingProvider);
setInternalState(notifier, "topics", topics);
notifier.activate();
- notifier.changed(
+ TopologyViewDiff diffView = new TopologyViewDiff(
buildView(new State("pub1", "sub1", 1000, 10, 0, -1, false)),
buildView(new State("pub1", "sub1", 2000, 13, 0, -1, false)));
+ notifier.changed(diffView);
verify(notifier, times(3)).processOffset(anyString(), any(DistributionQueueItem.class));
}
diff --git a/src/test/java/org/apache/sling/distribution/journal/impl/publisher/TopologyViewDiffTest.java b/src/test/java/org/apache/sling/distribution/journal/impl/publisher/TopologyViewDiffTest.java
index 66adba9..f078229 100644
--- a/src/test/java/org/apache/sling/distribution/journal/impl/publisher/TopologyViewDiffTest.java
+++ b/src/test/java/org/apache/sling/distribution/journal/impl/publisher/TopologyViewDiffTest.java
@@ -28,6 +28,7 @@ import org.junit.Test;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class TopologyViewDiffTest {
@@ -85,6 +86,33 @@ public class TopologyViewDiffTest {
}
@Test
+ public void testSubscribedAgentsChanged() {
+ TopologyView view1 = buildView(
+ new State("pub1", "sub1", 0, 10, 0, -1, false),
+ new State("pub1", "sub2", 0, 5, 0, -1, false),
+ new State("pub2", "sub1", 0, 100, 0, -1, false)
+ );
+
+ TopologyView view2 = buildView(
+ new State("pub1", "sub1", 0, 10, 0, -1, false),
+ // sub2 no longer in the view
+ new State("pub2", "sub1", 0, 100, 0, -1, false)
+ );
+
+ TopologyViewDiff viewDiff1 = new TopologyViewDiff(view1, view1);
+ assertFalse(viewDiff1.subscribedAgentsChanged());
+
+ TopologyViewDiff viewDiff2 = new TopologyViewDiff(view1, view2);
+ assertTrue(viewDiff2.subscribedAgentsChanged());
+ }
+
+ @Test
+ public void testSubscribedAgentsChangedEmptyViews() {
+ TopologyViewDiff viewDiff = new TopologyViewDiff(buildView(), buildView());
+ assertFalse(viewDiff.subscribedAgentsChanged());
+ }
+
+ @Test
public void testGetProcessedOffsetsBatch() throws Exception {
TopologyView view1 = buildView(
new State("pub1", "sub1", 0, 10, 0, -1, false),