Example #1
0
CTEST(txn, begin_with_no_parent)
{
	int r;
	struct txn *tx1;
	struct txn *tx2;
	struct txn *tx3;
	struct txnmgr *tm = txnmgr_new();
	LOGGER *logger = logger_new(NULL, tm);

	/* transaction 1 */
	r = txn_begin(NULL, logger, TXN_ISO_REPEATABLE, &tx1);
	ASSERT_EQUAL(1, r);
	ASSERT_EQUAL(0, tx1->txnid);
	ASSERT_EQUAL(1, tm->live_root_txnids->used);
	ASSERT_EQUAL(tx1->txnid, tm->live_root_txnids->txnids[0]);

	/* transaction 2 */
	r = txn_begin(NULL, logger, TXN_ISO_REPEATABLE, &tx2);
	ASSERT_EQUAL(1, r);
	ASSERT_EQUAL(1, tx2->txnid);
	ASSERT_EQUAL(tx1->txnid, tx2->txnid_clone->txnids[0]);
	ASSERT_EQUAL(tx2->txnid, tx2->txnid_clone->txnids[1]);

	/* transaction 3 */
	r = txn_begin(NULL, logger, TXN_ISO_SERIALIZABLE, &tx3);
	ASSERT_EQUAL(1, r);
	ASSERT_EQUAL(2, tx3->txnid);
	ASSERT_NULL(tx3->txnid_clone);

	logger_free(logger);
	txnmgr_free(tm);
}
Example #2
0
File: db.c Project: yqingp/testness
struct env *env_open(const char *home, uint32_t flags) {
    LOG;
	struct env *e;

	e = xcalloc(1, sizeof(*e));
	e->flags = flags;

	/* tree */
	e->inner_node_fanout = 16;
	e->inner_default_node_size = 4 << 20;		/* 4MB */
	e->leaf_default_node_size = 4 << 20;		/* 4MB */
	e->leaf_default_basement_size = 128 << 10;	/* 128KB */

	/* cache */
	e->cache_limits_bytes = 1024 << 20;
	e->cache_high_watermark = 80;		/* 80% */
	e->cache_flush_period_ms = 100;		/* 0.1s */
	e->cache_checkpoint_period_ms = 600000;	/* 60s */

	/* IO */
	e->use_directio = 1;
	e->redo_path = "./dbbench";
	e->enable_redo_log = 1;
	if (!home)
		home = ".";

	e->dir = xcalloc(1, strlen(home) + 1);
	xmemcpy(e->dir, (void*)home, strlen(home));
	ness_check_dir(e->dir);

	/* compress */
	e->compress_method = NESS_SNAPPY_METHOD;

	/* callback */
	e->bt_compare_func = bt_compare_func_builtin;

	/* internal */
	e->cache = cache_new(e);
    /* e->cache->cf_first->hdr->blocksize */
	nassert(e->cache);

	e->txnmgr = txnmgr_new();
	nassert(e->txnmgr);

	e->status = status_new();
	nassert(e->status);

	return e;
}
Example #3
0
CTEST(txn, begin_with_parent)
{
	int r;
	struct txn *tx1;
	struct txn *tx2;
	struct txn *tx3;
	struct txn *tx4;
	struct txnmgr *tm = txnmgr_new();
	LOGGER *logger = logger_new(NULL, tm);

	/* tx1: snapshot */
	r = txn_begin(NULL, logger, TXN_ISO_REPEATABLE, &tx1);
	ASSERT_EQUAL(1, r);
	ASSERT_EQUAL(0, tx1->txnid);
	ASSERT_EQUAL(1, tm->live_root_txnids->used);
	ASSERT_EQUAL(1, tx1->txnid_clone->used);
	ASSERT_EQUAL(tx1->txnid, tm->live_root_txnids->txnids[0]);

	/* tx2: snapshot */
	r = txn_begin(NULL, logger, TXN_ISO_REPEATABLE, &tx2);
	ASSERT_EQUAL(1, r);
	ASSERT_EQUAL(1, tx2->txnid);
	ASSERT_EQUAL(2, tx2->txnid_clone->used);
	ASSERT_EQUAL(tx1->txnid, tx2->txnid_clone->txnids[0]);
	ASSERT_EQUAL(tx2->txnid, tx2->txnid_clone->txnids[1]);

	/* tx3: not snapshot */
	r = txn_begin(NULL, logger, TXN_ISO_SERIALIZABLE, &tx3);
	ASSERT_EQUAL(1, r);
	ASSERT_EQUAL(2, tx3->txnid);
	ASSERT_NULL(tx3->txnid_clone);

	/* tx4: not snapshot with parent tx2 */
	r = txn_begin(tx2, logger, TXN_ISO_REPEATABLE, &tx4);
	ASSERT_EQUAL(1, r);
	ASSERT_EQUAL(3, tx4->txnid);
	ASSERT_EQUAL(2, tx4->txnid_clone->used);
	ASSERT_EQUAL(tx1->txnid, tx4->txnid_clone->txnids[0]);
	ASSERT_EQUAL(tx2->txnid, tx4->txnid_clone->txnids[1]);

	logger_free(logger);
	txnmgr_free(tm);
}