Exemplo n.º 1
0
Arquivo: main.c Projeto: jbreams/mongo
/*
 * Each thread inserts a set of keys into the record store database. The keys
 * are generated in such a way that there are large gaps in the key range.
 */
static void *
thread_func(void *arg)
{
	TEST_OPTS *opts;
	WT_CURSOR *cursor, *idx_cursor;
	WT_SESSION *session;
	uint64_t i, ins_rotor, ins_thr_idx, thr_idx, ts;
	uint64_t *obj_data;

	opts = (TEST_OPTS *)arg;
	thr_idx = __wt_atomic_fetch_addv64(&opts->next_threadid, 1);
	ts = g_ts;
	obj_data = dcalloc(
	    (NR_OBJECTS/NR_THREADS + 1) * NR_FIELDS, sizeof(*obj_data));

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

	testutil_check(session->open_cursor(
	    session, opts->uri, NULL, NULL, &cursor));
	testutil_check(session->open_cursor(
	    session, "table:index", NULL, NULL, &idx_cursor));

	for (ins_rotor = 1; ins_rotor < 10; ++ins_rotor) {
		for (ins_thr_idx = thr_idx, i = 0; ins_thr_idx < NR_OBJECTS;
		    ins_thr_idx += NR_THREADS, i += NR_FIELDS) {

			testutil_check(
			    session->begin_transaction(session, "sync=false"));

			cursor->set_key(cursor, ins_thr_idx << 40 | ins_rotor);
			cursor->set_value(cursor, ts,
			    obj_data[i+0], obj_data[i+1], obj_data[i+2],
			    obj_data[i+3], obj_data[i+4], obj_data[i+5],
			    obj_data[i+6], obj_data[i+7]);
			testutil_check(cursor->insert(cursor));

			idx_cursor->set_key(
			    idx_cursor, ins_thr_idx << 40 | ts);
			idx_cursor->set_value(idx_cursor, ins_rotor);
			testutil_check(idx_cursor->insert(idx_cursor));

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

			/* change object fields */
			++obj_data[i + ((ins_thr_idx + ins_rotor) % NR_FIELDS)];
			++obj_data[i +
			    ((ins_thr_idx + ins_rotor + 1) % NR_FIELDS)];

			++g_ts;
			/* 5K updates/sec */
			(void)usleep(1000000ULL * NR_THREADS / 5000);
		}
	}

	testutil_check(session->close(session, NULL));
	free(obj_data);
	return (NULL);
}
Exemplo n.º 2
0
/*
 * A thread dedicated to appending records into a table. Works with fixed
 * length column stores and variable length column stores.
 * One thread (the first thread created by an application) checks for a
 * terminating condition after each insert.
 */
WT_THREAD_RET
thread_append(void *arg)
{
	TEST_OPTS *opts;
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;
	uint64_t id, recno;
	char buf[64];

	opts = (TEST_OPTS *)arg;
	conn = opts->conn;

	id = __wt_atomic_fetch_addv64(&opts->next_threadid, 1);
	testutil_check(conn->open_session(conn, NULL, NULL, &session));
	testutil_check(
	    session->open_cursor(session, opts->uri, NULL, "append", &cursor));

	buf[0] = '\2';
	for (recno = 1; opts->running; ++recno) {
		if (opts->table_type == TABLE_FIX)
			cursor->set_value(cursor, buf[0]);
		else {
			testutil_check(__wt_snprintf(buf, sizeof(buf),
			    "%" PRIu64 " VALUE ------", recno));
			cursor->set_value(cursor, buf);
		}
		testutil_check(cursor->insert(cursor));
		if (id == 0) {
			testutil_check(
			    cursor->get_key(cursor, &opts->max_inserted_id));
			if (opts->max_inserted_id >= opts->nrecords)
				opts->running = false;
		}
	}

	return (WT_THREAD_RET_VALUE);
}