Skip to content

Commit

Permalink
rename cache_try_claim (from cache_claim) (vmware#525)
Browse files Browse the repository at this point in the history
* rename cache_claim to cache_try_claim

* format fixall

Co-authored-by: Jon Howell <[email protected]>
  • Loading branch information
jonhnet and Jon Howell authored Jan 6, 2023
1 parent 77e2883 commit 864c31a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ btree_node_claim(cache *cc, // IN
const btree_config *cfg, // IN
btree_node *node) // IN
{
return cache_claim(cc, node->page);
return cache_try_claim(cc, node->page);
}

static inline void
Expand Down
8 changes: 4 additions & 4 deletions src/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ typedef cache_async_result (*page_get_async_fn)(cache *cc,
typedef void (*page_async_done_fn)(cache *cc,
page_type type,
cache_async_ctxt *ctxt);
typedef bool (*page_claim_fn)(cache *cc, page_handle *page);
typedef bool (*page_try_claim_fn)(cache *cc, page_handle *page);
typedef void (*page_sync_fn)(cache *cc,
page_handle *page,
bool is_blocking,
Expand Down Expand Up @@ -179,7 +179,7 @@ typedef struct cache_ops {
page_get_async_fn page_get_async;
page_async_done_fn page_async_done;
page_generic_fn page_unget;
page_claim_fn page_claim;
page_try_claim_fn page_try_claim;
page_generic_fn page_unclaim;
page_generic_fn page_lock;
page_generic_fn page_unlock;
Expand Down Expand Up @@ -368,9 +368,9 @@ cache_unget(cache *cc, page_handle *page)
*----------------------------------------------------------------------
*/
static inline bool
cache_claim(cache *cc, page_handle *page)
cache_try_claim(cache *cc, page_handle *page)
{
return cc->ops->page_claim(cc, page);
return cc->ops->page_try_claim(cc, page);
}

/*
Expand Down
12 changes: 6 additions & 6 deletions src/clockcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void
clockcache_unget(clockcache *cc, page_handle *page);

bool
clockcache_claim(clockcache *cc, page_handle *page);
clockcache_try_claim(clockcache *cc, page_handle *page);

void
clockcache_unclaim(clockcache *cc, page_handle *page);
Expand Down Expand Up @@ -303,10 +303,10 @@ clockcache_unget_virtual(cache *c, page_handle *page)
}

bool
clockcache_claim_virtual(cache *c, page_handle *page)
clockcache_try_claim_virtual(cache *c, page_handle *page)
{
clockcache *cc = (clockcache *)c;
return clockcache_claim(cc, page);
return clockcache_try_claim(cc, page);
}

void
Expand Down Expand Up @@ -511,7 +511,7 @@ static cache_ops clockcache_ops = {
.page_get_async = clockcache_get_async_virtual,
.page_async_done = clockcache_async_done_virtual,
.page_unget = clockcache_unget_virtual,
.page_claim = clockcache_claim_virtual,
.page_try_claim = clockcache_try_claim_virtual,
.page_unclaim = clockcache_unclaim_virtual,
.page_lock = clockcache_lock_virtual,
.page_unlock = clockcache_unlock_virtual,
Expand Down Expand Up @@ -2488,7 +2488,7 @@ clockcache_unget(clockcache *cc, page_handle *page)

/*
*----------------------------------------------------------------------
* clockcache_claim --
* clockcache_try_claim --
*
* Upgrades a read lock to a claim. This function does not block and
* returns TRUE if the claim was successfully obtained.
Expand All @@ -2500,7 +2500,7 @@ clockcache_unget(clockcache *cc, page_handle *page)
*----------------------------------------------------------------------
*/
bool
clockcache_claim(clockcache *cc, page_handle *page)
clockcache_try_claim(clockcache *cc, page_handle *page)
{
uint32 entry_number = clockcache_page_to_entry_number(cc, page);

Expand Down
6 changes: 3 additions & 3 deletions src/memtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ memtable_maybe_rotate_and_get_insert_lock(memtable_context *ctxt,

if (memtable_is_full(&ctxt->cfg, &ctxt->mt[mt_no])) {
// If the current memtable is full, try to retire it.
if (cache_claim(cc, *lock_page)) {
if (cache_try_claim(cc, *lock_page)) {
// We successfully got the claim, so we do the finalization
cache_lock(cc, *lock_page);
memtable_transition(
Expand Down Expand Up @@ -168,7 +168,7 @@ memtable_uncontended_get_claim_lock_lookup_lock(memtable_context *ctxt)
{
page_handle *lock_page = memtable_get_lookup_lock(ctxt);
cache *cc = ctxt->cc;
bool claimed = cache_claim(cc, lock_page);
bool claimed = cache_try_claim(cc, lock_page);
platform_assert(claimed);
cache_lock(cc, lock_page);
return lock_page;
Expand Down Expand Up @@ -214,7 +214,7 @@ memtable_force_finalize(memtable_context *ctxt)
page_handle *lock_page =
cache_get(cc, lock_addr, TRUE, PAGE_TYPE_LOCK_NO_DATA);
uint64 wait = 100;
while (!cache_claim(cc, lock_page)) {
while (!cache_try_claim(cc, lock_page)) {
cache_unget(cc, lock_page);
platform_sleep_ns(wait);
wait *= 2;
Expand Down
5 changes: 3 additions & 2 deletions src/mini_allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ mini_full_lock_meta_tail(mini_allocator *mini)
while (1) {
uint64 meta_tail = mini->meta_tail;
meta_page = cache_get(mini->cc, meta_tail, TRUE, mini->type);
if (meta_tail == mini->meta_tail && cache_claim(mini->cc, meta_page)) {
if (meta_tail == mini->meta_tail && cache_try_claim(mini->cc, meta_page))
{
break;
}
cache_unget(mini->cc, meta_page);
Expand Down Expand Up @@ -206,7 +207,7 @@ mini_get_claim_meta_page(cache *cc, uint64 meta_addr, page_type type)
uint64 wait = 1;
while (1) {
meta_page = cache_get(cc, meta_addr, TRUE, type);
if (cache_claim(cc, meta_page)) {
if (cache_try_claim(cc, meta_page)) {
break;
}
cache_unget(cc, meta_page);
Expand Down
2 changes: 1 addition & 1 deletion src/shard_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ shard_log_write(log_handle *logh, key tuple_key, message msg, uint64 generation)
} else {
page = cache_get(cc, thread_data->addr, TRUE, PAGE_TYPE_LOG);
uint64 wait = 1;
while (!cache_claim(cc, page)) {
while (!cache_try_claim(cc, page)) {
platform_sleep_ns(wait);
wait = wait > 1024 ? wait : 2 * wait;
}
Expand Down
6 changes: 3 additions & 3 deletions src/trunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ static inline void
trunk_node_claim(cache *cc, trunk_node *node)
{
uint64 wait = 1;
while (!cache_claim(cc, node->page)) {
while (!cache_try_claim(cc, node->page)) {
uint64 addr = node->addr;
trunk_node_unget(cc, node);
platform_sleep_ns(wait);
Expand Down Expand Up @@ -907,7 +907,7 @@ trunk_set_super_block(trunk_handle *spl,
}
platform_assert_status_ok(rc);
super_page = cache_get(spl->cc, super_addr, TRUE, PAGE_TYPE_SUPERBLOCK);
while (!cache_claim(spl->cc, super_page)) {
while (!cache_try_claim(spl->cc, super_page)) {
platform_sleep_ns(wait);
wait *= 2;
}
Expand Down Expand Up @@ -3609,7 +3609,7 @@ trunk_node_get_claim_maybe_descend(trunk_handle *spl,
uint64 wait = 1;
while (1) {
trunk_node_get_maybe_descend(spl, req, node);
if (cache_claim(spl->cc, node->page)) {
if (cache_try_claim(spl->cc, node->page)) {
break;
}
trunk_node_unget(spl->cc, node);
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/cache_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test_cache_page_pin(cache *cc, page_handle **page_arr, uint64 page_capacity)
for (uint64 curr_page = 0; curr_page < page_capacity; curr_page++) {
page_handle *page =
cache_get(cc, page_arr[curr_page]->disk_addr, TRUE, PAGE_TYPE_MISC);
cache_claim(cc, page);
cache_try_claim(cc, page);
cache_lock(cc, page);
cache_pin(cc, page);
cache_unlock(cc, page);
Expand Down Expand Up @@ -177,7 +177,7 @@ test_cache_basic(cache *cc, clockcache_config *cfg, platform_heap_id hid)
uint32 i;
for (i = 0; i < cfg->page_capacity; i++) {
page_arr[i] = cache_get(cc, addr_arr[j + i], TRUE, PAGE_TYPE_MISC);
bool claim_obtained = cache_claim(cc, page_arr[i]);
bool claim_obtained = cache_try_claim(cc, page_arr[i]);
if (!claim_obtained) {
platform_error_log("Expected uncontested claim, but failed\n");
rc = STATUS_TEST_FAILED;
Expand Down Expand Up @@ -222,7 +222,7 @@ test_cache_basic(cache *cc, clockcache_config *cfg, platform_heap_id hid)
uint32 i;
for (i = 0; i < cfg->page_capacity; i++) {
page_arr[i] = cache_get(cc, addr_arr[j + i], TRUE, PAGE_TYPE_MISC);
bool claim_obtained = cache_claim(cc, page_arr[i]);
bool claim_obtained = cache_try_claim(cc, page_arr[i]);
if (!claim_obtained) {
platform_error_log("Expected uncontested claim, but failed\n");
rc = STATUS_TEST_FAILED;
Expand Down Expand Up @@ -410,7 +410,7 @@ cache_test_dirty_flush(cache *cc,
for (uint32 i = 0; i < cfg->page_capacity; i++) {
const uint32 idx = cache_test_index_itor_get(itor);
page_handle *ph = cache_get(cc, addr_arr[idx], TRUE, PAGE_TYPE_MISC);
bool claim_obtained = cache_claim(cc, ph);
bool claim_obtained = cache_try_claim(cc, ph);
if (!claim_obtained) {
platform_error_log("Expected uncontested claim, but failed\n");
rc = STATUS_TEST_FAILED;
Expand Down Expand Up @@ -798,7 +798,7 @@ test_writer_thread(void *arg)
}
do {
handle_arr[i] = cache_get(cc, addr_arr[i], TRUE, PAGE_TYPE_MISC);
if (cache_claim(cc, handle_arr[i])) {
if (cache_try_claim(cc, handle_arr[i])) {
break;
}
cache_unget(cc, handle_arr[i]);
Expand Down

0 comments on commit 864c31a

Please sign in to comment.