-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Clear space #3989
Clear space #3989
Conversation
Any tests? |
in the next pr. I'm worried that this PR is too big, no one wants to see it |
src/kvstore/NebulaStore.cpp
Outdated
@@ -427,6 +427,24 @@ void NebulaStore::removeSpace(GraphSpaceID spaceId, bool isListener) { | |||
} | |||
} | |||
|
|||
nebula::cpp2::ErrorCode NebulaStore::clearSpace(GraphSpaceID spaceId) { | |||
folly::RWSpinLock::WriteHolder wh(&lock_); |
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.
The lock_
is not for DML, it is used for partition related modify, e.g. when add space or drop part.
Maybe you could find all kv_engine by NebulaStore::space, and get all parts by NebulaStore::allParts
from kv_engine.
src/kvstore/NebulaStore.cpp
Outdated
auto spaceIt = this->spaces_.find(spaceId); | ||
if (spaceIt != this->spaces_.end()) { | ||
for (auto& part : spaceIt->second->parts_) { | ||
auto ret = part.second->cleanup(); |
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.
Perhaps you need grab the raft lock here. BTW, do we need to block write by meta?
} | ||
|
||
// 4. select the active hosts. | ||
std::vector<HostAddr> selectedHosts; |
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.
If not all alive, just return error
} | ||
|
||
// 3. Determine which hosts the space is distributed on. | ||
std::vector<HostAddr> distributedOnHosts; |
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.
Maybe just use a unordered_set? Not so important
|
||
void ClearSpaceProcessor::process(const cpp2::ClearSpaceReq& req) { | ||
folly::SharedMutex::ReadHolder rHolder(LockUtils::snapshotLock()); | ||
folly::SharedMutex::WriteHolder holder(LockUtils::lock()); |
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.
Why we need to use write lock here? BTW, do we really need to grab the snapshot lock here?
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.
LGTM, good job
->getMetaClient() | ||
->clearSpace(csNode->getSpaceName(), csNode->getIfExists()) | ||
.via(runner()) | ||
.thenValue([this, csNode, spaceIdRet, ftIndexes](StatusOr<bool> resp) { |
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.
better to move this ftIndexes into lambda function
std::move(pro)); | ||
} | ||
|
||
folly::collectAll(std::move(futures)) |
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.
prefer to return this future directly rather than using promise.
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.
In order to be consistent with other interfaces. And the upper layer also needs a future as return value.
And wait 2 seconds | ||
When executing query: | ||
""" | ||
CLEAR SPACE IF EXISTS clear_space; |
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.
Need you to consider the role of this operation? Could anyone clear the used space or only root user?
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.
only root can do this. https://confluence.nebula-graph.io/pages/viewpage.action?pageId=40535032
@@ -124,6 +124,7 @@ LABEL_FULL_WIDTH {CN_EN_FULL_WIDTH}{CN_EN_NUM_FULL_WIDTH}* | |||
"ADD" { return TokenType::KW_ADD; } | |||
"CREATE" { return TokenType::KW_CREATE;} | |||
"DROP" { return TokenType::KW_DROP; } | |||
"CLEAR" { return TokenType::KW_CLEAR; } |
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.
New reserved word means incompatible.
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.
Weird. Doesn't the incompatibility mean that the this function affects other functions?
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.
Means users maybe need to modify their application.
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.
If the user does not use the clear space function, then there is no need to modify it. Add a new syntax, I think it is forward compatible.
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.
When user has column of table named clear
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.
OK, I see.
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.
LGTM, excellent!
} | ||
|
||
// 5. Delete the space data on the corresponding hosts. | ||
auto clearRet = adminClient_->clearSpace(spaceId, hosts).get(); |
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.
When clearing data, other threads are writing data. At this time, how to ensure the correctness and consistency of data?
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.
There will be a write prohibition command later, which will require the user to add a write prohibition command before executing clear.
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.
Before clearing the space, do need to execute other SQL? Shouldn't it be triggered during clear space?
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.
trigger together is not easy to guarantee atomicity, e.g. the meta server goes down when writes are disabled. When it starts up again, the write prohibition is still there. This increases the processing complexity. Therefore, this version is simple, let the user manually execute the prohibition command first.
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.
👌, create snapshot has almost the same problem.
What type of PR is this?
What problem(s) does this PR solve?
Issue(s) number:
fix #3679
Description:
How do you solve it?
Special notes for your reviewer, ex. impact of this fix, design document, etc:
Checklist:
Tests:
Affects:
Release notes:
Please confirm whether to be reflected in release notes and how to describe: