Skip to content

Commit 79544fd

Browse files
committed
exmdb: make DB_LOCK_TIMEOUT configurable
1 parent 612d25b commit 79544fd

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

doc/exmdb_provider.4gx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,20 @@ warning log message. Use 0 to disable.
185185
Default: \fI10\fP
186186
.TP
187187
\fBmbox_contention_reject\fP
188-
If there are more than this many threads waiting to use a mailbox, refuse the
189-
particular exmdb RPC that is executing. Use 0 to disable.
188+
If there are more than this many threads waiting to use a mailbox, refuse new
189+
exmdb calls to the mailbox. Use 0 to disable. When a call is not rejected
190+
upfront like this, it will be added to the waiting queue. (mailbox access is
191+
serialized.)
190192
.br
191193
Default: \fI0\fP
192194
.TP
195+
\fBmbox_contention_reject_time\fP
196+
If an exmdb call was queued in the waiting list for too long (cf.
197+
mbox_contention_reject), the call will be aborted, error E-2207 logged, an
198+
error returned to the client.
199+
.br
200+
Default: \fI60s\fP
201+
.TP
193202
\fBnotify_stub_threads_num\fP
194203
For every remote exmdb server in exmdb_list.txt, establish and keep this many
195204
number of outbound connections for receiving notification RPCs.

exch/exmdb/db_engine.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ unsigned int g_exmdb_schema_upgrades, g_exmdb_search_pacing;
109109
unsigned long long g_exmdb_search_pacing_time = 2000000000;
110110
unsigned int g_exmdb_search_yield, g_exmdb_search_nice;
111111
unsigned int g_exmdb_pvt_folder_softdel;
112-
static constexpr auto DB_LOCK_TIMEOUT = std::chrono::seconds(60);
112+
unsigned long long g_exmdb_lock_timeout = 60000000000ULL;
113113

114114
static bool remove_from_hash(const decltype(g_hash_table)::value_type &, time_t);
115115
static void dbeng_notify_cttbl_modify_row(DB_ITEM *, uint64_t folder_id, uint64_t message_id);
@@ -213,10 +213,10 @@ db_item_ptr db_engine_get_db(const char *path, const char *parent_func)
213213
++pdb->reference;
214214
hhold.unlock();
215215
auto func_then = znul(pdb->giant_lock_func);
216-
if (!pdb->giant_lock.try_lock_for(DB_LOCK_TIMEOUT)) {
216+
if (!pdb->giant_lock.try_lock_for(std::chrono::nanoseconds(g_exmdb_lock_timeout))) {
217217
--pdb->reference;
218-
mlog(LV_ERR, "E-2207: %s: could not obtain exclusive access within %us (mailbox busy with <%s>/<%s>)",
219-
path, static_cast<unsigned int>(DB_LOCK_TIMEOUT.count()),
218+
mlog(LV_ERR, "E-2207: %s: could not obtain exclusive access within %llu ns (mailbox busy with <%s>/<%s>)",
219+
path, g_exmdb_lock_timeout,
220220
func_then, znul(pdb->giant_lock_func));
221221
return NULL;
222222
}
@@ -239,7 +239,7 @@ db_item_ptr db_engine_get_db(const char *path, const char *parent_func)
239239
pdb->last_time = time(nullptr);
240240
pdb->reference ++;
241241
hhold.unlock();
242-
if (!pdb->giant_lock.try_lock_for(DB_LOCK_TIMEOUT)) {
242+
if (!pdb->giant_lock.try_lock_for(std::chrono::nanoseconds(g_exmdb_lock_timeout))) {
243243
pdb->reference --;
244244
return NULL;
245245
}

exch/exmdb/db_engine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ extern BOOL db_engine_enqueue_populating_criteria(const char *dir, cpid_t, uint6
162162
extern bool db_engine_check_populating(const char *dir, uint64_t folder_id);
163163

164164
extern unsigned int g_exmdb_schema_upgrades, g_exmdb_search_pacing;
165-
extern unsigned long long g_exmdb_search_pacing_time;
165+
extern unsigned long long g_exmdb_search_pacing_time, g_exmdb_lock_timeout;
166166
extern unsigned int g_exmdb_search_yield, g_exmdb_search_nice;
167167
extern unsigned int g_exmdb_pvt_folder_softdel;
168168
extern std::string g_exmdb_ics_log_file;

exch/exmdb/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static constexpr cfg_directive exmdb_cfg_defaults[] = {
6363
{"max_rule_number", "1000", CFG_SIZE, "1", "2000"},
6464
{"max_store_message_count", "0", CFG_SIZE},
6565
{"mbox_contention_reject", "0", CFG_SIZE},
66+
{"mbox_contention_reject_time", "60s", CFG_TIME_NS},
6667
{"mbox_contention_warning", "10", CFG_SIZE},
6768
{"notify_stub_threads_num", "4", CFG_SIZE, "0"},
6869
{"populating_threads_num", "50", CFG_SIZE, "1", "50"},
@@ -106,6 +107,7 @@ static bool exmdb_provider_reload(std::shared_ptr<config_file> gxcfg = nullptr,
106107
exmdb_pf_read_states = pconfig->get_ll("exmdb_pf_read_states");
107108
g_exmdb_pvt_folder_softdel = pconfig->get_ll("exmdb_private_folder_softdelete");
108109
g_exmdb_search_pacing = pconfig->get_ll("exmdb_search_pacing");
110+
g_exmdb_lock_timeout = pconfig->get_ll("mbox_contention_reject_time");
109111
g_exmdb_search_yield = pconfig->get_ll("exmdb_search_yield");
110112
g_exmdb_search_nice = pconfig->get_ll("exmdb_search_nice");
111113
g_exmdb_search_pacing_time = pconfig->get_ll("exmdb_search_pacing_time");

0 commit comments

Comments
 (0)