Skip to content

Commit

Permalink
#182: avoid copying std::string in get_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jrse committed Aug 9, 2018
1 parent 86fadcb commit 64cfbae
Show file tree
Hide file tree
Showing 20 changed files with 545 additions and 337 deletions.
22 changes: 8 additions & 14 deletions src/dict-rados/dict-rados.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#ifdef HAVE_CONFIG_H
#include "dovecot-ceph-plugin-config.h"
#include "dovecot-ceph-plugin-config.h"
#endif

#include <limits.h>
Expand Down Expand Up @@ -346,9 +346,6 @@ int rados_dict_lookup(struct dict *_dict, pool_t pool, const char *key, const ch
return RADOS_COMMIT_RET_NOTFOUND;
}

static void rados_dict_transaction_private_complete_callback(completion_t comp, void *arg);
static void rados_dict_transaction_shared_complete_callback(completion_t comp, void *arg);

#define ENORESULT 1000

class rados_dict_transaction_context {
Expand All @@ -361,7 +358,6 @@ class rados_dict_transaction_context {
void *context = nullptr;
dict_transaction_commit_callback_t *callback;


map<string, string> set_map;
set<string> unset_set;
map<string, int64_t> atomic_inc_map;
Expand Down Expand Up @@ -403,7 +399,7 @@ class rados_dict_transaction_context {
return true;
} else if (!key.compare(0, strlen(DICT_PATH_SHARED), DICT_PATH_SHARED)) {
dirty_shared = true;
return false;
return false;
}
i_unreached();
}
Expand Down Expand Up @@ -531,8 +527,6 @@ void rados_dict_set_timestamp(struct dict_transaction_context *_ctx, const struc
}
#endif



void (*transaction_commit)(struct dict_transaction_context *ctx, bool async,
dict_transaction_commit_callback_t *callback, void *context);

Expand Down Expand Up @@ -563,15 +557,15 @@ int rados_dict_transaction_commit(struct dict_transaction_context *_ctx, bool as
ctx->atomic_inc_not_found ? RADOS_COMMIT_RET_NOTFOUND : (failed ? RADOS_COMMIT_RET_FAILED : RADOS_COMMIT_RET_OK);
if (callback != nullptr) {
#if DOVECOT_PREREQ(2, 3)
struct dict_commit_result result = {static_cast<dict_commit_ret>(ret), nullptr}; // TODO(p.mauritius): text?
callback(&result, ctx->context);
struct dict_commit_result result = {static_cast<dict_commit_ret>(ret), nullptr}; // TODO(p.mauritius): text?
callback(&result, ctx->context);
#else
callback(ret, ctx->context);
callback(ret, ctx->context);
#endif
}
}

delete ctx;
ctx = NULL;
delete ctx;
ctx = NULL;

#if DOVECOT_PREREQ(2, 3)
return;
Expand Down
35 changes: 23 additions & 12 deletions src/librmb/rados-mail-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,31 @@ RadosMailObject::~RadosMailObject() {}
void RadosMailObject::set_guid(const uint8_t *_guid) { memcpy(this->guid, _guid, sizeof(this->guid)); }

std::string RadosMailObject::to_string(const string &padding) {
string uid = get_metadata(RBOX_METADATA_MAIL_UID);
string recv_time_str = get_metadata(RBOX_METADATA_RECEIVED_TIME);
string p_size = get_metadata(RBOX_METADATA_PHYSICAL_SIZE);
string v_size = get_metadata(RBOX_METADATA_VIRTUAL_SIZE);

string rbox_version = get_metadata(RBOX_METADATA_VERSION);
string mailbox_guid = get_metadata(RBOX_METADATA_MAILBOX_GUID);
string mail_guid = get_metadata(RBOX_METADATA_GUID);
string mb_orig_name = get_metadata(RBOX_METADATA_ORIG_MAILBOX);
string uid;
get_metadata(RBOX_METADATA_MAIL_UID, &uid);
string recv_time_str;
get_metadata(RBOX_METADATA_RECEIVED_TIME, &recv_time_str);
string p_size;
get_metadata(RBOX_METADATA_PHYSICAL_SIZE, &p_size);
string v_size;
get_metadata(RBOX_METADATA_VIRTUAL_SIZE, &v_size);

string rbox_version;
get_metadata(RBOX_METADATA_VERSION, &rbox_version);
string mailbox_guid;
get_metadata(RBOX_METADATA_MAILBOX_GUID, &mailbox_guid);
string mail_guid;
get_metadata(RBOX_METADATA_GUID, &mail_guid);
string mb_orig_name;
get_metadata(RBOX_METADATA_ORIG_MAILBOX, &mb_orig_name);

// string keywords = get_metadata(RBOX_METADATA_OLDV1_KEYWORDS);
string flags = get_metadata(RBOX_METADATA_OLDV1_FLAGS);
string pvt_flags = get_metadata(RBOX_METADATA_PVT_FLAGS);
string from_envelope = get_metadata(RBOX_METADATA_FROM_ENVELOPE);
string flags;
get_metadata(RBOX_METADATA_OLDV1_FLAGS, &flags);
string pvt_flags;
get_metadata(RBOX_METADATA_PVT_FLAGS, &pvt_flags);
string from_envelope;
get_metadata(RBOX_METADATA_FROM_ENVELOPE, &from_envelope);

time_t ts = -1;
if (!recv_time_str.empty()) {
Expand Down
90 changes: 43 additions & 47 deletions src/librmb/rados-mail-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,54 +33,50 @@ class RadosMailObject {
RadosMailObject();
virtual ~RadosMailObject();

void set_oid(const char* _oid) {
this->oid = _oid;
}
void set_oid(const string& _oid) { this->oid = _oid; }
void set_guid(const uint8_t* guid);
void set_mail_size(const uint64_t& _size) { object_size = _size; }
void set_active_op(bool _active) { this->active_op = _active; }
void set_rados_save_date(const time_t& _save_date) { this->save_date_rados = _save_date; }

const string& get_oid() { return this->oid; }
const uint64_t& get_mail_size() { return this->object_size; }

time_t* get_rados_save_date() { return &this->save_date_rados; }
uint8_t* get_guid_ref() { return this->guid; }
librados::bufferlist* get_mail_buffer() { return &this->mail_buffer; }
map<string, ceph::bufferlist>* get_metadata() { return &this->attrset; }

map<AioCompletion*, ObjectWriteOperation*>* get_completion_op_map() { return &completion_op; }

string get_metadata(rbox_metadata_key key) {
string str_key(1, static_cast<char>(key));
return get_metadata(str_key);
}

string get_metadata(const string& key) {
string value;
if (attrset.find(key) != attrset.end()) {
value = attrset[key].to_str();
void set_oid(const char* _oid) { this->oid = _oid; }
void set_oid(const string& _oid) { this->oid = _oid; }
void set_guid(const uint8_t* guid);
void set_mail_size(const uint64_t& _size) { object_size = _size; }
void set_active_op(bool _active) { this->active_op = _active; }
void set_rados_save_date(const time_t& _save_date) { this->save_date_rados = _save_date; }

const string& get_oid() { return this->oid; }
const uint64_t& get_mail_size() { return this->object_size; }

time_t* get_rados_save_date() { return &this->save_date_rados; }
uint8_t* get_guid_ref() { return this->guid; }
librados::bufferlist* get_mail_buffer() { return &this->mail_buffer; }
map<string, ceph::bufferlist>* get_metadata() { return &this->attrset; }

map<AioCompletion*, ObjectWriteOperation*>* get_completion_op_map() { return &completion_op; }

void get_metadata(rbox_metadata_key key, std::string* value) {
string str_key(1, static_cast<char>(key));
get_metadata(str_key, value);
}
return value;
}

bool is_index_ref() { return index_ref; }
void set_index_ref(bool ref) { this->index_ref = ref; }
bool is_valid() { return valid; }
void set_valid(bool valid_) { valid = valid_; }
bool has_active_op() { return active_op; }
string to_string(const string& padding);
void add_metadata(const RadosMetadata& metadata) { attrset[metadata.key] = metadata.bl; }

map<string, ceph::bufferlist>* get_extended_metadata() { return &this->extended_attrset; }
void add_extended_metadata(RadosMetadata& metadata) { extended_attrset[metadata.key] = metadata.bl; }
const string get_extended_metadata(string& key) {
string value;
if (extended_attrset.find(key) != extended_attrset.end()) {
value = extended_attrset[key].to_str();

void get_metadata(const string& key, std::string* value) {
if (attrset.find(key) != attrset.end()) {
*value = attrset[key].to_str();
}
}
return value;

bool is_index_ref() { return index_ref; }
void set_index_ref(bool ref) { this->index_ref = ref; }
bool is_valid() { return valid; }
void set_valid(bool valid_) { valid = valid_; }
bool has_active_op() { return active_op; }
string to_string(const string& padding);
void add_metadata(const RadosMetadata& metadata) { attrset[metadata.key] = metadata.bl; }

map<string, ceph::bufferlist>* get_extended_metadata() { return &this->extended_attrset; }
void add_extended_metadata(RadosMetadata& metadata) { extended_attrset[metadata.key] = metadata.bl; }
const string get_extended_metadata(string& key) {
string value;
if (extended_attrset.find(key) != extended_attrset.end()) {
value = extended_attrset[key].to_str();
}
return value;
}

private:
Expand All @@ -98,10 +94,10 @@ const string get_extended_metadata(string& key) {
map<string, ceph::bufferlist> extended_attrset;
bool valid;
bool index_ref;

public:
static const char X_ATTR_VERSION_VALUE[];
static const char DATA_BUFFER_NAME[];

};

} // namespace librmb
Expand Down
4 changes: 3 additions & 1 deletion src/librmb/tools/rmb/mailbox_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ int MailboxTools::build_filename(librmb::RadosMailObject* mail_obj, std::string*
}

std::stringstream ss;
ss << mail_obj->get_metadata(librmb::RBOX_METADATA_MAIL_UID) << ".";
std::string m_mail_uid;
mail_obj->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &m_mail_uid);
ss << m_mail_uid << ".";
ss << mail_obj->get_oid();
*filename = ss.str();
return filename->empty() ? -1 : 0;
Expand Down
10 changes: 5 additions & 5 deletions src/librmb/tools/rmb/rados-mail-box.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ namespace librmb {

class RadosMailBox {
public:

RadosMailBox(const std::string& _mailbox_guid, int _mail_count, const std::string &_mbox_orig_name) : mailbox_guid(_mailbox_guid),
mail_count(_mail_count),
mbox_orig_name(_mbox_orig_name) {
RadosMailBox(const std::string &_mailbox_guid, int _mail_count, const std::string &_mbox_orig_name)
: mailbox_guid(_mailbox_guid), mail_count(_mail_count), mbox_orig_name(_mbox_orig_name) {
this->mailbox_size = 0;
this->total_mails = 0;
this->parser = nullptr;
Expand All @@ -50,7 +48,9 @@ class RadosMailBox {
it != parser->get_predicates().end(); ++it) {
if (mail->get_metadata()->find(it->first) != mail->get_metadata()->end()) {
std::string key = it->first;
if (it->second->eval(mail->get_metadata(key))) {
std::string value;
mail->get_metadata(key, &value);
if (it->second->eval(value)) {
mails.push_back(mail);
}
return;
Expand Down
Loading

0 comments on commit 64cfbae

Please sign in to comment.