kirklund commented on code in PR #7323:
URL: https://github.com/apache/geode/pull/7323#discussion_r857829574


##########
geode-core/src/main/java/org/apache/geode/internal/cache/wan/parallel/ParallelQueueSetPossibleDuplicateMessage.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.wan.parallel;
+
+import static org.apache.geode.cache.Region.SEPARATOR;
+import static 
org.apache.geode.internal.cache.LocalRegion.InitializationLevel.BEFORE_INITIAL_IMAGE;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.distributed.internal.PooledDistributionMessage;
+import org.apache.geode.internal.cache.BucketRegionQueue;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.internal.cache.LocalRegion.InitializationLevel;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.PartitionedRegionHelper;
+import org.apache.geode.internal.cache.wan.AbstractGatewaySender;
+import org.apache.geode.internal.serialization.DeserializationContext;
+import org.apache.geode.internal.serialization.SerializationContext;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+/**
+ * Sets events in the remote secondary queues to possible duplicate
+ *
+ * @since Geode 1.15
+ */
+public class ParallelQueueSetPossibleDuplicateMessage extends 
PooledDistributionMessage {
+
+  private static final Logger logger = LogService.getLogger();
+
+  private int reason;
+  private Map<String, Map<Integer, List<Object>>> regionToDuplicateEventsMap;
+
+  public static final int UNSUCCESSFULLY_DISPATCHED = 0;
+  public static final int RESET_BATCH = 1;
+  public static final int LOAD_FROM_TEMP_QUEUE = 2;
+  public static final int STOPPED_GATEWAY_SENDER = 3;
+
+
+  public ParallelQueueSetPossibleDuplicateMessage() {}
+
+  public ParallelQueueSetPossibleDuplicateMessage(int reason,
+      Map<String, Map<Integer, List<Object>>> regionToDuplicateEventsMap) {
+    this.reason = reason;
+    this.regionToDuplicateEventsMap = regionToDuplicateEventsMap;
+  }
+
+  @Override
+  public int getDSFID() {
+    return PARALLEL_QUEUE_SET_POSSIBLE_DUPLICATE_MESSAGE;
+  }
+
+  @Override
+  public String toString() {
+    String cname = getShortClassName();
+    final StringBuilder sb = new StringBuilder(cname);
+    sb.append("reason=" + reason);
+    sb.append(" regionToDispatchedKeysMap=" + regionToDuplicateEventsMap);

Review Comment:
   Please don't combine both appending and concatenation. Just use append:
   ```
   sb.append("reason=").append(reason);
   ```



##########
geode-core/src/test/java/org/apache/geode/internal/cache/wan/parallel/ParallelQueueSetPossibleDuplicateMessageJUnitTest.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.wan.parallel;
+
+import static org.apache.geode.cache.Region.SEPARATOR;
+import static 
org.apache.geode.internal.cache.wan.parallel.ParallelQueueSetPossibleDuplicateMessage.UNSUCCESSFULLY_DISPATCHED;
+import static 
org.apache.geode.internal.statistics.StatisticsClockFactory.disabledClock;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.internal.cache.BucketRegionQueue;
+import org.apache.geode.internal.cache.BucketRegionQueueHelper;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.PartitionedRegionHelper;
+import org.apache.geode.internal.cache.wan.AbstractGatewaySender;
+import org.apache.geode.internal.cache.wan.GatewaySenderEventImpl;
+import org.apache.geode.internal.cache.wan.GatewaySenderStats;
+import org.apache.geode.internal.statistics.DummyStatisticsFactory;
+import org.apache.geode.test.fake.Fakes;
+
+public class ParallelQueueSetPossibleDuplicateMessageJUnitTest {
+
+  private static final String GATEWAY_SENDER_ID = "ny";
+  private static final int BUCKET_ID = 85;
+  private static final long KEY = 198;
+
+  private GemFireCacheImpl cache;

Review Comment:
   Anytime you mock a Cache, please use `InternalCache` instead of 
`GemFireCacheImpl` unless you can use `Cache`.



##########
geode-core/src/main/java/org/apache/geode/internal/cache/wan/parallel/ParallelQueueSetPossibleDuplicateMessage.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.wan.parallel;
+
+import static org.apache.geode.cache.Region.SEPARATOR;
+import static 
org.apache.geode.internal.cache.LocalRegion.InitializationLevel.BEFORE_INITIAL_IMAGE;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.distributed.internal.PooledDistributionMessage;
+import org.apache.geode.internal.cache.BucketRegionQueue;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.internal.cache.LocalRegion.InitializationLevel;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.PartitionedRegionHelper;
+import org.apache.geode.internal.cache.wan.AbstractGatewaySender;
+import org.apache.geode.internal.serialization.DeserializationContext;
+import org.apache.geode.internal.serialization.SerializationContext;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+/**
+ * Sets events in the remote secondary queues to possible duplicate
+ *
+ * @since Geode 1.15
+ */
+public class ParallelQueueSetPossibleDuplicateMessage extends 
PooledDistributionMessage {
+
+  private static final Logger logger = LogService.getLogger();
+
+  private int reason;
+  private Map<String, Map<Integer, List<Object>>> regionToDuplicateEventsMap;
+
+  public static final int UNSUCCESSFULLY_DISPATCHED = 0;
+  public static final int RESET_BATCH = 1;
+  public static final int LOAD_FROM_TEMP_QUEUE = 2;
+  public static final int STOPPED_GATEWAY_SENDER = 3;
+
+
+  public ParallelQueueSetPossibleDuplicateMessage() {}
+
+  public ParallelQueueSetPossibleDuplicateMessage(int reason,
+      Map<String, Map<Integer, List<Object>>> regionToDuplicateEventsMap) {
+    this.reason = reason;
+    this.regionToDuplicateEventsMap = regionToDuplicateEventsMap;
+  }
+
+  @Override
+  public int getDSFID() {
+    return PARALLEL_QUEUE_SET_POSSIBLE_DUPLICATE_MESSAGE;
+  }
+
+  @Override
+  public String toString() {
+    String cname = getShortClassName();
+    final StringBuilder sb = new StringBuilder(cname);

Review Comment:
   It can frequently be useful to include the hashcode in the toString of 
various event and message types. You should consider doing this. You can copy 
the identity (ie hashcode) portion from `java.lang.Object.toString()` and use 
that along side the simple class name (I assume getShortClassName() is 
returning `getClass().getSimpleName()`... not sure why there's a dedicated 
method for that).



##########
geode-core/src/test/java/org/apache/geode/internal/cache/wan/parallel/ParallelQueueSetPossibleDuplicateMessageJUnitTest.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.wan.parallel;
+
+import static org.apache.geode.cache.Region.SEPARATOR;
+import static 
org.apache.geode.internal.cache.wan.parallel.ParallelQueueSetPossibleDuplicateMessage.UNSUCCESSFULLY_DISPATCHED;
+import static 
org.apache.geode.internal.statistics.StatisticsClockFactory.disabledClock;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;

Review Comment:
   Please use AssertJ for all assertions instead of these JUnit assertions.



##########
geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java:
##########
@@ -2187,6 +2187,13 @@ boolean doClose(String reason, Throwable 
systemFailureCause, boolean keepAlive,
         return false;
       }
 
+      for (GatewaySender sender : allGatewaySenders) {
+        try {
+          sender.prepareForStop();
+        } catch (Exception ignore) {
+        }

Review Comment:
   I think you should at least log this exception at `debug` level.



##########
geode-core/src/main/java/org/apache/geode/internal/cache/wan/parallel/ParallelQueueSetPossibleDuplicateMessage.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.wan.parallel;
+
+import static org.apache.geode.cache.Region.SEPARATOR;
+import static 
org.apache.geode.internal.cache.LocalRegion.InitializationLevel.BEFORE_INITIAL_IMAGE;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.distributed.internal.PooledDistributionMessage;
+import org.apache.geode.internal.cache.BucketRegionQueue;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.internal.cache.LocalRegion.InitializationLevel;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.PartitionedRegionHelper;
+import org.apache.geode.internal.cache.wan.AbstractGatewaySender;
+import org.apache.geode.internal.serialization.DeserializationContext;
+import org.apache.geode.internal.serialization.SerializationContext;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+/**
+ * Sets events in the remote secondary queues to possible duplicate
+ *
+ * @since Geode 1.15
+ */
+public class ParallelQueueSetPossibleDuplicateMessage extends 
PooledDistributionMessage {
+
+  private static final Logger logger = LogService.getLogger();
+
+  private int reason;
+  private Map<String, Map<Integer, List<Object>>> regionToDuplicateEventsMap;
+
+  public static final int UNSUCCESSFULLY_DISPATCHED = 0;
+  public static final int RESET_BATCH = 1;
+  public static final int LOAD_FROM_TEMP_QUEUE = 2;
+  public static final int STOPPED_GATEWAY_SENDER = 3;
+
+
+  public ParallelQueueSetPossibleDuplicateMessage() {}
+
+  public ParallelQueueSetPossibleDuplicateMessage(int reason,
+      Map<String, Map<Integer, List<Object>>> regionToDuplicateEventsMap) {
+    this.reason = reason;
+    this.regionToDuplicateEventsMap = regionToDuplicateEventsMap;
+  }
+
+  @Override
+  public int getDSFID() {
+    return PARALLEL_QUEUE_SET_POSSIBLE_DUPLICATE_MESSAGE;
+  }
+
+  @Override
+  public String toString() {
+    String cname = getShortClassName();
+    final StringBuilder sb = new StringBuilder(cname);
+    sb.append("reason=" + reason);
+    sb.append(" regionToDispatchedKeysMap=" + regionToDuplicateEventsMap);
+    sb.append(" sender=").append(getSender());
+    return sb.toString();
+  }
+
+  @Override
+  protected void process(ClusterDistributionManager dm) {
+    final boolean isDebugEnabled = logger.isDebugEnabled();
+    final InternalCache cache = dm.getCache();
+
+    if (cache == null) {
+      return;
+    }
+    final InitializationLevel oldLevel =
+        LocalRegion.setThreadInitLevelRequirement(BEFORE_INITIAL_IMAGE);
+    try {
+      for (String name : regionToDuplicateEventsMap.keySet()) {
+        final PartitionedRegion region = (PartitionedRegion) 
cache.getRegion(name);
+        if (region == null) {
+          continue;
+        }
+
+        AbstractGatewaySender abstractSender = 
region.getParallelGatewaySender();
+        // Find the map: bucketId to dispatchedKeys
+        // Find the bucket
+        // Destroy the keys
+        Map<Integer, List<Object>> bucketIdToDispatchedKeys =
+            this.regionToDuplicateEventsMap.get(name);
+        for (Integer bId : bucketIdToDispatchedKeys.keySet()) {
+          final String bucketFullPath =
+              SEPARATOR + PartitionedRegionHelper.PR_ROOT_REGION_NAME + 
SEPARATOR
+                  + region.getBucketName(bId);
+          BucketRegionQueue brq =
+              (BucketRegionQueue) 
cache.getInternalRegionByPath(bucketFullPath);
+
+          if (brq != null) {
+            if (reason == STOPPED_GATEWAY_SENDER) {

Review Comment:
   This is probably better represented as an AND: `if (brq != null && reason == 
STOPPED_GATEWAY_SENDER) {`.



##########
geode-core/src/test/java/org/apache/geode/internal/cache/wan/parallel/ParallelQueueSetPossibleDuplicateMessageJUnitTest.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.wan.parallel;
+
+import static org.apache.geode.cache.Region.SEPARATOR;
+import static 
org.apache.geode.internal.cache.wan.parallel.ParallelQueueSetPossibleDuplicateMessage.UNSUCCESSFULLY_DISPATCHED;
+import static 
org.apache.geode.internal.statistics.StatisticsClockFactory.disabledClock;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.internal.cache.BucketRegionQueue;
+import org.apache.geode.internal.cache.BucketRegionQueueHelper;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.PartitionedRegionHelper;
+import org.apache.geode.internal.cache.wan.AbstractGatewaySender;
+import org.apache.geode.internal.cache.wan.GatewaySenderEventImpl;
+import org.apache.geode.internal.cache.wan.GatewaySenderStats;
+import org.apache.geode.internal.statistics.DummyStatisticsFactory;
+import org.apache.geode.test.fake.Fakes;
+
+public class ParallelQueueSetPossibleDuplicateMessageJUnitTest {
+
+  private static final String GATEWAY_SENDER_ID = "ny";
+  private static final int BUCKET_ID = 85;
+  private static final long KEY = 198;
+
+  private GemFireCacheImpl cache;
+  private PartitionedRegion queueRegion;
+  private AbstractGatewaySender sender;
+  private PartitionedRegion rootRegion;
+  private BucketRegionQueue bucketRegionQueue;
+  private BucketRegionQueueHelper bucketRegionQueueHelper;
+  private GatewaySenderStats stats;
+
+  @Before
+  public void setUpGemFire() {
+    createCache();
+    createQueueRegion();
+    createGatewaySender();
+    createRootRegion();
+    createBucketRegionQueue();
+  }
+
+  private void createCache() {
+    // Mock cache
+    cache = Fakes.cache();

Review Comment:
   I think this is using the JMock Fakes that we're trying to get rid of. 
Please rewrite with Mockito and try to isolate this to 
`ParallelQueueSetPossibleDuplicateMessage` without mocking the whole stack.



##########
geode-core/src/main/java/org/apache/geode/cache/wan/GatewaySender.java:
##########
@@ -215,6 +216,13 @@ enum OrderPolicy {
    */
   void startWithCleanQueue();
 
+
+  /**
+   * prepare GatewaySender for closing of Cache.
+   */
+  @Experimental
+  void prepareForStop();

Review Comment:
   Anytime you add an experimental API, you should be more detailed in the 
javadoc and explain there that it's experimental and may change or be removed. 
You can find good examples of this on other APIs such as 
[MetricsPublishingService 
](https://github.com/apache/geode/blob/develop/geode-core/src/main/java/org/apache/geode/metrics/MetricsPublishingService.java).
   
   I also notice that none of the implementations actually have any code, so it 
seems really weird to add this API. We generally don't allow adding a new API 
unless it's actually implemented (ie has code that gets invoked in one or more 
impl classes). Why is this being added in this PR?



##########
geode-wan/src/distributedTest/java/org/apache/geode/internal/cache/wan/parallel/ParallelWANPersistenceEnabledGatewaySenderCheckPossibleDuplicateDUnitTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.wan.parallel;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.logging.log4j.Logger;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.internal.cache.wan.WANTestBase;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+import org.apache.geode.test.dunit.IgnoredException;
+import org.apache.geode.test.junit.categories.WanTest;
+
+@Category({WanTest.class})
+public class 
ParallelWANPersistenceEnabledGatewaySenderCheckPossibleDuplicateDUnitTest
+    extends WANTestBase {
+
+  private static final long serialVersionUID = 2L;
+  private static final Logger logger = LogService.getLogger();
+
+  public 
ParallelWANPersistenceEnabledGatewaySenderCheckPossibleDuplicateDUnitTest() {
+    super();
+  }
+
+  @Override
+  protected final void postSetUpWANTestBase() throws Exception {
+    // The restart tests log this string
+    IgnoredException.addIgnoredException("failed accepting client connection");
+  }
+
+  /**
+   * When gateway senders starts to unqueue, and check that received events are
+   * not marked as possible duplicate.
+   */
+  @Test
+  public void 
testPersistentPartitionedRegionWithGatewaySenderCheckReceiverNoPossibleDuplicate()
+      throws InterruptedException {
+    Integer lnPort = vm0.invoke(() -> 
WANTestBase.createFirstLocatorWithDSId(1));
+    Integer nyPort = vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, 
lnPort));
+

Review Comment:
   Please use primitives instead of wrapper classes like `Integer` where 
possible. Lots of the older code uses wrapper classes so you probably copied 
from those.



##########
geode-core/src/main/java/org/apache/geode/internal/cache/wan/AbstractGatewaySenderEventProcessor.java:
##########
@@ -1322,17 +1325,180 @@ protected void afterExecute() {
 
   protected abstract void enqueueEvent(GatewayQueueEvent<?, ?> event);
 
-  private void pendingEventsInBatchesMarkAsPossibleDuplicate() {
+  private void notifyPossibleDuplicate(int reason, List<?> events) {
+    Map<String, Map<Integer, List<Object>>> regionToDispatchedKeysMap = new 
HashMap<>();
+    boolean pgwsender = (getSender().isParallel()
+        && !(getDispatcher() instanceof GatewaySenderEventCallbackDispatcher));
+
+    for (Object o : events) {
+      if (o instanceof GatewaySenderEventImpl) {
+        GatewaySenderEventImpl ge = (GatewaySenderEventImpl) o;
+        if (!ge.getPossibleDuplicate()) {
+          if (pgwsender) {
+            addDuplicateEvent(regionToDispatchedKeysMap, ge);
+          }
+          ge.setPossibleDuplicate(true);
+        }
+      }
+    }
+
+    if (!pgwsender) {
+      return;
+    }
+
+    PartitionedRegion queueRegion;
+    if (queue instanceof ConcurrentParallelGatewaySenderQueue) {
+      queueRegion =
+          (PartitionedRegion) ((ConcurrentParallelGatewaySenderQueue) 
queue).getRegion();
+    } else {
+      queueRegion =
+          (PartitionedRegion) ((ParallelGatewaySenderQueue) queue).getRegion();
+    }
+
+    if (queueRegion == null || queueRegion.getRegionAdvisor() == null
+        || queueRegion.getDataStore() == null) {
+      return;
+    }
+
+    if (reason == STOPPED_GATEWAY_SENDER) {
+      final Set<Integer> buckets = 
queueRegion.getDataStore().getAllLocalPrimaryBucketIds();
+      if (regionToDispatchedKeysMap.isEmpty()) {
+        if (queueRegion.isSentGatewaySenderStoppedMessage()) {
+          return;
+        }
+        Map<Integer, List<Object>> bucketIdToDispatchedKeys = new HashMap<>();
+        for (Integer bId : buckets) {
+          bucketIdToDispatchedKeys.put(bId, Collections.emptyList());
+        }
+        regionToDispatchedKeysMap.put(queueRegion.getFullPath(), 
bucketIdToDispatchedKeys);
+
+      } else {
+        Map<Integer, List<Object>> bucketIdToDispatchedKeys =
+            regionToDispatchedKeysMap.get(queueRegion.getFullPath());
+        if (bucketIdToDispatchedKeys == null) {
+          return;
+        }
+        for (Integer bId : buckets) {
+          bucketIdToDispatchedKeys.putIfAbsent(bId, Collections.emptyList());
+        }
+      }
+    }
+
+    if (regionToDispatchedKeysMap.size() > 0) {
+      Set<InternalDistributedMember> recipients =
+          getAllRecipients(sender.getCache(), regionToDispatchedKeysMap);
+
+      if (recipients.isEmpty()) {
+        return;
+      }
+
+      if (reason == STOPPED_GATEWAY_SENDER) {
+        if (!queueRegion.isSentGatewaySenderStoppedMessage()) {
+          queueRegion.setSentGatewaySenderStoppedMessage(true);
+        }
+      }
+
+      InternalDistributedSystem ids = 
sender.getCache().getInternalDistributedSystem();
+      DistributionManager dm = ids.getDistributionManager();
+      dm.retainMembersWithSameOrNewerVersion(recipients, 
KnownVersion.GEODE_1_15_0);
+
+      if (!recipients.isEmpty()) {
+        if (logger.isDebugEnabled()) {
+          logger.debug(
+              "notifyPossibleDuplicate send 
ParallelQueueSetPossibleDuplicateMessage recipients {}.",
+              recipients);
+        }
+
+        ParallelQueueSetPossibleDuplicateMessage pqspdm =
+            new ParallelQueueSetPossibleDuplicateMessage(reason, 
regionToDispatchedKeysMap);
+        pqspdm.setRecipients(recipients);
+        dm.putOutgoing(pqspdm);
+      }
+    }
+
+  }
+
+  protected void addDuplicateEvent(
+      Map<String, Map<Integer, List<Object>>> regionToDispatchedKeysMap,
+      GatewaySenderEventImpl event) {
+    PartitionedRegion prQ = null;
+    int bucketId = -1;
+    Object key = null;
+    InternalCache cache = sender.getCache();
+    String regionPath = event.getRegionPath();
+
+    if (event.getRegion() != null) {
+      if (cache.getRegion(regionPath) instanceof DistributedRegion) {
+        prQ = ((ParallelGatewaySenderQueue) 
getQueue()).getRegion(event.getRegion().getFullPath());
+        bucketId = event.getEventId().getBucketID();
+        key = event.getEventId();
+      } else {
+        prQ = ((ParallelGatewaySenderQueue) 
getQueue()).getRegion(ColocationHelper
+            .getLeaderRegion((PartitionedRegion) 
event.getRegion()).getFullPath());
+        bucketId = event.getBucketId();
+        key = event.getShadowKey();
+      }
+    } else {
+      Region region = (PartitionedRegion) cache.getRegion(regionPath);
+      if (region != null && !region.isDestroyed()) {
+        if (region instanceof DistributedRegion) {
+          prQ = ((ParallelGatewaySenderQueue) 
getQueue()).getRegion(region.getFullPath());
+          bucketId = event.getBucketId();
+          key = event.getEventId();
+        } else {
+          prQ = ((ParallelGatewaySenderQueue) getQueue()).getRegion(
+              ColocationHelper.getLeaderRegion((PartitionedRegion) 
region).getFullPath());
+          bucketId = event.getBucketId();
+          key = event.getShadowKey();
+        }
+      }
+    }
+
+    if (prQ == null) {
+      return;
+    }
+
+    Map<Integer, List<Object>> bucketIdToDispatchedKeys =
+        regionToDispatchedKeysMap.get(prQ.getFullPath());
+    if (bucketIdToDispatchedKeys == null) {
+      bucketIdToDispatchedKeys = new ConcurrentHashMap<>();
+      regionToDispatchedKeysMap.put(prQ.getFullPath(), 
bucketIdToDispatchedKeys);
+    }
+
+    List<Object> dispatchedKeys = bucketIdToDispatchedKeys.get(bucketId);
+    if (dispatchedKeys == null) {
+      dispatchedKeys = new ArrayList<>();
+      bucketIdToDispatchedKeys.put(bucketId, dispatchedKeys);
+    }
+    dispatchedKeys.add(key);
+
+  }
+
+  public void prepareForStopProcessing() {
+    notifyPossibleDuplicate(STOPPED_GATEWAY_SENDER, pendingEventsInBatches());
+  }
+
+  private Set<InternalDistributedMember> getAllRecipients(InternalCache cache, 
Map map) {

Review Comment:
   Can `Map map` be typed here? I know some of the internals are still using 
raw types but we're trying to move away from raw types and some of the PRs 
include propagating the types around when possible.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to