Skip to content

Commit

Permalink
CLIENT-2294 Convert a batch node command to a single record command w…
Browse files Browse the repository at this point in the history
…hen the batch size for that node is one. This improves performance for small batch sizes.
  • Loading branch information
BrianNichols committed Nov 18, 2024
1 parent 0e85b8a commit 2503488
Show file tree
Hide file tree
Showing 4 changed files with 1,139 additions and 89 deletions.
91 changes: 89 additions & 2 deletions src/include/aerospike/aerospike_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ aerospike_key_get_async(
);

/**
* Lookup a record by key, then return specified bins.
* Read a record's bins given the NULL terminated bins array argument.
*
* ~~~~~~~~~~{.c}
* char* select[] = {"bin1", "bin2", "bin3", NULL};
Expand Down Expand Up @@ -164,7 +164,7 @@ aerospike_key_select(
);

/**
* Asynchronously lookup a record by key, then return specified bins.
* Asynchronously read a record's bins given the NULL terminated bins array argument.
*
* ~~~~~~~~~~{.c}
* void my_listener(as_error* err, as_record* record, void* udata, as_event_loop* event_loop)
Expand Down Expand Up @@ -209,6 +209,93 @@ aerospike_key_select_async(
as_async_record_listener listener, void* udata, as_event_loop* event_loop, as_pipe_listener pipe_listener
);

/**
* Read a record's bins given the bins array argument and the n_bins count.
*
* ~~~~~~~~~~{.c}
* char* select[] = {"bin1", "bin2", "bin3"};
*
* as_key key;
* as_key_init(&key, "ns", "set", "key");
*
* as_record* rec = NULL;
* if (aerospike_key_select_bins(&as, &err, NULL, &key, select, 3, &rec) != AEROSPIKE_OK) {
* printf("error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
* }
* else {
* as_record_destroy(rec);
* }
* ~~~~~~~~~~
*
* @param as The aerospike instance to use for this operation.
* @param err The as_error to be populated if an error occurs.
* @param policy The policy to use for this operation. If NULL, then the default policy will be used.
* @param key The key of the record.
* @param bins The array of bins to select. The array does not need a final NULL entry.
* @param n_bins The count of bins to select.
* @param rec The record to be populated with the data from request. If the record pointer is
* preset to NULL, the record will be created and initialized. If the record pointer
* is not NULL, the record is assumed to be valid and will be reused. Either way,
* the record must be preset.
*
* @return AEROSPIKE_OK if successful. Otherwise an error.
*
* @ingroup key_operations
*/
as_status
aerospike_key_select_bins(
aerospike* as, as_error* err, const as_policy_read* policy, const as_key* key,
const char* bins[], uint32_t n_bins, as_record** rec
);

/**
* Asynchronously read a record's bins given the bins array argument and the n_bins count.
*
* ~~~~~~~~~~{.c}
* void my_listener(as_error* err, as_record* record, void* udata, as_event_loop* event_loop)
* {
* if (err) {
* printf("Command failed: %d %s\n", err->code, err->message);
* return;
* }
* // Process record bins
* // Only call as_record_destroy(record) when command is successful (err == NULL) and
* // "as_policy_read.async_heap_rec" is true. Otherwise, the calling function will destroy the
* // record when the listener completes.
* }
*
* char* select[] = {"bin1", "bin2", "bin3"};
*
* as_key key;
* as_key_init(&key, "ns", "set", "key");
*
* as_status status = aerospike_key_select_bins_async(&as, &err, NULL, &key, select, 3, my_listener, NULL, NULL, NULL);
* ~~~~~~~~~~
*
* @param as The aerospike instance to use for this operation.
* @param err The as_error to be populated if an error occurs.
* @param policy The policy to use for this operation. If NULL, then the default policy will be used.
* @param key The key of the record.
* @param bins The bins to select. A NULL terminated array of NULL terminated strings.
* @param n_bins The count of bins to select.
* @param listener User function to be called with command results.
* @param udata User data to be forwarded to user callback.
* @param event_loop Event loop assigned to run this command. If NULL, an event loop will be chosen by round-robin.
* @param pipe_listener Enables command pipelining, if not NULL. The given callback is invoked after the current command
* has been sent to the server. This allows for issuing the next command even before receiving a
* result for the current command.
*
* @return AEROSPIKE_OK if async command successfully queued. Otherwise an error.
*
* @ingroup key_operations
*/
as_status
aerospike_key_select_bins_async(
aerospike* as, as_error* err, const as_policy_read* policy, const as_key* key, const char* bins[],
uint32_t n_bins, as_async_record_listener listener, void* udata, as_event_loop* event_loop,
as_pipe_listener pipe_listener
);

/**
* Check if a record exists in the cluster via its key. The record's metadata
* will be populated if the record exists.
Expand Down
14 changes: 14 additions & 0 deletions src/include/aerospike/as_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,19 @@ typedef struct as_policy_operate_s {
*/
bool async_heap_rec;

/**
* Should the client return a result for every operation.
*
* Some operations do not return a result by default. This can make it difficult to determine the
* result offset in the returned bin's result list. Setting this field to true makes it easier to identify
* the desired result offset.
*
* This field defaults to false for older operations (basic read/write/incr/touch and list) to
* preserve legacy behavior. Newer operations (map, expression, bit or HLL and batch
* write operations) force respond_all_ops to be true regardless of it's initial setting.
*/
bool respond_all_ops;

} as_policy_operate;

/**
Expand Down Expand Up @@ -1699,6 +1712,7 @@ as_policy_operate_init(as_policy_operate* p)
p->deserialize = true;
p->durable_delete = false;
p->async_heap_rec = false;
p->respond_all_ops = false;
return p;
}

Expand Down
Loading

0 comments on commit 2503488

Please sign in to comment.