Skip to content

Commit

Permalink
DAOS-6632 obj: add support for hints on the oclass generate API
Browse files Browse the repository at this point in the history
- choose oclass based on set redundancy and redundance factor of container.
- adjust oclass if shard sizing is indicated in hint, otherwise use
  max sharding.

Signed-off-by: Mohamad Chaarawi <mohamad.chaarawi@intel.com>
  • Loading branch information
mchaarawi committed Mar 5, 2021
1 parent 79e895a commit b5e2b50
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/include/daos_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ daos_obj_generate_id(daos_obj_id_t *oid, daos_ofeat_t ofeats,
oid->hi |= hdr;
}

#define DAOS_OC_RDD_BITS 4
#define DAOS_OC_SHD_BITS 6
#define DAOS_OC_RDD_SHIFT 0
#define DAOS_OC_SHD_SHIFT DAOS_OC_RDD_BITS
#define DAOS_OC_RDD_MAX_VAL ((1ULL << DAOS_OC_RDD_BITS) - 1)
#define DAOS_OC_SHD_MAX_VAL ((1ULL << DAOS_OC_SHD_BITS) - 1)
#define DAOS_OC_RDD_MASK (DAOS_OC_RDD_MAX_VAL << DAOS_OC_RDD_SHIFT)
#define DAOS_OC_SHD_MASK (DAOS_OC_SHD_MAX_VAL << DAOS_OC_SHD_SHIFT)

/** Flags for oclass hints */
enum {
/** Flags to control OC Redundancy */
Expand Down
13 changes: 7 additions & 6 deletions src/object/cli_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -5402,10 +5402,6 @@ daos_obj_generate_oid(daos_handle_t coh, daos_obj_id_t *oid,
struct pl_map_attr attr;
int rc;

/** TODO - unsupported for now */
if (cid == OC_UNKNOWN)
return -DER_INVAL;

/** select the oclass */
poh = dc_cont_hdl2pool_hdl(coh);
if (daos_handle_is_inval(poh))
Expand All @@ -5421,8 +5417,13 @@ daos_obj_generate_oid(daos_handle_t coh, daos_obj_id_t *oid,
D_DEBUG(DB_TRACE, "available domain=%d, targets=%d\n",
attr.pa_domain_nr, attr.pa_target_nr);

rc = daos_oclass_fit_max(cid, attr.pa_domain_nr, attr.pa_target_nr,
&cid);
/** TODO - unsupported for now */
if (cid == OC_UNKNOWN)
rc = dc_set_oclass(coh, attr.pa_domain_nr, attr.pa_target_nr,
ofeats, hints, &cid);
else
rc = daos_oclass_fit_max(cid, attr.pa_domain_nr,
attr.pa_target_nr, &cid);
if (rc)
return rc;

Expand Down
113 changes: 113 additions & 0 deletions src/object/obj_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,119 @@ daos_oclass_fit_max(daos_oclass_id_t oc_id, int domain_nr, int target_nr,
return oc ? 0 : -DER_NONEXIST;
}

int
dc_set_oclass(daos_handle_t coh, int domain_nr, int target_nr,
daos_ofeat_t ofeats, daos_oclass_hints_t hints,
daos_oclass_id_t *oc_id_p)
{
daos_prop_t *prop = NULL;
uint64_t rf_factor;
daos_oclass_id_t cid = 0;
struct daos_obj_class *oc;
struct daos_oclass_attr ca;
uint16_t shd, rdd;
int grp_size;
int rc;

/** get the Redundancy Factor from container */
prop = daos_prop_alloc(1);
if (prop == NULL)
return -DER_NOMEM;

prop->dpp_entries[0].dpe_type = DAOS_PROP_CO_REDUN_FAC;
rc = daos_cont_query(coh, NULL, prop, NULL);
if (rc) {
daos_prop_free(prop);
D_ERROR("daos_cont_query() failed (%d)\n", rc);
return rc;
}

rf_factor = prop->dpp_entries[0].dpe_val;
daos_prop_free(prop);

rdd = hints & DAOS_OC_RDD_MASK;
shd = hints & DAOS_OC_SHD_MASK;

/** first set a reasonable default based on RF */
switch (rf_factor) {
case DAOS_PROP_CO_REDUN_RF0:
if (rdd == DAOS_OC_RDD_DEF || rdd == DAOS_OC_RDD_NO)
cid = OC_SX;
else if (rdd == DAOS_OC_RDD_RP)
cid = OC_RP_2GX;
else
cid = OC_EC_2P1GX;
break;
case DAOS_PROP_CO_REDUN_RF1:
if (rdd == DAOS_OC_RDD_EC || ofeats & DAOS_OF_ARRAY ||
ofeats & DAOS_OF_ARRAY_BYTE)
cid = OC_EC_2P1GX;
else
cid = OC_RP_2GX;
break;
case DAOS_PROP_CO_REDUN_RF2:
if (rdd == DAOS_OC_RDD_EC || ofeats & DAOS_OF_ARRAY ||
ofeats & DAOS_OF_ARRAY_BYTE)
cid = OC_EC_2P2GX;
else
cid = OC_RP_3GX;
break;
case DAOS_PROP_CO_REDUN_RF3:
case DAOS_PROP_CO_REDUN_RF4:
return -DER_INVAL;
}

/** if there are no sharding hints, we can return */
if (shd == 0) {
oc = oclass_fit_max(cid, domain_nr, target_nr);
if (oc)
*oc_id_p = oc->oc_id;

return oc ? 0 : -DER_NONEXIST;
}

oc = oclass_ident2cl(cid);
if (!oc)
return -DER_INVAL;

memcpy(&ca, &oc->oc_attr, sizeof(ca));
grp_size = daos_oclass_grp_size(&ca);

/** adjust the group size based on the sharding hint */
switch (shd) {
case DAOS_OC_SHD_DEF:
case DAOS_OC_SHD_MAX:
ca.ca_grp_nr = DAOS_OBJ_GRP_MAX;
break;
case DAOS_OC_SHD_TINY:
ca.ca_grp_nr = 4;
break;
case DAOS_OC_SHD_REG:
ca.ca_grp_nr = max(128, target_nr * 25 / 100);
break;
case DAOS_OC_SHD_HI:
ca.ca_grp_nr = max(256, target_nr * 50 / 100);
break;
case DAOS_OC_SHD_EXT:
ca.ca_grp_nr = max(1024, target_nr * 80 / 100);
break;
default:
D_ERROR("Invalid sharding hint\n");
return -DER_INVAL;
}

if (ca.ca_grp_nr == DAOS_OBJ_GRP_MAX ||
ca.ca_grp_nr * grp_size > target_nr) {
/* search for the highest scalability in the allowed range */
ca.ca_grp_nr = max(1, (target_nr / grp_size));
}
oc = oclass_scale2cl(&ca);
if (oc)
*oc_id_p = oc->oc_id;

return oc ? 0 : -DER_NONEXIST;
}

/** a structure to map EC object class to EC codec structure */
struct daos_oc_ec_codec {
/** object class id */
Expand Down
5 changes: 5 additions & 0 deletions src/object/obj_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ struct dc_obj_verify_args {
struct dc_obj_verify_cursor cursor;
};

int
dc_set_oclass(daos_handle_t coh, int domain_nr, int target_nr,
daos_ofeat_t ofeats, daos_oclass_hints_t hints,
daos_oclass_id_t *oc_id_);

int dc_obj_shard_open(struct dc_object *obj, daos_unit_oid_t id,
unsigned int mode, struct dc_obj_shard *shard);
void dc_obj_shard_close(struct dc_obj_shard *shard);
Expand Down

0 comments on commit b5e2b50

Please sign in to comment.