This is an automated email from the ASF dual-hosted git repository. alberto pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push: new 0852113f1b GEODE-10409: Fix rebalance load model missing collocated regions at s… (#7839) 0852113f1b is described below commit 0852113f1b8086203ffdd99bae1afa250c2eaa3e Author: WeijieEST <108109958+weijie...@users.noreply.github.com> AuthorDate: Mon Sep 12 16:06:10 2022 +0800 GEODE-10409: Fix rebalance load model missing collocated regions at s… (#7839) * GEODE-10409: Fix rebalance load model missing collocated regions at server startup Assume region A collocated with A1 and A2, and a is the leader region, when rebalance at startup, rebalance will happened after the 3 region collocation completed, generally this happened in region A2. And when calculate rebalance load model from view of region A2, only leader region A and A2 itself will be added to the model, this commit fix the issue and make A1 also be added to the model. * add test cases to test rebalance model and remove the static mock * change test case to avoid changing existing methods for testing * improve test case --- .../partitioned/PartitionedRegionRebalanceOp.java | 4 +- .../PartitionedRegionRebalanceOpTest.java | 56 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/PartitionedRegionRebalanceOp.java b/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/PartitionedRegionRebalanceOp.java index ade143a761..65601c5407 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/PartitionedRegionRebalanceOp.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/PartitionedRegionRebalanceOp.java @@ -302,8 +302,8 @@ public class PartitionedRegionRebalanceOp { // anywhere I think. We need to make sure we don't do a rebalance unless we have // all of the colocated regions others do. Map<String, PartitionedRegion> colocatedRegionsMap = - ColocationHelper.getAllColocationRegions(targetRegion); - colocatedRegionsMap.put(targetRegion.getFullPath(), targetRegion); + ColocationHelper.getAllColocationRegions(leaderRegion); + colocatedRegionsMap.put(leaderRegion.getFullPath(), leaderRegion); final LinkedList<PartitionedRegion> colocatedRegions = new LinkedList<>(); for (PartitionedRegion colocatedRegion : colocatedRegionsMap.values()) { diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/PartitionedRegionRebalanceOpTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/PartitionedRegionRebalanceOpTest.java new file mode 100644 index 0000000000..92f106a723 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/PartitionedRegionRebalanceOpTest.java @@ -0,0 +1,56 @@ +/* + * 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.partitioned; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.junit.Test; + +import org.apache.geode.cache.PartitionAttributes; +import org.apache.geode.cache.PartitionAttributesFactory; +import org.apache.geode.cache.partition.PartitionRebalanceInfo; +import org.apache.geode.internal.cache.PartitionedRegion; +import org.apache.geode.internal.cache.PartitionedRegionTestHelper; +import org.apache.geode.internal.cache.partitioned.rebalance.MoveBuckets; +import org.apache.geode.internal.cache.partitioned.rebalance.RebalanceDirector; + + +public class PartitionedRegionRebalanceOpTest { + private PartitionedRegion leaderRegion; + private PartitionedRegion colocRegion1; + private PartitionedRegion colocRegion2; + + @Test + public void testRebalanceModelContainsAllColocatedRegionsWhenRebalanceTargetIsNotLeaderRegion() { + leaderRegion = + (PartitionedRegion) PartitionedRegionTestHelper.createPartionedRegion("leader"); + PartitionAttributesFactory paf = new PartitionAttributesFactory(); + PartitionAttributes pa = paf.setColocatedWith("/leader").create(); + colocRegion1 = + (PartitionedRegion) PartitionedRegionTestHelper.createPartionedRegion("colo1", pa); + colocRegion2 = + (PartitionedRegion) PartitionedRegionTestHelper.createPartionedRegion("colo2", pa); + RebalanceDirector director = new MoveBuckets(); + PartitionedRegionRebalanceOp rebalanceOp = + new PartitionedRegionRebalanceOp(colocRegion1, false, director, false, true, + new AtomicBoolean(false), null); + Set<PartitionRebalanceInfo> rebalanceInfo = rebalanceOp.execute(); + // 3 regions include the leader region and 2 colocated regions. + assertThat(rebalanceInfo).hasSize(3); + } +}