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

Clear space #3989

Merged
merged 17 commits into from
Mar 14, 2022
Merged

Clear space #3989

merged 17 commits into from
Mar 14, 2022

Conversation

zhaohaifei
Copy link
Contributor

@zhaohaifei zhaohaifei commented Mar 8, 2022

What type of PR is this?

  • bug
  • feature
  • enhancement

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:

  • Unit test(positive and negative cases)
  • Function test
  • Performance test
  • N/A

Affects:

  • Documentation affected (Please add the label if documentation needs to be modified.)
  • Incompatibility (If it breaks the compatibility, please describe it and add the label.)
  • If it's needed to cherry-pick (If cherry-pick to some branches is required, please label the destination version(s).)
  • Performance impacted: Consumes more CPU/Memory

Release notes:

Please confirm whether to be reflected in release notes and how to describe:

Added a clear space feature, which will clear space data and index data, but keep space schema and index schema.

@zhaohaifei zhaohaifei added ready-for-testing PR: ready for the CI test doc affected PR: improvements or additions to documentation ready for review labels Mar 8, 2022
@zhaohaifei zhaohaifei added this to the v3.1.0 milestone Mar 8, 2022
@zhaohaifei zhaohaifei requested review from CPWstatic, dutor and a team as code owners March 8, 2022 09:38
@zhaohaifei zhaohaifei requested a review from critical27 March 8, 2022 09:41
@Shylock-Hg
Copy link
Contributor

Shylock-Hg commented Mar 8, 2022

Any tests?

@zhaohaifei
Copy link
Contributor Author

Any tests?

in the next pr. I'm worried that this PR is too big, no one wants to see it

src/interface/meta.thrift Show resolved Hide resolved
@@ -427,6 +427,24 @@ void NebulaStore::removeSpace(GraphSpaceID spaceId, bool isListener) {
}
}

nebula::cpp2::ErrorCode NebulaStore::clearSpace(GraphSpaceID spaceId) {
folly::RWSpinLock::WriteHolder wh(&lock_);
Copy link
Contributor

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.

auto spaceIt = this->spaces_.find(spaceId);
if (spaceIt != this->spaces_.end()) {
for (auto& part : spaceIt->second->parts_) {
auto ret = part.second->cleanup();
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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());
Copy link
Contributor

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?

@zhaohaifei zhaohaifei requested a review from critical27 March 9, 2022 08:38
@zhaohaifei zhaohaifei added wip Solution: work in progress and removed ready-for-testing PR: ready for the CI test labels Mar 9, 2022
@zhaohaifei zhaohaifei changed the title Clear space [part 1] Clear space Mar 10, 2022
@zhaohaifei zhaohaifei added ready-for-testing PR: ready for the CI test and removed wip Solution: work in progress labels Mar 10, 2022
critical27
critical27 previously approved these changes Mar 10, 2022
Copy link
Contributor

@critical27 critical27 left a 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) {
Copy link
Contributor

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))
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -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; }
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

@Shylock-Hg Shylock-Hg Mar 11, 2022

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I see.

@Shylock-Hg Shylock-Hg added the incompatible PR: incompatible with the recently released version label Mar 10, 2022
yixinglu
yixinglu previously approved these changes Mar 14, 2022
Copy link
Contributor

@yixinglu yixinglu left a comment

Choose a reason for hiding this comment

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

LGTM, excellent!

critical27
critical27 previously approved these changes Mar 14, 2022
}

// 5. Delete the space data on the corresponding hosts.
auto clearRet = adminClient_->clearSpace(spaceId, hosts).get();
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@panda-sheep panda-sheep Mar 14, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc affected PR: improvements or additions to documentation incompatible PR: incompatible with the recently released version ready for review ready-for-testing PR: ready for the CI test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support “clear data” in the space
6 participants