forked from Seagate/cortx-rgw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rgw_sal_motr, motr_gc: [CORTX-33148] add MotrGC, MotrGC::GCWorker inf…
…ra code (Seagate#356) * rgw_sal_motr, motr_gc: [CORTX-33148] add MotrGC, MotrGC::GCWorker infra code Behaviour - With Garbage Collector enabled, MotrGC will have GC indexes & GC worker threads. - GC worker threads will run for the configured max processing time and then will wait for the configured time between two consecutive runs. Additions/Changes - Add the Garbage Collector infrastructure to support the start & stop of worker threads. - MotrGC class with the interfaces to initialize(), start(), stop() and finalize(). - GCWorker class with entry() and stop() methods. - Refactor Initialization of MotrStore - add setter methods to configure MotrStore - add initialize() method to call initialization of all the other components eg. MetadataCache, GC, (in future LC, QuotaHandler), etc. Signed-off-by: Sumedh Anantrao Kulkarni <sumedh.a.kulkarni@seagate.com>
- Loading branch information
1 parent
79cb730
commit b3669e9
Showing
6 changed files
with
247 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | ||
// vim: ts=2 sw=2 expandtab ft=cpp | ||
|
||
/* | ||
* Garbage Collector implementation for the CORTX Motr backend | ||
* | ||
* Copyright (C) 2022 Seagate Technology LLC and/or its Affiliates | ||
* | ||
* This is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License version 2.1, as published by the Free Software | ||
* Foundation. See file COPYING. | ||
* | ||
*/ | ||
|
||
#include "motr/gc/gc.h" | ||
|
||
void *MotrGC::GCWorker::entry() { | ||
std::unique_lock<std::mutex> lk(lock); | ||
ldpp_dout(dpp, 10) << __func__ << ": " << gc_thread_prefix | ||
<< worker_id << " started." << dendl; | ||
|
||
do { | ||
|
||
ldpp_dout(dpp, 10) << __func__ << ": " << gc_thread_prefix | ||
<< worker_id << " iteration" << dendl; | ||
cv.wait_for(lk, std::chrono::milliseconds(gc_interval * 10)); | ||
|
||
} while (! motr_gc->going_down()); | ||
|
||
ldpp_dout(dpp, 0) << __func__ << ": Stop signalled called for " | ||
<< gc_thread_prefix << worker_id << dendl; | ||
return nullptr; | ||
} | ||
|
||
void MotrGC::initialize() { | ||
// fetch max gc indices from config | ||
auto max_indices = std::min(cct->_conf->rgw_gc_max_objs, | ||
GC_MAX_SHARDS_PRIME); | ||
ldpp_dout(this, 50) << __func__ << ": max_indices = " << max_indices << dendl; | ||
|
||
index_names.reserve(max_indices); | ||
for (int i = 0; i < max_indices; i++) { | ||
// Append index name to the gc index list | ||
index_names.push_back(gc_index_prefix + std::to_string(i)); | ||
|
||
// [To be Implemented] create index in motr dix | ||
} | ||
|
||
} | ||
|
||
void MotrGC::finalize() { | ||
// [To be Implemented] undo steps from initialize stage | ||
} | ||
|
||
void MotrGC::start_processor() { | ||
// fetch max_concurrent_io i.e. max_threads to create from config. | ||
// start all the gc_worker threads | ||
auto max_workers = cct->_conf->rgw_gc_max_concurrent_io; | ||
ldpp_dout(this, 50) << __func__ << ": max_workers = " | ||
<< max_workers << dendl; | ||
workers.reserve(max_workers); | ||
for (int ix = 0; ix < max_workers; ++ix) { | ||
auto worker = std::make_unique<MotrGC::GCWorker>(this /* dpp */, | ||
cct, this, ix); | ||
worker->create((gc_thread_prefix + std::to_string(ix)).c_str()); | ||
workers.push_back(std::move(worker)); | ||
} | ||
} | ||
|
||
void MotrGC::stop_processor() { | ||
// gracefully shutdown all the gc threads. | ||
down_flag = true; | ||
for (auto& worker : workers) { | ||
worker->stop(); | ||
worker->join(); | ||
} | ||
workers.clear(); | ||
} | ||
|
||
void MotrGC::GCWorker::stop() { | ||
std::lock_guard l{lock}; | ||
cv.notify_all(); | ||
} | ||
|
||
bool MotrGC::going_down() { | ||
return down_flag; | ||
} | ||
|
||
unsigned MotrGC::get_subsys() const { | ||
return dout_subsys; | ||
} | ||
|
||
std::ostream& MotrGC::gen_prefix(std::ostream& out) const { | ||
return out << "garbage_collector: "; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | ||
// vim: ts=2 sw=2 expandtab ft=cpp | ||
|
||
/* | ||
* Garbage Collector Classes for the CORTX Motr backend | ||
* | ||
* Copyright (C) 2022 Seagate Technology LLC and/or its Affiliates | ||
* | ||
* This is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License version 2.1, as published by the Free Software | ||
* Foundation. See file COPYING. | ||
* | ||
*/ | ||
|
||
#ifndef __MOTR_GC_H__ | ||
#define __MOTR_GC_H__ | ||
|
||
#include "rgw_sal_motr.h" | ||
#include "common/Thread.h" | ||
#include <mutex> | ||
#include <condition_variable> | ||
#include <atomic> | ||
|
||
const int64_t GC_MAX_SHARDS_PRIME = 65521; | ||
static std::string gc_index_prefix = "gc."; | ||
static std::string gc_thread_prefix = "gc_thread_"; | ||
|
||
class MotrGC : public DoutPrefixProvider { | ||
private: | ||
CephContext *cct; | ||
rgw::sal::Store *store; | ||
int max_indices = 0; | ||
std::vector<std::string> index_names; | ||
std::atomic<bool> down_flag = false; | ||
|
||
public: | ||
class GCWorker : public Thread { | ||
private: | ||
const DoutPrefixProvider *dpp; | ||
CephContext *cct; | ||
MotrGC *motr_gc; | ||
int worker_id; | ||
uint32_t gc_interval = 60*60; // default: 24*60*60 sec | ||
std::mutex lock; | ||
std::condition_variable cv; | ||
public: | ||
GCWorker(const DoutPrefixProvider* _dpp, CephContext *_cct, | ||
MotrGC *_motr_gc, int _worker_id) | ||
: dpp(_dpp), | ||
cct(_cct), | ||
motr_gc(_motr_gc), | ||
worker_id(_worker_id) {}; | ||
|
||
void *entry() override; | ||
void stop(); | ||
}; | ||
std::vector<std::unique_ptr<MotrGC::GCWorker>> workers; | ||
|
||
MotrGC(CephContext *_cct, rgw::sal::Store* _store) | ||
: cct(_cct), store(_store) {} | ||
|
||
~MotrGC() { | ||
stop_processor(); | ||
finalize(); | ||
} | ||
|
||
void initialize(); | ||
void finalize(); | ||
|
||
void start_processor(); | ||
void stop_processor(); | ||
|
||
bool going_down(); | ||
|
||
// Set Up logging prefix for GC | ||
CephContext *get_cct() const override { return cct; } | ||
unsigned get_subsys() const; | ||
std::ostream& gen_prefix(std::ostream& out) const; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters