Skip to content

Commit

Permalink
#349 new config setting rbox_index_pool_name
Browse files Browse the repository at this point in the history
  • Loading branch information
jrse committed Nov 19, 2022
1 parent 5a96389 commit 95eae40
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 18 deletions.
10 changes: 3 additions & 7 deletions src/librmb/rados-cluster-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,11 @@ std::vector<std::string> RadosClusterImpl::list_pgs_for_pool(std::string &pool_n
"\"prefix\": \"pg ls-by-pool\", "
"\"poolstr\": \"" + pool_name + "\""
"}";

std::cout << "cmd: " << cmd << std::endl;


librados::bufferlist inbl;
librados::bufferlist outbl;
int res = RadosClusterImpl::cluster->mon_command(cmd, inbl, &outbl, nullptr);
std::cout << "inbl command " << inbl <<std::endl;
std::cout << "outbl command " << outbl.c_str() <<std::endl;

RadosClusterImpl::cluster->mon_command(cmd, inbl, &outbl, nullptr);

std::vector<std::string> list = RadosUtils::extractPgs(std::string(outbl.c_str()));

for (auto const &token: list) {
Expand Down
1 change: 1 addition & 0 deletions src/librmb/rados-dovecot-ceph-cfg-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RadosDovecotCephCfgImpl : public RadosDovecotCephCfg {

int get_chunk_size() override { return std::stoi(dovecot_cfg.get_chunk_size());}
std::string &get_pool_name() override { return dovecot_cfg.get_pool_name(); }
std::string &get_index_pool_name() override { return dovecot_cfg.get_index_pool_name(); };

std::string &get_key_prefix_keywords() override { return dovecot_cfg.get_key_prefix_keywords(); }
void update_metadata(const std::string &key, const char *value_) override {
Expand Down
2 changes: 2 additions & 0 deletions src/librmb/rados-dovecot-ceph-cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class RadosDovecotCephCfg {
virtual std::map<std::string, std::string> *get_config() = 0;

virtual std::string &get_pool_name() = 0;
virtual std::string &get_index_pool_name() = 0;

virtual bool is_update_attributes() = 0;

virtual void set_rbox_cfg_object_name(const std::string &value) = 0;
Expand Down
5 changes: 4 additions & 1 deletion src/librmb/rados-dovecot-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace librmb {

RadosConfig::RadosConfig()
: pool_name("rbox_pool_name"),
index_pool_name("rbox_index_pool_name"),
rbox_cfg_object_name("rbox_cfg_object_name"),
rbox_cluster_name("rbox_cluster_name"),
rados_username("rados_user_name"),
Expand All @@ -34,7 +35,7 @@ RadosConfig::RadosConfig()
rbox_object_search_threads("rbox_object_search_threads") {

config[pool_name] = "mail_storage";

config[index_pool_name] = "object_recovery";
config[rbox_cfg_object_name] = "rbox_cfg";
config[rbox_cluster_name] = "ceph";
config[rados_username] = "client.admin";
Expand Down Expand Up @@ -75,6 +76,8 @@ void RadosConfig::update_metadata(const std::string &key, const char *value_) {
std::string RadosConfig::to_string() {
std::stringstream ss;
ss << "Dovecot configuration: (90-plugin.conf)" << std::endl;
ss << " " << pool_name << "=" << config[pool_name] << std::endl;
ss << " " << index_pool_name << "=" << config[index_pool_name] << std::endl;
ss << " " << rbox_cfg_object_name << "=" << config[rbox_cfg_object_name] << std::endl;
ss << " " << rbox_cluster_name << "=" << config[rbox_cluster_name] << std::endl;
ss << " " << rados_username << "=" << config[rados_username] << std::endl;
Expand Down
4 changes: 3 additions & 1 deletion src/librmb/rados-dovecot-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class RadosConfig {
std::map<std::string, std::string> *get_config() { return &config; }

std::string &get_pool_name() { return config[pool_name]; }
std::string &get_index_pool_name() { return config[index_pool_name]; };

const std::string &get_rados_save_log_file() { return config[save_log]; }
bool is_config_valid() { return is_valid; }
void set_config_valid(bool is_valid_) { this->is_valid = is_valid_; }
Expand Down Expand Up @@ -79,7 +81,7 @@ class RadosConfig {
private:
std::map<std::string, std::string> config;
std::string pool_name;

std::string index_pool_name;
std::string rbox_cfg_object_name;
std::string rbox_cluster_name;
std::string rados_username;
Expand Down
31 changes: 25 additions & 6 deletions src/librmb/rados-storage-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ std::set<std::string> RadosStorageImpl::find_mails_async(const RadosMetadata *at
librados::IoCtx &RadosStorageImpl::get_io_ctx() { return io_ctx; }
librados::IoCtx &RadosStorageImpl::get_recovery_io_ctx() { return recovery_io_ctx; }

int RadosStorageImpl::open_connection(const std::string &poolname, const std::string &clustername,
int RadosStorageImpl::open_connection(const std::string &poolname, const std::string &index_pool,
const std::string &clustername,
const std::string &rados_username) {
if (cluster->is_connected() && io_ctx_created) {
// cluster is already connected!
Expand All @@ -289,25 +290,43 @@ int RadosStorageImpl::open_connection(const std::string &poolname, const std::st
if (cluster->init(clustername, rados_username) < 0) {
return -1;
}
return create_connection(poolname);
return create_connection(poolname, index_pool);
}
int RadosStorageImpl::open_connection(const std::string &poolname,
const std::string &clustername,
const std::string &rados_username) {
if (cluster->is_connected() && io_ctx_created) {
// cluster is already connected!
return 1;
}

if (cluster->init(clustername, rados_username) < 0) {
return -1;
}
return create_connection(poolname, poolname);
}
int RadosStorageImpl::open_connection(const string &poolname, const string &index_pool) {
if (cluster->init() < 0) {
return -1;
}
return create_connection(poolname, index_pool);
}

int RadosStorageImpl::open_connection(const string &poolname) {
if (cluster->init() < 0) {
return -1;
}
return create_connection(poolname);
return create_connection(poolname, poolname);
}

int RadosStorageImpl::create_connection(const std::string &poolname) {
int RadosStorageImpl::create_connection(const std::string &poolname, const std::string &index_pool){
// pool exists? else create
int err = cluster->io_ctx_create(poolname, &io_ctx);
if (err < 0) {
return err;
}

//TODO: FIX poolname path!
err = cluster->recovery_index_io_ctx("mail_storage_alt", &recovery_io_ctx);
err = cluster->recovery_index_io_ctx(index_pool, &recovery_io_ctx);
if (err < 0) {
return err;
}
Expand Down
8 changes: 7 additions & 1 deletion src/librmb/rados-storage-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class RadosStorageImpl : public RadosStorage {
std::set<std::string> find_mails_async(const RadosMetadata *attr, std::string &pool_name, int num_threads, void (*ptr)(std::string&)) override;

int open_connection(const std::string &poolname) override;
int open_connection(const std::string &poolname, const std::string &index_pool) override;


int open_connection(const std::string &poolname, const std::string &index_pool,
const std::string &clustername,
const std::string &rados_username) override;
int open_connection(const std::string &poolname, const std::string &clustername,
const std::string &rados_username) override;
void close_connection() override;
Expand Down Expand Up @@ -86,7 +92,7 @@ class RadosStorageImpl : public RadosStorage {
int ceph_index_delete(const std::set<std::string> &oids) override;

private:
int create_connection(const std::string &poolname);
int create_connection(const std::string &poolname,const std::string &index_pool);

private:
RadosCluster *cluster;
Expand Down
19 changes: 19 additions & 0 deletions src/librmb/rados-storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ underTest.ceph_index_add("dkfkjdf")
* */
virtual int open_connection(const std::string &poolname, const std::string &clustername,
const std::string &rados_username) = 0;

/*! open the rados connections with default cluster and username
* @param[in] poolname the poolname to connect to, in case this one does not exists, it will be created.
* @param[in] index_pool the poolname to store recovery index objects to.
* */
virtual int open_connection(const std::string &poolname, const std::string &index_pool) = 0;

/*! open the rados connection with given user and clustername
*
* @param[in] poolname the poolname to connect to, in case this one does not exists, it will be created.
* @param[in] index_pool the poolname to store recovery index objects to.
* @param[in] clustername custom clustername
* @param[in] rados_username custom username (client.xxx)
*
* @return linux error code or 0 if successful.
* */
virtual int open_connection(const std::string &poolname, const std::string &index_pool,
const std::string &clustername,
const std::string &rados_username) = 0;
/*!
* close the connection. (clean up structures to allow reconnect)
*/
Expand Down
4 changes: 3 additions & 1 deletion src/storage-rbox/doveadm-rbox-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ class RboxDoveadmPlugin {

int open_connection() {
return (config == nullptr) ? -1
: storage->open_connection(config->get_pool_name(), config->get_rados_cluster_name(),
: storage->open_connection(config->get_pool_name(),
config->get_index_pool_name(),
config->get_rados_cluster_name(),
config->get_rados_username());
}

Expand Down
5 changes: 4 additions & 1 deletion src/storage-rbox/rbox-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,14 @@ int rbox_open_rados_connection(struct mailbox *box, bool alt_storage) {
: librmb::WAIT_FOR_COMPLETE_AND_CB);
/* open connection to primary and alternative storage */
ret = rados_storage->open_connection(rbox->storage->config->get_pool_name(),
rbox->storage->config->get_index_pool_name(),
rbox->storage->config->get_rados_cluster_name(),
rbox->storage->config->get_rados_username());

if (alt_storage) {
ret = rbox->storage->alt->open_connection(box->list->set.alt_dir, rbox->storage->config->get_rados_cluster_name(),
ret = rbox->storage->alt->open_connection(box->list->set.alt_dir,
rbox->storage->config->get_index_pool_name(),
rbox->storage->config->get_rados_cluster_name(),
rbox->storage->config->get_rados_username());

rbox->storage->alt->set_ceph_wait_method(rbox->storage->config->is_ceph_aio_wait_for_safe_and_cb()
Expand Down
6 changes: 6 additions & 0 deletions src/tests/mocks/mock_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ class RadosStorageMock : public RadosStorage {
librados::ObjectWriteOperation *op));
MOCK_METHOD1(find_mails, librados::NObjectIterator(const RadosMetadata *attr));
MOCK_METHOD1(open_connection, int(const std::string &poolname));
MOCK_METHOD2(open_connection, int(const std::string &poolname, const std::string &index_pool));

MOCK_METHOD4(find_mails_async, std::set<std::string>(const RadosMetadata *attr, std::string &pool_name,int num_threads, void (*ptr)(std::string&)));

MOCK_METHOD4(open_connection,
int(const std::string &poolname, const std::string &index_pool, const std::string &clustername, const std::string &rados_username));

MOCK_METHOD3(open_connection,
int(const std::string &poolname, const std::string &clustername, const std::string &rados_username));
MOCK_METHOD0(close_connection, void());
Expand Down Expand Up @@ -185,6 +189,8 @@ class RadosDovecotCephCfgMock : public RadosDovecotCephCfg {
MOCK_METHOD0(get_config, std::map<std::string, std::string> *());

MOCK_METHOD0(get_pool_name, std::string &());
MOCK_METHOD0(get_index_pool_name, std::string &());

MOCK_METHOD0(is_update_attributes, bool());

MOCK_METHOD2(update_metadata, void(const std::string &key, const char *value_));
Expand Down

0 comments on commit 95eae40

Please sign in to comment.