Skip to content

Commit

Permalink
DAOS-16931 container: fix the oid iv check for same request
Browse files Browse the repository at this point in the history
on retry the priv pointer is always freed/allocated, so track the request from the origin rank through the iv tree with rank and the iv_value from cont_oid_alloc() that will always be valid..

Signed-off-by: Mohamad Chaarawi <[email protected]>
  • Loading branch information
mchaarawi committed Jan 20, 2025
1 parent 23518fa commit 3d945b1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/container/oid_iv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright 2017-2024 Intel Corporation.
* (C) Copyright 2017-2025 Intel Corporation.
* (C) Copyright 2025 Hewlett Packard Enterprise Development LP
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -32,7 +32,8 @@ struct oid_iv_entry {
struct oid_iv_range rg;
/** protect the entry */
ABT_mutex lock;
void *current_req;
d_rank_t current_req_rank;
void *current_req_ptr;
};

/** Priv data in the iv layer */
Expand Down Expand Up @@ -86,13 +87,15 @@ oid_iv_ent_refresh(struct ds_iv_entry *iv_entry, struct ds_iv_key *key,

D_ASSERT(priv);
num_oids = priv->num_oids;
D_DEBUG(DB_MD, "%u: ON REFRESH: num_oids = %zu, REF_RC = " DF_RC "\n", dss_self_rank(),
num_oids, DP_RC(ref_rc));
D_ASSERT(num_oids != 0);

entry = iv_entry->iv_value.sg_iovs[0].iov_buf;
D_ASSERT(entry != NULL);

D_DEBUG(DB_MD,
"%u: ON REFRESH: num_oids = %zu, REF_RC = " DF_RC " ENTRY rank %u Ptr = %p\n",
dss_self_rank(), num_oids, DP_RC(ref_rc), entry->current_req_rank,
entry->current_req_ptr);

/** if iv op failed, just release the entry lock acquired in update */
if (ref_rc != 0)
goto out;
Expand Down Expand Up @@ -130,17 +133,28 @@ oid_iv_ent_update(struct ds_iv_entry *ns_entry, struct ds_iv_key *iv_key,
d_rank_t myrank = dss_self_rank();
int rc;

if (src == NULL) {
D_DEBUG(DB_MD, "%u: ON UPDATE delete entry iv_entry %p\n", myrank, ns_entry);
ns_entry->iv_to_delete = 1;
return 0;
}

D_ASSERT(priv != NULL);
entry = ns_entry->iv_value.sg_iovs[0].iov_buf;
rc = ABT_mutex_trylock(entry->lock);
/** For retry requests, from _iv_op(), the lock may not be released in some cases. */
if (rc == ABT_ERR_MUTEX_LOCKED && entry->current_req != priv)
return -DER_BUSY;
oids = src->sg_iovs[0].iov_buf;

entry->current_req = priv;
avail = &entry->rg;
rc = ABT_mutex_trylock(entry->lock);
if (rc == ABT_ERR_MUTEX_LOCKED) {
if (entry->current_req_rank == oids->req_rank &&
entry->current_req_ptr == oids->req_ptr)
D_DEBUG(DB_MD, "%u: ON UPDATE - SAME REQ %p \n", myrank, src);
else
return -DER_BUSY;
}

oids = src->sg_iovs[0].iov_buf;
entry->current_req_rank = oids->req_rank;
entry->current_req_ptr = oids->req_ptr;
avail = &entry->rg;

if (myrank == oids->req_rank)
num_oids = oids->req_num_oids;
Expand Down Expand Up @@ -209,8 +223,6 @@ oid_iv_ent_get(struct ds_iv_entry *entry, void **_priv)
{
struct oid_iv_priv *priv;

D_DEBUG(DB_MD, "%u: OID GET\n", dss_self_rank());

D_ALLOC_PTR(priv);
if (priv == NULL)
return -DER_NOMEM;
Expand All @@ -222,7 +234,6 @@ static void
oid_iv_ent_put(struct ds_iv_entry *entry, void *priv)
{
D_ASSERT(priv != NULL);
D_DEBUG(DB_MD, "%u: ON PUT\n", dss_self_rank());
D_FREE(priv);
}

Expand Down Expand Up @@ -331,6 +342,7 @@ oid_iv_reserve(void *ns, uuid_t po_uuid, uuid_t co_uuid, uint64_t num_oids, d_sg
oids->num_oids = num_oids;
oids->req_rank = dss_self_rank();
oids->req_num_oids = num_oids;
oids->req_ptr = value;

rc = ds_iv_update(ns, &key, value, 0, CRT_IV_SYNC_NONE,
CRT_IV_SYNC_BIDIRECTIONAL, true /* retry */);
Expand Down
2 changes: 2 additions & 0 deletions src/container/srv_internal.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* (C) Copyright 2016-2024 Intel Corporation.
* (C) Copyright 2025 Hewlett Packard Enterprise Development LP
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
Expand Down Expand Up @@ -110,6 +111,7 @@ struct oid_iv_range {
daos_size_t num_oids;
daos_size_t req_num_oids;
d_rank_t req_rank;
void *req_ptr;
};

/* Container IV structure */
Expand Down

0 comments on commit 3d945b1

Please sign in to comment.