Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added HelixPopulateTool and tests. #1176

Merged
merged 2 commits into from
Jun 3, 2019
Merged

Conversation

zzmao
Copy link
Contributor

@zzmao zzmao commented May 30, 2019

Add HelixPopulateTool to create or update a helix cluster zk info.

@zzmao zzmao requested a review from jsjtzyy May 30, 2019 20:44
@codecov-io
Copy link

codecov-io commented May 30, 2019

Codecov Report

Merging #1176 into master will decrease coverage by 0.19%.
The diff coverage is 1.16%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master    #1176     +/-   ##
===========================================
- Coverage     69.86%   69.67%   -0.2%     
+ Complexity     5374     5371      -3     
===========================================
  Files           428      429      +1     
  Lines         32863    32949     +86     
  Branches       4147     4160     +13     
===========================================
- Hits          22960    22957      -3     
- Misses         8772     8856     +84     
- Partials       1131     1136      +5
Impacted Files Coverage Δ Complexity Δ
....github.ambry/clustermap/HelixVcrPopulateTool.java 0% <0%> (ø) 0 <0> (?)
...ithub.ambry.cloud/azure/AzureCloudDestination.java 81.67% <100%> (+0.09%) 26 <0> (ø) ⬇️
.../main/java/com.github.ambry.router/EncryptJob.java 92.1% <0%> (-5.27%) 4% <0%> (-1%)
...java/com.github.ambry.store/CompactionManager.java 87.33% <0%> (-2.67%) 19% <0%> (ø)
.../main/java/com.github.ambry.router/PutManager.java 87.42% <0%> (-0.63%) 29% <0%> (ø)
...src/main/java/com.github.ambry.commons/BlobId.java 93.18% <0%> (-0.36%) 71% <0%> (-1%)
...java/com.github.ambry.network/SSLTransmission.java 69.42% <0%> (-0.32%) 68% <0%> (-1%)
...in/java/com.github.ambry.store/BlobStoreStats.java 71.54% <0%> (-0.21%) 103% <0%> (ø)
...va/com.github.ambry.replication/ReplicaThread.java 74.52% <0%> (-0.19%) 65% <0%> (-1%)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6373104...3f9ada3. Read the comment docs.

@@ -0,0 +1,126 @@
/*
* Copyright 2017 LinkedIn Corp. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2019, please

@@ -0,0 +1,183 @@
/*
* Copyright 2017 LinkedIn Corp. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

private static String SEPARATOR = "/";
static List<String> ignoreResourceKeyWords = Arrays.asList("aggregation", "trigger", "stats");

public static void main(String args[]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use java style: String[] args

OptionSpec createClusterOpt = parser.accepts("createCluster",
"Create resources in dest by copying from src to dest. --createCluster --dest destZkEndpoint/destClusterName");
OptionSpec updateClusterOpt = parser.accepts("updateCluster",
"Update resources in dest by copying from src to dest. --updateCluster"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still don't quite understand Create resources in dest by copying from src to dest in createCluster. I feel like maybe we can change the description a little bit. Let's discuss offline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no copy required. Just create. Update.

if (options.has(updateClusterOpt)) {
System.out.println("Updating cluster: " + destClusterName);
String srcZkString = options.valueOf(srcOpt).split(SEPARATOR)[0];
String srcClusterName = options.valueOf(srcOpt).split(SEPARATOR)[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move System.out.println("Updating cluster: " + destClusterName); here and add more info like " from existing cluster: " + srcClusterName .

ClusterConfig clusterConfig = configAccessor.getClusterConfig(destClusterName);
clusterConfig.setPersistBestPossibleAssignment(true);
configAccessor.setClusterConfig(destClusterName, clusterConfig);
System.out.println("Cluster " + destClusterName + " create done.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: how about this:
System.out.println("Cluster " + destClusterName + " is successfully created!");

* @param destClusterName the dest cluster's name
*/
static void updateResourceAndPartition(String srcZkString, String srcClusterName, String destZkString,
String destClusterName, boolean dryRun) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add java doc for dryRun

}

/**
* Update dest cluster information based on src cluster. Dest cluster resource will be recreated if src cluster has any change.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor question: is recreated automatically? In other words, any changes in src cluster will trigger changes in dest cluster automatically?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I understand what you mean here by reading following code. However, I feel like it could be better to change the description as:
Dest cluster resource will be recreated if it mismatches that in src cluster.

}
}
}
System.out.println("Cluster " + destClusterName + " update done.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: how about System.out.println("Cluster " + destClusterName + " is successfully updated!");

Set<String> srcPartitions = srcAdmin.getResourceIdealState(srcClusterName, resource).getPartitionSet();
Set<String> destPartitions = destAdmin.getResourceIdealState(destClusterName, resource).getPartitionSet();
for (String partition : srcPartitions) {
if (!destPartitions.contains(partition)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if destPartitions has partition that is not in srcPartitions?

@zzmao
Copy link
Contributor Author

zzmao commented Jun 3, 2019

@jsjtzyy Addressed your comments and enhanced a test.

@jsjtzyy jsjtzyy merged commit 3ee2f2a into linkedin:master Jun 3, 2019
String destZkString = options.valueOf(destOpt).split(SEPARATOR)[0];
String destClusterName = options.valueOf(destOpt).split(SEPARATOR)[1];
if (!destClusterName.contains("VCR")) {
System.out.println("dest should be a VCR cluster.(VCR string should be included)");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.err.println.

destZkClient.setZkSerializer(new ZNRecordSerializer());
HelixAdmin destAdmin = new ZKHelixAdmin(destZkClient);
if (destAdmin.getClusters().contains(destClusterName)) {
System.out.println("Failed to create cluster becuase " + destClusterName + " already exist.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err

public static void main(String[] args) {
OptionParser parser = new OptionParser();
OptionSpec createClusterOpt = parser.accepts("createCluster",
"Create resources in dest cluster. --createCluster --dest destZkEndpoint/destClusterName");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it actually create resources or just the cluster?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just cluster.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add in comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issues addressed in #1179

System.out.println("DryRun: Drop Resource " + resource);
} else {
// This resource need to be recreate.
destAdmin.dropResource(destClusterName, resource);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this should only be done if the resource exists in dest and is different from src. You might need another boolean variable like dropChangedResource to condition this action.

System.out.println("DryRun: Add Resource " + resource + " with partition " + srcPartitions);
} else {
destAdmin.addResource(destClusterName, resource, idealState);
destAdmin.rebalance(destClusterName, resource, 3, "", "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not obvious what constant 3 refers to. Variable or comment would be helpful.

Copy link
Contributor

@lightningrob lightningrob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address comments in follow up PR.

jsjtzyy pushed a commit that referenced this pull request Jun 5, 2019
Fix some issue in #1176
Add controlResource and maintainCluster support.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants