Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAOS-4763 dfs: New API for anchor split to allow parallelizing dfs_readdir #2652

Merged
merged 5 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
47 changes: 47 additions & 0 deletions src/client/dfs/dfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <daos/common.h>
#include <daos/event.h>
#include <daos/container.h>
#include <daos/object.h>
#include <daos/array.h>

#include "daos.h"
Expand Down Expand Up @@ -3956,3 +3957,49 @@ dfs_umount_root_cont(dfs_t *dfs)
rc = daos_cont_close(coh, NULL);
return daos_der2errno(rc);
}

int
dfs_obj_anchor_split(dfs_obj_t *obj, uint32_t *nr, daos_anchor_t *anchors)
{
struct daos_obj_layout *layout;
int rc;

if (obj == NULL || nr == NULL || !S_ISDIR(obj->mode))
return EINVAL;

rc = dc_obj_layout_get(obj->oh, &layout);
if (rc)
return rc;

/** TBD - support more than per shard iteration */
if (*nr !=0 && *nr != layout->ol_nr) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(style) spaces required around that '!=' (ctx:WxV)

D_ERROR("For now, num anchors should be the same as what is"
"reported as optimal\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(style) break quoted strings at a space character

D_GOTO(out, rc = ENOSYS);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(style) ENOSYS means 'invalid syscall nr' and nothing else

}

*nr = layout->ol_nr;

if (anchors) {
uint32_t i;

for (i = 0; i < layout->ol_nr; i++) {
daos_anchor_set_zero(&anchors[i]);
dc_obj_shard2anchor(&anchors[i], i);
daos_anchor_set_flags(&anchors[i], DIOF_TO_SPEC_SHARD);
}
}
out:
daos_obj_layout_free(layout);
return rc;
}

int
dfs_obj_anchor_set(dfs_obj_t *obj, uint32_t index, daos_anchor_t *anchor)
{
/** TBD - support more than per shard iteration */
daos_anchor_set_zero(anchor);
dc_obj_shard2anchor(anchor, index);
daos_anchor_set_flags(anchor, DIOF_TO_SPEC_SHARD);
return 0;
}
38 changes: 38 additions & 0 deletions src/include/daos_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,44 @@ int
dfs_iterate(dfs_t *dfs, dfs_obj_t *obj, daos_anchor_t *anchor,
uint32_t *nr, size_t size, dfs_filler_cb_t op, void *udata);

/**
* Provide a function for large directories to split an anchor to be able to
* execute a parallel readdir or iterate. This routine suggests the optimal
* number of anchors to use instead of just 1 and optionally returns all those
* anchors. The user would allocate the array of anchors after querying the
* number of anchors needed. Alternatively, user does not provide an array and
* can call dfs_obj_anchor_set() for every anchor to set.
*
* The user could suggest how many anchors to split the iteration over. This
* feature is not supported yet.
*
* \param[in] obj Dir object to split anchor for.
* \param[in/out]
* nr [in]: Number of anchors requested and allocated in
* \a anchors. Pass 0 for DAOS to recommend split num.
* [out]: Number of anchors recommended if 0 is passed in.
* \param[in] anchors Optional array of anchors that are split.
*
* \return 0 on success, errno code on failure.
*/
int
dfs_obj_anchor_split(dfs_obj_t *obj, uint32_t *nr, daos_anchor_t *anchors);

/**
* Set an anchor with an index based on split done with dfs_obj_anchor_split.
* The anchor passed will be re-intialized and set to start and finish iteration
* based on the specified index.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(style) trailing whitespace

*
* \param[in] obj Dir object to split anchor for.
* \param[in] index Index of set this anchor for iteration.
* \param[in,out]
* anchor Hash anchor to set.
*
* \return 0 on success, errno code on failure.
*/
int
dfs_obj_anchor_set(dfs_obj_t *obj, uint32_t index, daos_anchor_t *anchor);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(style) trailing whitespace

/**
* Create a directory.
*
Expand Down
3 changes: 2 additions & 1 deletion src/object/cli_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,8 @@ obj_list_dkey_cb(tse_task_t *task, struct obj_list_arg *arg, unsigned int opc)

if (!daos_anchor_is_eof(anchor)) {
D_DEBUG(DB_IO, "More keys in shard %d\n", shard);
} else if ((shard < obj->cob_shards_nr - grp_size)) {
} else if (!(daos_anchor_get_flags(anchor) & DIOF_TO_SPEC_SHARD) &&
(shard < obj->cob_shards_nr - grp_size)) {
shard += grp_size;
D_DEBUG(DB_IO, "next shard %d grp %d nr %u\n",
shard, grp_size, obj->cob_shards_nr);
Expand Down