fix deadlock
All checks were successful
BlockStorage/repertory_osx_builds/pipeline/head This commit looks good
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good

This commit is contained in:
2023-11-18 23:53:03 -06:00
parent ee415d2e4a
commit 983587aeb7
3 changed files with 139 additions and 125 deletions

View File

@ -318,27 +318,27 @@ auto file_manager::is_processing(const std::string &api_path) const -> bool {
return false;
}
recur_mutex_lock open_lock(open_file_mtx_);
mutex_lock upload_lock(upload_mtx_);
unique_mutex_lock upload_lock(upload_mtx_);
if (upload_lookup_.find(api_path) != upload_lookup_.end()) {
return true;
}
upload_lock.unlock();
{
auto iterator = std::unique_ptr<rocksdb::Iterator>(
db_->NewIterator(rocksdb::ReadOptions(), upload_family_));
for (iterator->SeekToFirst(); iterator->Valid(); iterator->Next()) {
const auto parts = utils::string::split(iterator->key().ToString(), ':');
if (parts[1u] == api_path) {
if (parts.at(1U) == api_path) {
return true;
}
}
}
auto it = open_file_lookup_.find(api_path);
if (it != open_file_lookup_.end()) {
return it->second->is_modified() || not it->second->is_complete();
recur_mutex_lock open_lock(open_file_mtx_);
auto iter = open_file_lookup_.find(api_path);
if (iter != open_file_lookup_.end()) {
return iter->second->is_modified() || not iter->second->is_complete();
}
return false;
@ -484,18 +484,18 @@ void file_manager::remove_upload(const std::string &api_path, bool no_lock) {
return;
}
std::unique_ptr<mutex_lock> l;
std::unique_ptr<mutex_lock> lock;
if (not no_lock) {
l = std::make_unique<mutex_lock>(upload_mtx_);
lock = std::make_unique<mutex_lock>(upload_mtx_);
}
auto it = upload_lookup_.find(api_path);
if (it == upload_lookup_.end()) {
auto iter = upload_lookup_.find(api_path);
if (iter == upload_lookup_.end()) {
auto iterator = std::unique_ptr<rocksdb::Iterator>(
db_->NewIterator(rocksdb::ReadOptions(), upload_family_));
for (iterator->SeekToFirst(); iterator->Valid(); iterator->Next()) {
const auto parts = utils::string::split(iterator->key().ToString(), ':');
if (parts[1U] == api_path) {
if (parts.at(1U) == api_path) {
if (db_->Delete(rocksdb::WriteOptions(), upload_family_,
iterator->key())
.ok()) {
@ -511,15 +511,15 @@ void file_manager::remove_upload(const std::string &api_path, bool no_lock) {
db_->NewIterator(rocksdb::ReadOptions(), upload_active_family_));
for (iterator->SeekToFirst(); iterator->Valid(); iterator->Next()) {
const auto parts = utils::string::split(iterator->key().ToString(), ':');
if (parts[1U] == api_path) {
if (parts.at(1U) == api_path) {
db_->Delete(rocksdb::WriteOptions(), upload_active_family_,
iterator->key());
}
}
event_system::instance().raise<file_upload_removed>(
api_path, it->second->get_source_path());
api_path, iter->second->get_source_path());
it->second->cancel();
iter->second->cancel();
upload_lookup_.erase(api_path);
}
@ -846,7 +846,6 @@ void file_manager::store_resume(const i_open_file &o) {
return;
}
recur_mutex_lock open_lock(open_file_mtx_);
const auto res = db_->Put(rocksdb::WriteOptions(), default_family_,
o.get_api_path(), create_resume_entry(o).dump());
if (res.ok()) {