Skip to content

Commit

Permalink
#349 validate object (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrse committed Nov 26, 2022
1 parent eb41db1 commit 4efa9f1
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Change Log
## [0.0.46](https://github.com/ceph-dovecot/dovecot-ceph-plugin/tree/0.0.45) (2022-11-22)
- #349 bugfix doveadm rmb create ceph index validate object metadata

## [0.0.45](https://github.com/ceph-dovecot/dovecot-ceph-plugin/tree/0.0.45) (2022-11-22)
- #349 bugfix doveadm rmb return code not set

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.45], [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.46], [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 @@ -14,7 +14,7 @@
Name: dovecot-ceph-plugin
Summary: Dovecot Ceph RADOS plugins

Version: 0.0.45
Version: 0.0.46

Release: 0%{?dist}
URL: https://github.com/ceph-dovecot/dovecot-ceph-plugin
Expand Down
7 changes: 7 additions & 0 deletions src/librmb/rados-storage-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,13 @@ void RadosStorageImpl::free_rados_mail(librmb::RadosMail *mail) {
}
}

uint64_t RadosStorageImpl::ceph_index_size(){
uint64_t psize;
time_t pmtime;
get_recovery_io_ctx().stat(get_namespace(), &psize, &pmtime);
return psize;
}

int RadosStorageImpl::ceph_index_append(const std::string &oid) {
librados::bufferlist bl;
bl.append(RadosUtils::convert_to_ceph_index(oid));
Expand Down
1 change: 1 addition & 0 deletions src/librmb/rados-storage-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class RadosStorageImpl : public RadosStorage {

void free_rados_mail(librmb::RadosMail *mail) override;

uint64_t ceph_index_size() override;
int ceph_index_append(const std::string &oid) override;
int ceph_index_append(const std::set<std::string> &oids) override;
int ceph_index_overwrite(const std::set<std::string> &oids) override;
Expand Down
4 changes: 4 additions & 0 deletions src/librmb/rados-storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ underTest.ceph_index_add("dkfkjdf")
*/
virtual int ceph_index_delete() = 0;

/**
* returns the ceph index size
*/
virtual uint64_t ceph_index_size() = 0;

/*! read the complete mail object into bufferlist
*
Expand Down
17 changes: 13 additions & 4 deletions src/librmb/tools/rmb/rmb-commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,21 @@ static void aio_cb(rados_completion_t cb, void *arg) {
int RmbCommands::overwrite_ceph_object_index(std::set<std::string> &mail_oids){
return storage->ceph_index_overwrite(mail_oids);
}
std::set<std::string> RmbCommands::load_objects(){
std::set<std::string> RmbCommands::load_objects(librmb::RadosStorageMetadataModule *ms){
std::set<std::string> mail_list;
librados::NObjectIterator iter_guid =storage->find_mails(nullptr);
librados::NObjectIterator iter_guid = storage->find_mails(nullptr);
while (iter_guid != librados::NObjectIterator::__EndObjectIterator) {
mail_list.insert((*iter_guid).get_oid());
iter_guid++;
librmb::RadosMail mail;
mail.set_oid((*iter_guid).get_oid());

int load_metadata_ret = ms->load_metadata(&mail);
if (load_metadata_ret < 0 || !librmb::RadosUtils::validate_metadata(mail.get_metadata())) {
std::cerr << "metadata for object : " << mail.get_oid()->c_str() << " is not valid, skipping object " << std::endl;
iter_guid++;
continue;
}
mail_list.insert((*iter_guid).get_oid());
iter_guid++;
}
return mail_list;
}
Expand Down
2 changes: 1 addition & 1 deletion src/librmb/tools/rmb/rmb-commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RmbCommands {
void set_output_path(librmb::CmdLineParser *parser);

int overwrite_ceph_object_index(std::set<std::string> &mail_oids);
std::set<std::string> load_objects();
std::set<std::string> load_objects(librmb::RadosStorageMetadataModule *ms);
int remove_ceph_object_index();
int append_ceph_object_index(const std::set<std::string> &mail_oids);
private:
Expand Down
13 changes: 5 additions & 8 deletions src/storage-rbox/doveadm-rbox-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,7 @@ static int cmd_rmb_create_ceph_index_run(struct doveadm_mail_cmd_context *_ctx,
return -1;
}
if(rmb_cmds.remove_ceph_object_index() < 0){
i_error(" Error overwriting ceph object index");
delete ms;
_ctx->exit_code = -1;
return -1;
i_debug(" Error overwriting ceph object index");
}

if (user->namespaces != NULL) {
Expand All @@ -832,7 +829,7 @@ static int cmd_rmb_create_ceph_index_run(struct doveadm_mail_cmd_context *_ctx,
}

//append to index.
i_info("found %d mails in namespace",mail_objects.size());
i_info("found %s mails in namespace %d",info->vname, mail_objects.size());
if(rmb_cmds.append_ceph_object_index(mail_objects) < 0){
i_error(" Error overwriting ceph object index");
delete ms;
Expand All @@ -842,9 +839,10 @@ static int cmd_rmb_create_ceph_index_run(struct doveadm_mail_cmd_context *_ctx,
mail_objects.clear();
}
}
} // end of for
} // end of for

}else{
mail_objects = rmb_cmds.load_objects();
mail_objects = rmb_cmds.load_objects(ms);
if(rmb_cmds.overwrite_ceph_object_index(mail_objects) < 0){
i_error(" Error overwriting ceph object index");
delete ms;
Expand Down Expand Up @@ -900,7 +898,6 @@ static int iterate_list_objects(struct mail_namespace* ns, const struct mailbox_
continue;
}
std::string oid = guid_128_to_string(obox_rec->oid);
//TODO: add the oid to the ceph index!!!!
object_list.insert(oid);
}
if (mailbox_search_deinit(&search_ctx) < 0) {
Expand Down
5 changes: 5 additions & 0 deletions src/storage-rbox/rbox-save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,11 @@ int rbox_save_finish(struct mail_save_context *_ctx) {
if( r_storage->config->get_object_search_method() == 2){
// ceph config schalter an oder aus!
r_storage->s->ceph_index_append(*r_ctx->rados_mail->get_oid());
uint64_t index_size = r_storage->s->ceph_index_size();
// WARN if index reaches 80% of max object size
if((r_storage->s->get_max_object_size() / index_size) > 80) {
i_warning("ceph_index file(%d) close to exceed max_object size(%d), recalc index !",r_storage->s->get_max_object_size(), index_size );
}
}
}
if (r_storage->save_log->is_open()) {
Expand Down
3 changes: 3 additions & 0 deletions src/storage-rbox/rbox-sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ int rbox_sync_begin(struct rbox_mailbox *rbox, struct rbox_sync_context **ctx_r,
rebuild = (hdr->flags & MAIL_INDEX_HDR_FLAG_FSCKD) != 0;
#endif

//TODO: check ceph index size, if threshold size has been reached, stat mails
// and repair mailbox

ctx = i_new(struct rbox_sync_context, 1);
ctx->rbox = rbox;
i_array_init(&ctx->expunged_items, 32);
Expand Down
1 change: 1 addition & 0 deletions src/tests/mocks/mock_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class RadosStorageMock : public RadosStorage {

MOCK_METHOD0(create_anker, int());

MOCK_METHOD0(ceph_index_size,uint64_t());

MOCK_METHOD1(ceph_index_append,int(const std::string &oid));
MOCK_METHOD1(ceph_index_append,int(const std::set<std::string> &oids));
Expand Down

0 comments on commit 4efa9f1

Please sign in to comment.