-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/grant lease in create #213
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
Open
jessicayu626
wants to merge
6
commits into
develop
Choose a base branch
from
feature/grant-lease-in-create
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -404,7 +404,7 @@ void ZkNnClient::recover_lease(RecoverLeaseRequestProto &req, | |
| res.set_result(false); | ||
| return; | ||
| } | ||
| if (children.size() > 0) { | ||
| if (children.size() > 1) { | ||
| for (std::string child : children) { | ||
| LOG(ERROR) << "[recover_lease] Child: " + child; | ||
| } | ||
|
|
@@ -420,6 +420,10 @@ void ZkNnClient::recover_lease(RecoverLeaseRequestProto &req, | |
| return; | ||
| } | ||
| std::string lease_holder_client = children[0]; | ||
| if (lease_holder_client == client_name) { | ||
| res.set_result(true); | ||
| return; | ||
| } | ||
| if (lease_expired(lease_holder_client)) { | ||
| // TODO(elfyingying): start the lease recovery process | ||
| // that closes the file for the | ||
|
|
@@ -800,7 +804,8 @@ ZkNnClient::GetFileInfoResponse ZkNnClient::get_info( | |
| * Create a node in zookeeper corresponding to a file | ||
| */ | ||
| bool ZkNnClient::create_file_znode(const std::string &path, | ||
| FileZNode *znode_data) { | ||
| FileZNode *znode_data, | ||
| const std::string &client_name) { | ||
| int error_code; | ||
| if (!file_exists(path)) { | ||
| LOG(INFO) << "[create_file_znode] Creating file znode at " << path; | ||
|
|
@@ -837,6 +842,19 @@ bool ZkNnClient::create_file_znode(const std::string &path, | |
| << error_code; | ||
| return false; | ||
| } | ||
| // grant the client the lease | ||
| if (!zk->create(LeaseZookeeperPath(path) + '/' + | ||
| client_name, ZKWrapper::EMPTY_VECTOR, | ||
| error_code, false)) { | ||
| LOG(ERROR) << "[create_file_znode] ZK create lease client path failed" | ||
| << error_code; | ||
| return false; | ||
| } | ||
| // set the timestamp for the client that created the file | ||
| RenewLeaseRequestProto req; | ||
| req.set_clientname(client_name); | ||
| RenewLeaseResponseProto res; | ||
| renew_lease(req, res); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a workaround for creating a lease. Do we not have a "helper function" for creating leases? I might be wrong about there being a cleaner way though; just wondering. |
||
| } | ||
| return true; | ||
| } | ||
|
|
@@ -1237,7 +1255,7 @@ ZkNnClient::CreateResponse ZkNnClient::create_file( | |
| } | ||
|
|
||
| // if we failed, then do not set any status | ||
| if (!create_file_znode(path, &znode_data)) | ||
| if (!create_file_znode(path, &znode_data, request.clientname())) | ||
| return CreateResponse::FailedCreateZnode; | ||
|
|
||
| HdfsFileStatusProto *status = response.mutable_fs(); | ||
|
|
@@ -1358,6 +1376,7 @@ ZkNnClient::MkdirResponse ZkNnClient::mkdir(MkdirsRequestProto &request, | |
| ZkNnClient::MkdirResponse ZkNnClient::mkdir_helper(const std::string &path, | ||
| bool create_parent) { | ||
| LOG(INFO) << "[mkdir_helper] mkdir_helper called with input " << path; | ||
| std::string empty_string; | ||
| if (create_parent) { | ||
| std::vector<std::string> split_path; | ||
| boost::split(split_path, path, boost::is_any_of("/")); | ||
|
|
@@ -1377,7 +1396,7 @@ ZkNnClient::MkdirResponse ZkNnClient::mkdir_helper(const std::string &path, | |
| not_exist = true; | ||
| FileZNode znode_data; | ||
| set_mkdir_znode(&znode_data); | ||
| if (!create_file_znode(p_path, &znode_data)) { | ||
| if (!create_file_znode(p_path, &znode_data, empty_string)) { | ||
| // TODO(2016) unroll the created directories | ||
| return MkdirResponse::FailedZnodeCreation; | ||
| } | ||
|
|
@@ -1386,7 +1405,7 @@ ZkNnClient::MkdirResponse ZkNnClient::mkdir_helper(const std::string &path, | |
| } else { | ||
| FileZNode znode_data; | ||
| set_mkdir_znode(&znode_data); | ||
| return create_file_znode(path, &znode_data) ? | ||
| return create_file_znode(path, &znode_data, empty_string) ? | ||
| MkdirResponse::Ok : MkdirResponse::FailedZnodeCreation; | ||
| } | ||
| return MkdirResponse::Ok; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a fix for an unrelated bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a fix for a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍