kaisun2000 commented on a change in pull request #1123:
URL: https://github.com/apache/helix/pull/1123#discussion_r447922995
##########
File path:
helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/AssignmentMetadataStore.java
##########
@@ -95,53 +95,56 @@ protected AssignmentMetadataStore(BucketDataAccessor
bucketDataAccessor, String
* @return true if a new baseline was persisted.
* @throws HelixException if the method failed to persist the baseline.
*/
- // TODO: Enhance the return value so it is more intuitive to understand when
the persist fails and
- // TODO: when it is skipped.
public synchronized boolean persistBaseline(Map<String, ResourceAssignment>
globalBaseline) {
- // TODO: Make the write async?
- // If baseline hasn't changed, skip writing to metadata store
- if (compareAssignments(_globalBaseline, globalBaseline)) {
- return false;
- }
- // Persist to ZK
- HelixProperty combinedAssignments = combineAssignments(BASELINE_KEY,
globalBaseline);
- try {
- _dataAccessor.compressedBucketWrite(_baselinePath, combinedAssignments);
- } catch (IOException e) {
- // TODO: Improve failure handling
- throw new HelixException("Failed to persist baseline!", e);
- }
-
- // Update the in-memory reference
- _globalBaseline = globalBaseline;
- return true;
+ return persistAssignment(globalBaseline, getBaseline(), _baselinePath,
BASELINE_KEY);
}
/**
* @return true if a new best possible assignment was persisted.
* @throws HelixException if the method failed to persist the baseline.
*/
- // TODO: Enhance the return value so it is more intuitive to understand when
the persist fails and
- // TODO: when it is skipped.
public synchronized boolean persistBestPossibleAssignment(
Map<String, ResourceAssignment> bestPossibleAssignment) {
+ return persistAssignment(bestPossibleAssignment,
getBestPossibleAssignment(), _bestPossiblePath,
+ BEST_POSSIBLE_KEY);
+ }
+
+ public synchronized void clearAssignmentMetadata() {
+ persistAssignment(Collections.emptyMap(), getBaseline(), _baselinePath,
BASELINE_KEY);
+ persistAssignment(Collections.emptyMap(), getBestPossibleAssignment(),
_bestPossiblePath,
+ BEST_POSSIBLE_KEY);
+ }
+
+ /**
+ * @param newAssignment
+ * @param cachedAssignment
+ * @param path the path of the assignment record
+ * @param key the key of the assignment in the record
+ * @return true if a new assignment was persisted.
+ */
+ // TODO: Enhance the return value so it is more intuitive to understand when
the persist fails and
+ // TODO: when it is skipped.
+ private boolean persistAssignment(Map<String, ResourceAssignment>
newAssignment,
+ Map<String, ResourceAssignment> cachedAssignment, String path,
+ String key) {
// TODO: Make the write async?
- // If bestPossibleAssignment hasn't changed, skip writing to metadata store
- if (compareAssignments(_bestPossibleAssignment, bestPossibleAssignment)) {
+ // If the assignment hasn't changed, skip writing to metadata store
+ if (compareAssignments(cachedAssignment, newAssignment)) {
return false;
}
// Persist to ZK
- HelixProperty combinedAssignments =
- combineAssignments(BEST_POSSIBLE_KEY, bestPossibleAssignment);
+ HelixProperty combinedAssignments = combineAssignments(key, newAssignment);
try {
- _dataAccessor.compressedBucketWrite(_bestPossiblePath,
combinedAssignments);
+ _dataAccessor.compressedBucketWrite(path, combinedAssignments);
} catch (IOException e) {
// TODO: Improve failure handling
- throw new HelixException("Failed to persist BestPossibleAssignment!", e);
+ throw new HelixException(
Review comment:
What is going to catch this one?
----------------------------------------------------------------
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]