Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 28 additions & 161 deletions src/dtx/dtx_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,15 +883,10 @@ dtx_handle_reinit(struct dtx_handle *dth)

dth->dth_modify_shared = 0;
dth->dth_active = 0;
dth->dth_touched_leader_oid = 0;
dth->dth_local_tx_started = 0;
dth->dth_cos_done = 0;

dth->dth_op_seq = 0;
dth->dth_oid_cnt = 0;
dth->dth_oid_cap = 0;
D_FREE(dth->dth_oid_array);
dth->dth_dkey_hash = 0;
dth->dth_op_seq = 0;
dth->dth_dkey_hash = 0;
vos_dtx_rsrvd_fini(dth);

return vos_dtx_rsrvd_init(dth);
Expand Down Expand Up @@ -926,32 +921,29 @@ dtx_handle_init(struct dtx_id *dti, daos_handle_t xoh, struct dtx_epoch *epoch,
dth->dth_coh = xoh;
}

dth->dth_ver = pm_ver;
dth->dth_refs = 1;
dth->dth_mbs = mbs;

dth->dth_pinned = 0;
dth->dth_cos_done = 0;
dth->dth_modify_shared = 0;
dth->dth_active = 0;
dth->dth_touched_leader_oid = 0;
dth->dth_local_tx_started = 0;
dth->dth_solo = (flags & DTX_SOLO) ? 1 : 0;
dth->dth_drop_cmt = (flags & DTX_DROP_CMT) ? 1 : 0;
dth->dth_dist = (flags & DTX_DIST) ? 1 : 0;
dth->dth_for_migration = (flags & DTX_FOR_MIGRATION) ? 1 : 0;
dth->dth_ver = pm_ver;
dth->dth_refs = 1;
dth->dth_mbs = mbs;
dth->dth_pinned = 0;
dth->dth_cos_done = 0;
dth->dth_modify_shared = 0;
dth->dth_active = 0;
dth->dth_local_tx_started = 0;
dth->dth_solo = (flags & DTX_SOLO) ? 1 : 0;
dth->dth_drop_cmt = (flags & DTX_DROP_CMT) ? 1 : 0;
dth->dth_dist = (flags & DTX_DIST) ? 1 : 0;
dth->dth_for_migration = (flags & DTX_FOR_MIGRATION) ? 1 : 0;
dth->dth_ignore_uncommitted = (flags & DTX_IGNORE_UNCOMMITTED) ? 1 : 0;
dth->dth_prepared = (flags & DTX_PREPARED) ? 1 : 0;
dth->dth_epoch_owner = (flags & DTX_EPOCH_OWNER) ? 1 : 0;
dth->dth_aborted = 0;
dth->dth_already = 0;
dth->dth_need_validation = 0;
dth->dth_prepared = (flags & DTX_PREPARED) ? 1 : 0;
dth->dth_epoch_owner = (flags & DTX_EPOCH_OWNER) ? 1 : 0;
dth->dth_aborted = 0;
dth->dth_already = 0;
dth->dth_need_validation = 0;
dth->dth_local = (flags & DTX_LOCAL) ? 1 : 0;

dth->dth_dti_cos = dti_cos;
dth->dth_dti_cos_count = dti_cos_cnt;
dth->dth_ent = NULL;
dth->dth_flags = leader ? DTE_LEADER : 0;
dth->dth_dti_cos = dti_cos;
dth->dth_dti_cos_count = dti_cos_cnt;
dth->dth_ent = NULL;
dth->dth_flags = leader ? DTE_LEADER : 0;

if (flags & DTX_SYNC) {
dth->dth_flags |= DTE_BLOCK;
Expand All @@ -960,12 +952,11 @@ dtx_handle_init(struct dtx_id *dti, daos_handle_t xoh, struct dtx_epoch *epoch,
dth->dth_sync = 0;
}

dth->dth_op_seq = 0;
dth->dth_oid_cnt = 0;
dth->dth_oid_cap = 0;
dth->dth_oid_array = NULL;

dth->dth_dkey_hash = 0;
dth->dth_op_seq = 0;
dth->dth_local_oid_cnt = 0;
dth->dth_local_oid_cap = 0;
dth->dth_local_oid_array = NULL;
dth->dth_dkey_hash = 0;

if (!(flags & DTX_LOCAL)) {
if (daos_is_zero_dti(dti))
Expand Down Expand Up @@ -1001,83 +992,6 @@ dtx_handle_init(struct dtx_id *dti, daos_handle_t xoh, struct dtx_epoch *epoch,
return rc;
}

static int
dtx_insert_oid(struct dtx_handle *dth, daos_unit_oid_t *oid, bool touch_leader)
{
int start = 0;
int end = dth->dth_oid_cnt - 1;
int at;
int rc = 0;

do {
at = (start + end) / 2;
rc = daos_unit_oid_compare(dth->dth_oid_array[at], *oid);
if (rc == 0)
return 0;

if (rc > 0)
end = at - 1;
else
start = at + 1;
} while (start <= end);

if (dth->dth_oid_cnt == dth->dth_oid_cap) {
daos_unit_oid_t *oid_array;

D_ALLOC_ARRAY(oid_array, dth->dth_oid_cap << 1);
if (oid_array == NULL)
return -DER_NOMEM;

if (rc > 0) {
/* Insert before dth->dth_oid_array[at]. */
if (at > 0)
memcpy(&oid_array[0], &dth->dth_oid_array[0],
sizeof(*oid) * at);
oid_array[at] = *oid;
memcpy(&oid_array[at + 1], &dth->dth_oid_array[at],
sizeof(*oid) * (dth->dth_oid_cnt - at));
} else {
/* Insert after dth->dth_oid_array[at]. */
memcpy(&oid_array[0], &dth->dth_oid_array[0],
sizeof(*oid) * (at + 1));
oid_array[at + 1] = *oid;
if (at < dth->dth_oid_cnt - 1)
memcpy(&oid_array[at + 2],
&dth->dth_oid_array[at + 1],
sizeof(*oid) * (dth->dth_oid_cnt - 1 - at));
}

D_FREE(dth->dth_oid_array);
dth->dth_oid_array = oid_array;
dth->dth_oid_cap <<= 1;

goto out;
}

if (rc > 0) {
/* Insert before dth->dth_oid_array[at]. */
memmove(&dth->dth_oid_array[at + 1],
&dth->dth_oid_array[at],
sizeof(*oid) * (dth->dth_oid_cnt - at));
dth->dth_oid_array[at] = *oid;
} else {
/* Insert after dth->dth_oid_array[at]. */
if (at < dth->dth_oid_cnt - 1)
memmove(&dth->dth_oid_array[at + 2],
&dth->dth_oid_array[at + 1],
sizeof(*oid) * (dth->dth_oid_cnt - 1 - at));
dth->dth_oid_array[at + 1] = *oid;
}

out:
if (touch_leader)
dth->dth_touched_leader_oid = 1;

dth->dth_oid_cnt++;

return 0;
}

void
dtx_renew_epoch(struct dtx_epoch *epoch, struct dtx_handle *dth)
{
Expand Down Expand Up @@ -1110,51 +1024,6 @@ dtx_sub_init(struct dtx_handle *dth, daos_unit_oid_t *oid, uint64_t dkey_hash)
dth->dth_dkey_hash = dkey_hash;
dth->dth_op_seq++;

rc = daos_unit_oid_compare(dth->dth_leader_oid, *oid);
if (rc == 0) {
if (dth->dth_oid_array == NULL)
dth->dth_touched_leader_oid = 1;

if (dth->dth_touched_leader_oid)
goto out;

rc = dtx_insert_oid(dth, oid, true);

D_GOTO(out, rc);
}

if (dth->dth_oid_array == NULL) {
D_ASSERT(dth->dth_oid_cnt == 0);

/* 4 slots by default to hold rename case. */
dth->dth_oid_cap = 4;
D_ALLOC_ARRAY(dth->dth_oid_array, dth->dth_oid_cap);
if (dth->dth_oid_array == NULL)
D_GOTO(out, rc = -DER_NOMEM);

if (!dth->dth_touched_leader_oid) {
dth->dth_oid_array[0] = *oid;
dth->dth_oid_cnt = 1;

D_GOTO(out, rc = 0);
}

dth->dth_oid_cnt = 2;

if (rc > 0) {
dth->dth_oid_array[0] = *oid;
dth->dth_oid_array[1] = dth->dth_leader_oid;
} else {
dth->dth_oid_array[0] = dth->dth_leader_oid;
dth->dth_oid_array[1] = *oid;
}

D_GOTO(out, rc = 0);
}

rc = dtx_insert_oid(dth, oid, false);

out:
D_DEBUG(DB_IO, "Sub init DTX "DF_DTI" for object "DF_UOID
" dkey %lu, opc seq %d: "DF_RC"\n",
DP_DTI(&dth->dth_xid), DP_UOID(*oid),
Expand Down Expand Up @@ -1493,7 +1362,6 @@ dtx_leader_end(struct dtx_leader_handle *dlh, struct ds_cont_child *cont, int re
dth->dth_sync ? "sync" : "async", dth->dth_dti_cos_count,
dth->dth_cos_done ? dth->dth_dti_cos_count : 0, DP_RC(result));

D_FREE(dth->dth_oid_array);
D_FREE(dlh);
d_tm_dec_gauge(dtx_tls_get()->dt_dtx_leader_total, 1);

Expand Down Expand Up @@ -1617,7 +1485,6 @@ dtx_end(struct dtx_handle *dth, struct ds_cont_child *cont, int result)
vos_dtx_detach(dth);

out:
D_FREE(dth->dth_oid_array);
D_FREE(dth);

return result;
Expand Down
7 changes: 1 addition & 6 deletions src/dtx/tests/dts_structs.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ struct_dtx_handle(void **state)
SET_BITFIELD_1(dummy, dth_drop_cmt);
SET_BITFIELD_1(dummy, dth_modify_shared);
SET_BITFIELD_1(dummy, dth_active);
SET_BITFIELD_1(dummy, dth_touched_leader_oid);
SET_BITFIELD_1(dummy, dth_local_tx_started);
SET_BITFIELD_1(dummy, dth_shares_inited);
SET_BITFIELD_1(dummy, dth_dist);
Expand All @@ -75,7 +74,7 @@ struct_dtx_handle(void **state)
SET_BITFIELD_1(dummy, dth_local);
SET_BITFIELD_1(dummy, dth_epoch_owner);
SET_BITFIELD_1(dummy, dth_local_complete);
SET_BITFIELD(dummy, padding1, 12);
SET_BITFIELD(dummy, padding1, 13);

SET_FIELD(dummy, dth_dti_cos_count);
SET_FIELD(dummy, dth_dti_cos);
Expand All @@ -87,10 +86,6 @@ struct_dtx_handle(void **state)
SET_FIELD(dummy, dth_op_seq);
SET_FIELD(dummy, dth_deferred_used_cnt);
SET_FIELD(dummy, padding2);
SET_FIELD(dummy, dth_oid_cnt);
SET_FIELD(dummy, dth_oid_cap);
SET_FIELD(dummy, padding3);
SET_FIELD(dummy, dth_oid_array);
SET_FIELD(dummy, dth_local_oid_cnt);
SET_FIELD(dummy, dth_local_oid_cap);
SET_FIELD(dummy, padding4);
Expand Down
9 changes: 9 additions & 0 deletions src/include/daos/lru.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ daos_lru_ref_evict(struct daos_lru_cache *lcache, struct daos_llink *llink)
d_hash_rec_evict_at(&lcache->dlc_htable, &llink->ll_link);
}

/**
* Whether the item is evicted or not.
*/
static inline bool
daos_lru_is_evicted(struct daos_llink *llink)
{
return llink->ll_evicted != 0;
}

/**
* Evict the item from LRU before releasing the refcount on it, wait until
* the caller is the last one holds refcount.
Expand Down
33 changes: 11 additions & 22 deletions src/include/daos_srv/dtx_srv.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct dtx_local_oid_record {
* the most optimal way (packed). Please make sure that all necessary padding
* is explicit so it could be used in the future.
*/
/* clang-format off */
struct dtx_handle {
union {
struct dtx_entry dth_dte;
Expand Down Expand Up @@ -92,8 +93,6 @@ struct dtx_handle {
dth_modify_shared : 1,
/* The DTX entry is in active table. */
dth_active : 1,
/* Leader oid is touched. */
dth_touched_leader_oid : 1,
/* Local TX is started. */
dth_local_tx_started : 1,
/* The DTX share lists are inited. */
Expand All @@ -117,7 +116,7 @@ struct dtx_handle {
/* Locally generate the epoch. */
dth_epoch_owner : 1,
/* Flag to commit the local transaction */
dth_local_complete : 1, padding1 : 12;
dth_local_complete : 1, padding1 : 13;

/* The count the DTXs in the dth_dti_cos array. */
uint32_t dth_dti_cos_count;
Expand All @@ -138,25 +137,14 @@ struct dtx_handle {
uint16_t dth_deferred_used_cnt;
uint16_t padding2;

union {
struct {
/** The count of objects that are modified by this DTX. */
uint16_t dth_oid_cnt;
/** The total slots in the dth_oid_array. */
uint16_t dth_oid_cap;
uint32_t padding3;
/** If more than one objects are modified, the IDs are reocrded here. */
daos_unit_oid_t *dth_oid_array;
};
struct {
/** The count of objects stored in dth_local_oid_array. */
uint16_t dth_local_oid_cnt;
/** The total slots in the dth_local_oid_array. */
uint16_t dth_local_oid_cap;
uint32_t padding4;
/** The record of all objects touched by the local transaction. */
struct dtx_local_oid_record *dth_local_oid_array;
};
struct {
/** The count of objects stored in dth_local_oid_array. */
uint16_t dth_local_oid_cnt;
/** The total slots in the dth_local_oid_array. */
uint16_t dth_local_oid_cap;
uint32_t padding4;
/** The record of all objects touched by the local transaction. */
struct dtx_local_oid_record *dth_local_oid_array;
};

/* Hash of the dkey to be modified if applicable. Per modification. */
Expand All @@ -179,6 +167,7 @@ struct dtx_handle {
int dth_share_tbd_count;
uint32_t padding5;
};
/* clang-format on */

/* Each sub transaction handle to manage each sub thandle */
struct dtx_sub_status {
Expand Down
Loading
Loading