Skip to content

Commit f45804b

Browse files
JeremiaWjengelh
authored andcommitted
exmdb: let purge_softdelete EXRPC emit statistics
Transport statistical counts from purge_softdelete through the network interface (adjusted EXRPC definition). Add printf in mbop to print them. References: GXL-497, DESK-1881
1 parent a2be09d commit f45804b

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

exch/exmdb/store2.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ static bool folder_purge_softdel(db_conn_ptr &db, cpid_t cpid,
303303
* @age: soft-deleted items older than this age
304304
*/
305305
BOOL exmdb_server::purge_softdelete(const char *dir, const char *username,
306-
uint64_t folder_id, uint32_t del_flags, mapitime_t cutoff)
306+
uint64_t folder_id, uint32_t del_flags, mapitime_t cutoff,
307+
uint32_t *cnt_folders, uint32_t *cnt_messages,
308+
uint64_t *sz_normal, uint64_t *sz_fai)
307309
{
308310
del_flags &= DEL_FOLDERS;
309311

@@ -359,6 +361,15 @@ BOOL exmdb_server::purge_softdelete(const char *dir, const char *username,
359361
}
360362
if (!cu_adjust_store_size(db->psqlite, ADJ_DECREASE, normal_size, fai_size))
361363
return false;
364+
char nbuf[32], fbuf[32];
365+
HX_unit_size(nbuf, std::size(nbuf), normal_size + fai_size, 0, 0);
366+
HX_unit_size(fbuf, std::size(fbuf), fai_size, 0, 0);
367+
*cnt_messages = msg_count;
368+
*cnt_folders = fld_count;
369+
*sz_normal = normal_size;
370+
*sz_fai = fai_size;
371+
mlog(LV_NOTICE, "I-2401: purge_softdelete %s: deleted %u messages, %u folders, reclaimed %sB (and %sB FAI)",
372+
dir, msg_count, fld_count, nbuf, fbuf);
362373
if (xact.commit() != SQLITE_OK)
363374
return false;
364375
dg_notify(std::move(notifq));

include/gromox/exmdb_idef.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ EXMIDL(vacuum, (const char *dir))
131131
EXMIDL(unload_store, (const char *dir))
132132
EXMIDL(notify_new_mail, (const char *dir, uint64_t folder_id, uint64_t message_id))
133133
EXMIDL(store_eid_to_user, (const char *dir, const STORE_ENTRYID *store_eid, IDLOUT char **maildir, unsigned int *user_id, unsigned int *domain_id))
134-
EXMIDL(purge_softdelete, (const char *dir, const char *username, uint64_t folder_id, uint32_t del_flags, gromox::mapitime_t cutoff))
134+
EXMIDL(purge_softdelete, (const char *dir, const char *username, uint64_t folder_id, uint32_t del_flags, gromox::mapitime_t cutoff, IDLOUT uint32_t *cnt_folders, uint32_t *cnt_messages, uint64_t *sz_normal, uint64_t *sz_fai))
135135
EXMIDL(purge_datafiles, (const char *dir))
136136
EXMIDL(autoreply_tsquery, (const char *dir, const char *peer, uint64_t window, IDLOUT uint64_t *tdiff))
137137
EXMIDL(autoreply_tsupdate, (const char *dir, const char *peer))

include/gromox/exmdb_rpc.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,11 @@ struct exresp_imapfile_read final : public exresp {
13441344
std::string data;
13451345
};
13461346

1347+
struct exresp_purge_softdelete final : public exresp {
1348+
uint32_t cnt_folders = 0, cnt_messages = 0;
1349+
uint64_t sz_normal = 0, sz_fai = 0;
1350+
};
1351+
13471352
using exreq_ping_store = exreq;
13481353
using exreq_get_all_named_propids = exreq;
13491354
using exreq_get_store_all_proptags = exreq;
@@ -1381,7 +1386,7 @@ using exresp_vacuum = exresp;
13811386
using exresp_unload_store = exresp;
13821387
using exresp_ping_store = exresp;
13831388
using exresp_notify_new_mail = exresp;
1384-
using exresp_purge_softdelete = exresp;
1389+
13851390
using exresp_purge_datafiles = exresp;
13861391
using exresp_autoreply_tsupdate = exresp;
13871392
using exresp_recalc_store_size = exresp;

lib/exmdb_ext.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,6 +3722,22 @@ static pack_result exmdb_push(EXT_PUSH &x, const exresp_imapfile_read &d)
37223722
return x.p_bytes(d.data.data(), d.data.size());
37233723
}
37243724

3725+
static pack_result exmdb_pull(EXT_PULL &x, exresp_purge_softdelete &d)
3726+
{
3727+
TRY(x.g_uint32(&d.cnt_folders));
3728+
TRY(x.g_uint32(&d.cnt_messages));
3729+
TRY(x.g_uint64(&d.sz_normal));
3730+
return x.g_uint64(&d.sz_fai);
3731+
}
3732+
3733+
static pack_result exmdb_push(EXT_PUSH &x, const exresp_purge_softdelete &d)
3734+
{
3735+
TRY(x.p_uint32(d.cnt_folders));
3736+
TRY(x.p_uint32(d.cnt_messages));
3737+
TRY(x.p_uint64(d.sz_normal));
3738+
return x.p_uint64(d.sz_fai);
3739+
}
3740+
37253741
#define RSP_WITHOUT_ARGS \
37263742
E(ping_store) \
37273743
E(remove_store_properties) \
@@ -3751,7 +3767,6 @@ static pack_result exmdb_push(EXT_PUSH &x, const exresp_imapfile_read &d)
37513767
E(vacuum) \
37523768
E(unload_store) \
37533769
E(notify_new_mail) \
3754-
E(purge_softdelete) \
37553770
E(purge_datafiles) \
37563771
E(autoreply_tsupdate) \
37573772
E(recalc_store_size) \
@@ -3860,7 +3875,8 @@ static pack_result exmdb_push(EXT_PUSH &x, const exresp_imapfile_read &d)
38603875
E(autoreply_tsquery) \
38613876
E(imapfile_read) \
38623877
E(autoreply_getprop) \
3863-
E(autoreply_setprop)
3878+
E(autoreply_setprop) \
3879+
E(purge_softdelete)
38643880

38653881
/* exmdb_callid::connect, exmdb_callid::listen_notification not included */
38663882
/*

tools/mbop_purge.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,21 @@ int main(int argc, char **argv)
4242
return EXIT_FAILURE;
4343
}
4444
unsigned int flags = g_recursive ? DEL_FOLDERS : 0;
45+
uint32_t st_folders = 0, st_messages = 0;
46+
uint64_t sz_normal = 0, sz_fai = 0;
4547
auto ok = exmdb_client->purge_softdelete(g_storedir, nullptr,
46-
eid, flags, age);
48+
eid, flags, age, &st_folders, &st_messages,
49+
&sz_normal, &sz_fai);
4750
if (!ok) {
4851
mbop_fprintf(stderr, "purge_softdel %s failed\n", *argv);
4952
return EXIT_FAILURE;
5053
}
54+
char nbuf[32], fbuf[32];
55+
HX_unit_size(nbuf, std::size(nbuf), sz_normal, 0, 0);
56+
HX_unit_size(fbuf, std::size(fbuf), sz_fai, 0, 0);
57+
printf("purge_softdelete: deleted %u messages, %u folders, reclaimed %sB (and %sB FAI)\n",
58+
static_cast<unsigned int>(st_messages),
59+
static_cast<unsigned int>(st_folders), nbuf, fbuf);
5160
}
5261
return EXIT_SUCCESS;
5362
}

0 commit comments

Comments
 (0)