Merge pull request #45882 from ivancich/wip-index-completion-mgr-crash

rgw: address crash and race in RGWIndexCompletionManager

Reviewed-by: Daniel Gryniewicz <dang@redhat.com>
Reviewed-by: Adam C. Emerson <aemerson@redhat.com>
Reviewed-by: Matt Benjamin <mbenjami@redhat.com>
This commit is contained in:
J. Eric Ivancich 2022-04-30 11:26:15 -04:00 committed by GitHub
commit 8310bd5762
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -774,7 +774,7 @@ struct complete_op_data {
class RGWIndexCompletionManager {
RGWRados* const store;
const int num_shards;
const uint32_t num_shards;
ceph::containers::tiny_vector<ceph::mutex> locks;
std::vector<set<complete_op_data*>> completions;
std::vector<complete_op_data*> retry_completions;
@ -784,7 +784,10 @@ class RGWIndexCompletionManager {
bool _stop{false};
std::thread retry_thread;
std::atomic<int> cur_shard {0};
// used to distribute the completions and the locks they use across
// their respective vectors; it will get incremented and can wrap
// around back to 0 without issue
std::atomic<uint32_t> cur_shard {0};
void process();
@ -797,7 +800,7 @@ class RGWIndexCompletionManager {
retry_thread.join();
}
for (int i = 0; i < num_shards; ++i) {
for (uint32_t i = 0; i < num_shards; ++i) {
std::lock_guard l{locks[i]};
for (auto c : completions[i]) {
c->stop();
@ -806,10 +809,8 @@ class RGWIndexCompletionManager {
completions.clear();
}
int next_shard() {
int result = cur_shard % num_shards;
cur_shard++;
return result;
uint32_t next_shard() {
return cur_shard++ % num_shards;
}
public: