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

curvefs/metaserver: fix trash bugs #2948

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

wuhongsong
Copy link
Contributor

What problem does this PR solve?

Issue Number: #xxx

Problem Summary:

What is changed and how it works?

What's Changed:

How it Works:

Side effects(Breaking backward compatibility? Performance regression?):

Check List

  • Relevant documentation/comments is changed or added
  • I acknowledge that all my contributions will be made under the project's license

@wuhongsong wuhongsong force-pushed the fix_trash_1205 branch 3 times, most recently from 1e01fc6 to f6cd9d5 Compare December 6, 2023 11:17
@wuhongsong
Copy link
Contributor Author

cicheck

* @param[in] logIndex: the index of raft log
* @return
*/
MetaStatusCode UpdateDeletingKey(const Inode& inode, int64_t logIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

UpdateDeletingKey to AddDeletedInode maybe more clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix

*/
MetaStatusCode UpdateDeletingKey(const Inode& inode, int64_t logIndex);

MetaStatusCode ClearDelKey(const Key4Inode& key);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto RemoveDeletedInode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix

@@ -866,5 +869,27 @@ bool MetaStoreImpl::InitStorage() {
return kvStorage_->Open();
}

void MetaStoreImpl::LoadDeletedInodes() {
Copy link
Contributor

Choose a reason for hiding this comment

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

LoadDeletedInodes is the responsibility of InodeManager, Each partition has one InodeManager and InodeStorage, you can load deleted inodes with InodeManager and add to trash_ in InodeManager by pass and the deleted inode loaded are all belong to this partition and trash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix

LOG(ERROR) << "Begin transaction failed";
return MetaStatusCode::STORAGE_INTERNAL_ERROR;
}
auto rc = txn->HSet(table4DelInode_, skey , inode);
Copy link
Contributor

Choose a reason for hiding this comment

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

The value does not need to be the entire inode, dtime is enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix

}

void TrashImpl::Add(uint64_t inodeId, uint64_t dtime) {
void TrashImpl::Add(uint64_t inodeId, uint64_t dtime, bool deleted) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why deleted needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tell reboot or not

LockGuard lg(itemsMutex_);
trashItems_.erase(inodeId);
auto it = std::find(trashItems_.begin(), trashItems_.end(), item);
if (it != trashItems_.end()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The remove of rocksdb data can do here also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix

@@ -446,6 +441,13 @@ MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest& request,
return MetaStatusCode::STORAGE_INTERNAL_ERROR;
}
}

if (needAddTrash) {
inodeStorage_->UpdateDeletingKey(old, logIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

add and delete op all deal in trash is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix

@wuhongsong
Copy link
Contributor Author

cicheck

@wuhongsong
Copy link
Contributor Author

cicheck

namespace storage {

#define DELETEPREFIXINKV "deleting:"
Copy link
Contributor

Choose a reason for hiding this comment

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

this is needn't

@@ -123,6 +129,13 @@ std::string NameGenerator::Format(KEY_TYPE type, uint32_t partitionId) {
return absl::StrCat(type, kDelimiter, absl::string_view(buf, sizeof(buf)));
}

std::string NameGenerator::FormatDel(KEY_TYPE type, uint32_t partitionId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need

@@ -54,6 +55,7 @@ static bool CompareType(const std::string& str, KEY_TYPE keyType) {

NameGenerator::NameGenerator(uint32_t partitionId)
: tableName4Inode_(Format(kTypeInode, partitionId)),
tableName4DelInode_(FormatDel(kTypeInode, partitionId)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a new type like 'kTypeDelInode'

@wuhongsong
Copy link
Contributor Author

cicheck

@wuhongsong
Copy link
Contributor Author

cicheck

@wuhongsong
Copy link
Contributor Author

cicheck

@wuhongsong
Copy link
Contributor Author

cicheck

2 similar comments
@wuhongsong
Copy link
Contributor Author

cicheck

@wuhongsong
Copy link
Contributor Author

cicheck

@wuhongsong
Copy link
Contributor Author

cicheck

{
LockGuard lgItems(itemsMutex_);
trashItems_.insert(temp.begin(), temp.end());
trashItems_.swap(temp);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can not swap, the trashItem already has some new item

@@ -100,7 +109,7 @@ void TrashImpl::ScanTrash() {
return;
}

std::unordered_map<uint64_t, uint64_t> temp;
std::map<uint64_t, uint64_t> temp;
Copy link
Contributor

Choose a reason for hiding this comment

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

unordered_map is space friendly here

}

void TrashImpl::Remove(uint64_t inodeId) {
if (isStop_) {
return;
}
LockGuard lg(itemsMutex_);
trashItems_.erase(inodeId);
auto it = trashItems_.find(inodeId);
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need find here and can erase directly

<< ", partitionId = " << partitionId_
trashItems_.emplace(inodeId, dtime);

VLOG(6) << "Add trash item success"
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't remove fsId and partitionId, inodeId can be same in different fs

std::map<std::string, uint64_t>* item, const std::string prefix) {
std::string sprefix = absl::StrCat("0", ":", prefix);
VLOG(3) << "load deleted inodes from: " << options_.dataDir
<< ", " << sprefix << ", " << prefix;
Copy link
Contributor

Choose a reason for hiding this comment

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

code alignment

}
delete it;
VLOG(3) << "load deleted inodes end, size is: " << item->size()
<< ", " << counts << ", " << options_.dataDir;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

void InodeStorage::LoadDeletedInodes(std::map<std::string, uint64_t> * inodes) {
VLOG(6) << "load deleted key start with: " << table4DelInode_;
kvStorage_->GetPrefix(inodes, table4DelInode_);
VLOG(6) << "oad deleted over";
Copy link
Contributor

Choose a reason for hiding this comment

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

load

inodeStorage_->LoadDeletedInodes(&items);
VLOG(3) << "build trash items size: " << items.size();
std::vector<std::string> names;
for (auto iter : items) {
Copy link
Contributor

Choose a reason for hiding this comment

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

for (auto& iter : items)

@@ -116,24 +125,30 @@ void TrashImpl::ScanTrash() {
LOG(ERROR) << "DeleteInodeAndData fail, fsId = " << fsId_
<< ", inodeId = " << it->first
<< ", ret = " << MetaStatusCode_Name(ret);
RemoveDeletedInode(it->first);
Copy link
Contributor

Choose a reason for hiding this comment

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

RemoveDeleteInode in func Remove

}
}

void TrashImpl::RemoveDeletedInode(uint64_t inodeId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe void is not good. Some warning log may need if Remove fail.

@wuhongsong
Copy link
Contributor Author

cicheck

3 similar comments
@wuhongsong
Copy link
Contributor Author

cicheck

@YunhuiChen
Copy link
Contributor

cicheck

@wuhongsong
Copy link
Contributor Author

cicheck

@wuhongsong
Copy link
Contributor Author

cicheck

1 similar comment
@wuhongsong
Copy link
Contributor Author

cicheck

@wuhongsong
Copy link
Contributor Author

cicheck

@wuhongsong wuhongsong merged commit 754b19e into opencurve:master Dec 13, 2023
4 checks passed
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