Example #1
0
File: main.c Project: DINKIN/mongo
/*
 * Function for repeatedly running checkpoint operations.
 */
static WT_THREAD_RET
do_checkpoints(void *_opts)
{
	TEST_OPTS *opts;
	WT_SESSION *session;
	time_t now, start;
	int ret;

	opts = (TEST_OPTS *)_opts;
	(void)time(&start);
	(void)time(&now);

	while (difftime(now, start) < RUNTIME) {
		testutil_check(
		    opts->conn->open_session(opts->conn, NULL, NULL, &session));

		if ((ret = session->checkpoint(session, "force")) != 0)
			if (ret != EBUSY && ret != ENOENT)
				testutil_die(ret, "session.checkpoint");

		testutil_check(session->close(session, NULL));

		/*
		 * A short sleep to let operations process and avoid back to
		 * back checkpoints locking up resources.
		 */
		sleep(1);
		(void)time(&now);
	}

	return (WT_THREAD_RET_VALUE);
}
 Status WiredTigerKVEngine::repairIdent( OperationContext* opCtx,
                                         const StringData& ident ) {
     WiredTigerSession session( _conn, -1 );
     WT_SESSION* s = session.getSession();
     string uri = _uri(ident);
     return wtRCToStatus( s->compact(s, uri.c_str(), NULL ) );
 }
Example #3
0
/*
 * Open and close cursor on a table.
 */
void
op_cursor(void *arg)
{
	TEST_OPTS *opts;
	TEST_PER_THREAD_OPTS *args;
	WT_CURSOR *cursor;
	WT_SESSION *session;
	int i, ret;

	args = (TEST_PER_THREAD_OPTS *)arg;
	opts = args->testopts;

	testutil_check(
	    opts->conn->open_session(opts->conn, NULL, NULL, &session));

	if ((ret = session->open_cursor(
	    session, opts->uri, NULL, NULL, &cursor)) != 0) {
		if (ret != ENOENT && ret != EBUSY)
			testutil_die(ret, "session.open_cursor");
	} else {
		/* Put some data in if asked to. */
		if (args->testopts->do_data_ops) {
			for (i = 0; i < 1000; i++) {
				cursor->set_key(cursor, i);
				cursor->set_value(cursor, "abcdef");
				cursor->insert(cursor);
			}
		}
		testutil_check(cursor->close(cursor));
	}

	testutil_check(session->close(session, NULL));
	args->thread_counter++;
}
Example #4
0
/*
 * Create a table and open a bulk cursor on it.
 */
void
op_bulk(void *arg)
{
	TEST_OPTS *opts;
	TEST_PER_THREAD_OPTS *args;
	WT_CURSOR *c;
	WT_SESSION *session;
	int ret;

	args = (TEST_PER_THREAD_OPTS *)arg;
	opts = args->testopts;

	testutil_check(
	    opts->conn->open_session(opts->conn, NULL, NULL, &session));

	if ((ret = session->create(session,
	    opts->uri, DEFAULT_TABLE_SCHEMA)) != 0)
		if (ret != EEXIST && ret != EBUSY)
			testutil_die(ret, "session.create");

	if (ret == 0) {
		__wt_yield();
		if ((ret = session->open_cursor(session,
		    opts->uri, NULL, "bulk,checkpoint_wait=false", &c)) == 0) {
			 testutil_check(c->close(c));
		} else if (ret != ENOENT && ret != EBUSY && ret != EINVAL)
			testutil_die(ret, "session.open_cursor bulk");
	}

	testutil_check(session->close(session, NULL));
	args->thread_counter++;
}
        virtual RecordStore* newCappedRecordStore( const std::string& ns,
                                                   int64_t cappedMaxSize,
                                                   int64_t cappedMaxDocs ) {

            WiredTigerRecoveryUnit* ru = new WiredTigerRecoveryUnit( _sessionCache );
            OperationContextNoop txn( ru );
            string uri = "table:a.b";

            CollectionOptions options;
            options.capped = true;

            StatusWith<std::string> result =
                WiredTigerRecordStore::generateCreateString(ns, options, "");
            ASSERT_TRUE(result.isOK());
            std::string config = result.getValue();

            {
                WriteUnitOfWork uow(&txn);
                WT_SESSION* s = ru->getSession()->getSession();
                invariantWTOK( s->create( s, uri.c_str(), config.c_str() ) );
                uow.commit();
            }

            return new WiredTigerRecordStore( &txn, ns, uri, true, cappedMaxSize, cappedMaxDocs );
        }
Example #6
0
/*! [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);
}
Example #7
0
static void
file_create(SHARED_CONFIG *cfg, const char *name)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int ret;
	char config[128];

	conn = cfg->conn;

	testutil_check(conn->open_session(conn, NULL, NULL, &session));

	testutil_check(__wt_snprintf(config, sizeof(config),
	    "key_format=%s,"
	    "internal_page_max=%d,"
	    "split_deepen_min_child=200,"
	    "leaf_page_max=%d,"
	    "%s",
	    cfg->ftype == ROW ? "S" : "r", 16 * 1024, 128 * 1024,
	    cfg->ftype == FIX ? ",value_format=3t" : ""));

	if ((ret = session->create(session, name, config)) != 0)
		if (ret != EEXIST)
			testutil_die(ret, "session.create");

	testutil_check(session->close(session, NULL));
}
Example #8
0
File: file.c Project: DINKIN/mongo
void
obj_bulk(void)
{
	WT_CURSOR *c;
	WT_SESSION *session;
	int ret;

	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
		testutil_die(ret, "conn.session");

	if ((ret = session->create(session, uri, config)) != 0)
		if (ret != EEXIST && ret != EBUSY)
			testutil_die(ret, "session.create");

	if (ret == 0) {
		__wt_yield();
		if ((ret = session->open_cursor(
		    session, uri, NULL, "bulk", &c)) == 0) {
			if ((ret = c->close(c)) != 0)
				testutil_die(ret, "cursor.close");
		} else if (ret != ENOENT && ret != EBUSY && ret != EINVAL)
			testutil_die(ret, "session.open_cursor bulk");
	}
	if ((ret = session->close(session, NULL)) != 0)
		testutil_die(ret, "session.close");
}
Example #9
0
/*! [thread scan] */
void *
scan_thread(void *conn_arg)
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;
	const char *key, *value;
	int ret;

	conn = conn_arg;
	ret = conn->open_session(conn, NULL, NULL, &session);
	ret = session->open_cursor(
	    session, "table:access", NULL, NULL, &cursor);

	/* Show all records. */
	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);
	}
	if (ret != WT_NOTFOUND)
		fprintf(stderr,
		    "WT_CURSOR.next: %s\n", session->strerror(session, ret));

	return (NULL);
}
Example #10
0
File: file.c Project: DINKIN/mongo
void
obj_create_unique(int force)
{
	WT_SESSION *session;
	int ret;
	char new_uri[64];

	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
		testutil_die(ret, "conn.session");

	/* Generate a unique object name. */
	if ((ret = pthread_rwlock_wrlock(&single)) != 0)
		testutil_die(ret, "pthread_rwlock_wrlock single");
	testutil_check(__wt_snprintf(
	    new_uri, sizeof(new_uri), "%s.%u", uri, ++uid));
	if ((ret = pthread_rwlock_unlock(&single)) != 0)
		testutil_die(ret, "pthread_rwlock_unlock single");

	if ((ret = session->create(session, new_uri, config)) != 0)
		testutil_die(ret, "session.create");

	__wt_yield();
	while ((ret = session->drop(
	    session, new_uri, force ? "force" : NULL)) != 0)
		if (ret != EBUSY)
			testutil_die(ret, "session.drop: %s", new_uri);

	if ((ret = session->close(session, NULL)) != 0)
		testutil_die(ret, "session.close");
}
Example #11
0
int
main(int argc, char *argv[])
{
	WT_SESSION *session;
	clock_t ce, cs;
	pthread_t idlist[100];
	uint64_t i, id;
	char buf[100];

	opts = &_opts;
	memset(opts, 0, sizeof(*opts));
	opts->table_type = TABLE_ROW;
	opts->n_append_threads = N_APPEND_THREADS;
	opts->nrecords = N_RECORDS;
	testutil_check(testutil_parse_opts(argc, argv, opts));
	testutil_make_work_dir(opts->home);

	snprintf(buf, sizeof(buf), 
	    "create,"
	    "cache_size=%s,"
	    "eviction=(threads_max=5),"
	    "statistics=(fast)",
	    opts->table_type == TABLE_FIX ? "500MB" : "2GB");
	testutil_check(wiredtiger_open(opts->home, NULL, buf, &opts->conn));
	testutil_check(
	    opts->conn->open_session(opts->conn, NULL, NULL, &session));
	snprintf(buf, sizeof(buf),
	    "key_format=r,value_format=%s,"
	    "allocation_size=4K,leaf_page_max=64K",
	    opts->table_type == TABLE_FIX ? "8t" : "S");
	testutil_check(session->create(session, opts->uri, buf));
	testutil_check(session->close(session, NULL));

	page_init(5000);

	/* Force to disk and re-open. */
	testutil_check(opts->conn->close(opts->conn, NULL));
	testutil_check(wiredtiger_open(opts->home, NULL, NULL, &opts->conn));

	(void)signal(SIGINT, onsig);

	cs = clock();
	id = 0;
	for (i = 0; i < opts->n_append_threads; ++i, ++id) {
		printf("append: %" PRIu64 "\n", id);
		testutil_check(pthread_create(
		    &idlist[id], NULL, thread_append, (void *)opts));
	}

	for (i = 0; i < id; ++i)
		testutil_check(pthread_join(idlist[i], NULL));

	ce = clock();
	printf("%" PRIu64 "M records: %.2lf processor seconds\n",
	    opts->max_inserted_id / MILLION,
	    (ce - cs) / (double)CLOCKS_PER_SEC);

	testutil_cleanup(opts);
	return (EXIT_SUCCESS);
}
Example #12
0
File: main.c Project: ajdavis/mongo
static void
sweep_stats(void)
{
	static const int list[] = {
		WT_STAT_CONN_CURSOR_SWEEP_BUCKETS,
		WT_STAT_CONN_CURSOR_SWEEP_CLOSED,
		WT_STAT_CONN_CURSOR_SWEEP_EXAMINED,
		WT_STAT_CONN_CURSOR_SWEEP,
		WT_STAT_CONN_DH_SWEEP_REF,
		WT_STAT_CONN_DH_SWEEP_CLOSE,
		WT_STAT_CONN_DH_SWEEP_REMOVE,
		WT_STAT_CONN_DH_SWEEP_TOD,
		WT_STAT_CONN_DH_SWEEPS,
		WT_STAT_CONN_DH_SESSION_SWEEPS,
		-1
	};
	WT_SESSION *session;
	WT_CURSOR *cursor;
	uint64_t value;
	int i;
	const char *desc, *pvalue;

	testutil_check(conn->open_session(conn, NULL, NULL, &session));
	testutil_check(session->open_cursor(
	    session, "statistics:", NULL, NULL, &cursor));
	for (i = 0;; ++i) {
		if (list[i] == -1)
			break;
		cursor->set_key(cursor, list[i]);
		testutil_check(cursor->search(cursor));
		testutil_check(
		    cursor->get_value(cursor, &desc, &pvalue, &value));
		printf("\t" "%s=%s\n", desc, pvalue);
	}
}
Example #13
0
/*
 * check_copy --
 *	Confirm the hot backup worked.
 */
static void
check_copy(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int ret;

	wts_open(RUNDIR_BACKUP, 0, &conn);

	/*
	 * Open a session and verify the store; some data-sources don't support
	 * verify.
	 *
	 * XXX
	 * LSM can deadlock if WT_SESSION methods are called at the wrong time,
	 * don't do that for now.
	 */
	if (!DATASOURCE("lsm") && !DATASOURCE("memrata")) {
		if ((ret = conn->open_session(
		    conn, NULL, NULL, &session)) != 0)
			die(ret, "connection.open_session");

		if ((ret = session->verify(session, g.uri, NULL)) != 0)
			die(ret, "session.verify: %s", g.uri);
	}

	if ((ret = conn->close(conn, NULL)) != 0)
		die(ret, "connection.close: %s", RUNDIR_BACKUP);
}
	bool indexInsert(size_t indexId, fstring key, llong recId) override {
		assert(started == m_status);
		assert(indexId < m_indices.size());
		WT_ITEM item;
		WT_SESSION* ses = m_session.ses;
		const Schema& schema = m_sconf.getIndexSchema(indexId);
		WT_CURSOR* cur = m_indices[indexId].insert;
		WtWritableIndex::setKeyVal(schema, cur, key, recId, &item, &m_wrtBuf);
		int err = cur->insert(cur);
		m_sizeDiff += sizeof(llong) + key.size();
		if (schema.m_isUnique) {
			if (WT_DUPLICATE_KEY == err) {
				return false;
			}
			if (err) {
				THROW_STD(invalid_argument
					, "ERROR: wiredtiger insert unique index: %s", ses->strerror(ses, err));
			}
		}
		else {
			if (WT_DUPLICATE_KEY == err) {
				assert(0); // assert in debug
				return true; // ignore in release
			}
			if (err) {
				THROW_STD(invalid_argument
					, "ERROR: wiredtiger insert multi index: %s", ses->strerror(ses, err));
			}
		}
		return true;
	}
Example #15
0
/*
 * Ensure that icount matches the number of records in the 
 * existing table.
 */
int find_table_count(CONFIG *cfg)
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;
	char *key;
	int ret;

	conn = cfg->conn;

	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) {
		lprintf(cfg, ret, 0,
		    "open_session failed finding existing table count");
		goto err;
	}
	if ((ret = session->open_cursor(session, cfg->uri,
	    NULL, NULL, &cursor)) != 0) {
		lprintf(cfg, ret, 0,
		    "open_cursor failed finding existing table count");
		goto err;
	}
	if ((ret = cursor->prev(cursor)) != 0) {
		lprintf(cfg, ret, 0,
		    "cursor prev failed finding existing table count");
		goto err;
	}
	cursor->get_key(cursor, &key);
	cfg->icount = (uint32_t)atoi(key);

err:	session->close(session, NULL);
	return (ret);
}
Example #16
0
File: main.c Project: ajdavis/mongo
static void
page_init(uint64_t n)
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;
	uint64_t recno, vrecno;
	char buf[64];

	conn = opts->conn;

	testutil_check(conn->open_session(conn, NULL, NULL, &session));
	testutil_check(
	    session->open_cursor(session, opts->uri, NULL, "append", &cursor));

	vrecno = 0;
	buf[0] = '\2';
	for (recno = 1;; ++recno) {
		if (opts->table_type == TABLE_FIX)
			cursor->set_value(cursor, buf[0]);
		else {
			if (recno % 3 == 0)
				++vrecno;
			testutil_check(__wt_snprintf(buf,
			    sizeof(buf), "%" PRIu64 " VALUE ------", vrecno));
			cursor->set_value(cursor, buf);
		}
		testutil_check(cursor->insert(cursor));
		testutil_check(cursor->get_key(cursor, &opts->max_inserted_id));
		if (opts->max_inserted_id >= n)
			break;
	}
}
Example #17
0
/*
 * col_remove --
 *	Remove a row from a column-store file.
 */
static void
col_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp)
{
	WT_SESSION *session;
	int notfound, ret;

	session = cursor->session;

	/* Log the operation */
	if (g.logging == LOG_OPS)
		(void)session->msg_printf(
		    session, "%-10s%" PRIu64, "remove", keyno);

	cursor->set_key(cursor, keyno);
	ret = cursor->remove(cursor);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "col_remove: remove %" PRIu64 " by key", keyno);
	*notfoundp = ret == WT_NOTFOUND;

	if (!SINGLETHREADED)
		return;

	/*
	 * Deleting a fixed-length item is the same as setting the bits to 0;
	 * do the same thing for the BDB store.
	 */
	if (g.c_file_type == FIX) {
		key_gen((uint8_t *)key->data, &key->size, keyno, 0);
		bdb_update(key->data, key->size, "\0", 1, &notfound);
	} else
		bdb_remove(keyno, &notfound);

	(void)notfound_chk("col_remove", ret, notfound, keyno);
}
Example #18
0
int
main(void)
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;
	int ret;

	ret = wiredtiger_open(home, NULL, "create,statistics=(all)", &conn);
	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, NULL, &cursor);
	cursor->set_key(cursor, "key");
	cursor->set_value(cursor, "value");
	ret = cursor->insert(cursor);
	cursor->close(cursor);

	ret = session->checkpoint(session, NULL);

	ret = print_database_stats(session);

	ret = print_file_stats(session);

	ret = print_overflow_pages(session);

	ret = print_derived_stats(session);

	return (conn->close(conn, NULL) == 0 ? ret : EXIT_FAILURE);
}
Example #19
0
/*
 * row_update --
 *	Update a row in a row-store file.
 */
static void
row_update(
    WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t keyno, int insert)
{
	WT_SESSION *session;
	int notfound, ret;

	session = cursor->session;

	key_gen((uint8_t *)key->data, &key->size, keyno, insert);
	value_gen((uint8_t *)value->data, &value->size, keyno);

	/* Log the operation */
	if (g.logging == LOG_OPS)
		(void)session->msg_printf(session, "%-10s{%.*s}\n%-10s{%.*s}",
		    insert ? "insertK" : "putK",
		    (int)key->size, (char *)key->data,
		    insert ? "insertV" : "putV",
		    (int)value->size, (char *)value->data);

	cursor->set_key(cursor, key);
	cursor->set_value(cursor, value);
	ret = cursor->insert(cursor);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret,
		    "row_update: %s row %" PRIu64 " by key",
		    insert ? "insert" : "update", keyno);

	if (!SINGLETHREADED)
		return;

	bdb_update(key->data, key->size, value->data, value->size, &notfound);
	(void)notfound_chk("row_update", ret, notfound, keyno);
}
Example #20
0
/*
 * row_remove --
 *	Remove an row from a row-store file.
 */
static void
row_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp)
{
	WT_SESSION *session;
	int notfound, ret;

	session = cursor->session;

	key_gen((uint8_t *)key->data, &key->size, keyno, 0);

	/* Log the operation */
	if (g.logging == LOG_OPS)
		(void)session->msg_printf(
		    session, "%-10s%" PRIu64, "remove", keyno);

	cursor->set_key(cursor, key);
	ret = cursor->remove(cursor);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "row_remove: remove %" PRIu64 " by key", keyno);
	*notfoundp = ret == WT_NOTFOUND;

	if (!SINGLETHREADED)
		return;

	bdb_remove(keyno, &notfound);
	(void)notfound_chk("row_remove", ret, notfound, keyno);
}
Example #21
0
    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;

    }
    TEST(WiredTigerUtilTest, GetStatisticsValueAsUInt8) {
        WiredTigerUtilHarnessHelper harnessHelper("statistics=(all)");
        WiredTigerRecoveryUnit recoveryUnit(harnessHelper.getSessionCache());
        WiredTigerSession* session = recoveryUnit.getSession(NULL);
        WT_SESSION* wtSession = session->getSession();
        ASSERT_OK(wtRCToStatus(wtSession->create(wtSession, "table:mytable", NULL)));

        // Use data source statistics that has a value > 256 on an empty table.
        StatusWith<uint64_t> resultUInt64 = WiredTigerUtil::getStatisticsValue(
            session->getSession(),
            "statistics:table:mytable", "statistics=(fast)", WT_STAT_DSRC_ALLOCATION_SIZE);
        ASSERT_OK(resultUInt64.getStatus());
        ASSERT_GREATER_THAN(resultUInt64.getValue(),
            static_cast<uint64_t>(std::numeric_limits<uint8_t>::max()));

        // Ensure that statistics value retrieved as an 8-bit unsigned value
        // is capped at maximum value for that type.
        StatusWith<uint8_t> resultUInt8 = WiredTigerUtil::getStatisticsValueAs<uint8_t>(
            session->getSession(),
            "statistics:table:mytable", "statistics=(fast)", WT_STAT_DSRC_ALLOCATION_SIZE);
        ASSERT_OK(resultUInt8.getStatus());
        ASSERT_EQUALS(std::numeric_limits<uint8_t>::max(), resultUInt8.getValue());

        // Read statistics value as signed 16-bit value with alternative maximum value to
        // std::numeric_limits.
        StatusWith<int16_t> resultInt16 = WiredTigerUtil::getStatisticsValueAs<int16_t>(
            session->getSession(),
            "statistics:table:mytable", "statistics=(fast)", WT_STAT_DSRC_ALLOCATION_SIZE,
            static_cast<int16_t>(100));
        ASSERT_OK(resultInt16.getStatus());
        ASSERT_EQUALS(static_cast<uint8_t>(100), resultInt16.getValue());
    }
Example #23
0
void
wts_salvage(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int ret;

	conn = g.wts_conn;

	track("salvage", 0ULL, NULL);

	/*
	 * Save a copy of the interesting files so we can replay the salvage
	 * step as necessary.
	 */
	if ((ret = system(
	    "cd RUNDIR && "
	    "rm -rf slvg.copy && "
	    "mkdir slvg.copy && "
	    "cp WiredTiger* wt* slvg.copy/")) != 0)
		die(ret, "salvage copy step failed");

	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
		die(ret, "connection.open_session");
	if ((ret = session->salvage(session, g.uri, NULL)) != 0)
		die(ret, "session.salvage: %s", g.uri);
	if ((ret = session->close(session, NULL)) != 0)
		die(ret, "session.close");
}
Example #24
0
static void
file_create(const char *name)
{
    WT_SESSION *session;
    int ret;
    char *p, *end, config[128];

    if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
        testutil_die(ret, "conn.session");

    p = config;
    end = config + sizeof(config);
    p += snprintf(p, (size_t)(end - p),
                  "key_format=%s,"
                  "internal_page_max=%d,"
                  "leaf_page_max=%d,",
                  ftype == ROW ? "u" : "r", 16 * 1024, 128 * 1024);
    if (ftype == FIX)
        (void)snprintf(p, (size_t)(end - p), ",value_format=3t");

    if ((ret = session->create(session, name, config)) != 0)
        if (ret != EEXIST)
            testutil_die(ret, "session.create");

    if ((ret = session->close(session, NULL)) != 0)
        testutil_die(ret, "session.close");
}
Example #25
0
File: main.c Project: ajdavis/mongo
static void *
compact_thread(void *args)
{
	WT_SESSION *session;

	session = (WT_SESSION *)args;
	testutil_check(session->compact(session, name, NULL));
	return (NULL);
}
void WiredTigerRecoveryUnit::_txnClose(bool commit) {
    invariant(_isActive(), toString(_state));
    WT_SESSION* s = _session->getSession();
    if (_timer) {
        const int transactionTime = _timer->millis();
        // `serverGlobalParams.slowMs` can be set to values <= 0. In those cases, give logging a
        // break.
        if (transactionTime >= std::max(1, serverGlobalParams.slowMS)) {
            LOG(kSlowTransactionSeverity) << "Slow WT transaction. Lifetime of SnapshotId "
                                          << _mySnapshotId << " was " << transactionTime << "ms";
        }
    }

    int wtRet;
    if (commit) {
        if (!_commitTimestamp.isNull()) {
            const std::string conf = "commit_timestamp=" + integerToHex(_commitTimestamp.asULL());
            invariantWTOK(s->timestamp_transaction(s, conf.c_str()));
            _isTimestamped = true;
        }

        wtRet = s->commit_transaction(s, nullptr);
        LOG(3) << "WT commit_transaction for snapshot id " << _mySnapshotId;
    } else {
        wtRet = s->rollback_transaction(s, nullptr);
        invariant(!wtRet);
        LOG(3) << "WT rollback_transaction for snapshot id " << _mySnapshotId;
    }

    if (_isTimestamped) {
        if (!_orderedCommit) {
            // We only need to update oplog visibility where commits can be out-of-order with
            // respect to their assigned optime and such commits might otherwise be visible.
            // This should happen only on primary nodes.
            _oplogManager->triggerJournalFlush();
        }
        _isTimestamped = false;
    }
    invariantWTOK(wtRet);

    invariant(!_lastTimestampSet || _commitTimestamp.isNull(),
              str::stream() << "Cannot have both a _lastTimestampSet and a "
                               "_commitTimestamp. _lastTimestampSet: "
                            << _lastTimestampSet->toString()
                            << ". _commitTimestamp: "
                            << _commitTimestamp.toString());

    // We reset the _lastTimestampSet between transactions. Since it is legal for one
    // transaction on a RecoveryUnit to call setTimestamp() and another to call
    // setCommitTimestamp().
    _lastTimestampSet = boost::none;

    _prepareTimestamp = Timestamp();
    _mySnapshotId = nextSnapshotId.fetchAndAdd(1);
    _isOplogReader = false;
    _orderedCommit = true;  // Default value is true; we assume all writes are ordered.
}
Example #27
0
 void WiredTigerRecoveryUnit::_txnOpen() {
     invariant( !_active );
     WT_SESSION *s = _session->getSession();
     _syncing = _syncing || awaitCommitData.numWaitingForSync.load() > 0;
     invariantWTOK( s->begin_transaction(s, _syncing ? "sync=true" : NULL) );
     LOG(2) << "WT begin_transaction";
     _timer.reset();
     _active = true;
 }
Example #28
0
/*
 * wts_stats --
 *	Dump the run's statistics.
 */
void
wts_stats(void)
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;
	FILE *fp;
	const char *pval, *desc;
	uint64_t v;
	int ret;

	track("stat", 0ULL, NULL);

	conn = g.wts_conn;
	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
		die(ret, "connection.open_session");

	if ((fp = fopen("__stats", "w")) == NULL)
		die(errno, "fopen: __stats");

	/* Connection statistics. */
	if ((ret = session->open_cursor(session,
	    "statistics:", NULL, NULL, &cursor)) != 0)
		die(ret, "session.open_cursor");

	while ((ret = cursor->next(cursor)) == 0 &&
	    (ret = cursor->get_value(cursor, &desc, &pval, &v)) == 0)
		if (fprintf(fp, "%s=%s\n", desc, pval) < 0)
			die(errno, "fprintf");

	if (ret != WT_NOTFOUND)
		die(ret, "cursor.next");
	if ((ret = cursor->close(cursor)) != 0)
		die(ret, "cursor.close");

	/* File statistics. */
	if ((ret = session->open_cursor(session,
	    "statistics:" WT_TABLENAME, NULL, NULL, &cursor)) != 0)
		die(ret, "session.open_cursor");

	while ((ret = cursor->next(cursor)) == 0 &&
	    (ret = cursor->get_value(cursor, &desc, &pval, &v)) == 0)
		if (fprintf(fp, "%s=%s\n", desc, pval) < 0)
			die(errno, "fprintf");

	if (ret != WT_NOTFOUND)
		die(ret, "cursor.next");
	if ((ret = cursor->close(cursor)) != 0)
		die(ret, "cursor.close");

	if ((ret = fclose(fp)) != 0)
		die(ret, "fclose");

	if ((ret = session->close(session, NULL)) != 0)
		die(ret, "session.close");
}
Example #29
0
void
wts_rebalance(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	char cmd[1024];

	if (g.c_rebalance == 0)
		return;

	track("rebalance", 0ULL, NULL);

	/* Dump the current object. */
	testutil_check(__wt_snprintf(cmd, sizeof(cmd),
	    ".." DIR_DELIM_STR ".." DIR_DELIM_STR "wt"
	    " -h %s dump -f %s/rebalance.orig %s",
	    g.home, g.home, g.uri));
	testutil_checkfmt(system(cmd), "command failed: %s", cmd);

	/* Rebalance, then verify the object. */
	wts_reopen();
	conn = g.wts_conn;
	testutil_check(conn->open_session(conn, NULL, NULL, &session));
	if (g.logging != 0)
		(void)g.wt_api->msg_printf(g.wt_api, session,
		    "=============== rebalance start ===============");

	testutil_checkfmt(
	    session->rebalance(session, g.uri, NULL), "%s", g.uri);

	if (g.logging != 0)
		(void)g.wt_api->msg_printf(g.wt_api, session,
		    "=============== rebalance stop ===============");
	testutil_check(session->close(session, NULL));

	wts_verify("post-rebalance verify");
	wts_close();

	testutil_check(__wt_snprintf(cmd, sizeof(cmd),
	    ".." DIR_DELIM_STR ".." DIR_DELIM_STR "wt"
	    " -h %s dump -f %s/rebalance.new %s",
	    g.home, g.home, g.uri));
	testutil_checkfmt(system(cmd), "command failed: %s", cmd);

	/* Compare the old/new versions of the object. */
#ifdef _WIN32
	testutil_check(__wt_snprintf(cmd, sizeof(cmd),
	    "fc /b %s\\rebalance.orig %s\\rebalance.new > NUL",
	    g.home, g.home));
#else
	testutil_check(__wt_snprintf(cmd, sizeof(cmd),
	    "cmp %s/rebalance.orig %s/rebalance.new > /dev/null",
	    g.home, g.home));
#endif
	testutil_checkfmt(system(cmd), "command failed: %s", cmd);
}
Example #30
0
 void WiredTigerEngine::CompactRange(const Slice& begin, const Slice& end)
 {
     ContextHolder& holder = GetContextHolder();
     WT_SESSION* session = holder.session;
     if (NULL == session)
     {
         return;
     }
     session->compact(session, ARDB_TABLE, NULL);
 }