mivanac commented on code in PR #7323: URL: https://github.com/apache/geode/pull/7323#discussion_r858370721
########## 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: Updated ########## 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: Updated -- 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]
