Skip to content

Commit

Permalink
#346 fix segmentation fault rbox_copy
Browse files Browse the repository at this point in the history
  • Loading branch information
jrse committed Oct 20, 2022
1 parent a3c4d25 commit 8f1f4c6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## [0.0.42](https://github.com/ceph-dovecot/dovecot-ceph-plugin/tree/0.0.42) (2022-10-18)
- #346 segmentation fault (rbox_copy) if rbox_mail is null

## [0.0.41](https://github.com/ceph-dovecot/dovecot-ceph-plugin/tree/0.0.41) (2022-09-27)
- #342 multithreading bugfix and additional logging

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
AC_PREREQ([2.59])


AC_INIT([dovecot-ceph-plugin], [0.0.41], [https://github.com/ceph-dovecot/dovecot-ceph-plugin/issues/new], ,[https://github.com/ceph-dovecot/dovecot-ceph-plugin])
AC_INIT([dovecot-ceph-plugin], [0.0.42], [https://github.com/ceph-dovecot/dovecot-ceph-plugin/issues/new], ,[https://github.com/ceph-dovecot/dovecot-ceph-plugin])


AC_CONFIG_AUX_DIR([.])
Expand Down
2 changes: 1 addition & 1 deletion rpm/dovecot-ceph-plugin.spec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Name: dovecot-ceph-plugin
Summary: Dovecot Ceph RADOS plugins


Version: 0.0.41
Version: 0.0.42

Release: 0%{?dist}
URL: https://github.com/ceph-dovecot/dovecot-ceph-plugin
Expand Down
47 changes: 35 additions & 12 deletions src/librmb/rados-storage-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,44 +203,67 @@ std::set<std::string> RadosStorageImpl::find_mails_async(const RadosMetadata *at

std::set<std::string> oid_list;
std::mutex oid_list_mutex;

// Define a Lambda Expression
auto f = [](const std::vector<std::string> &list, std::mutex &oid_mutex, std::set<std::string> &oids, librados::IoCtx *io_ctx,
void (*ptr)(std::string&), std::string osd) {


// Thread!!
auto f = [](const std::vector<std::string> &list,
std::mutex &oid_mutex,
std::set<std::string> &oids,
librados::IoCtx *io_ctx,
void (*ptr)(std::string&),
std::string osd,
ceph::bufferlist &filter) {

int total_count = 0;
for (auto const &pg: list) {

uint64_t ppool;
uint32_t pseed;
int r = sscanf(pg.c_str(), "%llu.%x", (long long unsigned *)&ppool, &pseed);

librados::NObjectIterator iter= io_ctx->nobjects_begin(pseed);
librados::NObjectIterator iter= io_ctx->nobjects_begin(pseed, filter);
int count = 0;
while (iter != librados::NObjectIterator::__EndObjectIterator) {
std::string oid = iter->get_oid();
{
std::lock_guard<std::mutex> guard(oid_mutex);
oids.insert(oid);
count++;
}
iter++;
}
std::string t = "osd "+ osd +" pg done " + pg;
total_count+=count;
std::string t = "osd "+ osd +" pg done " + pg + " objects " + std::to_string(count);
(*ptr)(t);
}
std::string t = "done with osd "+ osd ;
std::string t = "done with osd "+ osd + " total: " + std::to_string(total_count);
(*ptr)(t);
};
};

//std::string pool_mame = "mail_storage";
std::map<std::string, std::vector<std::string>> osd_pg_map = cluster->list_pgs_osd_for_pool(pool_name);
std::vector<std::thread> threads;


std::string filter_name = PLAIN_FILTER_NAME;
ceph::bufferlist filter_bl;

encode(filter_name, filter_bl);
encode("_" + attr->key, filter_bl);
encode(attr->bl.to_str(), filter_bl);
std::string msg_1 = "buffer set";
(*ptr)(msg_1);

for (const auto& x : osd_pg_map){
if(threads.size() == num_threads){
threads[0].join();
threads.erase(threads.begin());
}
threads.push_back(std::thread(f, std::ref(x.second),std::ref(oid_list_mutex),std::ref(oid_list), &get_io_ctx(), ptr, x.first));

if(x.first == "oon") {
std::string create_msg = "skipping thread for osd: "+ x.first;
(*ptr)(create_msg);
continue;
}
threads.push_back(std::thread(f, std::ref(x.second),std::ref(oid_list_mutex),std::ref(oid_list), &get_io_ctx(), ptr, x.first, std::ref(filter_bl)));
std::string create_msg = "creating thread for osd: "+ x.first;
(*ptr)(create_msg);
}
Expand Down
19 changes: 16 additions & 3 deletions src/storage-rbox/rbox-sync-rebuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ extern "C" {
#include "data-stack.h"
}

#include <sys/time.h>

#include "rbox-sync-rebuild.h"

#include "rbox-storage.hpp"
Expand Down Expand Up @@ -187,7 +189,7 @@ int rbox_sync_rebuild_entry(struct index_rebuild_context *ctx, std::map<std::str

sync_add_objects_ret =
rbox_sync_add_object(ctx, *it->get_oid(), &(*it), rebuild_ctx->alt_storage, rebuild_ctx->next_uid);
i_info("re-adding mail oid:(%s) with uid: %d to mailbox %s (%s) ", it->get_oid()->c_str(), rebuild_ctx->next_uid, mailbox_guid.c_str(), ctx->box->name );
i_debug("re-adding mail oid:(%s) with uid: %d to mailbox %s (%s) ", it->get_oid()->c_str(), rebuild_ctx->next_uid, mailbox_guid.c_str(), ctx->box->name );

if (sync_add_objects_ret < 0) {
i_error("sync_add_object: oid(%s), alt_storage(%d),uid(%d)", it->get_oid()->c_str(),
Expand Down Expand Up @@ -462,11 +464,22 @@ int repair_namespace(struct mail_namespace *ns, bool force, struct rbox_storage
std::string pool_name = r_storage->s->get_pool_name();

if( r_storage->config->get_object_search_method() == 1) {
mail_list = r_storage->s->find_mails_async(nullptr,
librmb::RadosMetadata filter(rbox_metadata_key::RBOX_METADATA_ORIG_MAILBOX, "INBOX");

long milli_time, seconds, useconds;
struct timeval start_time, end_time;
gettimeofday(&start_time, NULL);

mail_list = r_storage->s->find_mails_async(&filter,
pool_name,
r_storage->config->get_object_search_threads(),
&cb);
i_info("multithreading done");
gettimeofday(&end_time, NULL);
seconds = end_time.tv_sec - start_time.tv_sec; //seconds
useconds = end_time.tv_usec - start_time.tv_usec; //milliseconds
milli_time = ((seconds) * 1000 + useconds/1000.0);

i_info("multithreading done : took: %ld ms", (milli_time));
}else{
i_info("Ceph connection established using namespace: %s",r_storage->s->get_namespace().c_str());
i_info("Loading mails... ");
Expand Down

0 comments on commit 8f1f4c6

Please sign in to comment.