int wt_id2entry_delete( Operation *op, WT_SESSION *session, Entry *e ) { int rc; WT_CURSOR *cursor = NULL; rc = session->open_cursor(session, WT_TABLE_ID2ENTRY, NULL, NULL, &cursor); if ( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_id2entry_delete) ": open_cursor failed: %s (%d)\n", wiredtiger_strerror(rc), rc, 0 ); goto done; } cursor->set_key(cursor, e->e_id); rc = cursor->remove(cursor); if ( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_id2entry_delete) ": remove failed: %s (%d)\n", wiredtiger_strerror(rc), rc, 0 ); goto done; } done: if(cursor){ cursor->close(cursor); } return rc; }
int main(int argc, char *argv[]) { WT_CONNECTION *conn; int ret; (void)argc; /* Unused variable */ /* * This code deliberately doesn't use the standard test_util macros, * we don't want to link against that code to smoke-test a build. */ (void)system("rm -rf WT_HOME && mkdir WT_HOME"); /* Open a connection to the database, creating it if necessary. */ if ((ret = wiredtiger_open("WT_HOME", NULL, "create", &conn)) != 0) { fprintf(stderr, "%s: wiredtiger_open: %s\n", argv[0], wiredtiger_strerror(ret)); return (EXIT_FAILURE); } /* Close the connection to the database. */ if ((ret = conn->close(conn, NULL)) != 0) { fprintf(stderr, "%s: WT_CONNECTION.close: %s\n", argv[0], wiredtiger_strerror(ret)); return (EXIT_FAILURE); } return (EXIT_SUCCESS); }
/* * Log printf - output a log message. */ int lprintf(CONFIG *cfg, int err, uint32_t level, const char *fmt, ...) { va_list ap; if (err == 0 && level <= cfg->verbose) { va_start(ap, fmt); vfprintf(cfg->logf, fmt, ap); va_end(ap); fprintf(cfg->logf, "\n"); if (level < cfg->verbose) { va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); printf("\n"); } } if (err == 0) return (0); /* We are dealing with an error. */ va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, " Error: %s\n", wiredtiger_strerror(err)); if (cfg->logf != NULL) { va_start(ap, fmt); vfprintf(cfg->logf, fmt, ap); va_end(ap); fprintf(cfg->logf, " Error: %s\n", wiredtiger_strerror(err)); } return (0); }
int main(void) { int ret; WT_CONNECTION *conn; WT_SESSION *session; /*! [processes] */ /* Open a connection to the database, creating it if necessary. */ if ((ret = wiredtiger_open(home, NULL, "create,multiprocess", &conn)) != 0) fprintf(stderr, "Error connecting to %s: %s\n", home, wiredtiger_strerror(ret)); /* Open a session for the current thread's work. */ if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) fprintf(stderr, "Error opening a session on %s: %s\n", home, wiredtiger_strerror(ret)); /* XXX Do some work... */ /* Note: closing the connection implicitly closes open session(s). */ if ((ret = conn->close(conn, NULL)) != 0) fprintf(stderr, "Error connecting to %s: %s\n", home, wiredtiger_strerror(ret)); /*! [processes] */ return (ret); }
int util_backup(WT_SESSION *session, int argc, char *argv[]) { WT_CURSOR *cursor; WT_DECL_RET; int ch; char *config; const char *directory, *name; config = NULL; while ((ch = util_getopt(argc, argv, "t:")) != EOF) switch (ch) { case 't': if (append_target(util_optarg, &config)) return (1); break; case '?': default: return (usage()); } argc -= util_optind; argv += util_optind; if (argc != 1) { (void)usage(); goto err; } directory = *argv; if ((ret = session->open_cursor( session, "backup:", NULL, config, &cursor)) != 0) { fprintf(stderr, "%s: cursor open(backup:) failed: %s\n", progname, wiredtiger_strerror(ret)); goto err; } /* Copy the files. */ while ( (ret = cursor->next(cursor)) == 0 && (ret = cursor->get_key(cursor, &name)) == 0) if ((ret = copy(name, directory)) != 0) goto err; if (ret == WT_NOTFOUND) ret = 0; if (ret != 0) { fprintf(stderr, "%s: cursor next(backup:) failed: %s\n", progname, wiredtiger_strerror(ret)); goto err; } err: if (config != NULL) free(config); if (cbuf != NULL) free(cbuf); return (ret); }
int main(void) { WT_CONNECTION *conn; WT_SESSION *session; int i, j, k, ret; /* * Create a clean test directory for this run of the test program if the * environment variable isn't already set (as is done by make check). */ if (getenv("WIREDTIGER_HOME") == NULL) { home = "WT_HOME"; ret = system("rm -rf WT_HOME && mkdir WT_HOME"); } else home = NULL; /* Open a connection to the database, creating it if necessary. */ if ((ret = wiredtiger_open(home, NULL, "create", &conn)) != 0) { fprintf(stderr, "Error connecting to %s: %s\n", home == NULL ? "." : home, wiredtiger_strerror(ret)); return (EXIT_FAILURE); } /* Open a session for the current thread's work. */ if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) { fprintf(stderr, "Error opening a session on %s: %s\n", home == NULL ? "." : home, wiredtiger_strerror(ret)); return (EXIT_FAILURE); } { /*! [packing] */ size_t size; char buf[50]; ret = wiredtiger_struct_size(session, &size, "iii", 42, 1000, -9); if (size > sizeof(buf)) { /* Allocate a bigger buffer. */ } ret = wiredtiger_struct_pack(session, buf, size, "iii", 42, 1000, -9); ret = wiredtiger_struct_unpack(session, buf, size, "iii", &i, &j, &k); /*! [packing] */ } /* Note: closing the connection implicitly closes open session(s). */ if ((ret = conn->close(conn, NULL)) != 0) { fprintf(stderr, "Error closing %s: %s\n", home == NULL ? "." : home, wiredtiger_strerror(ret)); return (EXIT_FAILURE); } return (EXIT_SUCCESS); }
int main(void) { WT_CONNECTION *conn; WT_CURSOR *cursor; WT_SESSION *session; int ret; /* Open a connection to the database, creating it if necessary. */ if ((ret = wiredtiger_open(home, NULL, "create", &conn)) != 0) fprintf(stderr, "Error connecting to %s: %s\n", home, wiredtiger_strerror(ret)); /* Open a session for the current thread's work. */ if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) fprintf(stderr, "Error opening a session on %s: %s\n", home, wiredtiger_strerror(ret)); ret = session->create(session, "table:world", "key_format=r,value_format=5sii," "columns=(id,country,population,area)"); /*! [open cursor #1] */ ret = session->open_cursor(session, "table:world", NULL, NULL, &cursor); /*! [open cursor #1] */ /*! [open cursor #2] */ ret = session->open_cursor(session, "table:world(country,population)", NULL, NULL, &cursor); /*! [open cursor #2] */ /*! [open cursor #3] */ ret = session->open_cursor(session, "statistics:", NULL, NULL, &cursor); /*! [open cursor #3] */ /* Create a simple string table to illustrate basic operations. */ ret = session->create(session, "table:map", "key_format=S,value_format=S"); ret = session->open_cursor(session, "table:map", NULL, NULL, &cursor); ret = cursor_insert(cursor); ret = cursor_reset(cursor); ret = cursor_forward_scan(cursor); ret = cursor_reset(cursor); ret = cursor_reverse_scan(cursor); ret = cursor_update(cursor); ret = cursor_remove(cursor); ret = cursor->close(cursor); /* Note: closing the connection implicitly closes open session(s). */ if ((ret = conn->close(conn, NULL)) != 0) fprintf(stderr, "Error connecting to %s: %s\n", home, wiredtiger_strerror(ret)); return (ret); }
/* * log_print_err -- * Report an error and return the error. */ int log_print_err(const char *m, int e, int fatal) { if (fatal) { g.running = 0; g.status = e; } fprintf(stderr, "%s: %s: %s\n", g.progname, m, wiredtiger_strerror(e)); if (g.logfp != NULL) fprintf(g.logfp, "%s: %s: %s\n", g.progname, m, wiredtiger_strerror(e)); return (e); }
/*! [thread main] */ int main(void) { WT_SESSION *session; WT_CURSOR *cursor; pthread_t threads[NUM_THREADS]; int i, ret; if ((ret = wiredtiger_open(home, NULL, "create", &conn)) != 0) fprintf(stderr, "Error connecting to %s: %s\n", home, wiredtiger_strerror(ret)); /* Note: further error checking omitted for clarity. */ ret = conn->open_session(conn, NULL, NULL, &session); ret = session->create(session, "table:access", "key_format=S,value_format=S"); ret = session->open_cursor(session, "table:access", NULL, "overwrite", &cursor); cursor->set_key(cursor, "key1"); cursor->set_value(cursor, "value1"); ret = cursor->insert(cursor); ret = session->close(session, NULL); for (i = 0; i < NUM_THREADS; i++) ret = pthread_create(&threads[i], NULL, scan_thread, NULL); for (i = 0; i < NUM_THREADS; i++) ret = pthread_join(threads[i], NULL); ret = conn->close(conn, NULL); return (ret); }
/* * die -- * Report an error and quit, dumping the configuration. */ void die(int e, const char *fmt, ...) { va_list ap; /* Single-thread error handling. */ (void)pthread_rwlock_wrlock(&g.death_lock); /* Try and turn off tracking so it doesn't obscure the error message. */ if (g.track) { g.track = 0; fprintf(stderr, "\n"); } if (fmt != NULL) { /* Death message. */ fprintf(stderr, "%s: ", g.progname); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); if (e != 0) fprintf(stderr, ": %s", wiredtiger_strerror(e)); fprintf(stderr, "\n"); } /* Flush/close any logging information. */ fclose_and_clear(&g.logfp); fclose_and_clear(&g.randfp); /* Display the configuration that failed. */ if (g.run_cnt) config_print(1); exit(EXIT_FAILURE); }
static void fail(int ret) { fprintf(stderr, "%s: %d (%s)\n", "wt2336_fileop_basic", ret, wiredtiger_strerror(ret)); exit(ret); }
/* * __handler_failure -- * Report the failure of an application-configured event handler. */ static void __handler_failure(WT_SESSION_IMPL *session, int error, const char *which, int error_handler_failed) { WT_EVENT_HANDLER *handler; WT_SESSION *wt_session; /* * !!! * SECURITY: * Buffer placed at the end of the stack in case snprintf overflows. */ char s[256]; (void)snprintf(s, sizeof(s), "application %s event handler failed: %s", which, wiredtiger_strerror(error)); /* * Use the error handler to report the failure, unless it was the error * handler that failed. If it was the error handler that failed, or a * call to the error handler fails, use the default error handler. */ wt_session = (WT_SESSION *)session; handler = session->event_handler; if (!error_handler_failed && handler->handle_error != __handle_error_default && handler->handle_error(handler, wt_session, error, s) == 0) return; (void)__handle_error_default(NULL, wt_session, error, s); }
WiredTigerEngine::ContextHolder& WiredTigerEngine::GetContextHolder() { ContextHolder& holder = m_context.GetValue(); if (NULL == holder.session) { int ret = 0; if ((ret = m_db->open_session(m_db, NULL, NULL, &holder.session)) != 0) { ERROR_LOG("Error opening a session on %s: %s", m_cfg.path.c_str(), wiredtiger_strerror(ret)); } else { if (m_cfg.init_table_options.empty()) { m_cfg.init_table_options = "key_format=u,value_format=u,prefix_compression=true,collator=ardb_comparator"; } else { if (m_cfg.init_table_options.find("collator=ardb_comparator") == std::string::npos) { m_cfg.init_table_options.append(",collator=ardb_comparator"); } } ret = holder.session->create(holder.session, ARDB_TABLE, m_cfg.init_table_options.c_str()); CHECK_WT_RETURN(ret); } holder.engine = this; } return holder; }
int wt_tool_entry_open( BackendDB *be, int mode ) { struct wt_info *wi = (struct wt_info *) be->be_private; WT_CONNECTION *conn = wi->wi_conn; int rc; wc = wt_ctx_init(wi); if( !wc ){ Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_tool_entry_open) ": wt_ctx_get failed: %s (%d)\n", 0, 0, 0 ); return -1; } rc = wc->session->open_cursor(wc->session, WT_TABLE_ID2ENTRY"(entry)" ,NULL, NULL, &reader); if ( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_tool_entry_open) ": cursor open failed: %s (%d)\n", wiredtiger_strerror(rc), rc, 0 ); return -1; } return 0; }
wt_ctx * wt_ctx_init(struct wt_info *wi) { int rc; wt_ctx *wc; wc = ch_malloc( sizeof( wt_ctx ) ); if( !wc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_ctx_init) ": cannot allocate memory\n", 0, 0, 0 ); return NULL; } memset(wc, 0, sizeof(wt_ctx)); if(!wc->session){ rc = wi->wi_conn->open_session(wi->wi_conn, NULL, NULL, &wc->session); if( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_ctx_session) ": open_session error %s(%d)\n", wiredtiger_strerror(rc), rc, 0 ); return NULL; } } return wc; }
/* * die -- * Report an error and quit. */ void die(int e, const char *fmt, ...) { va_list ap; if (fmt != NULL) { /* Death message. */ fprintf(stderr, "%s: ", g.progname); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); if (e != 0) fprintf(stderr, ": %s", wiredtiger_strerror(e)); fprintf(stderr, "\n"); } /* Flush/close any logging information. */ if (g.logfp != NULL) (void)fclose(g.logfp); if (g.rand_log != NULL) (void)fclose(g.rand_log); /* Display the configuration that failed. */ config_print(1); exit(EXIT_FAILURE); }
static int wt_id2entry_put( Operation *op, WT_SESSION *session, Entry *e, const char *config ) { struct berval bv; WT_CURSOR *cursor = NULL; WT_ITEM item; int rc; rc = entry_encode( e, &bv ); if(rc != LDAP_SUCCESS){ return -1; } item.size = bv.bv_len; item.data = bv.bv_val; rc = session->open_cursor(session, WT_TABLE_ID2ENTRY, NULL, config, &cursor); if ( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_id2entry_put) ": open_cursor failed: %s (%d)\n", wiredtiger_strerror(rc), rc, 0 ); goto done; } cursor->set_key(cursor, e->e_id); cursor->set_value(cursor, e->e_ndn, &item); rc = cursor->insert(cursor); if ( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_id2entry_put) ": insert failed: %s (%d)\n", wiredtiger_strerror(rc), rc, 0 ); goto done; } done: ch_free( bv.bv_val ); if(cursor){ cursor->close(cursor); } return rc; }
int wt_id2entry( BackendDB *be, WT_SESSION *session, ID id, Entry **ep ){ int rc; WT_CURSOR *cursor = NULL; WT_ITEM item; EntryHeader eh; int eoff; Entry *e = NULL; rc = session->open_cursor(session, WT_TABLE_ID2ENTRY"(entry)", NULL, NULL, &cursor); if ( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_id2entry) ": open_cursor failed: %s (%d)\n", wiredtiger_strerror(rc), rc, 0 ); goto done; } cursor->set_key(cursor, id); rc = cursor->search(cursor); if ( rc ) { goto done; } cursor->get_value(cursor, &item); rc = wt_entry_header( &item, &eh ); eoff = eh.data - (char *)item.data; eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + item.size; eh.bv.bv_val = ch_malloc( eh.bv.bv_len ); memset(eh.bv.bv_val, 0xff, eh.bv.bv_len); eh.data = eh.bv.bv_val + eh.nvals * sizeof( struct berval ); memcpy(eh.data, item.data, item.size); eh.data += eoff; rc = entry_decode( &eh, &e ); if ( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_id2entry) ": entry decode error: %s (%d)\n", rc, 0, 0 ); goto done; } e->e_id = id; *ep = e; done: if(cursor){ cursor->close(cursor); } return rc; }
static WT_CURSOR* create_wiredtiger_cursor(WT_SESSION* session) { WT_CURSOR* cursor = NULL; int ret = session->open_cursor(session, ARDB_TABLE, NULL, "raw", &cursor); if (0 != ret) { ERROR_LOG("Error create cursor for reason: %s", wiredtiger_strerror(ret)); return NULL; } return cursor; }
/* * Log printf - output a log message. */ void lprintf(const WTPERF *wtperf, int err, uint32_t level, const char *fmt, ...) { CONFIG_OPTS *opts; va_list ap; opts = wtperf->opts; if (err == 0 && level <= opts->verbose) { va_start(ap, fmt); vfprintf(wtperf->logf, fmt, ap); va_end(ap); fprintf(wtperf->logf, "\n"); if (level < opts->verbose) { va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); printf("\n"); } } if (err == 0) return; /* We are dealing with an error. */ va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, " Error: %s\n", wiredtiger_strerror(err)); if (wtperf->logf != NULL) { va_start(ap, fmt); vfprintf(wtperf->logf, fmt, ap); va_end(ap); fprintf(wtperf->logf, " Error: %s\n", wiredtiger_strerror(err)); } /* Never attempt to continue if we got a panic from WiredTiger. */ if (err == WT_PANIC) abort(); }
int main(void) { int ret; WT_CONNECTION *conn; WT_SESSION *session; /* * Create a clean test directory for this run of the test program if the * environment variable isn't already set (as is done by make check). */ if (getenv("WIREDTIGER_HOME") == NULL) { home = "WT_HOME"; ret = system("rm -rf WT_HOME && mkdir WT_HOME"); } else home = NULL; /* Open a connection to the database, creating it if necessary. */ if ((ret = wiredtiger_open(home, NULL, "create", &conn)) != 0) fprintf(stderr, "Error connecting to %s: %s\n", home == NULL ? "." : home, wiredtiger_strerror(ret)); /*! [add collator nocase] */ ret = conn->add_collator(conn, "nocase", &nocasecoll, NULL); /*! [add collator nocase] */ /*! [add collator prefix10] */ ret = conn->add_collator(conn, "prefix10", &pcoll10.iface, NULL); /* Open a session for the current thread's work. */ if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) fprintf(stderr, "Error opening a session on %s: %s\n", home == NULL ? "." : home, wiredtiger_strerror(ret)); /* Do some work... */ ret = conn->close(conn, NULL); /*! [add collator prefix10] */ return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE); }
int WiredTigerEngine::Put(const Slice& key, const Slice& value, const Options& options) { ContextHolder& holder = GetContextHolder(); WT_SESSION* session = holder.session; if (NULL == session) { return -1; } // if (holder.trasc_ref > 0) // { // PutOperation* op = new PutOperation; // op->key.assign((const char*) key.data(), key.size()); // op->value.assign((const char*) value.data(), value.size()); // m_write_queue.Push(op); // holder.readonly_transc = false; // return 0; // } int ret = 0; WT_CURSOR *cursor = holder.batch == NULL ? create_wiredtiger_cursor(session) : holder.batch; if (NULL == cursor) { return -1; } WT_ITEM key_item, value_item; key_item.data = key.data(); key_item.size = key.size(); value_item.data = value.data(); value_item.size = value.size(); cursor->set_key(cursor, &key_item); cursor->set_value(cursor, &value_item); ret = cursor->insert(cursor); if (0 != ret) { ERROR_LOG("Error write data for reason: %s", wiredtiger_strerror(ret)); ret = -1; } if (holder.batch == NULL) { ret = cursor->close(cursor); CHECK_WT_RETURN(ret); } else { holder.IncBatchWriteCount(); if (holder.batch_write_count >= m_cfg.batch_commit_watermark) { holder.RestartBatchWrite(); } } return ret; }
WT_CURSOR * wt_ctx_index_cursor(wt_ctx *wc, struct berval *name, int create) { WT_CURSOR *cursor = NULL; WT_SESSION *session = wc->session; char tablename[1024]; int rc; snprintf(tablename, sizeof(tablename), "table:%s", name->bv_val); rc = session->open_cursor(session, tablename, NULL, "overwrite=false", &cursor); if (rc == ENOENT && create) { rc = session->create(session, tablename, "key_format=uQ," "value_format=x," "columns=(key, id, none)"); if( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(indexer) ": table \"%s\": " "cannot create idnex table: %s (%d)\n", tablename, wiredtiger_strerror(rc), rc); return NULL; } rc = session->open_cursor(session, tablename, NULL, "overwrite=false", &cursor); } if ( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_id2entry_put) ": open cursor failed: %s (%d)\n", wiredtiger_strerror(rc), rc, 0 ); return NULL; } return cursor; }
/* * die -- * Report an error and quit. */ void die(int e, const char *fmt, ...) { va_list ap; fprintf(stderr, "%s: ", progname); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); if (e != 0) fprintf(stderr, ": %s", wiredtiger_strerror(e)); fprintf(stderr, "\n"); exit(EXIT_FAILURE); }
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; int ret; (void)flags; /* Unused */ ret = 0; /*! [async get type] */ /* Retrieve the operation's WT_ASYNC_OPTYPE type. */ type = op->get_type(op); /*! [async get type] */ /*! [async get identifier] */ /* Retrieve the operation's 64-bit identifier. */ id = op->get_id(op); /*! [async get identifier] */ /* 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) { /*! [async get the operation's string key] */ ret = op->get_key(op, &k); key = k.data; /*! [async get the operation's string key] */ /*! [async get the operation's string value] */ ret = op->get_value(op, &v); value = v.data; /*! [async get the operation's string value] */ ATOMIC_ADD(asynckey->num_keys, 1); printf("Id %" PRIu64 " got record: %s : %s\n", id, key, value); } return (ret); }
ID wt_tool_entry_next( BackendDB *be ) { int rc; ID id; rc = reader->next(reader); switch( rc ){ case 0: break; case WT_NOTFOUND: return NOID; default: Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_tool_entry_next) ": next failed: %s (%d)\n", wiredtiger_strerror(rc), rc, 0 ); return NOID; } rc = reader->get_key(reader, &id); if( rc ){ Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_tool_entry_next) ": get_key failed: %s (%d)\n", wiredtiger_strerror(rc), rc, 0 ); } rc = reader->get_value(reader, &item); if( rc ){ Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_tool_entry_next) ": get_value failed: %s (%d)\n", wiredtiger_strerror(rc), rc, 0 ); } return id; }
/* * Log printf - output a log message. */ void lprintf(const CONFIG *cfg, int err, uint32_t level, const char *fmt, ...) { va_list ap; if (err == 0 && level <= cfg->verbose) { va_start(ap, fmt); vfprintf(cfg->logf, fmt, ap); va_end(ap); fprintf(cfg->logf, "\n"); if (level < cfg->verbose) { va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); printf("\n"); } } if (err == 0) return; /* We are dealing with an error. */ va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, " Error: %s\n", wiredtiger_strerror(err)); if (cfg->logf != NULL) { va_start(ap, fmt); vfprintf(cfg->logf, fmt, ap); va_end(ap); fprintf(cfg->logf, " Error: %s\n", wiredtiger_strerror(err)); } /* Never attempt to continue if we got a panic from WiredTiger. */ if (err == WT_PANIC) exit(1); }
int main(void) { /*! [access example connection] */ WT_CONNECTION *conn; WT_CURSOR *cursor; WT_SESSION *session; const char *key, *value; int ret; if ((ret = wiredtiger_open(home, NULL, "create", &conn)) != 0 || (ret = conn->open_session(conn, NULL, NULL, &session)) != 0) { fprintf(stderr, "Error connecting to %s: %s\n", home, wiredtiger_strerror(ret)); return (ret); } /*! [access example connection] */ /*! [access example table create] */ ret = session->create(session, "table:access", "key_format=S,value_format=S"); /*! [access example table create] */ /*! [access example cursor open] */ ret = session->open_cursor(session, "table:access", NULL, NULL, &cursor); /*! [access example cursor open] */ /*! [access example cursor insert] */ cursor->set_key(cursor, "key1"); /* Insert a record. */ cursor->set_value(cursor, "value1"); ret = cursor->insert(cursor); /*! [access example cursor insert] */ /*! [access example cursor list] */ ret = cursor->reset(cursor); /* Restart the scan. */ while ((ret = cursor->next(cursor)) == 0) { ret = cursor->get_key(cursor, &key); ret = cursor->get_value(cursor, &value); printf("Got record: %s : %s\n", key, value); } /*! [access example cursor list] */ /*! [access example close] */ ret = conn->close(conn, NULL); /*! [access example close] */ return (ret); }
int main(void) { WT_CONNECTION *conn; WT_SESSION *session; char buf[50]; size_t size; int i, j, k, ret; /* Open a connection to the database, creating it if necessary. */ if ((ret = wiredtiger_open(home, NULL, "create", &conn)) != 0) fprintf(stderr, "Error connecting to %s: %s\n", home, wiredtiger_strerror(ret)); /* Open a session for the current thread's work. */ if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) fprintf(stderr, "Error opening a session on %s: %s\n", home, wiredtiger_strerror(ret)); /*! [packing] */ ret = wiredtiger_struct_size(session, &size, "iii", 42, 1000, -9); if (size > sizeof(buf)) { /* Allocate a bigger buffer. */ } ret = wiredtiger_struct_pack(session, buf, size, "iii", 42, 1000, -9); ret = wiredtiger_struct_unpack(session, buf, size, "iii", &i, &j, &k); /*! [packing] */ /* Note: closing the connection implicitly closes open session(s). */ if ((ret = conn->close(conn, NULL)) != 0) fprintf(stderr, "Error connecting to %s: %s\n", home, wiredtiger_strerror(ret)); return (ret); }
static int setup_copy(WT_CONNECTION **wt_connp, WT_SESSION **sessionp) { int ret; if ((ret = wiredtiger_open(home2, NULL, CONN_CONFIG, wt_connp)) != 0) { fprintf(stderr, "Error connecting to %s: %s\n", home1, wiredtiger_strerror(ret)); 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); }