Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jrse #238#237 #240

Merged
merged 2 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/dict-rados/dict-rados.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ struct dict_iterate_context *rados_dict_iterate_init(struct dict *_dict, const c
private_keys.insert(key);
}
}

bufferlist bl_private;
bufferlist bl_shared;
if (private_keys.size() + shared_keys.size() > 0) {
AioCompletion *private_read_completion = nullptr;
ObjectReadOperation private_read_op;
Expand Down Expand Up @@ -714,9 +715,8 @@ struct dict_iterate_context *rados_dict_iterate_init(struct dict *_dict, const c
}
}

bufferlist bl;
int err =
d->get_private_io_ctx().aio_operate(d->get_private_oid(), private_read_completion, &private_read_op, &bl);
int err = d->get_private_io_ctx().aio_operate(d->get_private_oid(), private_read_completion, &private_read_op,
&bl_private);
#ifdef DEBUG
i_debug("rados_dict_iterate_init(): private err=%d(%s)", err, strerror(-err));
#endif
Expand Down Expand Up @@ -745,8 +745,8 @@ struct dict_iterate_context *rados_dict_iterate_init(struct dict *_dict, const c
}
}

bufferlist bl;
int err = d->get_shared_io_ctx().aio_operate(d->get_shared_oid(), shared_read_completion, &shared_read_op, &bl);
int err =
d->get_shared_io_ctx().aio_operate(d->get_shared_oid(), shared_read_completion, &shared_read_op, &bl_shared);
#ifdef DEBUG
i_debug("rados_dict_iterate_init(): shared err=%d(%s)", err, strerror(-err));
#endif
Expand Down
24 changes: 19 additions & 5 deletions src/storage-rbox/rbox-mail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ static int rbox_mail_metadata_get(struct rbox_mail *rmail, enum rbox_metadata_ke
rmail->rados_mail->get_metadata(key, &val);
if (val != NULL) {
*value_r = i_strdup(val);
} else {
return -1;
}
FUNC_END();
return 0;
Expand Down Expand Up @@ -393,7 +395,7 @@ static int rbox_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED, s
rados_storage->set_namespace(rados_storage->get_namespace());
}

/* Pop3 needs this. it looks like rbox_index_mail_set_seq is not called. */
/* Pop3 needs this. it looks like rbox_index_mail_set_seq is not called. */
if (rmail->rados_mail == nullptr) {
// make sure that mail_object is initialized,
// else create and load guid from index.
Expand Down Expand Up @@ -481,14 +483,26 @@ int rbox_get_guid_metadata(struct rbox_mail *mail, const char **value_r) {
*value_r = guid_128_to_string(mail->index_guid);
return 0;
}
char *value = NULL;
// lost for some reason, use fallback
// index is empty. we have to check the object attributes do we have to tell someone that the index is broken?
if (rbox_mail_metadata_get(mail, rbox_metadata_key::RBOX_METADATA_GUID, &value) < 0) {
if (rbox_mail_metadata_get(mail, rbox_metadata_key::RBOX_METADATA_GUID, value_r) < 0) {
return -1;
}
*value_r = t_strdup(value);

// found the guid in xattributes.
// restore the index extension header quietly.
guid_128_from_string(*value_r, mail->index_guid);
struct index_mail *imail = &mail->imail;
struct mail *_mail = (struct mail *)mail;
struct rbox_mailbox *mbox = (struct rbox_mailbox *)_mail->box;

i_warning("guid for mail with uid : %d, seq = %d was lost restoring guid.", _mail->uid, _mail->seq);

/* save the 128bit GUID/OID to index record */
struct obox_mail_index_record rec;
memcpy(rec.guid, mail->index_guid, sizeof(mail->index_guid));
memcpy(rec.oid, mail->index_oid, sizeof(mail->index_oid));
mail_index_update_ext(_mail->transaction->itrans, imail->mail.mail.seq, mbox->ext_id, &rec, NULL);

return 0;
}

Expand Down
32 changes: 30 additions & 2 deletions src/tests/storage-rbox/it_test_check_metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,40 @@ TEST_F(StorageTest, check_metadata) {

struct rbox_mail *rmail = (struct rbox_mail *)mail;
ASSERT_FALSE(guid_128_is_empty(rmail->index_guid));
char *guid = guid_128_to_string(rmail->index_guid);
const char *guid = guid_128_to_string(rmail->index_guid);

i_debug("GUID values: %s : metadata in mails_cache: rmail->index_guid '%s'", value, guid);
// test re-write guid to index. simulate index_guid is empty.
guid_128_empty(rmail->index_guid);
char *value_2 = NULL;
if (mail_get_special(mail, MAIL_FETCH_GUID, &value_2) < 0) {
FAIL();
}
// we need to free it here!!!
i_free(value_2);

ASSERT_FALSE(guid_128_is_empty(rmail->index_guid));
char *guid2 = guid_128_to_string(rmail->index_guid);

i_debug("GUID values: %s : metadata in mails_cache: rmail->index_guid '%s'", value, guid);
ASSERT_STREQ(guid, guid2);
ASSERT_STREQ(value, guid);

// check that index is still ok !
const void *rec_data = NULL;
struct rbox_mailbox *rbox = (struct rbox_mailbox *)mail->transaction->box;
mail_index_lookup_ext(mail->transaction->view, mail->seq, rbox->ext_id, &rec_data, NULL);
if (rec_data == NULL) {
FAIL();
}
const struct obox_mail_index_record *obox_rec = static_cast<const struct obox_mail_index_record *>(rec_data);
guid_128_t obox_guid;
guid_128_t obox_oid;

memcpy(obox_guid, obox_rec->guid, sizeof(obox_rec->guid));
memcpy(obox_oid, obox_rec->oid, sizeof(obox_rec->oid));
ASSERT_STREQ(guid_128_to_string(obox_guid), guid2);
ASSERT_STREQ(guid_128_to_string(obox_oid), guid_128_to_string(rmail->index_oid));

const char *value2 = NULL;
if (mail_get_special(mail, MAIL_FETCH_MAILBOX_NAME, &value2) < 0) {
FAIL();
Expand Down