Using aerospike_key_operate_async along with aerospike_key_operate API

I am using C client library(synchronous) and our OS is Ubuntu 18.04. Both client and server versions are latest builds. Let me explain my usecase

In our case a record has multiple bins and each bin is a simple integer counter. So every write in our application is of the form “incr bin1, bin7 for this record”, “incr bin9, bin11 for this record” etc… We are using the aerospike_key_operate() API and so far so good. All our data is in-memory and we never write to disk. We don’t use any event loops etc in our application.

Unfortunately, Now we have 2 data centers(DC) that are few milliseconds away and we’ve formed 2 cluters(can’t form 1 cluster since network latency is substantial) and we want that writes(increments on counters) on one DC should reflect on another as well, so that the counter value when fetched is “cumulative”. The way XDR is implemented in Aerospike, I can’t use that(active-active replication) as I want the counters to be “cumulative” and not “overwritten” i.e I want to replicate the exact queries rather than “overwrite” records.

So as a solution, I am thinking about creating 2 clients, 1 client connects to local cluster and another to remote cluster. Whenever I want to perform a write operation I do aerospike_key_operate() on local cluster(which is synchronous) BUT I want to do aerospike_key_operate() on remote cluster in ASYNC way i.e I don’t want to block for response(which would only indicate failure or sucess since I am only performing increments on multiple bins of a record and not reading any bin)…i.e I want to use aerospike_key_operate() API in fire and forget way without waiting for response. Note that operations are only increments and no read is performed during these writes. I thought that aerospike_key_operate_async() would help me, but a sample program written using that and called using aerospike_key_operate_async(&client, &err, NULL, &key, &ops, NULL, NULL, NULL, NULL)) != AEROSPIKE_OK) is crashing. Can you guys help me?

Regards kartik

aerospike_key_operate_async() requires the listener argument. To perform fire and forget, provide a listener that does nothing.

static void ignore_result(as_error* err, as_record* record, void* udata, as_event_loop* event_loop)
{
}

aerospike_key_operate_async(&client, &err, NULL, &key, &ops, ignore_result, NULL, NULL, NULL);

Thanks a lot for your reply. Do I need to use event based client library to use the above async api. My observation is that I need to use event base client library(I’ve used libev based) and also I need to add the following code before I connect with cluster.

if (! as_event_create_loops(1)) {
	printf("Failed to create event loop\n");
	return -1;
}

Otherwise, my application is crashing with following backtrace

(gdb) bt

#0 as_event_loop_get () at src/include/aerospike/as_event.h:395

#1 as_event_assign (event_loop=) at src/include/aerospike/as_event_internal.h:654

#2 as_async_record_command_create (parse_results=, size=, pipe_listener=0x0, event_loop=, udata=0x0, listener=0x5651bb0f41a0 <ignore_result>, flags=1 ‘\001’, deserialize=, partition=, ns=, replica=, policy=0x5651bb2f616c <client+300>, cluster=0x5651bbb2a430) at src/include/aerospike/as_async.h:131

#3 aerospike_key_operate_async (as=, err=, policy=0x5651bb2f616c <client+300>, key=0x7ffc5fe7f870, ops=0x7ffc5fe7f850, listener=0x5651bb0f41a0 <ignore_result>, udata=0x0, event_loop=0x0, pipe_listener=0x0) at src/main/aerospike/aerospike_key.c:909

#4 0x00005651bb0f44b5 in send_nbt_allowance (str=0x5651bb0f4f52 “hello”, btc=0x7ffc5fe7fdc0, n=3) at asd_async.c:113

#5 0x00005651bb0f4b68 in main () at asd_async.c:231

Please correct me if my observation is wrong. Can I use async API without compiling my application with event based aerospike library? And do I need to add as_event_create_loops(1) before connecting to the cluster?

Regards kartik

An event library is required to perform async commands. See README.

as_event_create_loops() must also be called before performing async commands. See Tutorial.

© 2015 Copyright Aerospike, Inc. | All rights reserved. Creators of the Aerospike Database.