Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 87e883b

Browse files
author
Hua Huang
committed
Fix UT and ST when DTM is enabled but not configured in conf.xc.
The REDO messages might come as a re-send, so the replay should be indempotent. So checking if the eolq is already ended is necessary. Signed-off-by: Hua Huang <[email protected]>
1 parent 0cd7e68 commit 87e883b

File tree

9 files changed

+103
-13
lines changed

9 files changed

+103
-13
lines changed

cas/service.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,22 @@ static int cas_dtm0_logrec_add(struct m0_fom *fom0,
11261126
int i;
11271127
int rc;
11281128

1129+
/*
1130+
* It is impossible to commit a transaction without DTM0 service up and
1131+
* running.
1132+
*/
1133+
if (dtms == NULL) {
1134+
static uint32_t count = 0;
1135+
if (count == 0) {
1136+
M0_LOG(M0_FATAL, "DTM is enabled but is not "
1137+
"configured in conf. Skip "
1138+
"DTM now. Please Check!");
1139+
count++; /* Only print the message at the first time. */
1140+
}
1141+
return 0; /* FIXME but now let's skip it if no DTM service. */
1142+
}
1143+
M0_ASSERT(dtms != NULL);
1144+
11291145
for (i = 0; i < msg->dtd_ps.dtp_nr; ++i) {
11301146
if (m0_fid_eq(&msg->dtd_ps.dtp_pa[i].p_fid,
11311147
&dtms->dos_generic.rs_service_fid)) {

cas/ut/client_ut.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ static char *cas_startup_cmd[] = {
8989
"-w", "10", "-F",
9090
"-f", M0_UT_CONF_PROCESS,
9191
"-c", M0_SRC_PATH("cas/ut/conf.xc")
92+
/* FIXME If DTM is enabled, the above conf.xc must be updated to include
93+
* DTM0 services. */
9294
};
9395

9496
static const char *cdbnames[] = { "cas1" };

dtm0/fop.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,18 @@ M0_INTERNAL int m0_dtm0_on_committed(struct m0_fom *fom,
324324
* It is impossible to commit a transaction without DTM0 service up and
325325
* running.
326326
*/
327+
if (dtms == NULL) {
328+
static uint32_t count = 0;
329+
if (count == 0) {
330+
M0_LOG(M0_FATAL, "DTM is enabled but is not "
331+
"configured in conf. Skip "
332+
"DTM now. Please Check!");
333+
count++; /* Only print the message at the first time. */
334+
}
335+
return 0; /* FIXME but now let's skip it if no DTM service. */
336+
}
327337
M0_PRE(dtms != NULL);
338+
328339
log = dtms->dos_log;
329340
M0_PRE(log != NULL);
330341
/* It is impossible to commit something on a volatile log. */

dtm0/recovery.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,7 @@ static void m0_be_queue__finish(struct m0_be_queue *bq, struct m0_buf *item)
13961396
}
13971397
M0_POST(bq->bq_the_end);
13981398
m0_be_queue_unlock(bq);
1399+
M0_LOG(M0_DEBUG, "The queue %p is ended.", bq);
13991400
}
14001401
#define M0_BE_QUEUE__FINISH(bq, item_type) ({ \
14011402
item_type item; \
@@ -2262,15 +2263,18 @@ m0_ut_remach_populate(struct m0_dtm0_recovery_machine *m,
22622263
}
22632264
}
22642265

2266+
/**
2267+
* This function is called as a postmortem after a REDO message has already
2268+
* been replayed. It checks if the REDO message contains EOL flag. If yes,
2269+
* an EOL item is added to the EOL queue. This is to end the queue.
2270+
*/
22652271
M0_INTERNAL void
22662272
m0_dtm0_recovery_machine_redo_post(struct m0_dtm0_recovery_machine *m,
22672273
struct dtm0_req_fop *redo,
22682274
struct m0_be_op *op)
22692275
{
2270-
bool is_eol =
2271-
!!(redo->dtr_flags & M0_BITS(M0_DMF_EOL));
2272-
bool is_eviction =
2273-
!!(redo->dtr_flags & M0_BITS(M0_DMF_EVICTION));
2276+
bool is_eol = !!(redo->dtr_flags & M0_BITS(M0_DMF_EOL));
2277+
bool is_eviction = !!(redo->dtr_flags & M0_BITS(M0_DMF_EVICTION));
22742278
const struct m0_fid *initiator = &redo->dtr_initiator;
22752279
struct eolq_item item = {};
22762280
struct recovery_fom *rf;
@@ -2287,11 +2291,14 @@ m0_dtm0_recovery_machine_redo_post(struct m0_dtm0_recovery_machine *m,
22872291
.ei_type = EIT_EOL,
22882292
.ei_source = *initiator,
22892293
};
2294+
/* Similar to eolq_post(). Maybe call it directly? */
22902295
m0_be_queue_lock(&rf->rf_eolq);
2291-
M0_ASSERT_INFO(!rf->rf_eolq.bq_the_end,
2292-
"REDOs are not allowed if local recovery"
2293-
" has already been finished.");
2294-
M0_BE_QUEUE_PUT(&rf->rf_eolq, op, &item);
2296+
if (!rf->rf_eolq.bq_the_end)
2297+
M0_BE_QUEUE_PUT(&rf->rf_eolq, op, &item);
2298+
else {
2299+
m0_be_op_active(op);
2300+
m0_be_op_done(op);
2301+
}
22952302
m0_be_queue_unlock(&rf->rf_eolq);
22962303
} else {
22972304
M0_LOG(M0_WARN,

layout/ut/plan.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ static int lap_ut_init(void)
311311
{
312312
int rc;
313313

314+
m0_fi_enable("m0_dtm0_in_ut", "ut");
315+
314316
rc = lap_ut_server_start();
315317
M0_ASSERT(rc == 0);
316318

@@ -325,6 +327,7 @@ static int lap_ut_fini(void)
325327
lap_ut_client_stop();
326328
lap_ut_server_stop();
327329

330+
m0_fi_disable("m0_dtm0_in_ut", "ut");
328331
return 0;
329332
}
330333

motr/client_init.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,11 +1644,27 @@ int m0_client_init(struct m0_client **m0c_p,
16441644

16451645
if (ENABLE_DTM0) {
16461646
struct m0_reqh_service *reqh_svc;
1647+
struct m0_confc *confc = m0_reqh2confc(&m0c->m0c_reqh);
1648+
if (M0_IS0(confc)) {
1649+
M0_LOG(M0_FATAL, "DTM is enabled, but the confc is not "
1650+
"initialised. This happens in UT to "
1651+
"test failure cases. If not, please "
1652+
"check! Skip DTM now");
1653+
rc = 0;
1654+
goto skip_dtm; /* FIXME */
1655+
}
16471656

16481657
rc = m0_conf_process2service_get(m0_reqh2confc(&m0c->m0c_reqh),
16491658
&m0c->m0c_reqh.rh_fid,
16501659
M0_CST_DTM0, &cli_svc_fid);
1651-
M0_ASSERT(rc == 0);
1660+
if (rc != 0) {
1661+
M0_LOG(M0_FATAL, "DTM is enabled, but DTM service is"
1662+
" not defined in conf.\nPlease check"
1663+
" the conf file for more details\n"
1664+
"Now let's just skip DTM init");
1665+
rc = 0;
1666+
goto skip_dtm; /* FIXME Please add DTM service. */
1667+
}
16521668

16531669
if (m0_dtm0_in_ut()) {
16541670
/* When in UT, m0c_reqh.rh_fid is the same as the
@@ -1677,6 +1693,7 @@ int m0_client_init(struct m0_client **m0c_p,
16771693
ha_process_event(m0c, M0_CONF_HA_PROCESS_DTM_RECOVERED);
16781694
}
16791695

1696+
skip_dtm:
16801697
if (conf->mc_is_addb_init) {
16811698
char buf[64];
16821699
/* Default client addb record file size set to 128M */
@@ -1714,7 +1731,10 @@ void m0_client_fini(struct m0_client *m0c, bool fini_m0)
17141731
M0_PRE(m0_sm_conf_is_initialized(&m0_op_conf));
17151732
M0_PRE(m0_sm_conf_is_initialized(&entity_conf));
17161733
M0_PRE(m0c != NULL);
1734+
1735+
/* FIXME please see m0_client_init()
17171736
M0_PRE(ergo(ENABLE_DTM0, m0c->m0c_dtms != NULL));
1737+
*/
17181738

17191739
if (m0c->m0c_dtms != NULL)
17201740
m0_dtm_client_service_stop(&m0c->m0c_dtms->dos_generic);

motr/idx.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,18 @@ static int idx_op_init(struct m0_idx *idx, int opcode,
217217

218218
if (ENABLE_DTM0 && !(flags & M0_OIF_NO_DTM) &&
219219
M0_IN(op->op_code, (M0_IC_PUT, M0_IC_DEL))) {
220+
if (m0c->m0c_dtms == NULL) {
221+
static uint32_t count = 0;
222+
if (count == 0) {
223+
M0_LOG(M0_FATAL, "DTM is enabled but is not "
224+
"configured in conf. Skip "
225+
"DTM now. Please Check!");
226+
count++;
227+
/* Only print the msg at the first time. */
228+
}
229+
oi->oi_dtx = NULL;
230+
goto skip_dtm; /* FIXME Add DTM service to conf */
231+
}
220232
M0_ASSERT(m0c->m0c_dtms != NULL);
221233
oi->oi_dtx = m0_dtx0_alloc(m0c->m0c_dtms, oi->oi_sm_grp);
222234
if (oi->oi_dtx == NULL)
@@ -226,6 +238,7 @@ static int idx_op_init(struct m0_idx *idx, int opcode,
226238
M0_ADDB2_ADD(M0_AVI_CLIENT_TO_DIX, cid, did);
227239
} else
228240
oi->oi_dtx = NULL;
241+
skip_dtm:
229242

230243
if (opcode == M0_EO_CREATE && entity->en_type == M0_ET_IDX &&
231244
entity->en_flags & M0_ENF_META) {

motr/st/mt/mt_fom.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ static int st_common_tick(struct m0_fom *fom, void *data, int *phase,
214214
int *rcs = fctx->sfc_rcs;
215215
int64_t ci;
216216
int rc;
217+
int batch;
218+
219+
batch = CMT_BATCH;
220+
if (ENABLE_DTM0)
221+
batch = 0; /* A single k/v in a DIX op. */
217222

218223
M0_LOG(M0_DEBUG, "i=%d fired=%d rqtype=%d",
219224
fctx->sfc_i, !!fctx->sfc_fired, rqtype);
@@ -229,7 +234,7 @@ static int st_common_tick(struct m0_fom *fom, void *data, int *phase,
229234
M0_SET0(vals);
230235
st_kv_alloc_and_fill(keys, vals,
231236
(int)ci * CMT_BATCH_OFF,
232-
(int)ci * CMT_BATCH_OFF + CMT_BATCH,
237+
(int)ci * CMT_BATCH_OFF + batch,
233238
M0_IN(rqtype, (REQ_GET, REQ_DEL)));
234239
switch(rqtype) {
235240
case REQ_CREATE:
@@ -279,7 +284,7 @@ static int st_common_tick(struct m0_fom *fom, void *data, int *phase,
279284
case REQ_GET:
280285
ci = fctx->sfc_ci;
281286
st_vals_check(keys, vals, (int)ci * CMT_BATCH_OFF,
282-
(int)ci * CMT_BATCH_OFF + CMT_BATCH);
287+
(int)ci * CMT_BATCH_OFF + batch);
283288
default:
284289
M0_ASSERT(m0_forall(i, CMT_IDXS_NR, rcs[i] == 0));
285290
}

motr/ut/idx_dix.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ static void ut_dix_record_ops(bool dist, uint32_t cr_get_flags,
466466
struct m0_op_common *oc;
467467
struct m0_op_idx *oi;
468468

469+
if (ENABLE_DTM0) /* If DTM0 enabled, no multiple keys/vals in a op. */
470+
return;
469471
idx_dix_ut_init();
470472
general_ifid_fill(&ifid, dist);
471473
m0_container_init(&realm, NULL, &M0_UBER_REALM, ut_m0c);
@@ -809,12 +811,23 @@ static void ut_dix_record_ops_non_dist_no_dtm(void)
809811
ut_dix_record_ops(false, 0, M0_OIF_NO_DTM);
810812
}
811813

814+
static int ut_suite_idx_dix_init()
815+
{
816+
m0_fi_enable("m0_dtm0_in_ut", "ut");
817+
return 0;
818+
}
819+
static int ut_suite_idx_dix_fini()
820+
{
821+
m0_fi_disable("m0_dtm0_in_ut", "ut");
822+
return 0;
823+
}
824+
812825

813826
struct m0_ut_suite ut_suite_idx_dix = {
814827
.ts_name = "idx-dix",
815828
.ts_owners = "Egor",
816-
.ts_init = NULL,
817-
.ts_fini = NULL,
829+
.ts_init = ut_suite_idx_dix_init,
830+
.ts_fini = ut_suite_idx_dix_fini,
818831
.ts_tests = {
819832
{ "init-fini", ut_dix_init_fini, "Egor" },
820833
{ "namei-ops-dist", ut_dix_namei_ops_dist, "Egor" },

0 commit comments

Comments
 (0)