int main(void) { int ret; { /*! [Open a connection] */ WT_CONNECTION *conn; const char *home = "WT_TEST"; ret = wiredtiger_open(home, NULL, "create,transactional", &conn); /*! [Open a connection] */ (void)conn->close(conn, NULL); } /*! [Get the WiredTiger library version #1] */ printf("WiredTiger version %s\n", wiredtiger_version(NULL, NULL, NULL)); /*! [Get the WiredTiger library version #1] */ { /*! [Get the WiredTiger library version #2] */ int major, minor, patch; (void)wiredtiger_version(&major, &minor, &patch); printf("WiredTiger version is %d, %d (patch %d)\n", major, minor, patch); /*! [Get the WiredTiger library version #2] */ } return (ret); }
const std::string WiredTigerEngine::Stats() { std::string info; int major_v, minor_v, patch; (void) wiredtiger_version(&major_v, &minor_v, &patch); info.append("WiredTiger version:").append(stringfromll(major_v)).append(".").append(stringfromll(minor_v)).append( ".").append(stringfromll(patch)).append("\r\n"); info.append("WiredTiger Init Options:").append(m_cfg.init_options).append("\r\n"); info.append("WiredTiger Table Init Options:").append(m_cfg.init_table_options).append("\r\n"); ContextHolder& holder = m_context.GetValue(); WT_SESSION* session = holder.session; if (NULL == session) { return info; } WT_CURSOR *cursor; int ret; /*! [statistics database function] */ if ((ret = session->open_cursor(session, "statistics:", NULL, NULL, &cursor)) == 0) { print_cursor(cursor, info); cursor->close(cursor); } if ((ret = session->open_cursor(session, "statistics:table:ardb", NULL, NULL, &cursor)) == 0) { print_cursor(cursor, info); cursor->close(cursor); } return info; }
/* * __wt_turtle_update -- * Update the turtle file. */ int __wt_turtle_update(WT_SESSION_IMPL *session, const char *key, const char *value) { WT_FSTREAM *fs; WT_DECL_RET; int vmajor, vminor, vpatch; const char *version; fs = NULL; /* * Create the turtle setup file: we currently re-write it from scratch * every time. */ WT_RET(__wt_fopen(session, WT_METADATA_TURTLE_SET, WT_FS_OPEN_CREATE | WT_FS_OPEN_EXCLUSIVE, WT_STREAM_WRITE, &fs)); version = wiredtiger_version(&vmajor, &vminor, &vpatch); WT_ERR(__wt_fprintf(session, fs, "%s\n%s\n%s\n" "major=%d,minor=%d,patch=%d\n%s\n%s\n", WT_METADATA_VERSION_STR, version, WT_METADATA_VERSION, vmajor, vminor, vpatch, key, value)); /* Flush the stream and rename the file into place. */ ret = __wt_sync_and_rename( session, &fs, WT_METADATA_TURTLE_SET, WT_METADATA_TURTLE); /* Close any file handle left open, remove any temporary file. */ err: WT_TRET(__wt_fclose(session, &fs)); WT_TRET(__wt_remove_if_exists(session, WT_METADATA_TURTLE_SET, false)); return (ret); }
/* * dump_prefix -- * Output the dump file header prefix. */ static int dump_prefix(WT_SESSION *session, int hex) { int vmajor, vminor, vpatch; (void)wiredtiger_version(&vmajor, &vminor, &vpatch); if (printf( "WiredTiger Dump (WiredTiger Version %d.%d.%d)\n", vmajor, vminor, vpatch) < 0 || printf("Format=%s\n", hex ? "hex" : "print") < 0 || printf("Header\n") < 0) return (util_err(session, EIO, NULL)); return (0); }
/* * __wt_turtle_update -- * Update the turtle file. */ int __wt_turtle_update( WT_SESSION_IMPL *session, const char *key, const char *value) { FILE *fp; WT_DECL_RET; int vmajor, vminor, vpatch; const char *version; char *path; fp = NULL; path = NULL; /* * Create the turtle setup file: we currently re-write it from scratch * every time. */ WT_RET(__wt_filename(session, WT_METADATA_TURTLE_SET, &path)); if ((fp = fopen(path, "w")) == NULL) ret = __wt_errno(); __wt_free(session, path); if (fp == NULL) return (ret); version = wiredtiger_version(&vmajor, &vminor, &vpatch); WT_ERR_TEST((fprintf(fp, "%s\n%s\n%s\n" "major=%d,minor=%d,patch=%d\n%s\n%s\n", WT_METADATA_VERSION_STR, version, WT_METADATA_VERSION, vmajor, vminor, vpatch, key, value) < 0), __wt_errno()); ret = fclose(fp); fp = NULL; WT_ERR_TEST(ret == EOF, __wt_errno()); WT_ERR( __wt_rename(session, WT_METADATA_TURTLE_SET, WT_METADATA_TURTLE)); if (0) { err: WT_TRET(__wt_remove(session, WT_METADATA_TURTLE_SET)); } if (fp != NULL) WT_TRET(fclose(fp) == 0 ? 0 : __wt_errno()); return (ret); }
/* * dump_prefix -- * Output the dump file header prefix. */ static int dump_prefix(WT_SESSION *session, bool hex, bool json) { int vmajor, vminor, vpatch; (void)wiredtiger_version(&vmajor, &vminor, &vpatch); if (!json && (printf( "WiredTiger Dump (WiredTiger Version %d.%d.%d)\n", vmajor, vminor, vpatch) < 0 || printf("Format=%s\n", hex ? "hex" : "print") < 0 || printf("Header\n") < 0)) return (util_err(session, EIO, NULL)); else if (json && printf( " \"%s\" : \"%d (%d.%d.%d)\",\n", DUMP_JSON_VERSION_MARKER, DUMP_JSON_CURRENT_VERSION, vmajor, vminor, vpatch) < 0) return (util_err(session, EIO, NULL)); return (0); }
/* * __wt_turtle_update -- * Update the turtle file. */ int __wt_turtle_update( WT_SESSION_IMPL *session, const char *key, const char *value) { WT_FH *fh; WT_DECL_ITEM(buf); WT_DECL_RET; int vmajor, vminor, vpatch; const char *version; fh = NULL; /* * Create the turtle setup file: we currently re-write it from scratch * every time. */ WT_RET(__wt_open( session, WT_METADATA_TURTLE_SET, 1, 1, WT_FILE_TYPE_TURTLE, &fh)); version = wiredtiger_version(&vmajor, &vminor, &vpatch); WT_ERR(__wt_scr_alloc(session, 2 * 1024, &buf)); WT_ERR(__wt_buf_fmt(session, buf, "%s\n%s\n%s\n" "major=%d,minor=%d,patch=%d\n%s\n%s\n", WT_METADATA_VERSION_STR, version, WT_METADATA_VERSION, vmajor, vminor, vpatch, key, value)); WT_ERR(__wt_write(session, fh, 0, buf->size, buf->data)); /* Flush the handle and rename the file into place. */ ret = __wt_sync_and_rename_fh( session, &fh, WT_METADATA_TURTLE_SET, WT_METADATA_TURTLE); /* Close any file handle left open, remove any temporary file. */ err: WT_TRET(__wt_close(session, &fh)); WT_TRET(__wt_remove_if_exists(session, WT_METADATA_TURTLE_SET)); __wt_scr_free(session, &buf); return (ret); }
int main(void) { WT_CONNECTION *conn; int ret; /*! [Open a connection] */ ret = wiredtiger_open(home, NULL, "create,cache_size=500M", &conn); /*! [Open a connection] */ if (ret == 0) connection_ops(conn); /* * The connection has been closed. */ #ifdef MIGHT_NOT_RUN /* * This example code gets run, and the compression libraries might not * be installed, causing the open to fail. The documentation requires * the code snippets, use #ifdef's to avoid running it. */ /*! [Configure bzip2 extension] */ ret = wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_bzip2.so]", &conn); /*! [Configure bzip2 extension] */ if (ret == 0) (void)conn->close(conn, NULL); /*! [Configure snappy extension] */ ret = wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_snappy.so]", &conn); /*! [Configure snappy extension] */ if (ret == 0) (void)conn->close(conn, NULL); /*! [Configure zlib extension] */ ret = wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_zlib.so]", &conn); /*! [Configure zlib extension] */ if (ret == 0) (void)conn->close(conn, NULL); /* * This example code gets run, and direct I/O might not be available, * causing the open to fail. The documentation requires code snippets, * use #ifdef's to avoid running it. */ /* Might Not Run: direct I/O may not be available. */ /*! [Configure direct_io for data files] */ ret = wiredtiger_open(home, NULL, "create,direct_io=[data]", &conn); /*! [Configure direct_io for data files] */ if (ret == 0) (void)conn->close(conn, NULL); #endif /*! [Configure file_extend] */ ret = wiredtiger_open( home, NULL, "create,file_extend=(data=16MB)", &conn); /*! [Configure file_extend] */ if (ret == 0) (void)conn->close(conn, NULL); /*! [Statistics configuration] */ ret = wiredtiger_open(home, NULL, "create,statistics=(all)", &conn); /*! [Statistics configuration] */ if (ret == 0) (void)conn->close(conn, NULL); /*! [Statistics logging] */ ret = wiredtiger_open( home, NULL, "create,statistics_log=(wait=30)", &conn); /*! [Statistics logging] */ if (ret == 0) (void)conn->close(conn, NULL); /*! [Statistics logging with a table] */ ret = wiredtiger_open(home, NULL, "create," "statistics_log=(sources=(\"table:table1\",\"table:table2\"))", &conn); /*! [Statistics logging with a table] */ if (ret == 0) (void)conn->close(conn, NULL); /*! [Statistics logging with all tables] */ ret = wiredtiger_open(home, NULL, "create,statistics_log=(sources=(\"table:\"))", &conn); /*! [Statistics logging with all tables] */ if (ret == 0) (void)conn->close(conn, NULL); #ifdef MIGHT_NOT_RUN /* * This example code gets run, and a non-existent log file path might * cause the open to fail. The documentation requires code snippets, * use #ifdef's to avoid running it. */ /*! [Statistics logging with path] */ ret = wiredtiger_open(home, NULL, "create," "statistics_log=(wait=120,path=/log/log.%m.%d.%y)", &conn); /*! [Statistics logging with path] */ if (ret == 0) (void)conn->close(conn, NULL); #endif /*! [Get the WiredTiger library version #1] */ printf("WiredTiger version %s\n", wiredtiger_version(NULL, NULL, NULL)); /*! [Get the WiredTiger library version #1] */ { /*! [Get the WiredTiger library version #2] */ int major, minor, patch; (void)wiredtiger_version(&major, &minor, &patch); printf("WiredTiger version is %d, %d (patch %d)\n", major, minor, patch); /*! [Get the WiredTiger library version #2] */ } return (ret); }
int main(void) { WT_CONNECTION *conn; int 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] */ ret = wiredtiger_open(home, NULL, "create,cache_size=5GB,log=(enabled,recover=on)", &conn); /*! [Open a connection] */ if (ret == 0) ret = connection_ops(conn); /* * The connection has been closed. */ #ifdef MIGHT_NOT_RUN /* * This example code gets run, and the compression libraries might not * be installed, causing the open to fail. The documentation requires * the code snippets, use #ifdef's to avoid running it. */ /*! [Configure lz4 extension] */ ret = wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_lz4.so]", &conn); /*! [Configure lz4 extension] */ if (ret == 0) (void)conn->close(conn, NULL); /*! [Configure snappy extension] */ ret = wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_snappy.so]", &conn); /*! [Configure snappy extension] */ if (ret == 0) (void)conn->close(conn, NULL); /*! [Configure zlib extension] */ ret = wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_zlib.so]", &conn); /*! [Configure zlib extension] */ if (ret == 0) (void)conn->close(conn, NULL); /*! [Configure zlib extension with compression level] */ ret = wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/" "libwiredtiger_zlib.so=[config=[compression_level=3]]]", &conn); /*! [Configure zlib extension with compression level] */ if (ret == 0) (void)conn->close(conn, NULL); /*! [Configure zstd extension] */ ret = wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_zstd.so]", &conn); /*! [Configure zstd extension] */ if (ret == 0) (void)conn->close(conn, NULL); /*! [Configure zstd extension with compression level] */ ret = wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/" "libwiredtiger_zstd.so=[config=[compression_level=9]]]", &conn); /*! [Configure zstd extension with compression level] */ if (ret == 0) (void)conn->close(conn, NULL); /* * This example code gets run, and direct I/O might not be available, * causing the open to fail. The documentation requires code snippets, * use #ifdef's to avoid running it. */ /* Might Not Run: direct I/O may not be available. */ /*! [Configure direct_io for data files] */ ret = wiredtiger_open(home, NULL, "create,direct_io=[data]", &conn); /*! [Configure direct_io for data files] */ if (ret == 0) (void)conn->close(conn, NULL); #endif /*! [Configure file_extend] */ ret = wiredtiger_open( home, NULL, "create,file_extend=(data=16MB)", &conn); /*! [Configure file_extend] */ if (ret == 0) ret = conn->close(conn, NULL); /*! [Eviction configuration] */ /* * Configure eviction to begin at 90% full, and run until the cache * is only 75% dirty. */ ret = wiredtiger_open(home, NULL, "create,eviction_trigger=90,eviction_dirty_target=75", &conn); /*! [Eviction configuration] */ if (ret == 0) ret = conn->close(conn, NULL); /*! [Eviction worker configuration] */ /* Configure up to four eviction threads */ ret = wiredtiger_open(home, NULL, "create,eviction_trigger=90,eviction=(threads_max=4)", &conn); /*! [Eviction worker configuration] */ if (ret == 0) ret = conn->close(conn, NULL); /*! [Statistics configuration] */ ret = wiredtiger_open(home, NULL, "create,statistics=(all)", &conn); /*! [Statistics configuration] */ if (ret == 0) ret = conn->close(conn, NULL); /*! [Statistics logging] */ ret = wiredtiger_open( home, NULL, "create,statistics_log=(wait=30)", &conn); /*! [Statistics logging] */ if (ret == 0) ret = conn->close(conn, NULL); #ifdef MIGHT_NOT_RUN /* * Don't run this code, statistics logging doesn't yet support tables. */ /*! [Statistics logging with a table] */ ret = wiredtiger_open(home, NULL, "create, statistics_log=(" "sources=(\"table:table1\",\"table:table2\"), wait=5)", &conn); /*! [Statistics logging with a table] */ if (ret == 0) ret = conn->close(conn, NULL); /* * Don't run this code, statistics logging doesn't yet support indexes. */ /*! [Statistics logging with a source type] */ ret = wiredtiger_open(home, NULL, "create, statistics_log=(sources=(\"index:\"), wait=5)", &conn); /*! [Statistics logging with a source type] */ if (ret == 0) ret = conn->close(conn, NULL); /* * Don't run this code, because memory checkers get very upset when we * leak memory. */ (void)wiredtiger_open(home, NULL, "create", &conn); /*! [Connection close leaking memory] */ ret = conn->close(conn, "leak_memory=true"); /*! [Connection close leaking memory] */ #endif /*! [Get the WiredTiger library version #1] */ printf("WiredTiger version %s\n", wiredtiger_version(NULL, NULL, NULL)); /*! [Get the WiredTiger library version #1] */ { /*! [Get the WiredTiger library version #2] */ int major_v, minor_v, patch; (void)wiredtiger_version(&major_v, &minor_v, &patch); printf("WiredTiger version is %d, %d (patch %d)\n", major_v, minor_v, patch); /*! [Get the WiredTiger library version #2] */ } return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE); }
/* * __conn_single -- * Confirm that no other thread of control is using this database. */ static int __conn_single(WT_SESSION_IMPL *session, const char **cfg) { WT_CONFIG_ITEM cval; WT_CONNECTION_IMPL *conn, *t; WT_DECL_RET; off_t size; uint32_t len; int created; char buf[256]; conn = S2C(session); /* * Optionally create the wiredtiger flag file if it doesn't already * exist. We don't actually care if we create it or not, the "am I the * only locker" tests are all that matter. */ WT_RET(__wt_config_gets(session, cfg, "create", &cval)); WT_RET(__wt_open(session, WT_SINGLETHREAD, cval.val == 0 ? 0 : 1, 0, 0, &conn->lock_fh)); /* * Lock a byte of the file: if we don't get the lock, some other process * is holding it, we're done. Note the file may be zero-length length, * and that's OK, the underlying call supports acquisition of locks past * the end-of-file. */ if (__wt_bytelock(conn->lock_fh, (off_t)0, 1) != 0) WT_ERR_MSG(session, EBUSY, "%s", "WiredTiger database is already being managed by another " "process"); /* Check to see if another thread of control has this database open. */ __wt_spin_lock(session, &__wt_process.spinlock); TAILQ_FOREACH(t, &__wt_process.connqh, q) if (t->home != NULL && t != conn && strcmp(t->home, conn->home) == 0) { ret = EBUSY; break; } __wt_spin_unlock(session, &__wt_process.spinlock); if (ret != 0) WT_ERR_MSG(session, EBUSY, "%s", "WiredTiger database is already being managed by another " "thread in this process"); /* * If the size of the file is 0, we created it (or we're racing with * the thread that created it, it doesn't matter), write some bytes * into the file. Strictly speaking, this isn't even necessary, but * zero-length files always make me nervous. */ WT_ERR(__wt_filesize(session, conn->lock_fh, &size)); if (size == 0) { len = (uint32_t)snprintf(buf, sizeof(buf), "%s\n%s\n", WT_SINGLETHREAD, wiredtiger_version(NULL, NULL, NULL)); WT_ERR(__wt_write( session, conn->lock_fh, (off_t)0, (uint32_t)len, buf)); created = 1; } else created = 0; /* * If we found a zero-length WiredTiger lock file, and eventually ended * as the database owner, return that we created the database. (There * is a theoretical chance that another process created the WiredTiger * lock file but we won the race to add the WT_CONNECTION_IMPL structure * to the process' list. It doesn't much matter, only one thread will * be told it created the database.) */ conn->is_new = created; return (0); err: if (conn->lock_fh != NULL) { WT_TRET(__wt_close(session, conn->lock_fh)); conn->lock_fh = NULL; } return (ret); }
int main(int argc, char *argv[]) { WT_CONNECTION *conn; WT_DECL_RET; WT_SESSION *session; size_t len; int ch, major_v, minor_v, tret, (*func)(WT_SESSION *, int, char *[]); const char *cmd_config, *config, *p1, *p2, *p3, *rec_config; char *p, *secretkey; bool logoff, recover, salvage; conn = NULL; p = NULL; /* Get the program name. */ if ((progname = strrchr(argv[0], '/')) == NULL) progname = argv[0]; else ++progname; command = ""; /* Check the version against the library build. */ (void)wiredtiger_version(&major_v, & minor_v, NULL); if (major_v != WIREDTIGER_VERSION_MAJOR || minor_v != WIREDTIGER_VERSION_MINOR) { fprintf(stderr, "%s: program build version %d.%d does not match " "library build version %d.%d\n", progname, WIREDTIGER_VERSION_MAJOR, WIREDTIGER_VERSION_MINOR, major_v, minor_v); return (EXIT_FAILURE); } cmd_config = config = secretkey = NULL; /* * We default to returning an error if recovery needs to be run. * Generally we expect this to be run after a clean shutdown. * The printlog command disables logging entirely. If recovery is * needed, the user can specify -R to run recovery. */ rec_config = REC_ERROR; logoff = recover = salvage = false; /* Check for standard options. */ while ((ch = __wt_getopt(progname, argc, argv, "C:E:h:LRSVv")) != EOF) switch (ch) { case 'C': /* wiredtiger_open config */ cmd_config = __wt_optarg; break; case 'E': /* secret key */ free(secretkey); /* lint: set more than once */ if ((secretkey = strdup(__wt_optarg)) == NULL) { (void)util_err(NULL, errno, NULL); goto err; } memset(__wt_optarg, 0, strlen(__wt_optarg)); break; case 'h': /* home directory */ home = __wt_optarg; break; case 'L': /* no logging */ rec_config = REC_LOGOFF; logoff = true; break; case 'R': /* recovery */ rec_config = REC_RECOVER; recover = true; break; case 'S': /* salvage */ rec_config = REC_SALVAGE; salvage = true; break; case 'V': /* version */ printf("%s\n", wiredtiger_version(NULL, NULL, NULL)); goto done; case 'v': /* verbose */ verbose = true; break; case '?': default: usage(); goto err; } if ((logoff && recover) || (logoff && salvage) || (recover && salvage)) { fprintf(stderr, "Only one of -L, -R, and -S is allowed.\n"); goto err; } argc -= __wt_optind; argv += __wt_optind; /* The next argument is the command name. */ if (argc < 1) { usage(); goto err; } command = argv[0]; /* Reset getopt. */ __wt_optreset = __wt_optind = 1; func = NULL; switch (command[0]) { case 'a': if (strcmp(command, "alter") == 0) func = util_alter; break; case 'b': if (strcmp(command, "backup") == 0) func = util_backup; break; case 'c': if (strcmp(command, "compact") == 0) func = util_compact; else if (strcmp(command, "copyright") == 0) { util_copyright(); goto done; } else if (strcmp(command, "create") == 0) { func = util_create; config = "create"; } break; case 'd': if (strcmp(command, "downgrade") == 0) func = util_downgrade; else if (strcmp(command, "drop") == 0) func = util_drop; else if (strcmp(command, "dump") == 0) func = util_dump; break; case 'l': if (strcmp(command, "list") == 0) func = util_list; else if (strcmp(command, "load") == 0) { func = util_load; config = "create"; } else if (strcmp(command, "loadtext") == 0) { func = util_loadtext; config = "create"; } break; case 'p': if (strcmp(command, "printlog") == 0) { func = util_printlog; rec_config = REC_LOGOFF; } break; case 'r': if (strcmp(command, "read") == 0) func = util_read; else if (strcmp(command, "rebalance") == 0) func = util_rebalance; else if (strcmp(command, "rename") == 0) func = util_rename; break; case 's': if (strcmp(command, "salvage") == 0) func = util_salvage; else if (strcmp(command, "stat") == 0) { func = util_stat; config = "statistics=(all)"; } break; case 't' : if (strcmp(command, "truncate") == 0) func = util_truncate; break; case 'u': if (strcmp(command, "upgrade") == 0) func = util_upgrade; break; case 'v': if (strcmp(command, "verify") == 0) func = util_verify; break; case 'w': if (strcmp(command, "write") == 0) func = util_write; break; default: break; } if (func == NULL) { usage(); goto err; } /* Build the configuration string. */ len = 10; /* some slop */ p1 = p2 = p3 = ""; len += strlen("error_prefix=wt"); if (config != NULL) len += strlen(config); if (cmd_config != NULL) len += strlen(cmd_config); if (secretkey != NULL) { len += strlen(secretkey) + 30; p1 = ",encryption=(secretkey="; p2 = secretkey; p3 = ")"; } len += strlen(rec_config); if ((p = malloc(len)) == NULL) { (void)util_err(NULL, errno, NULL); goto err; } if ((ret = __wt_snprintf(p, len, "error_prefix=wt,%s,%s,%s%s%s%s", config == NULL ? "" : config, cmd_config == NULL ? "" : cmd_config, rec_config, p1, p2, p3)) != 0) { (void)util_err(NULL, ret, NULL); goto err; } config = p; /* Open the database and a session. */ if ((ret = wiredtiger_open(home, verbose ? verbose_handler : NULL, config, &conn)) != 0) { (void)util_err(NULL, ret, NULL); goto err; } if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) { (void)util_err(NULL, ret, NULL); goto err; } /* Call the function. */ ret = func(session, argc, argv); if (0) { err: ret = 1; } done: /* Close the database. */ if (conn != NULL && (tret = conn->close(conn, NULL)) != 0 && ret == 0) ret = tret; free(p); free(secretkey); return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE); }
int wt_back_initialize( BackendInfo *bi ) { static char *controls[] = { LDAP_CONTROL_ASSERT, LDAP_CONTROL_MANAGEDSAIT, LDAP_CONTROL_NOOP, LDAP_CONTROL_PAGEDRESULTS, LDAP_CONTROL_PRE_READ, LDAP_CONTROL_POST_READ, LDAP_CONTROL_SUBENTRIES, LDAP_CONTROL_X_PERMISSIVE_MODIFY, NULL }; /* initialize the database system */ Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(wt_back_initialize) ": initialize WiredTiger backend\n", 0, 0, 0 ); bi->bi_flags |= SLAP_BFLAG_INCREMENT | SLAP_BFLAG_SUBENTRIES | SLAP_BFLAG_ALIASES | SLAP_BFLAG_REFERRALS; bi->bi_controls = controls; { /* version check */ Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(wt_back_initialize) ": %s\n", wiredtiger_version(NULL, NULL, NULL), 0, 0 ); } bi->bi_open = 0; bi->bi_close = 0; bi->bi_config = 0; bi->bi_destroy = 0; bi->bi_db_init = wt_db_init; bi->bi_db_config = config_generic_wrapper; bi->bi_db_open = wt_db_open; bi->bi_db_close = wt_db_close; bi->bi_db_destroy = wt_db_destroy; bi->bi_op_add = wt_add; bi->bi_op_bind = wt_bind; bi->bi_op_unbind = 0; bi->bi_op_search = wt_search; bi->bi_op_compare = wt_compare; bi->bi_op_modify = wt_modify; bi->bi_op_modrdn = 0; bi->bi_op_delete = wt_delete; bi->bi_op_abandon = 0; bi->bi_extended = 0; bi->bi_chk_referrals = 0; bi->bi_operational = wt_operational; bi->bi_entry_release_rw = wt_entry_release; bi->bi_entry_get_rw = wt_entry_get; bi->bi_tool_entry_open = wt_tool_entry_open; bi->bi_tool_entry_close = wt_tool_entry_close; bi->bi_tool_entry_first = backend_tool_entry_first; bi->bi_tool_entry_first_x = wt_tool_entry_first_x; bi->bi_tool_entry_next = wt_tool_entry_next; bi->bi_tool_entry_get = wt_tool_entry_get; bi->bi_tool_entry_put = wt_tool_entry_put; bi->bi_tool_entry_reindex = wt_tool_entry_reindex; bi->bi_connection_init = 0; bi->bi_connection_destroy = 0; return wt_back_init_cf( bi ); }
int main(int argc, char *argv[]) { WT_CONNECTION *conn; WT_DECL_RET; WT_SESSION *session; size_t len; int ch, major_v, minor_v, tret, (*func)(WT_SESSION *, int, char *[]); char *p; const char *cmd_config, *config; conn = NULL; p = NULL; /* Get the program name. */ if ((progname = strrchr(argv[0], '/')) == NULL) progname = argv[0]; else ++progname; command = ""; /* Check the version against the library build. */ (void)wiredtiger_version(&major_v, & minor_v, NULL); if (major_v != WIREDTIGER_VERSION_MAJOR || minor_v != WIREDTIGER_VERSION_MINOR) { fprintf(stderr, "%s: program build version %d.%d does not match " "library build version %d.%d\n", progname, WIREDTIGER_VERSION_MAJOR, WIREDTIGER_VERSION_MINOR, major_v, minor_v); return (EXIT_FAILURE); } /* Check for standard options. */ cmd_config = config = NULL; while ((ch = util_getopt(argc, argv, "C:h:Vv")) != EOF) switch (ch) { case 'C': /* wiredtiger_open config */ cmd_config = util_optarg; break; case 'h': /* home directory */ home = util_optarg; break; case 'V': /* version */ printf("%s\n", wiredtiger_version(NULL, NULL, NULL)); return (EXIT_SUCCESS); case 'v': /* verbose */ verbose = 1; break; case '?': default: return (usage()); } argc -= util_optind; argv += util_optind; /* The next argument is the command name. */ if (argc < 1) return (usage()); command = argv[0]; /* Reset getopt. */ util_optreset = 1; util_optind = 1; func = NULL; switch (command[0]) { case 'b': if (strcmp(command, "backup") == 0) func = util_backup; break; case 'c': if (strcmp(command, "compact") == 0) func = util_compact; else if (strcmp(command, "copyright") == 0) { util_copyright(); return (EXIT_SUCCESS); } else if (strcmp(command, "create") == 0) { func = util_create; config = "create"; } break; case 'd': if (strcmp(command, "drop") == 0) func = util_drop; else if (strcmp(command, "dump") == 0) func = util_dump; break; case 'l': if (strcmp(command, "list") == 0) func = util_list; else if (strcmp(command, "load") == 0) { func = util_load; config = "create"; } else if (strcmp(command, "loadtext") == 0) { func = util_loadtext; config = "create"; } break; case 'p': if (strcmp(command, "printlog") == 0) func = util_printlog; break; case 'r': if (strcmp(command, "read") == 0) func = util_read; else if (strcmp(command, "rename") == 0) func = util_rename; break; case 's': if (strcmp(command, "salvage") == 0) func = util_salvage; else if (strcmp(command, "stat") == 0) { func = util_stat; config = "statistics=(all)"; } break; case 'u': if (strcmp(command, "upgrade") == 0) func = util_upgrade; break; case 'v': if (strcmp(command, "verify") == 0) func = util_verify; break; case 'w': if (strcmp(command, "write") == 0) func = util_write; break; default: break; } if (func == NULL) return (usage()); /* Build the configuration string, as necessary. */ if (config == NULL) config = cmd_config; else if (cmd_config != NULL) { len = strlen(cmd_config) + strlen(config) + 10; if ((p = malloc(len)) == NULL) { ret = util_err(errno, NULL); goto err; } (void)snprintf(p, len, "%s,%s", config, cmd_config); config = p; } /* Open the database and a session. */ if ((ret = wiredtiger_open(home, verbose ? verbose_handler : NULL, config, &conn)) != 0) { ret = util_err(ret, NULL); goto err; } if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) { ret = util_err(ret, NULL); goto err; } /* Call the function. */ ret = func(session, argc, argv); /* Close the database. */ err: if (conn != NULL && (tret = conn->close(conn, NULL)) != 0 && ret == 0) ret = tret; if (p != NULL) free(p); return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE); }
int main(int argc, char *argv[]) { WT_CONNECTION *conn; home = example_setup(argc, argv); /*! [Open a connection] */ error_check(wiredtiger_open(home, NULL, "create,cache_size=5GB,log=(enabled,recover=on),statistics=(all)", &conn)); /*! [Open a connection] */ connection_ops(conn); /* * The connection has been closed. */ #ifdef MIGHT_NOT_RUN /* * This example code gets run, and the compression libraries might not * be installed, causing the open to fail. The documentation requires * the code snippets, use #ifdef's to avoid running it. */ /*! [Configure lz4 extension] */ error_check(wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_lz4.so]", &conn)); /*! [Configure lz4 extension] */ error_check(conn->close(conn, NULL)); /*! [Configure snappy extension] */ error_check(wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_snappy.so]", &conn)); /*! [Configure snappy extension] */ error_check(conn->close(conn, NULL)); /*! [Configure zlib extension] */ error_check(wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_zlib.so]", &conn)); /*! [Configure zlib extension] */ error_check(conn->close(conn, NULL)); /*! [Configure zlib extension with compression level] */ error_check(wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/" "libwiredtiger_zlib.so=[config=[compression_level=3]]]", &conn)); /*! [Configure zlib extension with compression level] */ error_check(conn->close(conn, NULL)); /*! [Configure zstd extension] */ error_check(wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_zstd.so]", &conn)); /*! [Configure zstd extension] */ error_check(conn->close(conn, NULL)); /*! [Configure zstd extension with compression level] */ error_check(wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/" "libwiredtiger_zstd.so=[config=[compression_level=9]]]", &conn)); /*! [Configure zstd extension with compression level] */ error_check(conn->close(conn, NULL)); /* * This example code gets run, and direct I/O might not be available, * causing the open to fail. The documentation requires code snippets, * use #ifdef's to avoid running it. */ /* Might Not Run: direct I/O may not be available. */ /*! [Configure direct_io for data files] */ error_check(wiredtiger_open( home, NULL, "create,direct_io=[data]", &conn)); /*! [Configure direct_io for data files] */ error_check(conn->close(conn, NULL)); #endif /*! [Configure file_extend] */ error_check(wiredtiger_open( home, NULL, "create,file_extend=(data=16MB)", &conn)); /*! [Configure file_extend] */ error_check(conn->close(conn, NULL)); /*! [Eviction configuration] */ /* * Configure eviction to begin at 90% full, and run until the cache * is only 75% dirty. */ error_check(wiredtiger_open(home, NULL, "create,eviction_trigger=90,eviction_dirty_target=75", &conn)); /*! [Eviction configuration] */ error_check(conn->close(conn, NULL)); /*! [Eviction worker configuration] */ /* Configure up to four eviction threads */ error_check(wiredtiger_open(home, NULL, "create,eviction_trigger=90,eviction=(threads_max=4)", &conn)); /*! [Eviction worker configuration] */ error_check(conn->close(conn, NULL)); /*! [Statistics configuration] */ error_check(wiredtiger_open( home, NULL, "create,statistics=(all)", &conn)); /*! [Statistics configuration] */ error_check(conn->close(conn, NULL)); /*! [Statistics logging] */ error_check(wiredtiger_open( home, NULL, "create,statistics_log=(wait=30)", &conn)); /*! [Statistics logging] */ error_check(conn->close(conn, NULL)); #ifdef MIGHT_NOT_RUN /* * Don't run this code, statistics logging doesn't yet support tables. */ /*! [Statistics logging with a table] */ error_check(wiredtiger_open(home, NULL, "create, statistics_log=(" "sources=(\"table:table1\",\"table:table2\"), wait=5)", &conn)); /*! [Statistics logging with a table] */ error_check(conn->close(conn, NULL)); /* * Don't run this code, statistics logging doesn't yet support indexes. */ /*! [Statistics logging with a source type] */ error_check(wiredtiger_open(home, NULL, "create, statistics_log=(sources=(\"index:\"), wait=5)", &conn)); /*! [Statistics logging with a source type] */ error_check(conn->close(conn, NULL)); /* * Don't run this code, because memory checkers get very upset when we * leak memory. */ error_check(wiredtiger_open(home, NULL, "create", &conn)); /*! [Connection close leaking memory] */ error_check(conn->close(conn, "leak_memory=true")); /*! [Connection close leaking memory] */ #endif /*! [Get the WiredTiger library version #1] */ printf("WiredTiger version %s\n", wiredtiger_version(NULL, NULL, NULL)); /*! [Get the WiredTiger library version #1] */ { /*! [Get the WiredTiger library version #2] */ int major_v, minor_v, patch; (void)wiredtiger_version(&major_v, &minor_v, &patch); printf("WiredTiger version is %d, %d (patch %d)\n", major_v, minor_v, patch); /*! [Get the WiredTiger library version #2] */ } { /*! [Calculate a modify operation] */ WT_MODIFY mod[3]; int nmod = 3; WT_ITEM prev, newv; prev.data = "the quick brown fox jumped over the lazy dog. " \ "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. " \ "the quick brown fox jumped over the lazy dog. " \ "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. "; prev.size = strlen(prev.data); newv.data = "A quick brown fox jumped over the lazy dog. " \ "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. " \ "then a quick brown fox jumped over the lazy dog. " \ "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. " \ "then what?"; newv.size = strlen(newv.data); error_check(wiredtiger_calc_modify(NULL, &prev, &newv, 20, mod, &nmod)); /*! [Calculate a modify operation] */ } { const char *buffer = "some string"; size_t len = strlen(buffer); /*! [Checksum a buffer] */ uint32_t crc32c, (*func)(const void *, size_t); func = wiredtiger_crc32c_func(); crc32c = func(buffer, len); /*! [Checksum a buffer] */ (void)crc32c; } return (EXIT_SUCCESS); }