Shows how to access the database log files.
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef _WIN32
#include <unistd.h>
#else
#define snprintf _snprintf
#endif
#include <wiredtiger.h>
static const char *home1 = "WT_HOME_LOG_1";
static const char *home2 = "WT_HOME_LOG_2";
static const char * const uri = "table:logtest";
#define CONN_CONFIG "create,cache_size=100MB,log=(archive=false,enabled=true)"
#define MAX_KEYS 10
static int
{
int ret;
CONN_CONFIG, wt_connp)) != 0) {
fprintf(stderr, "Error connecting to %s: %s\n",
return (ret);
}
ret = (*wt_connp)->open_session(*wt_connp, NULL, NULL, sessionp);
ret = (*sessionp)->create(*sessionp, uri,
"key_format=S,value_format=S");
return (ret);
}
static int
{
int ret;
const char *key, *key_copy, *value, *value_copy;
ret = session->
open_cursor(session, uri, NULL, NULL, &cursor);
ret = sess_copy->
open_cursor(sess_copy, uri, NULL, NULL, &curs_copy);
while ((ret = cursor->
next(cursor)) == 0) {
ret = curs_copy->
next(curs_copy);
ret = cursor->
get_key(cursor, &key);
ret = curs_copy->
get_key(curs_copy, &key_copy);
ret = curs_copy->
get_value(curs_copy, &value_copy);
if (strcmp(key, key_copy) != 0 ||
strcmp(value, value_copy) != 0) {
fprintf(stderr,
"Mismatched: key %s, key_copy %s "
"value %s value_copy %s\n",
key, key_copy, value, value_copy);
return (1);
}
}
fprintf(stderr,
ret = cursor->
close(cursor);
ret = curs_copy->
next(curs_copy);
fprintf(stderr,
ret = curs_copy->
close(curs_copy);
return (ret);
}
static void
print_record(
WT_LSN *lsn, uint32_t opcount,
uint32_t rectype, uint32_t optype, uint64_t txnid, uint32_t fileid,
{
printf(
"LSN [%" PRIu32 "][%" PRIu64 "].%" PRIu32
": record type %" PRIu32 " optype %" PRIu32
" txnid %" PRIu64 " fileid %" PRIu32,
rectype, optype, txnid, fileid);
printf(
" key size %zu value size %zu\n", key->
size, value->
size);
printf(
"Application Record: %s\n", (
char *)value->
data);
}
static int
{
uint64_t txnid;
uint32_t fileid, opcount, optype, rectype;
int ret;
ret = session->
open_cursor(session,
"log:", NULL, NULL, &cursor);
while ((ret = cursor->
next(cursor)) == 0) {
&rectype, &optype, &fileid, &logrec_key, &logrec_value);
print_record(&lsn, opcount,
rectype, optype, txnid, fileid, &logrec_key, &logrec_value);
}
ret = 0;
ret = cursor->
close(cursor);
return (ret);
}
static int
{
uint64_t txnid;
uint32_t fileid, opcount, optype, rectype;
int first, i, in_txn, ret;
ret = setup_copy(&wt_conn2, &session2);
ret = session->
open_cursor(session,
"log:", NULL, NULL, &cursor);
ret = session2->
open_cursor(session2, uri, NULL,
"raw=true", &cursor2);
i = 0;
in_txn = 0;
txnid = 0;
memset(&lsnsave, 0, sizeof(lsnsave));
while ((ret = cursor->
next(cursor)) == 0) {
if (++i == MAX_KEYS)
lsnsave = lsn;
ret = cursor->
get_value(cursor, &txnid, &rectype,
&optype, &fileid, &logrec_key, &logrec_value);
print_record(&lsn, opcount,
rectype, optype, txnid, fileid, &logrec_key, &logrec_value);
if (in_txn && opcount == 0) {
in_txn = 0;
}
if (!in_txn) {
NULL);
in_txn = 1;
}
cursor2->
set_key(cursor2, &logrec_key);
ret = cursor2->
insert(cursor2);
}
}
if (in_txn)
ret = cursor2->
close(cursor2);
if (compare_tables(session, session2))
printf("compare failed\n");
ret = session2->
close(session2, NULL);
ret = wt_conn2->
close(wt_conn2, NULL);
ret = cursor->
reset(cursor);
printf("Reset to saved...\n");
first = 1;
while ((ret = cursor->
get_key(cursor,
if (first) {
first = 0;
fprintf(stderr,
"search returned the wrong LSN\n");
exit (1);
}
}
ret = cursor->
get_value(cursor, &txnid, &rectype,
&optype, &fileid, &logrec_key, &logrec_value);
print_record(&lsn, opcount,
rectype, optype, txnid, fileid, &logrec_key, &logrec_value);
ret = cursor->
next(cursor);
if (ret != 0)
break;
}
ret = cursor->
close(cursor);
return (ret);
}
int
main(void)
{
int i, record_count, ret;
char cmd_buf[256], k[16], v[16];
snprintf(cmd_buf, sizeof(cmd_buf), "rm -rf %s %s && mkdir %s %s",
home1, home2, home1, home2);
if ((ret = system(cmd_buf)) != 0) {
fprintf(stderr, "%s: failed ret %d\n", cmd_buf, ret);
return (ret);
}
CONN_CONFIG, &wt_conn)) != 0) {
fprintf(stderr, "Error connecting to %s: %s\n",
return (ret);
}
ret = session->
create(session, uri,
"key_format=S,value_format=S");
ret = session->
open_cursor(session, uri, NULL, NULL, &cursor);
for (record_count = 0, i = 0; i < MAX_KEYS; i++, record_count++) {
snprintf(k, sizeof(k), "key%d", i);
snprintf(v, sizeof(v), "value%d", i);
}
for (i = MAX_KEYS; i < MAX_KEYS+5; i++, record_count++) {
snprintf(k, sizeof(k), "key%d", i);
snprintf(v, sizeof(v), "value%d", i);
}
ret = cursor->
close(cursor);
ret = session->
log_printf(session,
"Wrote %d records", record_count);
ret = wt_conn->
close(wt_conn, NULL);
CONN_CONFIG, &wt_conn)) != 0) {
fprintf(stderr, "Error connecting to %s: %s\n",
return (ret);
}
ret = simple_walk_log(session);
ret = walk_log(session);
ret = wt_conn->
close(wt_conn, NULL);
return (ret);
}