Version 3.1.1
WT_ASYNC_CALLBACK Struct Reference

The interface implemented by applications to accept notifications of the completion of asynchronous operations. More...

Public Attributes

int(* notify )(WT_ASYNC_CALLBACK *cb, WT_ASYNC_OP *op, int op_ret, uint32_t flags)
 Callback to receive completion notification. More...
 

Detailed Description

The interface implemented by applications to accept notifications of the completion of asynchronous operations.

Applications register their implementation with WiredTiger by calling WT_CONNECTION::async_new_op.

while ((ret = conn->async_new_op(conn,
"table:async", NULL, &ex_asynckeys.iface, &op)) != 0) {
/*
* If we used up all the handles, pause and retry to
* give the workers a chance to catch up.
*/
fprintf(stderr,
"asynchronous operation handle not available\n");
if (ret == EBUSY)
sleep(1);
else
return (EXIT_FAILURE);
}
Examples:
ex_async.c.

Member Data Documentation

◆ notify

int(* WT_ASYNC_CALLBACK::notify) (WT_ASYNC_CALLBACK *cb, WT_ASYNC_OP *op, int op_ret, uint32_t flags)

Callback to receive completion notification.

Parameters
[in]opthe operation handle
[in]op_retthe result of the async operation
[in]flagscurrently unused
Returns
zero for success, non-zero to indicate an error.
typedef struct {
uint32_t num_keys;
} ASYNC_KEYS;
static int
async_callback(WT_ASYNC_CALLBACK *cb,
WT_ASYNC_OP *op, int wiredtiger_error, uint32_t flags)
{
ASYNC_KEYS *asynckey = (ASYNC_KEYS *)cb;
WT_ITEM k, v;
const char *key, *value;
uint64_t id;
(void)flags; /* Unused */
/* Retrieve the operation's WT_ASYNC_OPTYPE type. */
type = op->get_type(op);
/* Retrieve the operation's 64-bit identifier. */
id = op->get_id(op);
/* Check for a WiredTiger error. */
if (wiredtiger_error != 0) {
fprintf(stderr,
"ID %" PRIu64 " error %d: %s\n",
id, wiredtiger_error,
wiredtiger_strerror(wiredtiger_error));
global_error = wiredtiger_error;
return (1);
}
/* If doing a search, retrieve the key/value pair. */
if (type == WT_AOP_SEARCH) {
error_check(op->get_key(op, &k));
key = k.data;
error_check(op->get_value(op, &v));
value = v.data;
ATOMIC_ADD(asynckey->num_keys, 1);
printf("Id %" PRIu64 " got record: %s : %s\n", id, key, value);
}
return (0);
}