Skip to content

Commit

Permalink
Merge pull request ceph#46023 from linuxbox2/wip-dbstore-shutdown
Browse files Browse the repository at this point in the history
rgw: dbstore: add mechanism to signal gc_worker to exit
  • Loading branch information
mattbenjamin committed Apr 28, 2022
2 parents dbca951 + 991adad commit 5d4e82b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/rgw/store/dbstore/common/dbstore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ int DB::createGC(const DoutPrefixProvider *dpp) {
}

int DB::stopGC() {
if (gc_worker)
if (gc_worker) {
gc_worker->signal_stop();
gc_worker->join();
}
return 0;
}

Expand Down Expand Up @@ -2040,6 +2042,8 @@ int DB::delete_stale_objs(const DoutPrefixProvider *dpp, const std::string& buck

void *DB::GC::entry() {
do {
std::unique_lock<std::mutex> lk(mtx);

ldpp_dout(dpp, 2) << " DB GC started " << dendl;
int max = 100;
RGWUserBuckets buckets;
Expand Down Expand Up @@ -2071,15 +2075,18 @@ void *DB::GC::entry() {
user_marker = user.id;

/* XXX: If using locks, unlock here and reacquire in the next iteration */
std::this_thread::sleep_for(std::chrono::milliseconds(100));
cv.wait_for(lk, std::chrono::milliseconds(100));
if (stop_signalled) {
goto done;
}
}
} while(is_truncated);

bucket_marker.clear();
std::this_thread::sleep_for(std::chrono::milliseconds(gc_interval*10));

} while(1);
cv.wait_for(lk, std::chrono::milliseconds(gc_interval*10));
} while(! stop_signalled);

done:
return nullptr;
}

Expand Down
13 changes: 12 additions & 1 deletion src/rgw/store/dbstore/common/dbstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <string>
#include <stdio.h>
#include <iostream>
#include <mutex>
#include <condition_variable>
// this seems safe to use, at least for now--arguably, we should
// prefer header-only fmt, in general
#undef FMT_HEADER_ONLY
Expand Down Expand Up @@ -1668,6 +1670,9 @@ class DB {
* gc_obj_min_wait: Min. time to wait before deleting any data post its creation.
*
*/
std::mutex mtx;
std::condition_variable cv;
bool stop_signalled = false;
uint32_t gc_interval = 24*60*60; //sec ; default: 24*60*60
uint32_t gc_obj_min_wait = 60*60; //60*60sec default
std::string bucket_marker;
Expand All @@ -1678,7 +1683,13 @@ class DB {
dpp(_dpp), db(_db) {}

void *entry() override;


void signal_stop() {
std::lock_guard<std::mutex> lk_guard(mtx);
stop_signalled = true;
cv.notify_one();
}

friend class DB;
};
std::unique_ptr<DB::GC> gc_worker;
Expand Down

0 comments on commit 5d4e82b

Please sign in to comment.