From 603dae563a96f358a0edeff4eb675258a8981d0f Mon Sep 17 00:00:00 2001 From: Jan Radon Date: Sun, 20 Nov 2022 16:33:25 +0100 Subject: [PATCH] #349 changed the remove function, initial index creation: append after each mailbox --- src/librmb/rados-storage-impl.cpp | 2 +- src/librmb/rados-storage-impl.h | 2 +- src/librmb/rados-storage.h | 2 +- src/librmb/tools/rmb/rmb-commands.cpp | 7 ++++++ src/librmb/tools/rmb/rmb-commands.h | 2 ++ src/storage-rbox/doveadm-rbox-plugin.cpp | 30 ++++++++++++++---------- src/tests/mocks/mock_test.h | 2 +- 7 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/librmb/rados-storage-impl.cpp b/src/librmb/rados-storage-impl.cpp index 1e12d2c4..37e57274 100644 --- a/src/librmb/rados-storage-impl.cpp +++ b/src/librmb/rados-storage-impl.cpp @@ -612,7 +612,7 @@ std::set RadosStorageImpl::ceph_index_read() { index = RadosUtils::ceph_index_to_set(bl.c_str()); return index; } -int RadosStorageImpl::ceph_index_delete(const std::set &oids) { +int RadosStorageImpl::ceph_index_delete() { return get_recovery_io_ctx().remove(get_namespace()); } diff --git a/src/librmb/rados-storage-impl.h b/src/librmb/rados-storage-impl.h index 25c493a1..11ab2856 100644 --- a/src/librmb/rados-storage-impl.h +++ b/src/librmb/rados-storage-impl.h @@ -89,7 +89,7 @@ class RadosStorageImpl : public RadosStorage { int ceph_index_append(const std::set &oids) override; int ceph_index_overwrite(const std::set &oids) override; std::set ceph_index_read() override; - int ceph_index_delete(const std::set &oids) override; + int ceph_index_delete() override; private: int create_connection(const std::string &poolname,const std::string &index_pool); diff --git a/src/librmb/rados-storage.h b/src/librmb/rados-storage.h index c720c4d2..c3d36fe9 100644 --- a/src/librmb/rados-storage.h +++ b/src/librmb/rados-storage.h @@ -218,7 +218,7 @@ underTest.ceph_index_add("dkfkjdf") /** * remove oids from index object */ - virtual int ceph_index_delete(const std::set &oids) = 0; + virtual int ceph_index_delete() = 0; /*! read the complete mail object into bufferlist diff --git a/src/librmb/tools/rmb/rmb-commands.cpp b/src/librmb/tools/rmb/rmb-commands.cpp index b77b6a97..4bfb3def 100644 --- a/src/librmb/tools/rmb/rmb-commands.cpp +++ b/src/librmb/tools/rmb/rmb-commands.cpp @@ -436,6 +436,13 @@ std::set RmbCommands::load_objects(){ } return mail_list; } +int RmbCommands::remove_ceph_object_index(){ + return storage->ceph_index_delete(); +} +int RmbCommands::append_ceph_object_index(const std::set &mail_oids){ + return storage->ceph_index_append(mail_oids); +} + int RmbCommands::load_objects(librmb::RadosStorageMetadataModule *ms, std::list &mail_objects, std::string &sort_string, bool load_metadata) { time_t begin = time(NULL); diff --git a/src/librmb/tools/rmb/rmb-commands.h b/src/librmb/tools/rmb/rmb-commands.h index 9ad0ef98..85bdcff1 100644 --- a/src/librmb/tools/rmb/rmb-commands.h +++ b/src/librmb/tools/rmb/rmb-commands.h @@ -67,6 +67,8 @@ class RmbCommands { int overwrite_ceph_object_index(std::set &mail_oids); std::set load_objects(); + int remove_ceph_object_index(); + int append_ceph_object_index(const std::set &mail_oids); private: std::map *opts; librmb::RadosStorage *storage; diff --git a/src/storage-rbox/doveadm-rbox-plugin.cpp b/src/storage-rbox/doveadm-rbox-plugin.cpp index 19a56ec3..9680a2a9 100644 --- a/src/storage-rbox/doveadm-rbox-plugin.cpp +++ b/src/storage-rbox/doveadm-rbox-plugin.cpp @@ -802,6 +802,11 @@ static int cmd_rmb_create_ceph_index_run(struct doveadm_mail_cmd_context *_ctx, delete ms; return -1; } + if(rmb_cmds.remove_ceph_object_index() < 0){ + i_error(" Error overwriting ceph object index"); + delete ms; + return -1; + } if (user->namespaces != NULL) { struct mail_namespace *ns = mail_namespace_find_inbox(user->namespaces); @@ -824,25 +829,26 @@ 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()); + if(rmb_cmds.append_ceph_object_index(mail_objects) < 0){ + i_error(" Error overwriting ceph object index"); + delete ms; + return -1; + } + mail_objects.clear(); } } } // end of for }else{ mail_objects = rmb_cmds.load_objects(); + if(rmb_cmds.overwrite_ceph_object_index(mail_objects) < 0){ + i_error(" Error overwriting ceph object index"); + delete ms; + return -1; + } + i_info("found %d mails in namespace",mail_objects.size()); } - if(mail_objects.empty()){ - i_info("refreshing the index with full object search!!!!"); - mail_objects = rmb_cmds.load_objects(); - } - - i_info("found %d mails in namespace",mail_objects.size()); - if(rmb_cmds.overwrite_ceph_object_index(mail_objects) < 0){ - i_error(" Error overwriting ceph object index"); - delete ms; - return -1; - } i_info("index created"); delete ms; diff --git a/src/tests/mocks/mock_test.h b/src/tests/mocks/mock_test.h index 813bd367..e465f636 100644 --- a/src/tests/mocks/mock_test.h +++ b/src/tests/mocks/mock_test.h @@ -88,7 +88,7 @@ class RadosStorageMock : public RadosStorage { MOCK_METHOD1(ceph_index_append,int(const std::set &oids)); MOCK_METHOD1(ceph_index_overwrite,int(const std::set &oids)); MOCK_METHOD0(ceph_index_read,std::set()); - MOCK_METHOD1(ceph_index_delete,int(const std::set &oids)); + MOCK_METHOD0(ceph_index_delete,int()); }; class RadosStorageMetadataMock : public RadosStorageMetadataModule {