}
int DB::stopGC() {
- if (gc_worker)
+ if (gc_worker) {
+ gc_worker->signal_stop();
gc_worker->join();
+ }
return 0;
}
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;
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;
}
#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
* 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;
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;