Ejemplo n.º 1
0
int cache_create_node_and_pin(struct cache_file *cf,
                              uint32_t height,
                              uint32_t children,
                              struct node **n)
{
	NID next_nid;
	struct cpair *p;
	struct node *new_node;
	struct cache *c = cf->cache;

	next_nid = hdr_next_nid((struct tree*)cf->args);
	if (height == 0)
		new_node = leaf_alloc_empty(next_nid);
	else
		new_node = nonleaf_alloc_empty(next_nid, height, children);

	p = cpair_new();
	cpair_init(p, new_node, cf);

	/* default lock type is L_WRITE */
	write_lock(&p->value_lock);

	*n = new_node;

	/* add to cache list */
	write_lock(&c->clock_lock);
	_cache_insert(c, p);
	write_unlock(&c->clock_lock);

	return NESS_OK;
}
Ejemplo n.º 2
0
CTEST(node_serial_test, leaf_empty)
{
	int ret = 0;
	int fd = ness_os_open(BRT_FILE, O_RDWR | O_CREAT, 0777);
	struct block *b = block_new();
	struct hdr *hdr = (struct hdr*)xcalloc(1, sizeof(*hdr));
	struct options *opts = options_new();

	/*
	 * dummy brt leaf
	 */
	uint64_t nid = 3;

	struct node *dummy_leaf = leaf_alloc_empty(nid);
	leaf_alloc_bsm(dummy_leaf);
	ret = serialize_node_to_disk(fd, b, dummy_leaf, hdr);
	ASSERT_TRUE(ret > 0);
	//free
	node_free(dummy_leaf);

	struct node *dummy_leaf1;
	ret = deserialize_node_from_disk(fd, b, nid, &dummy_leaf1, 0);
	ASSERT_TRUE(ret > 0);
	ASSERT_EQUAL(0, basement_count(dummy_leaf1->u.l.le->bsm));
	//free
	node_free(dummy_leaf1);

	ness_os_close(fd);
	block_free(b);
	xfree(hdr);
	options_free(opts);
	xcheck_all_free();
}
Ejemplo n.º 3
0
CTEST(node_serial_test, leaf_2_record)
{
	int ret = 0;
	int fd = ness_os_open(BRT_FILE, O_RDWR | O_CREAT, 0777);
	struct block *b = block_new();
	struct hdr *hdr = (struct hdr*)xcalloc(1, sizeof(*hdr));
	struct options *opts = options_new();

	/*
	 * dummy brt leaf
	 */
	uint64_t nid = 3;

	struct node *dummy_leaf = leaf_alloc_empty(nid);
	leaf_alloc_bsm(dummy_leaf);

	MSN msn = 0U;
	struct xids *xids = NULL;
	struct msg k, v;
	k.size = 6;
	k.data = "hello";
	v.size = 6;
	v.data = "world";
	basement_put(dummy_leaf->u.l.le->bsm, &k, &v, MSG_INSERT, msn, xids);

	struct msg k1, v1;
	k1.size = 6;
	k1.data = "hellx";
	v1.size = 6;
	v1.data = "worlx";
	basement_put(dummy_leaf->u.l.le->bsm, &k1, &v1, MSG_INSERT, msn, xids);

	ret = serialize_node_to_disk(fd, b, dummy_leaf, hdr);
	ASSERT_TRUE(ret > 0);

	//free
	node_free(dummy_leaf);

	struct node *dummy_leaf1;
	ret = deserialize_node_from_disk(fd, b, nid, &dummy_leaf1, 0);
	ASSERT_TRUE(ret > 0);

	ASSERT_EQUAL(2, basement_count(dummy_leaf1->u.l.le->bsm));

	struct basement_iter iter;
	basement_iter_init(&iter, dummy_leaf1->u.l.le->bsm);
	basement_iter_seek(&iter, &k);
	ASSERT_EQUAL(1, iter.valid);
	ASSERT_STR("world", iter.val.data);

	basement_iter_seek(&iter, &k1);
	ASSERT_EQUAL(1, iter.valid);
	ASSERT_STR("worlx", iter.val.data);

	//free
	node_free(dummy_leaf1);

	ness_os_close(fd);
	block_free(b);
	xfree(hdr);
	options_free(opts);
	xcheck_all_free();
}