-
Notifications
You must be signed in to change notification settings - Fork 522
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
Conversation
1e01fc6
to
f6cd9d5
Compare
cicheck |
f6cd9d5
to
914faf4
Compare
914faf4
to
21bb6a3
Compare
* @param[in] logIndex: the index of raft log | ||
* @return | ||
*/ | ||
MetaStatusCode UpdateDeletingKey(const Inode& inode, int64_t logIndex); |
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.
UpdateDeletingKey
to AddDeletedInode
maybe more clearer
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.
fix
*/ | ||
MetaStatusCode UpdateDeletingKey(const Inode& inode, int64_t logIndex); | ||
|
||
MetaStatusCode ClearDelKey(const Key4Inode& key); |
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.
Ditto RemoveDeletedInode
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.
fix
@@ -866,5 +869,27 @@ bool MetaStoreImpl::InitStorage() { | |||
return kvStorage_->Open(); | |||
} | |||
|
|||
void MetaStoreImpl::LoadDeletedInodes() { |
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.
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.
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.
fix
LOG(ERROR) << "Begin transaction failed"; | ||
return MetaStatusCode::STORAGE_INTERNAL_ERROR; | ||
} | ||
auto rc = txn->HSet(table4DelInode_, skey , inode); |
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 value does not need to be the entire inode, dtime is enough
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.
fix
} | ||
|
||
void TrashImpl::Add(uint64_t inodeId, uint64_t dtime) { | ||
void TrashImpl::Add(uint64_t inodeId, uint64_t dtime, bool deleted) { |
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 deleted
needed?
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.
tell reboot or not
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()) { |
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 remove of rocksdb data can do here also.
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.
fix
@@ -446,6 +441,13 @@ MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest& request, | |||
return MetaStatusCode::STORAGE_INTERNAL_ERROR; | |||
} | |||
} | |||
|
|||
if (needAddTrash) { | |||
inodeStorage_->UpdateDeletingKey(old, logIndex); |
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.
add and delete op all deal in trash is better.
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.
fix
21bb6a3
to
57748b1
Compare
1eb1450
to
d635cf6
Compare
610f6ab
to
288bc9c
Compare
288bc9c
to
2700f65
Compare
cicheck |
0304c53
to
3b5db6a
Compare
cicheck |
3b5db6a
to
e304ccd
Compare
namespace storage { | ||
|
||
#define DELETEPREFIXINKV "deleting:" |
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.
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) { |
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.
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)), |
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.
Add a new type like 'kTypeDelInode'
cicheck |
e304ccd
to
cee94ad
Compare
cicheck |
cee94ad
to
b36a0aa
Compare
cicheck |
b36a0aa
to
bf8a57d
Compare
cicheck |
2 similar comments
cicheck |
cicheck |
bf8a57d
to
e56d6a6
Compare
cicheck |
curvefs/src/metaserver/trash.cpp
Outdated
{ | ||
LockGuard lgItems(itemsMutex_); | ||
trashItems_.insert(temp.begin(), temp.end()); | ||
trashItems_.swap(temp); |
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.
Can not swap, the trashItem already has some new item
curvefs/src/metaserver/trash.cpp
Outdated
@@ -100,7 +109,7 @@ void TrashImpl::ScanTrash() { | |||
return; | |||
} | |||
|
|||
std::unordered_map<uint64_t, uint64_t> temp; | |||
std::map<uint64_t, uint64_t> temp; |
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.
unordered_map is space friendly here
curvefs/src/metaserver/trash.cpp
Outdated
} | ||
|
||
void TrashImpl::Remove(uint64_t inodeId) { | ||
if (isStop_) { | ||
return; | ||
} | ||
LockGuard lg(itemsMutex_); | ||
trashItems_.erase(inodeId); | ||
auto it = trashItems_.find(inodeId); |
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.
don't need find here and can erase directly
<< ", partitionId = " << partitionId_ | ||
trashItems_.emplace(inodeId, dtime); | ||
|
||
VLOG(6) << "Add trash item success" |
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.
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; |
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.
code alignment
} | ||
delete it; | ||
VLOG(3) << "load deleted inodes end, size is: " << item->size() | ||
<< ", " << counts << ", " << options_.dataDir; |
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.
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"; |
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.
load
inodeStorage_->LoadDeletedInodes(&items); | ||
VLOG(3) << "build trash items size: " << items.size(); | ||
std::vector<std::string> names; | ||
for (auto iter : items) { |
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.
for (auto& iter : items)
curvefs/src/metaserver/trash.cpp
Outdated
@@ -116,24 +125,30 @@ void TrashImpl::ScanTrash() { | |||
LOG(ERROR) << "DeleteInodeAndData fail, fsId = " << fsId_ | |||
<< ", inodeId = " << it->first | |||
<< ", ret = " << MetaStatusCode_Name(ret); | |||
RemoveDeletedInode(it->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.
RemoveDeleteInode in func Remove
} | ||
} | ||
|
||
void TrashImpl::RemoveDeletedInode(uint64_t inodeId) { |
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 void is not good. Some warning log may need if Remove fail.
e56d6a6
to
941d39b
Compare
cicheck |
3 similar comments
cicheck |
cicheck |
cicheck |
941d39b
to
54430cf
Compare
cicheck |
1 similar comment
cicheck |
54430cf
to
d86bba3
Compare
cicheck |
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