WiredTiger: WT_ASYNC_CALLBACK Struct Reference

| Version 3.1.0

Fork me on GitHub Join my user group
List of all members | Public Attributes
WT_ASYNC_CALLBACK Struct Reference
WiredTiger API

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] | op | the operation handle
  [in] | op_ret | the result of the async operation
  [in] | flags | currently unused

Returns
  zero for success, non-zero to indicate an error.

typedef struct {
WT_ASYNC_CALLBACK iface;
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_ASYNC_OPTYPE type;
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);
}