diff --git a/ci/test_files_to_stash.txt b/ci/test_files_to_stash.txt index 3624539561a..02823db171a 100755 --- a/ci/test_files_to_stash.txt +++ b/ci/test_files_to_stash.txt @@ -34,6 +34,7 @@ build/*/*/src/engine/tests/drpc_listener_tests, build/*/*/src/mgmt/tests/srv_drpc_tests, build/*/*/src/object/tests/cli_checksum_tests, build/*/*/src/object/tests/srv_checksum_tests, +build/*/*/src/object/tests/srv_ec_agg_tests, build/*/*/src/pool/tests/pool_cli_tests, build/*/*/src/security/tests/cli_security_tests, build/*/*/src/security/tests/srv_acl_tests, diff --git a/src/container/srv_target.c b/src/container/srv_target.c index f7df41f278e..a07e2e05407 100644 --- a/src/container/srv_target.c +++ b/src/container/srv_target.c @@ -691,6 +691,11 @@ cont_child_alloc_ref(void *co_uuid, unsigned int ksize, void *po_uuid, if (cont == NULL) return -DER_NOMEM; + /* What was written without DTX before is not known. The write timestamp cache of the keys + * can be older than this container child: it belongs to the xstream. + */ + cont->sc_ec_nontx_timestamp = d_hlc_get(); + rc = ABT_mutex_create(&cont->sc_open_mutex); if (rc != ABT_SUCCESS) { rc = dss_abterr2der(rc); @@ -2832,13 +2837,16 @@ ds_cont_eph_report(struct ds_pool *pool) (min_ec_agg_eph != 0 && ec_eph->cte_last_ec_agg_epoch != 0 && min_ec_agg_eph <= ec_eph->cte_last_ec_agg_epoch && min_stable_eph <= ec_eph->cte_last_stable_epoch)) { + /* The EC aggregation epoch of a target can go back: a scan finds a replica + * to be visited again below it, or a forced scan reports its ranges one by + * one. Only the stable epoch is not expected to. + */ if (min_ec_agg_eph > 0 && min_stable_eph > 0 && - (min_ec_agg_eph < ec_eph->cte_last_ec_agg_epoch || - min_stable_eph < ec_eph->cte_last_stable_epoch)) - D_ERROR("ignore for now, min_ec_agg_eph " DF_X64 " < " DF_X64 ", " - "or min_stable_eph " DF_X64 " < " DF_X64 ", " DF_UUID "\n", - min_ec_agg_eph, ec_eph->cte_last_ec_agg_epoch, + min_stable_eph < ec_eph->cte_last_stable_epoch) + D_ERROR("ignore for now, min_stable_eph " DF_X64 " < " DF_X64 ", " + "min_ec_agg_eph " DF_X64 "/" DF_X64 ", " DF_UUID "\n", min_stable_eph, ec_eph->cte_last_stable_epoch, + min_ec_agg_eph, ec_eph->cte_last_ec_agg_epoch, DP_UUID(ec_eph->cte_cont_uuid)); else D_DEBUG(DB_MD, @@ -2963,3 +2971,10 @@ ds_cont_ec_timestamp_update(struct ds_cont_child *cont) { cont->sc_ec_update_timestamp = d_hlc_get(); } + +void +ds_cont_ec_nontx_timestamp_update(struct ds_cont_child *cont) +{ + cont->sc_ec_update_timestamp = d_hlc_get(); + cont->sc_ec_nontx_timestamp = cont->sc_ec_update_timestamp; +} diff --git a/src/include/daos_srv/container.h b/src/include/daos_srv/container.h index 504002427b6..9e49eee93a5 100644 --- a/src/include/daos_srv/container.h +++ b/src/include/daos_srv/container.h @@ -141,6 +141,11 @@ struct ds_cont_child { * if it needs to do EC aggregate. */ uint64_t sc_ec_update_timestamp; + /* Timestamp of the last EC update without DTX (migration), it is not seen by the write + * timestamp cache of the keys. In memory only, starts as the time the container child + * was created. + */ + uint64_t sc_ec_nontx_timestamp; /* The objects with committable DTXs in DRAM. */ daos_handle_t sc_dtx_cos_hdl; @@ -307,6 +312,8 @@ int void ds_cont_track_eph_free(struct ds_pool *pool); void ds_cont_ec_timestamp_update(struct ds_cont_child *cont); +void +ds_cont_ec_nontx_timestamp_update(struct ds_cont_child *cont); typedef int(*cont_rdb_iter_cb_t)(uuid_t pool_uuid, uuid_t cont_uuid, struct rdb_tx *tx, void *arg); int ds_cont_rdb_iterate(struct cont_svc *svc, cont_rdb_iter_cb_t iter_cb, void *cb_arg); diff --git a/src/include/daos_srv/vos_types.h b/src/include/daos_srv/vos_types.h index 0d3d4db9959..fdcc9b0067d 100644 --- a/src/include/daos_srv/vos_types.h +++ b/src/include/daos_srv/vos_types.h @@ -397,8 +397,14 @@ enum { VOS_IT_FOR_AGG = (1 << 9), /** Checking whether the target is aborted or not. */ VOS_IT_FOR_CHECK = (1 << 10), + /** The filter callback gets the epoch of the latest write as id_agg_write, rather than the + * stored timestamp of the writes which need aggregation, which is not maintained for + * every write. Object: vo_max_write. Key: the write timestamp cache, which a write + * without DTX does not update. DAOS_EPOCH_MAX if it is not known. + */ + VOS_IT_AGG_LAST_WRITE = (1 << 11), /** Mask for all flags */ - VOS_IT_MASK = (1 << 11) - 1, + VOS_IT_MASK = (1 << 12) - 1, }; typedef struct { diff --git a/src/object/srv_ec_agg_range.h b/src/object/srv_ec_agg_range.h new file mode 100644 index 00000000000..441b91b66bf --- /dev/null +++ b/src/object/srv_ec_agg_range.h @@ -0,0 +1,194 @@ +/** + * (C) Copyright 2026 Hewlett Packard Enterprise Development LP + * + * SPDX-License-Identifier: BSD-2-Clause-Patent + */ +/** + * How EC aggregation of a container shard goes over the epoch ranges of a round, see + * cont_ec_aggregate_cb(). It does not depend on the engine, so that unit tests can drive it. + * + * The EC aggregation epoch of the shard (sc_ec_agg_eph) says that everything at or below it was + * processed. The epoch reported for the boundary is derived from it, and a rebuild or a degraded + * fetch reads the data of the shard at that boundary, so the epoch must not pass a replica which + * was not visited. + */ + +#ifndef __SRV_EC_AGG_RANGE_H__ +#define __SRV_EC_AGG_RANGE_H__ + +#include + +enum ec_agg_range_act { + /** Iterate the objects of the range. */ + EC_AGG_RANGE_SCAN, + /** Nothing was written since the range was processed, it is done without iteration. */ + EC_AGG_RANGE_IDLE, + /** Leave the range to a later round, the aggregation epoch is not changed. */ + EC_AGG_RANGE_SKIP, +}; + +/** Result of a range. Not zero: end the round without error, a forced scan is not done. */ +enum ec_agg_range_res { + /** The range is done. */ + EC_AGG_RANGE_DONE = 0, + /** The scan does not count (pool map updated, no boundary yet), nothing is changed. */ + EC_AGG_RANGE_VOID = 1, + /** Something is to be visited again at or below the aggregation epoch, it is reported. */ + EC_AGG_RANGE_HELD = 2, +}; + +/** One epoch range of a round, i.e. one call of cont_ec_aggregate_cb(). */ +struct ec_agg_range { + /** Upper bound of the range. */ + daos_epoch_t ar_hi; + /** EC aggregation epoch when the range was started. */ + daos_epoch_t ar_agg_eph; + /** Pool map version when the range was started. */ + uint32_t ar_map_ver; + /** Forced scan: what is below the aggregation epoch is verified again. */ + bool ar_force; + /** Nothing to do for an object which was last written at or below this epoch. */ + daos_epoch_t ar_filter_eph; + /** The write timestamp cache of the keys can be relied on, see ec_agg_range_skip_key(). */ + bool ar_key_filter; +}; + +/** + * An object is left out if its last write is known, and is covered by what was processed. + * + * \param[in] last_write Epoch of the last write of the object, zero or DAOS_EPOCH_MAX + * if it is not known. + */ +static inline bool +ec_agg_range_skip_obj(const struct ec_agg_range *ar, daos_epoch_t last_write) +{ + return last_write != 0 && last_write <= ar->ar_filter_eph; +} + +/** + * A key of an object which passed is left out by its last write in the write timestamp cache. + * + * The cache does not see a write without DTX (migration), so it is only relied on once what was + * processed covers the last of those writes, see ar_key_filter. + * + * \param[in] last_write What the cache has for the key, DAOS_EPOCH_MAX on a miss. + */ +static inline bool +ec_agg_range_skip_key(const struct ec_agg_range *ar, daos_epoch_t last_write) +{ + return ar->ar_key_filter && last_write != 0 && last_write <= ar->ar_filter_eph; +} + +/** + * Start a range. + * + * \param[in] epr The range, the lower bound is inclusive. + * \param[in] force_scan Scan forced from the lower bound of the range, the aggregation + * epoch does not say what was processed for this scan. + * \param[in] agg_eph EC aggregation epoch of the shard. + * \param[in] map_ver Pool map version of the target. + * \param[in] now Current HLC. + * \param[in] nontx_ts Timestamp of the last update without DTX of the container shard, + * or of the creation of the container child if that is later. Zero + * if it is not known. + * \param[in,out] update_ts Timestamp of the last update of the container shard, kept in + * memory only. + */ +static inline enum ec_agg_range_act +ec_agg_range_begin(struct ec_agg_range *ar, const daos_epoch_range_t *epr, bool force_scan, + daos_epoch_t agg_eph, uint32_t map_ver, daos_epoch_t now, daos_epoch_t nontx_ts, + daos_epoch_t *update_ts) +{ + /* Not known after a restart. Whatever was written before is older than now, and is not + * skipped until the aggregation epoch passes it. + */ + if (*update_ts == 0) + *update_ts = now; + + ar->ar_hi = epr->epr_hi; + ar->ar_agg_eph = agg_eph; + ar->ar_map_ver = map_ver; + ar->ar_force = force_scan; + ar->ar_filter_eph = 0; + ar->ar_key_filter = false; + + /* Only a range which continues what was processed can move the aggregation epoch. The + * range before this one was not completed, or the epoch was reset: an incremental scan + * of a later round covers this range. + */ + if (epr->epr_lo > agg_eph && epr->epr_lo - agg_eph > 1) + return EC_AGG_RANGE_SKIP; + + /* The lower bound is inclusive: what was written at it is not processed yet. */ + if (!force_scan) + ar->ar_filter_eph = agg_eph; + else if (epr->epr_lo > 0) + ar->ar_filter_eph = epr->epr_lo - 1; + + if (ar->ar_filter_eph != 0 && ar->ar_filter_eph >= *update_ts) + return EC_AGG_RANGE_IDLE; + + ar->ar_key_filter = nontx_ts != 0 && ar->ar_filter_eph >= nontx_ts; + + return EC_AGG_RANGE_SCAN; +} + +/** The boundary of the container is not known yet, nothing can be scanned. */ +static inline int +ec_agg_range_no_boundary(bool force_scan) +{ + return force_scan ? EC_AGG_RANGE_VOID : EC_AGG_RANGE_DONE; +} + +/** + * Settle a range which was scanned without error, or was idle. + * + * \param[in] map_ver Pool map version of the target. + * \param[in] min_unagg Lowest epoch which was visited and has to be visited again, + * DAOS_EPOCH_MAX if there is none. + * \param[in,out] agg_eph EC aggregation epoch of the shard. + * \param[out] report Epoch to be reported for the boundary, optional. + * + * \return See enum ec_agg_range_res. + */ +static inline int +ec_agg_range_end(const struct ec_agg_range *ar, uint32_t map_ver, daos_epoch_t min_unagg, + daos_epoch_t *agg_eph, daos_epoch_t *report) +{ + daos_epoch_t done; + daos_epoch_t held; + + /* A pool map update since ec_agg_range_begin() resets the aggregation epoch to the + * boundary, possibly to the same value: what was scanned with the old layout does not + * count. A scan which was retried after a yield is still one scan. + */ + if (*agg_eph != ar->ar_agg_eph || map_ver != ar->ar_map_ver) + return EC_AGG_RANGE_VOID; + + /* what has to be visited again holds the epoch back */ + done = min_unagg - 1 < ar->ar_hi ? min_unagg - 1 : ar->ar_hi; + if (done > *agg_eph) + *agg_eph = done; + if (report != NULL) { + /* The boundary is the epoch which a recovery reads at, inclusive: below what has + * to be visited again, also when the aggregation epoch is not. + */ + held = min_unagg - 1; + *report = held < *agg_eph ? held : *agg_eph; + /* A forced scan does not report over what it verified so far: a later range of it + * can still find something to be visited again below the aggregation epoch. + */ + if (ar->ar_force && *report > ar->ar_hi) + *report = ar->ar_hi; + } + + /* E.g. a scan forced from zero found a replica left for the leader. The epoch is not moved + * back; the round ends so that the next range does not report over the lower epoch. + */ + if (min_unagg <= ar->ar_agg_eph) + return EC_AGG_RANGE_HELD; + + return EC_AGG_RANGE_DONE; +} + +#endif /* __SRV_EC_AGG_RANGE_H__ */ diff --git a/src/object/srv_ec_aggregate.c b/src/object/srv_ec_aggregate.c index 6f96ca62313..f9a5dd30548 100644 --- a/src/object/srv_ec_aggregate.c +++ b/src/object/srv_ec_aggregate.c @@ -58,6 +58,7 @@ #include #include "obj_ec.h" #include "srv_internal.h" +#include "srv_ec_agg_range.h" #define EC_AGG_ITERATION_MAX 1024 #define EC_AGG_PROCESS_CREDITS 128 @@ -135,7 +136,7 @@ struct ec_agg_param { struct ec_agg_pool_info ap_pool_info; /* pool/cont info */ struct ec_agg_entry ap_agg_entry; /* entry used for each OID */ daos_epoch_range_t ap_epr; /* hi/lo extent threshold */ - daos_epoch_t ap_filter_eph; /* Aggregatable filter epoch */ + struct ec_agg_range ap_range; /* Epoch range being processed */ daos_epoch_t ap_min_unagg_eph; /* minimum unaggregate epoch */ /* HLC when this aggregation was set up, i.e. not older than any rebuild finished before * the engine started, see agg_stripe_has_newer(). @@ -2667,15 +2668,22 @@ agg_filter(daos_handle_t ih, vos_iter_desc_t *desc, void *cb_arg, unsigned int * } check: - if (desc->id_agg_write <= agg_param->ap_filter_eph) { + /* An object is left out by the epoch of its latest write, a key of an object which passed + * by the write timestamp cache if that can be relied on, see VOS_IT_AGG_LAST_WRITE. + */ + if (desc->id_type == VOS_ITER_OBJ + ? ec_agg_range_skip_obj(&agg_param->ap_range, desc->id_agg_write) + : ec_agg_range_skip_key(&agg_param->ap_range, desc->id_agg_write)) { if (desc->id_type == VOS_ITER_OBJ) - D_DEBUG(DB_EPC, "Skip oid:"DF_UOID" agg_epoch="DF_X64" filter="DF_X64"\n", + D_DEBUG(DB_EPC, + "Skip oid:" DF_UOID " last write=" DF_X64 " filter=" DF_X64 "\n", DP_UOID(desc->id_oid), desc->id_agg_write, - agg_param->ap_filter_eph); + agg_param->ap_range.ar_filter_eph); else - D_DEBUG(DB_EPC, "Skip key:"DF_KEY" agg_epoch="DF_X64" filter="DF_X64"\n", + D_DEBUG(DB_EPC, + "Skip key:" DF_KEY " last write=" DF_X64 " filter=" DF_X64 "\n", DP_KEY(&desc->id_key), desc->id_agg_write, - agg_param->ap_filter_eph); + agg_param->ap_range.ar_filter_eph); agg_param->ap_credits += EC_AGG_FILTER_CREDITS; *acts = VOS_ITER_CB_SKIP; goto done; @@ -2970,7 +2978,8 @@ cont_ec_aggregate_cb(struct ds_cont_child *cont, daos_epoch_range_t *epr, struct dtx_id dti = { 0 }; struct dtx_epoch epoch = { 0 }; daos_unit_oid_t oid = { 0 }; - uint64_t ec_agg_eph; + struct ec_agg_range *range = &ec_agg_param->ap_range; + daos_epoch_t report; int blocks = 0; int rc = 0; @@ -2991,7 +3000,7 @@ cont_ec_aggregate_cb(struct ds_cont_child *cont, daos_epoch_range_t *epr, if (!cont->sc_ec_agg_eph_valid) { D_DEBUG(DB_EPC, DF_CONT ": pause EC aggregation for sc_ec_agg_eph_boundary.\n", DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid)); - return 0; + return ec_agg_range_no_boundary(flags & VOS_AGG_FL_FORCE_SCAN); } if (cont->sc_ec_agg_eph == 0) { @@ -3001,38 +3010,33 @@ cont_ec_aggregate_cb(struct ds_cont_child *cont, daos_epoch_range_t *epr, cont->sc_ec_agg_eph = cont->sc_ec_agg_eph_boundary; } - if (cont->sc_ec_update_timestamp == 0) { - vos_cont_info_t info; - - /* load the timestamp of the last write that can be aggregated from VOS */ - vos_cont_query(ec_agg_param->ap_cont_handle, &info); - cont->sc_ec_update_timestamp = info.ci_agg_write; - } - - ec_agg_eph = cont->sc_ec_agg_eph; + /* The timestamp which VOS stores for the writes which need aggregation is not used: it is + * not maintained for every write, and zero does not mean "nothing to aggregate". + */ ec_agg_param->ap_min_unagg_eph = DAOS_EPOCH_MAX; - if (flags & VOS_AGG_FL_FORCE_SCAN) { - /** We don't want to use the latest container aggregation epoch for the filter - * in this case. We instead use the lower bound of the epoch range. - */ - ec_agg_param->ap_filter_eph = epr->epr_lo; - } else { - ec_agg_param->ap_filter_eph = MAX(epr->epr_lo, cont->sc_ec_agg_eph); - } - - if (ec_agg_param->ap_filter_eph != 0 && - ec_agg_param->ap_filter_eph >= cont->sc_ec_update_timestamp) { + switch (ec_agg_range_begin(range, epr, flags & VOS_AGG_FL_FORCE_SCAN, cont->sc_ec_agg_eph, + cont->sc_pool->spc_map_version, d_hlc_get(), + cont->sc_ec_nontx_timestamp, &cont->sc_ec_update_timestamp)) { + case EC_AGG_RANGE_SKIP: + D_DEBUG(DB_EPC, + DF_CONT " range " DF_X64 "-" DF_X64 " does not continue " DF_X64 "\n", + DP_CONT(cont->sc_pool_uuid, cont->sc_uuid), epr->epr_lo, epr->epr_hi, + cont->sc_ec_agg_eph); + return 0; + case EC_AGG_RANGE_IDLE: D_DEBUG(DB_EPC, DF_CONT " skip EC agg " DF_U64 ">= " DF_U64 "\n", - DP_CONT(cont->sc_pool_uuid, cont->sc_uuid), ec_agg_param->ap_filter_eph, + DP_CONT(cont->sc_pool_uuid, cont->sc_uuid), range->ar_filter_eph, cont->sc_ec_update_timestamp); goto update_hae; + default: + break; } iter_param.ip_hdl = cont->sc_hdl; iter_param.ip_epr.epr_lo = epr->epr_lo; iter_param.ip_epr.epr_hi = epr->epr_hi; iter_param.ip_epc_expr = VOS_IT_EPC_RR; - iter_param.ip_flags = VOS_IT_RECX_VISIBLE | VOS_IT_FOR_AGG; + iter_param.ip_flags = VOS_IT_RECX_VISIBLE | VOS_IT_FOR_AGG | VOS_IT_AGG_LAST_WRITE; iter_param.ip_recx.rx_idx = 0ULL; iter_param.ip_recx.rx_nr = ~PARITY_INDICATOR; iter_param.ip_filter_cb = agg_filter; @@ -3098,32 +3102,35 @@ cont_ec_aggregate_cb(struct ds_cont_child *cont, daos_epoch_range_t *epr, /* If pool map updated during this round of aggregation, the sc_ec_agg_eph * possibly be reset by ds_cont_child_reset_ec_agg_eph_all(). * For that case should not bump local sc_ec_agg_eph and rescan from the reset - * value (sc_ec_agg_eph_boundary). + * value (sc_ec_agg_eph_boundary): end the round, the next one selects its ranges + * by the new epoch. */ - if (cont->sc_ec_agg_eph != ec_agg_eph) { - D_INFO(DF_CONT " sc_ec_agg_eph changed from " DF_X64 " to " DF_X64 - " don't bump EC aggregation epoch", - DP_CONT(cont->sc_pool_uuid, cont->sc_uuid), ec_agg_eph, - cont->sc_ec_agg_eph); + rc = + ec_agg_range_end(range, cont->sc_pool->spc_map_version, + ec_agg_param->ap_min_unagg_eph, &cont->sc_ec_agg_eph, &report); + if (rc == EC_AGG_RANGE_VOID) { + D_INFO( + DF_CONT " sc_ec_agg_eph " DF_X64 " -> " DF_X64 ", map version %u -> %u," + " don't bump EC aggregation epoch", + DP_CONT(cont->sc_pool_uuid, cont->sc_uuid), range->ar_agg_eph, + cont->sc_ec_agg_eph, range->ar_map_ver, cont->sc_pool->spc_map_version); return rc; } - /* rescan replicas left for the leader so they keep holding back the boundary */ - cont->sc_ec_agg_eph = - max(cont->sc_ec_agg_eph, min(epr->epr_hi, ec_agg_param->ap_min_unagg_eph - 1)); if (!cont->sc_stopping && cont->sc_query_ec_agg_eph) { - uint64_t orig, cur, cur_eph; + uint64_t orig, cur; - cur_eph = min(ec_agg_param->ap_min_unagg_eph, cont->sc_ec_agg_eph); orig = d_hlc2sec(*cont->sc_query_ec_agg_eph); - cur = d_hlc2sec(cur_eph); - if (orig && cur > orig && (cur - orig) >= 600) + cur = d_hlc2sec(report); + /* a forced scan reports its ranges one by one, from the snapshots */ + if (orig && cur > orig && (cur - orig) >= 600 && + !(flags & VOS_AGG_FL_FORCE_SCAN)) D_WARN(DF_CONT" Sluggish EC boundary bumping: " ""DF_U64" -> "DF_U64", gap:"DF_U64"\n", DP_CONT(cont->sc_pool_uuid, cont->sc_uuid), orig, cur, cur - orig); - *cont->sc_query_ec_agg_eph = cur_eph; + *cont->sc_query_ec_agg_eph = report; } } diff --git a/src/object/srv_obj_migrate.c b/src/object/srv_obj_migrate.c index 89c5b6d8e8b..dac71623137 100644 --- a/src/object/srv_obj_migrate.c +++ b/src/object/srv_obj_migrate.c @@ -1960,6 +1960,7 @@ migrate_dkey(struct migrate_pool_tls *tls, struct migrate_one *mrone, { struct ds_cont_child *cont = NULL; daos_handle_t oh = DAOS_HDL_INVAL; + bool ec_touched = false; int rc; D_ASSERT(dss_get_module_info()->dmi_xs_id != 0); @@ -1982,6 +1983,11 @@ migrate_dkey(struct migrate_pool_tls *tls, struct migrate_one *mrone, D_GOTO(out, rc); } + /* From here on the EC object can be modified, with or without error. These writes have + * no DTX and are not from a client, so nothing else tells EC aggregation to scan. + */ + ec_touched = daos_oclass_is_ec(&mrone->mo_oca); + /* punch the object */ if (mrone->mo_obj_punch_eph) { rc = vos_obj_punch(cont->sc_hdl, mrone->mo_oid, @@ -2023,8 +2029,11 @@ migrate_dkey(struct migrate_pool_tls *tls, struct migrate_one *mrone, tls->mpt_size += mrone->mo_size; out: - if (cont != NULL) + if (cont != NULL) { + if (ec_touched) + ds_cont_ec_nontx_timestamp_update(cont); ds_cont_child_put(cont); + } return rc; } diff --git a/src/object/tests/SConscript b/src/object/tests/SConscript index 56fc8a015d0..9cd9a6c0ace 100644 --- a/src/object/tests/SConscript +++ b/src/object/tests/SConscript @@ -16,6 +16,8 @@ def scons(): LIBS=['daos_common_pmem', 'gurt', 'cmocka', 'vos', 'bio', 'ssl', 'abt']) + unit_env.d_test_program(['srv_ec_agg_tests.c'], LIBS=['cmocka']) + unit_env.d_test_program(['cli_checksum_tests.c', '../cli_csum.c', '../../common/tests_lib.c'], diff --git a/src/object/tests/srv_ec_agg_tests.c b/src/object/tests/srv_ec_agg_tests.c new file mode 100644 index 00000000000..392cdcf4036 --- /dev/null +++ b/src/object/tests/srv_ec_agg_tests.c @@ -0,0 +1,473 @@ +/* + * (C) Copyright 2026 Hewlett Packard Enterprise Development LP + * + * SPDX-License-Identifier: BSD-2-Clause-Patent + */ + +/** + * How EC aggregation goes over the epoch ranges of a round, see src/object/srv_ec_agg_range.h. + */ +#include +#include +#include +#include +#include +#include +#include + +#include "../srv_ec_agg_range.h" + +/** What cont_ec_aggregate_cb() works on: a container shard, and the scan of one range. */ +struct shard { + daos_epoch_t sh_agg_eph; /* sc_ec_agg_eph */ + daos_epoch_t sh_report; /* *sc_query_ec_agg_eph */ + daos_epoch_t sh_update_ts; /* sc_ec_update_timestamp */ + uint32_t sh_map_ver; /* spc_map_version */ + bool sh_valid; /* sc_ec_agg_eph_valid */ + /* the scan */ + int sh_scans; /* ranges which were iterated */ + daos_epoch_t sh_min_unagg; /* lowest epoch the scan has to visit again */ + int sh_busy; /* attempts which hit a conflict, the scan yields and retries */ + /* a pool map update while the scan yields */ + bool sh_map_update; + daos_epoch_t sh_boundary; /* sc_ec_agg_eph_boundary */ + daos_epoch_t sh_filter; /* filter of the last range which was iterated */ +}; + +/** update_child_map(): reset to the boundary, new map version */ +static void +map_update(struct shard *sh) +{ + sh->sh_agg_eph = sh->sh_boundary; + sh->sh_map_ver++; +} + +/** One call of cont_ec_aggregate_cb(), with the same order of the steps. */ +static int +range_cb(struct shard *sh, daos_epoch_t lo, daos_epoch_t hi, bool force_scan, daos_epoch_t now) +{ + struct ec_agg_range ar; + daos_epoch_range_t epr = {.epr_lo = lo, .epr_hi = hi}; + daos_epoch_t min_unagg = DAOS_EPOCH_MAX; + daos_epoch_t report; + int attempt; + int rc; + + if (!sh->sh_valid) + return ec_agg_range_no_boundary(force_scan); + + switch (ec_agg_range_begin(&ar, &epr, force_scan, sh->sh_agg_eph, sh->sh_map_ver, now, 0, + &sh->sh_update_ts)) { + case EC_AGG_RANGE_SKIP: + return 0; + case EC_AGG_RANGE_IDLE: + break; + default: + sh->sh_scans++; + sh->sh_filter = ar.ar_filter_eph; + /* retry: the range is not started again */ + for (attempt = 0; attempt <= sh->sh_busy; attempt++) { + if (sh->sh_map_update && attempt == 0) + map_update(sh); + } + min_unagg = sh->sh_min_unagg; + break; + } + + rc = ec_agg_range_end(&ar, sh->sh_map_ver, min_unagg, &sh->sh_agg_eph, &report); + if (rc != EC_AGG_RANGE_VOID) + sh->sh_report = report; + return rc; +} + +static void +shard_init(struct shard *sh, daos_epoch_t agg_eph, daos_epoch_t update_ts) +{ + memset(sh, 0, sizeof(*sh)); + sh->sh_agg_eph = agg_eph; + sh->sh_boundary = agg_eph; + sh->sh_report = agg_eph; + sh->sh_update_ts = update_ts; + sh->sh_map_ver = 5; + sh->sh_valid = true; + sh->sh_min_unagg = DAOS_EPOCH_MAX; +} + +/* After a restart nothing is known about the last update: what was written before the first round + * must be scanned, whatever the upper bound of the first range is. + */ +static void +restart_scans_until_epoch_passes(void **state) +{ + struct shard sh; + + shard_init(&sh, 100, 0); + + /* first round at 500: a write at 490 is above the upper bound of the range */ + assert_int_equal(range_cb(&sh, 0, 480, false, 500), 0); + assert_int_equal(sh.sh_scans, 1); + assert_int_equal(sh.sh_update_ts, 500); + assert_int_equal(sh.sh_agg_eph, 480); + + /* so the next round is not idle */ + assert_int_equal(range_cb(&sh, 0, 520, false, 540), 0); + assert_int_equal(sh.sh_scans, 2); + assert_int_equal(sh.sh_agg_eph, 520); + + /* the epoch passed the restart, idle from now on */ + assert_int_equal(range_cb(&sh, 0, 560, false, 580), 0); + assert_int_equal(sh.sh_scans, 2); + assert_int_equal(sh.sh_agg_eph, 560); + assert_int_equal(sh.sh_report, 560); +} + +/* Neither range is iterated and both return 0, but only the one which continues the aggregation + * epoch is done. + */ +static void +idle_range_vs_tail_range(void **state) +{ + struct shard sh; + + shard_init(&sh, 100, 90); + assert_int_equal(range_cb(&sh, 101, 150, false, 200), 0); + assert_int_equal(sh.sh_scans, 0); + assert_int_equal(sh.sh_agg_eph, 150); + assert_int_equal(sh.sh_report, 150); + + shard_init(&sh, 100, 90); + assert_int_equal(range_cb(&sh, 102, 150, false, 200), 0); + assert_int_equal(sh.sh_scans, 0); + assert_int_equal(sh.sh_agg_eph, 100); + assert_int_equal(sh.sh_report, 100); +} + +/* Snapshot at 200. The first range leaves a replica of epoch 150 for the leader, the range after + * the snapshot must not move the epoch over it. It is not an error, and a later round goes on. + */ +static void +tail_range_after_incomplete_range(void **state) +{ + struct shard sh; + + shard_init(&sh, 100, 300); + sh.sh_min_unagg = 150; + assert_int_equal(range_cb(&sh, 0, 200, false, 420), 0); + assert_int_equal(sh.sh_scans, 1); + assert_int_equal(sh.sh_agg_eph, 149); + assert_int_equal(sh.sh_report, 149); + + assert_int_equal(range_cb(&sh, 201, 400, false, 420), 0); + assert_int_equal(sh.sh_scans, 1); + assert_int_equal(sh.sh_agg_eph, 149); + assert_int_equal(sh.sh_report, 149); + + /* the leader aggregated the replica */ + sh.sh_min_unagg = DAOS_EPOCH_MAX; + assert_int_equal(range_cb(&sh, 0, 200, false, 460), 0); + assert_int_equal(sh.sh_agg_eph, 200); + assert_int_equal(range_cb(&sh, 201, 440, false, 460), 0); + assert_int_equal(sh.sh_scans, 3); + assert_int_equal(sh.sh_agg_eph, 440); + assert_int_equal(sh.sh_report, 440); +} + +/* Snapshot at 200, the aggregation epoch is at 300 already. A scan forced from zero, after another + * snapshot was deleted, finds a replica of epoch 150 which is left for the leader. The epoch is not + * moved back, but 149 is reported and the round ends: the range after the snapshot would report + * 400. The forced scan is not done, so the next round visits the replica again. + */ +static void +forced_scan_finds_older_replica(void **state) +{ + struct shard sh; + + shard_init(&sh, 300, 350); + sh.sh_min_unagg = 150; + assert_int_equal(range_cb(&sh, 0, 200, true, 420), EC_AGG_RANGE_HELD); + assert_int_equal(sh.sh_scans, 1); + assert_int_equal(sh.sh_agg_eph, 300); + assert_int_equal(sh.sh_report, 149); + + /* next round, the same */ + assert_int_equal(range_cb(&sh, 0, 200, true, 460), EC_AGG_RANGE_HELD); + assert_int_equal(sh.sh_scans, 2); + assert_int_equal(sh.sh_report, 149); + + /* the leader aggregated the replica: the forced scan goes over both ranges */ + sh.sh_min_unagg = DAOS_EPOCH_MAX; + assert_int_equal(range_cb(&sh, 0, 200, true, 500), EC_AGG_RANGE_DONE); + assert_int_equal(sh.sh_agg_eph, 300); + assert_int_equal(sh.sh_report, 200); + assert_int_equal(range_cb(&sh, 201, 480, true, 500), EC_AGG_RANGE_DONE); + assert_int_equal(sh.sh_agg_eph, 480); + assert_int_equal(sh.sh_report, 480); + + /* the same if the replica is right at the aggregation epoch */ + shard_init(&sh, 150, 350); + sh.sh_min_unagg = 150; + assert_int_equal(range_cb(&sh, 0, 200, true, 420), EC_AGG_RANGE_HELD); + assert_int_equal(sh.sh_agg_eph, 150); + assert_int_equal(sh.sh_report, 149); + /* and for an incremental scan */ + shard_init(&sh, 150, 350); + sh.sh_min_unagg = 150; + assert_int_equal(range_cb(&sh, 0, 200, false, 420), EC_AGG_RANGE_HELD); + assert_int_equal(sh.sh_report, 149); + + /* a replica above the aggregation epoch holds it back as before, the range is done */ + shard_init(&sh, 100, 350); + sh.sh_min_unagg = 150; + assert_int_equal(range_cb(&sh, 0, 200, true, 420), EC_AGG_RANGE_DONE); + assert_int_equal(sh.sh_agg_eph, 149); + assert_int_equal(sh.sh_report, 149); +} + +/* Snapshots at 100 and 200, the aggregation epoch is at 300, a replica of epoch 150 is left for the + * leader. The forced scan is retried from zero by every round: its first range has nothing to be + * visited again, but it must not report the aggregation epoch, over the replica which the second + * range is going to find again. + */ +static void +forced_scan_retried(void **state) +{ + struct shard sh; + int round; + + shard_init(&sh, 300, 350); + for (round = 0; round < 2; round++) { + sh.sh_min_unagg = DAOS_EPOCH_MAX; + assert_int_equal(range_cb(&sh, 0, 100, true, 420), EC_AGG_RANGE_DONE); + assert_int_equal(sh.sh_agg_eph, 300); + assert_int_equal(sh.sh_report, 100); + + sh.sh_min_unagg = 150; + assert_int_equal(range_cb(&sh, 101, 200, true, 420), EC_AGG_RANGE_HELD); + assert_int_equal(sh.sh_agg_eph, 300); + assert_int_equal(sh.sh_report, 149); + } + + /* the leader aggregated the replica */ + sh.sh_min_unagg = DAOS_EPOCH_MAX; + assert_int_equal(range_cb(&sh, 0, 100, true, 500), EC_AGG_RANGE_DONE); + assert_int_equal(sh.sh_report, 100); + assert_int_equal(range_cb(&sh, 101, 200, true, 500), EC_AGG_RANGE_DONE); + assert_int_equal(sh.sh_report, 200); + assert_int_equal(range_cb(&sh, 201, 480, true, 500), EC_AGG_RANGE_DONE); + assert_int_equal(sh.sh_agg_eph, 480); + assert_int_equal(sh.sh_report, 480); + + /* an incremental scan reports the aggregation epoch as before */ + shard_init(&sh, 300, 350); + assert_int_equal(range_cb(&sh, 201, 480, false, 500), EC_AGG_RANGE_DONE); + assert_int_equal(sh.sh_agg_eph, 480); + assert_int_equal(sh.sh_report, 480); +} + +/* A pool map update during the scan, the aggregation epoch was at the boundary already so its + * value is the same after the reset. The range is void, the round ends without error. + */ +static void +map_update_same_epoch(void **state) +{ + struct shard sh; + int force; + + for (force = 0; force < 2; force++) { + shard_init(&sh, 100, 300); + sh.sh_map_update = true; + assert_int_equal(range_cb(&sh, 0, 200, force, 420), 1); + assert_int_equal(sh.sh_scans, 1); + assert_int_equal(sh.sh_map_ver, 6); + assert_int_equal(sh.sh_agg_eph, 100); + assert_int_equal(sh.sh_report, 100); + } + + /* the reset changed the value */ + shard_init(&sh, 100, 300); + sh.sh_boundary = 50; + sh.sh_map_update = true; + assert_int_equal(range_cb(&sh, 0, 200, false, 420), 1); + assert_int_equal(sh.sh_agg_eph, 50); + assert_int_equal(sh.sh_report, 100); +} + +/* The first attempt of the scan hits a conflict and yields, the pool map is updated meanwhile, the + * retry goes on from where the scan was and succeeds: still void. + */ +static void +map_update_during_busy_retry(void **state) +{ + struct shard sh; + + shard_init(&sh, 100, 300); + sh.sh_busy = 1; + sh.sh_map_update = true; + assert_int_equal(range_cb(&sh, 0, 200, false, 420), 1); + assert_int_equal(sh.sh_agg_eph, 100); + assert_int_equal(sh.sh_report, 100); + + /* a retry alone is fine */ + shard_init(&sh, 100, 300); + sh.sh_busy = 1; + assert_int_equal(range_cb(&sh, 0, 200, false, 420), 0); + assert_int_equal(sh.sh_agg_eph, 200); + assert_int_equal(sh.sh_report, 200); +} + +/* Nothing can be scanned before the boundary is known. A forced scan is not done then. */ +static void +no_boundary(void **state) +{ + struct shard sh; + + shard_init(&sh, 100, 300); + sh.sh_valid = false; + assert_int_equal(range_cb(&sh, 0, 200, true, 420), 1); + assert_int_equal(range_cb(&sh, 0, 200, false, 420), 0); + assert_int_equal(sh.sh_scans, 0); + assert_int_equal(sh.sh_agg_eph, 100); + assert_int_equal(sh.sh_report, 100); + assert_int_equal(sh.sh_update_ts, 300); +} + +/* Which objects a range leaves out, by the epoch of their latest write. */ +static void +object_filter(void **state) +{ + struct ec_agg_range ar; + daos_epoch_range_t epr = {.epr_lo = 0, .epr_hi = 150}; + daos_epoch_t ts = 300; + + /* incremental scan: everything at or below the aggregation epoch was processed */ + assert_int_equal(ec_agg_range_begin(&ar, &epr, false, 100, 5, 420, 0, &ts), + EC_AGG_RANGE_SCAN); + assert_true(ec_agg_range_skip_obj(&ar, 100)); + assert_false(ec_agg_range_skip_obj(&ar, 101)); + /* not known */ + assert_false(ec_agg_range_skip_obj(&ar, 0)); + assert_false(ec_agg_range_skip_obj(&ar, DAOS_EPOCH_MAX)); + + /* same if the range starts right above the aggregation epoch, i.e. after a snapshot */ + epr.epr_lo = 101; + assert_int_equal(ec_agg_range_begin(&ar, &epr, false, 100, 5, 420, 0, &ts), + EC_AGG_RANGE_SCAN); + assert_true(ec_agg_range_skip_obj(&ar, 100)); + assert_false(ec_agg_range_skip_obj(&ar, 101)); + + /* forced scan: the aggregation epoch does not count, the lower bound is inclusive */ + assert_int_equal(ec_agg_range_begin(&ar, &epr, true, 200, 5, 420, 0, &ts), + EC_AGG_RANGE_SCAN); + assert_true(ec_agg_range_skip_obj(&ar, 100)); + assert_false(ec_agg_range_skip_obj(&ar, 101)); + assert_false(ec_agg_range_skip_obj(&ar, 150)); + + epr.epr_lo = 0; + assert_int_equal(ec_agg_range_begin(&ar, &epr, true, 200, 5, 420, 0, &ts), + EC_AGG_RANGE_SCAN); + assert_false(ec_agg_range_skip_obj(&ar, 1)); +} + +/* Which keys of an object which passed a range leaves out, by the write timestamp cache. */ +static void +key_filter(void **state) +{ + struct ec_agg_range ar; + daos_epoch_range_t epr = {.epr_lo = 0, .epr_hi = 150}; + daos_epoch_t ts = 300; + + /* no write without DTX since the container child was created at 50, which the aggregation + * epoch passed: as for an object, but for a miss of the cache + */ + assert_int_equal(ec_agg_range_begin(&ar, &epr, false, 100, 5, 420, 50, &ts), + EC_AGG_RANGE_SCAN); + assert_true(ec_agg_range_skip_key(&ar, 100)); + assert_false(ec_agg_range_skip_key(&ar, 101)); + assert_false(ec_agg_range_skip_key(&ar, DAOS_EPOCH_MAX)); + + /* The container child was created at 110, the aggregation epoch did not reach it. The cache + * is of the xstream and can be older than the child: an entry for a write before a + * migration which the child does not know about. + */ + assert_int_equal(ec_agg_range_begin(&ar, &epr, false, 100, 5, 420, 110, &ts), + EC_AGG_RANGE_SCAN); + assert_false(ec_agg_range_skip_key(&ar, 90)); + /* not known at all */ + assert_int_equal(ec_agg_range_begin(&ar, &epr, false, 100, 5, 420, 0, &ts), + EC_AGG_RANGE_SCAN); + assert_false(ec_agg_range_skip_key(&ar, 90)); + + /* a migration wrote at 110, above the aggregation epoch: the cache may have an older write + * for the key of what was migrated + */ + assert_int_equal(ec_agg_range_begin(&ar, &epr, false, 100, 5, 420, 110, &ts), + EC_AGG_RANGE_SCAN); + assert_false(ec_agg_range_skip_key(&ar, 90)); + assert_false(ec_agg_range_skip_key(&ar, 100)); + /* the object filter does not depend on it */ + assert_true(ec_agg_range_skip_obj(&ar, 100)); + + /* the aggregation epoch reached it: everything written by then was visited */ + assert_int_equal(ec_agg_range_begin(&ar, &epr, false, 110, 5, 420, 110, &ts), + EC_AGG_RANGE_SCAN); + assert_true(ec_agg_range_skip_key(&ar, 90)); + assert_true(ec_agg_range_skip_key(&ar, 110)); + assert_false(ec_agg_range_skip_key(&ar, 111)); + + /* forced scan: by the lower bound of the range, which is inclusive */ + epr.epr_lo = 101; + assert_int_equal(ec_agg_range_begin(&ar, &epr, true, 200, 5, 420, 50, &ts), + EC_AGG_RANGE_SCAN); + assert_true(ec_agg_range_skip_key(&ar, 100)); + assert_false(ec_agg_range_skip_key(&ar, 101)); + assert_int_equal(ec_agg_range_begin(&ar, &epr, true, 200, 5, 420, 110, &ts), + EC_AGG_RANGE_SCAN); + assert_false(ec_agg_range_skip_key(&ar, 100)); + + /* a range which is left to a later round */ + epr.epr_lo = 102; + assert_int_equal(ec_agg_range_begin(&ar, &epr, false, 100, 5, 420, 50, &ts), + EC_AGG_RANGE_SKIP); + assert_false(ec_agg_range_skip_key(&ar, 90)); +} + +/* A forced scan of a range in which nothing was written is idle, and is done. It does not move + * the aggregation epoch back. + */ +static void +forced_scan_idle(void **state) +{ + struct shard sh; + + shard_init(&sh, 300, 90); + assert_int_equal(range_cb(&sh, 101, 150, true, 420), 0); + assert_int_equal(sh.sh_scans, 0); + assert_int_equal(sh.sh_agg_eph, 300); + + /* written at the lower bound: not idle */ + shard_init(&sh, 300, 101); + assert_int_equal(range_cb(&sh, 101, 150, true, 420), 0); + assert_int_equal(sh.sh_scans, 1); + assert_int_equal(sh.sh_filter, 100); + assert_int_equal(sh.sh_agg_eph, 300); +} + +int +main(int argc, char **argv) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(restart_scans_until_epoch_passes), + cmocka_unit_test(idle_range_vs_tail_range), + cmocka_unit_test(tail_range_after_incomplete_range), + cmocka_unit_test(forced_scan_finds_older_replica), + cmocka_unit_test(forced_scan_retried), + cmocka_unit_test(map_update_same_epoch), + cmocka_unit_test(map_update_during_busy_retry), + cmocka_unit_test(no_boundary), + cmocka_unit_test(object_filter), + cmocka_unit_test(key_filter), + cmocka_unit_test(forced_scan_idle), + }; + + return cmocka_run_group_tests_name("EC aggregation epoch ranges", tests, NULL, NULL); +} diff --git a/src/vos/tests/vts_io.c b/src/vos/tests/vts_io.c index fdad31e03bb..a569f2864e2 100644 --- a/src/vos/tests/vts_io.c +++ b/src/vos/tests/vts_io.c @@ -1,6 +1,6 @@ /** * (C) Copyright 2016-2024 Intel Corporation. - * (C) Copyright 2025 Hewlett Packard Enterprise Development LP + * (C) Copyright 2025-2026 Hewlett Packard Enterprise Development LP * * SPDX-License-Identifier: BSD-2-Clause-Patent */ @@ -3057,6 +3057,168 @@ static const struct CMUnitTest iterator_tests[] = { NULL}, }; +/** What the filter callback is given as id_agg_write, per level. */ +struct agg_write_info { + daos_epoch_t awi_obj; + daos_epoch_t awi_dkey; + daos_epoch_t awi_akey; +}; + +static int +agg_write_filter_cb(daos_handle_t ih, vos_iter_desc_t *desc, void *cb_arg, unsigned int *acts) +{ + struct agg_write_info *info = cb_arg; + + switch (desc->id_type) { + case VOS_ITER_OBJ: + info->awi_obj = desc->id_agg_write; + break; + case VOS_ITER_DKEY: + info->awi_dkey = desc->id_agg_write; + break; + case VOS_ITER_AKEY: + info->awi_akey = desc->id_agg_write; + break; + default: + break; + } + return 0; +} + +static int +agg_write_pre_cb(daos_handle_t ih, vos_iter_entry_t *entry, vos_iter_type_t type, + vos_iter_param_t *param, void *cb_arg, unsigned int *acts) +{ + return 0; +} + +static void +agg_write_iterate(struct io_test_args *arg, uint32_t flags, struct agg_write_info *info) +{ + vos_iter_param_t param = {0}; + struct vos_iter_anchors anchors = {0}; + int rc; + + memset(info, 0, sizeof(*info)); + param.ip_hdl = arg->ctx.tc_co_hdl; + param.ip_flags = VOS_IT_RECX_VISIBLE | flags; + param.ip_epc_expr = VOS_IT_EPC_RR; + param.ip_ih = DAOS_HDL_INVAL; + param.ip_epr.epr_hi = DAOS_EPOCH_MAX; + param.ip_filter_cb = agg_write_filter_cb; + param.ip_filter_arg = info; + rc = vos_iterate(¶m, VOS_ITER_OBJ, true, &anchors, agg_write_pre_cb, NULL, info, NULL); + assert_rc_equal(rc, 0); +} + +/* With VOS_IT_AGG_LAST_WRITE the filter callback gets the epoch of the latest write of the object, + * and what the write timestamp cache has for a key, rather than the timestamp of the last write + * which needs aggregation: that one is not updated by every write. + */ +static void +iter_agg_last_write_test(void **state) +{ + struct io_test_args *arg = *state; + struct agg_write_info info; + struct vos_obj_df *obj_df; + struct dtx_handle *dth; + daos_epoch_t tx_epoch; + daos_key_t dkey; + daos_iod_t iod = {0}; + daos_recx_t recx; + d_sg_list_t sgl; + d_iov_t val_iov; + char buf[16]; + char dkey_buf[UPDATE_DKEY_SIZE]; + char akey_buf[UPDATE_AKEY_SIZE]; + unsigned long old_flags = arg->ta_flags; + int rc; + + arg->ta_flags = 0; + test_args_reset(arg, VPOOL_SIZE, 0, VPOOL_SIZE, 0); + /* have the timestamp of the writes which need aggregation recorded */ + vos_hdl2pool(arg->ctx.tc_po_hdl)->vp_feats |= VOS_POOL_FEAT_AGG_OPT; + + arg->oid = gen_oid(arg->otype); + vts_key_gen(&dkey_buf[0], arg->dkey_size, true, arg); + set_iov(&dkey, &dkey_buf[0], is_daos_obj_type_set(arg->otype, DAOS_OT_DKEY_UINT64)); + vts_key_gen(&akey_buf[0], arg->akey_size, false, arg); + set_iov(&iod.iod_name, &akey_buf[0], is_daos_obj_type_set(arg->otype, DAOS_OT_AKEY_UINT64)); + iod.iod_type = DAOS_IOD_ARRAY; + iod.iod_size = 1; + iod.iod_nr = 1; + iod.iod_recxs = &recx; + memset(buf, 'x', sizeof(buf)); + d_iov_set(&val_iov, buf, sizeof(buf)); + sgl.sg_nr = 1; + sgl.sg_nr_out = 0; + sgl.sg_iovs = &val_iov; + + /* an overwrite needs aggregation */ + recx.rx_idx = 0; + recx.rx_nr = sizeof(buf); + rc = io_test_obj_update(arg, 10, 0, &dkey, &iod, &sgl, NULL, true); + assert_rc_equal(rc, 0); + rc = io_test_obj_update(arg, 20, 0, &dkey, &iod, &sgl, NULL, true); + assert_rc_equal(rc, 0); + /* an extent which is neither overlapped nor adjacent does not */ + recx.rx_idx = 1000; + rc = io_test_obj_update(arg, 30, 0, &dkey, &iod, &sgl, NULL, true); + assert_rc_equal(rc, 0); + + agg_write_iterate(arg, 0, &info); + assert_int_equal(info.awi_obj, 20); + assert_int_equal(info.awi_dkey, 20); + assert_int_equal(info.awi_akey, 20); + + agg_write_iterate(arg, VOS_IT_AGG_LAST_WRITE, &info); + assert_int_equal(info.awi_obj, 30); + assert_true(info.awi_dkey == DAOS_EPOCH_MAX); + assert_true(info.awi_akey == DAOS_EPOCH_MAX); + + /* A write with DTX is seen by the write timestamp cache of the keys. Its epoch has to be + * above the bound of the container, which is the HLC of the open. + */ + tx_epoch = d_hlc_get(); + arg->ta_flags = TF_ZERO_COPY; + recx.rx_idx = 2000; + vts_dtx_begin(&arg->oid, arg->ctx.tc_co_hdl, tx_epoch, 0, &dth); + rc = io_test_obj_update(arg, tx_epoch, 0, &dkey, &iod, &sgl, dth, true); + assert_rc_equal(rc, 0); + vts_dtx_end(dth); + arg->ta_flags = 0; + agg_write_iterate(arg, VOS_IT_AGG_LAST_WRITE, &info); + assert_true(info.awi_obj == tx_epoch); + assert_true(info.awi_dkey == tx_epoch); + assert_true(info.awi_akey == tx_epoch); + + /* A later one without DTX, as of migration, is not: the keys still report the write + * before it, only the object tells. The caller has to know about such writes. + */ + recx.rx_idx = 3000; + rc = io_test_obj_update(arg, tx_epoch + 1, 0, &dkey, &iod, &sgl, NULL, true); + assert_rc_equal(rc, 0); + agg_write_iterate(arg, VOS_IT_AGG_LAST_WRITE, &info); + assert_true(info.awi_obj == tx_epoch + 1); + assert_true(info.awi_dkey == tx_epoch); + assert_true(info.awi_akey == tx_epoch); + + /* the stored timestamp is still what the iterator gives without the flag */ + agg_write_iterate(arg, 0, &info); + assert_int_equal(info.awi_obj, 20); + assert_int_equal(info.awi_akey, 20); + + /* the epoch of the latest write of the object is not known */ + rc = vos_oi_find(vos_hdl2cont(arg->ctx.tc_co_hdl), arg->oid, &obj_df, NULL); + assert_rc_equal(rc, 0); + obj_df->vo_max_write = 0; + agg_write_iterate(arg, VOS_IT_AGG_LAST_WRITE, &info); + assert_true(info.awi_obj == DAOS_EPOCH_MAX); + obj_df->vo_max_write = tx_epoch + 1; + + arg->ta_flags = old_flags; +} + static const struct CMUnitTest io_tests[] = { {"VOS203: Simple update/fetch/verify test", io_simple_one_key, NULL, NULL}, {"VOS204: Simple Punch test", io_simple_punch, NULL, NULL}, @@ -3070,6 +3232,7 @@ static const struct CMUnitTest io_tests[] = { {"VOS245.1: Object iter test with anchor (for oid)", oid_iter_test_with_anchor, oid_iter_test_setup, NULL}, {"VOS250.0: vos_iterate tests - Check single callback", vos_iterate_test, NULL, NULL}, + {"VOS250.1: vos_iterate with VOS_IT_AGG_LAST_WRITE", iter_agg_last_write_test, NULL, NULL}, {"VOS280: Same Obj ID on two containers (obj_cache test)", io_simple_one_key_cross_container, NULL, NULL}, {"VOS281.0: Fetch from non existent object", io_fetch_no_exist_object, NULL, NULL}, diff --git a/src/vos/vos_obj.c b/src/vos/vos_obj.c index 70f13c85b90..0138d2a25a6 100644 --- a/src/vos/vos_obj.c +++ b/src/vos/vos_obj.c @@ -1119,7 +1119,8 @@ key_iter_fetch(struct vos_obj_iter *oiter, vos_iter_entry_t *ent, feats = dbtree_feats_get(&krec->kr_btr); else feats = evt_feats_get(&krec->kr_evt); - if (!vos_feats_agg_time_get(feats, &desc.id_agg_write)) { + if ((oiter->it_flags & VOS_IT_AGG_LAST_WRITE) || + !vos_feats_agg_time_get(feats, &desc.id_agg_write)) { if (desc.id_type == VOS_ITER_DKEY) ts_type = VOS_TS_TYPE_DKEY; else diff --git a/src/vos/vos_obj_index.c b/src/vos/vos_obj_index.c index 328dc77fdf4..f1c95afb6be 100644 --- a/src/vos/vos_obj_index.c +++ b/src/vos/vos_obj_index.c @@ -670,7 +670,10 @@ oi_iter_match_probe(struct vos_iterator *iter, daos_anchor_t *anchor, uint32_t f feats = dbtree_feats_get(&obj->vo_tree); - if (!vos_feats_agg_time_get(feats, &desc.id_agg_write)) { + if (oiter->oit_flags & VOS_IT_AGG_LAST_WRITE) { + desc.id_agg_write = + obj->vo_max_write != 0 ? obj->vo_max_write : DAOS_EPOCH_MAX; + } else if (!vos_feats_agg_time_get(feats, &desc.id_agg_write)) { /* Upgrading case, set it to latest known epoch */ if (obj->vo_max_write == 0) vos_ilog_last_update(&obj->vo_ilog, VOS_TS_TYPE_OBJ, diff --git a/utils/utest.yaml b/utils/utest.yaml index 71ff3461d47..e7375d32e1b 100644 --- a/utils/utest.yaml +++ b/utils/utest.yaml @@ -155,6 +155,7 @@ - cmd: ["src/vos/tests/pool_scrubbing_tests"] - cmd: ["src/object/tests/srv_checksum_tests"] - cmd: ["src/object/tests/cli_checksum_tests"] + - cmd: ["src/object/tests/srv_ec_agg_tests"] - name: bio base: "BUILD_DIR" tests: