Skip to content

curvefs/metaserver: fix trash bugs#2948

Merged
wuhongsong merged 1 commit intoopencurve:masterfrom
wuhongsong:fix_trash_1205
Dec 13, 2023
Merged

curvefs/metaserver: fix trash bugs#2948
wuhongsong merged 1 commit intoopencurve:masterfrom
wuhongsong:fix_trash_1205

Conversation

@wuhongsong
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

cicheck

Comment thread curvefs/src/metaserver/inode_storage.h Outdated
* @param[in] logIndex: the index of raft log
* @return
*/
MetaStatusCode UpdateDeletingKey(const Inode& inode, int64_t logIndex);
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fix

Comment thread curvefs/src/metaserver/inode_storage.h Outdated
*/
MetaStatusCode UpdateDeletingKey(const Inode& inode, int64_t logIndex);

MetaStatusCode ClearDelKey(const Key4Inode& key);
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fix

return kvStorage_->Open();
}

void MetaStoreImpl::LoadDeletedInodes() {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread curvefs/src/metaserver/trash.cpp Outdated
LockGuard lg(itemsMutex_);
trashItems_.erase(inodeId);
auto it = std::find(trashItems_.begin(), trashItems_.end(), item);
if (it != trashItems_.end()) {
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fix

}

if (needAddTrash) {
inodeStorage_->UpdateDeletingKey(old, logIndex);
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fix

@wuhongsong wuhongsong closed this Dec 8, 2023
@wuhongsong wuhongsong reopened this Dec 8, 2023
@wuhongsong wuhongsong closed this Dec 8, 2023
@wuhongsong wuhongsong reopened this Dec 8, 2023
@wuhongsong wuhongsong force-pushed the fix_trash_1205 branch 2 times, most recently from 1eb1450 to d635cf6 Compare December 8, 2023 13:23
@wuhongsong wuhongsong closed this Dec 8, 2023
@wuhongsong wuhongsong reopened this Dec 8, 2023
@wuhongsong wuhongsong force-pushed the fix_trash_1205 branch 2 times, most recently from 610f6ab to 288bc9c Compare December 8, 2023 14:32
@wuhongsong wuhongsong closed this Dec 8, 2023
@wuhongsong wuhongsong reopened this Dec 8, 2023
@wuhongsong wuhongsong closed this Dec 9, 2023
@wuhongsong wuhongsong reopened this Dec 9, 2023
@wuhongsong
Copy link
Copy Markdown
Contributor Author

cicheck

@wuhongsong
Copy link
Copy Markdown
Contributor Author

cicheck


namespace storage {

#define DELETEPREFIXINKV "deleting:"
Copy link
Copy Markdown
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

return absl::StrCat(type, kDelimiter, absl::string_view(buf, sizeof(buf)));
}

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

Choose a reason for hiding this comment

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

don't need


NameGenerator::NameGenerator(uint32_t partitionId)
: tableName4Inode_(Format(kTypeInode, partitionId)),
tableName4DelInode_(FormatDel(kTypeInode, partitionId)),
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

cicheck

@wuhongsong
Copy link
Copy Markdown
Contributor Author

cicheck

@wuhongsong
Copy link
Copy Markdown
Contributor Author

cicheck

@wuhongsong
Copy link
Copy Markdown
Contributor Author

cicheck

2 similar comments
@wuhongsong
Copy link
Copy Markdown
Contributor Author

cicheck

@wuhongsong
Copy link
Copy Markdown
Contributor Author

cicheck

@wuhongsong
Copy link
Copy Markdown
Contributor Author

cicheck

Comment thread curvefs/src/metaserver/trash.cpp Outdated
{
LockGuard lgItems(itemsMutex_);
trashItems_.insert(temp.begin(), temp.end());
trashItems_.swap(temp);
Copy link
Copy Markdown
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

Comment thread curvefs/src/metaserver/trash.cpp Outdated
}

std::unordered_map<uint64_t, uint64_t> temp;
std::map<uint64_t, uint64_t> temp;
Copy link
Copy Markdown
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

Comment thread curvefs/src/metaserver/trash.cpp Outdated
}
LockGuard lg(itemsMutex_);
trashItems_.erase(inodeId);
auto it = trashItems_.find(inodeId);
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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)

Comment thread curvefs/src/metaserver/trash.cpp Outdated
LOG(ERROR) << "DeleteInodeAndData fail, fsId = " << fsId_
<< ", inodeId = " << it->first
<< ", ret = " << MetaStatusCode_Name(ret);
RemoveDeletedInode(it->first);
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

cicheck

3 similar comments
@wuhongsong
Copy link
Copy Markdown
Contributor Author

cicheck

@YunhuiChen
Copy link
Copy Markdown
Contributor

cicheck

@wuhongsong
Copy link
Copy Markdown
Contributor Author

cicheck

@wuhongsong
Copy link
Copy Markdown
Contributor Author

cicheck

1 similar comment
@wuhongsong
Copy link
Copy Markdown
Contributor Author

cicheck

@wuhongsong
Copy link
Copy Markdown
Contributor Author

cicheck

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