You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geode.apache.org by GitBox <gi...@apache.org> on 2020/04/21 23:44:48 UTC

[GitHub] [geode] DonalEvans commented on a change in pull request #4909: GEODE-7953: Restore Redundancy Internal API

DonalEvans commented on a change in pull request #4909:
URL: https://github.com/apache/geode/pull/4909#discussion_r412566753



##########
File path: geode-core/src/main/java/org/apache/geode/cache/control/RestoreRedundancyResults.java
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.cache.control;
+
+import java.util.Map;
+
+import org.apache.geode.cache.partition.PartitionRebalanceInfo;
+import org.apache.geode.internal.cache.control.RegionRedundancyStatus;
+import org.apache.geode.internal.cache.partitioned.PartitionedRegionRebalanceOp;
+
+/**
+ * A class to collect the results of restore redundancy operations for one or more regions and
+ * determine the success of failure of the operation.
+ */
+public interface RestoreRedundancyResults {
+
+  /**
+   * {@link #SUCCESS} is defined as every included region having fully satisfied redundancy.
+   * {@link #FAILURE} is defined as at least one region that is configured to have redundant copies
+   * having fewer than its configured number of redundant copies.
+   * {@link #ERROR} is for cases when the restore redundancy operation was unable to begin or threw
+   * an exception.
+   */
+  enum Status {
+    SUCCESS,
+    FAILURE,
+    ERROR
+  }
+
+  /**
+   * Adds the contents of another {@link RestoreRedundancyResults} object to this one, including
+   * both {@link RegionRedundancyStatus} objects and information on the number of primaries
+   * reassigned and the time taken to reassign them.
+   *
+   * @param results a {@link RestoreRedundancyResults} object whose contents will be added to this
+   *        one.
+   */
+  void addRegionResults(RestoreRedundancyResults results);
+
+  /**
+   * Adds information regarding the number of primaries reassigned and the time taken to reassign
+   * them during a restore redundancy operation.
+   *
+   * @param details a {@link PartitionRebalanceInfo} generated by a
+   *        {@link PartitionedRegionRebalanceOp} operation.
+   */
+  void addPrimaryReassignmentDetails(PartitionRebalanceInfo details);
+
+  /**
+   * Adds one {@link RegionRedundancyStatus} to the result set.
+   *
+   * @param regionResult The {@link RegionRedundancyStatus} to be added to the result set.
+   */
+  void addRegionResult(RegionRedundancyStatus regionResult);

Review comment:
       Good call. I've removed the mutators from the interface and moved `RegionRedundancyStatus` to no longer be internal.

##########
File path: geode-core/src/main/java/org/apache/geode/internal/cache/control/RegionRedundancyStatus.java
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.control;
+
+import java.io.Serializable;
+
+import org.apache.geode.internal.cache.PartitionedRegion;
+
+/**
+ * Used to calculate and store the redundancy status for a {@link PartitionedRegion}.
+ */
+public class RegionRedundancyStatus implements Serializable {

Review comment:
       Done.

##########
File path: geode-core/src/main/java/org/apache/geode/internal/cache/control/RestoreRedundancyBuilderImpl.java
##########
@@ -0,0 +1,177 @@
+/*
+ * 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.control;
+
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+
+import org.apache.geode.cache.RegionDestroyedException;
+import org.apache.geode.cache.control.RestoreRedundancyBuilder;
+import org.apache.geode.cache.control.RestoreRedundancyResults;
+import org.apache.geode.cache.partition.PartitionRebalanceInfo;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.partitioned.PartitionedRegionRebalanceOp;
+import org.apache.geode.internal.cache.partitioned.rebalance.RestoreRedundancyDirector;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+
+class RestoreRedundancyBuilderImpl implements RestoreRedundancyBuilder {
+
+  private final InternalCache cache;
+  private final InternalResourceManager manager;
+  private Set<String> includedRegions;
+  private Set<String> excludedRegions;
+  private boolean shouldReassign = true;
+  private ScheduledExecutorService executor;
+
+  public RestoreRedundancyBuilderImpl(InternalCache cache) {
+    this.cache = cache;
+    this.manager = cache.getInternalResourceManager();
+    this.executor = this.manager.getExecutor();
+  }
+
+  @Override
+  public RestoreRedundancyBuilder includeRegions(Set<String> regions) {
+    this.includedRegions = regions;
+    return this;
+  }
+
+  @Override
+  public RestoreRedundancyBuilder excludeRegions(Set<String> regions) {
+    this.excludedRegions = regions;
+    return this;
+  }
+
+  @Override
+  public RestoreRedundancyBuilder setReassignPrimaries(boolean shouldReassign) {
+    this.shouldReassign = shouldReassign;
+    return this;
+  }
+
+  @Override
+  public CompletableFuture<RestoreRedundancyResults> start() {

Review comment:
       If child colocated regions are automatically rejected, then if we explicitly include a child region in the restore redundancy operation but not its parent, no work will be done. This could make life difficult for users who might not know which region in a colocation group is the parent, so the behaviour implemented here is to restore redundancy to all regions in the colocation group if any one of them is included, regardless of whether it's the parent or not.
   
   The missing logic is also not strictly needed here, since if we call `execute()` on a `PartitionedRegionRebalanceOp` for a colocated region, we will either rebalance the entire colocation group (if it's the first region in the group to be executed on) or we'll exit early because `isRebalanceNecessary()` will return false (if any of the other regions in the group have already been executed on), so no additional work is being done at the region level.
   
   The design for this class was originally much closer to what is seen in `RebalanceFactoryImpl`, but following feedback on the RFC in which several people requested that the `start()` method return a `CompletableFuture` rather than a separate Operation class, this approach was taken. I agree that it would be better to have both operations use the same logic, but `RebalanceOperation` and `RebalanceFactory` are both public APIs and so can't be easily changed, and there was a strong agreement on the RFC to use a `CompletableFuture` rather than the existing approach, so I'm not sure it's possible to make everyone happy here.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org