Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions include/splinterdb/splinterdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,16 @@ splinterdb_close(splinterdb **kvs);
// Insert a key and value.
// Relies on data_config->encode_message
int
splinterdb_insert(const splinterdb *kvsb, slice key, slice value);
splinterdb_insert(splinterdb *kvsb, slice key, slice value);

// Delete a given key and any associated value / messages
int
splinterdb_delete(const splinterdb *kvsb, slice key);
splinterdb_delete(splinterdb *kvsb, slice key);

// Insert a key and value.
// Relies on data_config->encode_message
int
splinterdb_update(const splinterdb *kvsb, slice key, slice delta);
splinterdb_update(splinterdb *kvsb, slice key, slice delta);

// Lookups

Expand Down Expand Up @@ -254,7 +254,7 @@ splinterdb_lookup_result_value(const splinterdb_lookup_result *result, // IN
//
// result must have first been initialized using splinterdb_lookup_result_init
int
splinterdb_lookup(const splinterdb *kvs, // IN
splinterdb_lookup(splinterdb *kvs, // IN
slice key, // IN
splinterdb_lookup_result *result // IN/OUT
);
Expand Down Expand Up @@ -318,7 +318,7 @@ typedef struct splinterdb_iterator splinterdb_iterator;
//
// If start_key is NULL_SLICE, the iterator will start before the minimum key
int
splinterdb_iterator_init(const splinterdb *kvs, // IN
splinterdb_iterator_init(splinterdb *kvs, // IN
splinterdb_iterator **iter, // OUT
slice start_key // IN
);
Expand Down Expand Up @@ -395,7 +395,7 @@ void
splinterdb_stats_print_insertion(const splinterdb *kvs);

void
splinterdb_stats_print_lookup(const splinterdb *kvs);
splinterdb_stats_print_lookup(splinterdb *kvs);

void
splinterdb_stats_reset(splinterdb *kvs);
81 changes: 55 additions & 26 deletions src/clockcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -3127,29 +3127,29 @@ clockcache_init(clockcache *cc, // OUT
cc->heap_id = hid;

/* lookup maps addrs to entries, entry contains the entries themselves */
cc->lookup =
TYPED_ARRAY_MALLOC(cc->heap_id, cc->lookup, allocator_page_capacity);
if (!cc->lookup) {
platform_status rc = platform_buffer_init(
&cc->lookup_bh, allocator_page_capacity * sizeof(cc->lookup[0]));
if (!SUCCESS(rc)) {
goto alloc_error;
}
cc->lookup = platform_buffer_getaddr(&cc->lookup_bh);
for (i = 0; i < allocator_page_capacity; i++) {
cc->lookup[i] = CC_UNMAPPED_ENTRY;
}

cc->entry =
TYPED_ARRAY_ZALLOC(cc->heap_id, cc->entry, cc->cfg->page_capacity);
if (!cc->entry) {
rc = platform_buffer_init(&cc->entry_bh,
cc->cfg->page_capacity * sizeof(cc->entry[0]));
if (!SUCCESS(rc)) {
goto alloc_error;
}

platform_status rc = STATUS_NO_MEMORY;
cc->entry = platform_buffer_getaddr(&cc->entry_bh);

/* data must be aligned because of O_DIRECT */
rc = platform_buffer_init(&cc->bh, cc->cfg->capacity);
rc = platform_buffer_init(&cc->data_bh, cc->cfg->capacity);
if (!SUCCESS(rc)) {
goto alloc_error;
}
cc->data = platform_buffer_getaddr(&cc->bh);
cc->data = platform_buffer_getaddr(&cc->data_bh);

/* Set up the entries */
for (i = 0; i < cc->cfg->page_capacity; i++) {
Expand All @@ -3172,11 +3172,12 @@ clockcache_init(clockcache *cc, // OUT
cc->refcount = platform_buffer_getaddr(&cc->rc_bh);

/* Separate ref counts for pins */
cc->pincount =
TYPED_ARRAY_ZALLOC(cc->heap_id, cc->pincount, cc->cfg->page_capacity);
if (!cc->pincount) {
rc = platform_buffer_init(&cc->pincount_bh,
cc->cfg->page_capacity * sizeof(cc->pincount[0]));
if (!SUCCESS(rc)) {
goto alloc_error;
}
cc->pincount = platform_buffer_getaddr(&cc->pincount_bh);

/* The hands and associated page */
cc->free_hand = 0;
Expand All @@ -3185,13 +3186,14 @@ clockcache_init(clockcache *cc, // OUT
cc->per_thread[thr_i].free_hand = CC_UNMAPPED_ENTRY;
cc->per_thread[thr_i].enable_sync_get = TRUE;
}
cc->batch_busy =
TYPED_ARRAY_ZALLOC(cc->heap_id,
cc->batch_busy,
cc->cfg->page_capacity / CC_ENTRIES_PER_BATCH);
if (!cc->batch_busy) {

rc = platform_buffer_init(&cc->batch_bh,
cc->cfg->page_capacity / CC_ENTRIES_PER_BATCH
* sizeof(cc->batch_busy[0]));
if (!SUCCESS(rc)) {
goto alloc_error;
}
cc->batch_busy = platform_buffer_getaddr(&cc->batch_bh);

return STATUS_OK;

Expand All @@ -3209,6 +3211,7 @@ clockcache_init(clockcache *cc, // OUT
void
clockcache_deinit(clockcache *cc) // IN/OUT
{
platform_status rc;
platform_assert(cc != NULL);

if (cc->logfile) {
Expand All @@ -3219,35 +3222,61 @@ clockcache_deinit(clockcache *cc) // IN/OUT
}

if (cc->lookup) {
platform_free(cc->heap_id, cc->lookup);
rc = platform_buffer_deinit(&cc->lookup_bh);
if (!SUCCESS(rc)) {
platform_error_log("platform_buffer_deinit(&cc->lookup_bh) failed: %s",
platform_status_to_string(rc));
}
cc->lookup = NULL;
}
if (cc->entry) {
for (int i = 0; i < cc->cfg->page_capacity; i++) {
async_wait_queue_deinit(&cc->entry[i].waiters);
}
platform_free(cc->heap_id, cc->entry);
rc = platform_buffer_deinit(&cc->entry_bh);
if (!SUCCESS(rc)) {
platform_error_log("platform_buffer_deinit(&cc->entry_bh) failed: %s",
platform_status_to_string(rc));
}
cc->entry = NULL;
}

debug_only platform_status rc = STATUS_TEST_FAILED;
if (cc->data) {
rc = platform_buffer_deinit(&cc->bh);
rc = platform_buffer_deinit(&cc->data_bh);

// We expect above to succeed. Anyway, we are in the process of
// dismantling the clockcache, hence, for now, can't do much by way
// of reporting errors further upstream.
debug_assert(SUCCESS(rc), "rc=%s", platform_status_to_string(rc));
if (!SUCCESS(rc)) {
platform_error_log("platform_buffer_deinit(&cc->data_bh) failed: %s",
platform_status_to_string(rc));
}
cc->data = NULL;
}
if (cc->refcount) {
rc = platform_buffer_deinit(&cc->rc_bh);
debug_assert(SUCCESS(rc), "rc=%s", platform_status_to_string(rc));
if (!SUCCESS(rc)) {
platform_error_log("platform_buffer_deinit(&cc->rc_bh) failed: %s",
platform_status_to_string(rc));
}
cc->refcount = NULL;
}

if (cc->pincount) {
platform_free_volatile(cc->heap_id, cc->pincount);
rc = platform_buffer_deinit(&cc->pincount_bh);
if (!SUCCESS(rc)) {
platform_error_log(
"platform_buffer_deinit(&cc->pincount_bh) failed: %s",
platform_status_to_string(rc));
}
cc->pincount = NULL;
}
if (cc->batch_busy) {
platform_free_volatile(cc->heap_id, cc->batch_busy);
rc = platform_buffer_deinit(&cc->batch_bh);
if (!SUCCESS(rc)) {
platform_error_log("platform_buffer_deinit(&cc->batch_bh) failed: %s",
platform_status_to_string(rc));
}
cc->batch_busy = NULL;
}
}
16 changes: 10 additions & 6 deletions src/clockcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,26 @@ struct clockcache {
allocator *al;
io_handle *io;

uint32 *lookup;
clockcache_entry *entry;
buffer_handle bh; // actual memory for pages
char *data; // convenience pointer for bh
buffer_handle lookup_bh;
uint32 *lookup; // Convenience pointer for lookup_bh
buffer_handle entry_bh;
clockcache_entry *entry; // Convenience pointer for entry_bh
buffer_handle data_bh; // actual memory for pages
char *data; // convenience pointer for bh
platform_log_handle *logfile;
platform_heap_id heap_id;

// Distributed locks (the write bit is in the status uint32 of the entry)
buffer_handle rc_bh;
volatile uint16 *refcount;
volatile uint8 *pincount;
buffer_handle pincount_bh;
volatile uint8 *pincount; // Convenience pointer for pincount_bh

// Clock hands and related metadata
volatile uint32 evict_hand;
volatile uint32 free_hand;
volatile bool32 *batch_busy;
buffer_handle batch_bh;
volatile bool32 *batch_busy; // Convenience pointer for batch_bh
uint64 cleaner_gap;

volatile struct {
Expand Down
Loading