This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
rgw_sal_motr, motr_gc: [CORTX-33148] add MotrGC, MotrGC::GCWorker infra code #356
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0a50508
rgw_sal_motr, motr_gc: [CORTX-33148] Add MotrGC class
sumedhak27 543a44d
rgw_sal_motr, motr_gc: [CORTX-33148] Add MotrGC::GCWorker class
sumedhak27 cbc95ae
rgw_sal_motr, motr_gc: [CORTX-33148] implement MotrGC::start_processor()
sumedhak27 76ae806
rgw_sal_motr: [CORTX-33148] fix init_metadata_cache bug
sumedhak27 bc6b0e4
motr_gc: [CORTX-33148] partially implement MotrGC::initialize()
sumedhak27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__ | ||
sachinpunadikar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#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; | ||
jjxsg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need to add more files in future. Better to add cmakelist in motr directory and add that directory here.
ref. https://github.com/Seagate/cortx-rgw/blob/main/src/rgw/store/dbstore/CMakeLists.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I tried adding a subdirectory, but the compilation failed initially, I did not try to resolve it.
Will try it again in the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The below code works but I have to repeat the lines from
src/rgw/CMakeLists.txt
in the new file,does anyone know how to avoid that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andriytk @siningwuseagate can you please help here?