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; }
CTEST(node_serial_test, node_2th_part_empty) { int ret = 0; NID nid; uint32_t n_children = 3; 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(); /* * serialize */ struct node *dummy_node; hdr->last_nid++; nid = hdr->last_nid; dummy_node = nonleaf_alloc_empty(nid, 1, n_children); nonleaf_alloc_buffer(dummy_node); struct msg p0; p0.size = 6; p0.data = "pivot0"; msgcpy(&dummy_node->u.n.pivots[0], &p0); struct msg p1; p1.size = 6; p1.data = "pivot1"; msgcpy(&dummy_node->u.n.pivots[1], &p1); MSN msn = 0U; struct xids *xids = NULL; struct msg k, v; k.size = 5; k.data = "hello"; v.size = 5; v.data = "world"; basement_put(dummy_node->u.n.parts[0].buffer, &k, &v, MSG_INSERT, msn, xids); hdr->method = NESS_QUICKLZ_METHOD; ret = serialize_node_to_disk(fd, b, dummy_node, hdr); ASSERT_TRUE(ret > 0); node_free(dummy_node); //deserialize int light = 0; struct node *dummy_node1; ret = deserialize_node_from_disk(fd, b, nid, &dummy_node1, light); ASSERT_TRUE(ret > 0); ASSERT_EQUAL(1, dummy_node1->height); ASSERT_EQUAL(3, dummy_node1->u.n.n_children); ASSERT_DATA((const unsigned char*)"pivot0", 6, (const unsigned char*)dummy_node1->u.n.pivots[0].data, dummy_node1->u.n.pivots[0].size); ASSERT_DATA((const unsigned char*)"pivot1", 6, (const unsigned char*)dummy_node1->u.n.pivots[1].data, dummy_node1->u.n.pivots[1].size); ASSERT_EQUAL(3, dummy_node1->u.n.n_children); if (!light) { int cmp; struct basement_iter iter; struct basement *bsm; bsm = dummy_node1->u.n.parts[0].buffer; basement_iter_init(&iter, bsm); int mb_c = basement_count(dummy_node1->u.n.parts[0].buffer); ASSERT_EQUAL(1, mb_c); basement_iter_seek(&iter, &k); ret = basement_iter_valid(&iter); ASSERT_EQUAL(1, ret); cmp = msg_key_compare(&k, &iter.key); ASSERT_EQUAL(0, cmp); cmp = msg_key_compare(&v, &iter.val); ASSERT_EQUAL(0, cmp); mb_c = basement_count(dummy_node1->u.n.parts[1].buffer); ASSERT_EQUAL(0, mb_c); } node_free(dummy_node1); ness_os_close(fd); block_free(b); xfree(hdr); options_free(opts); xcheck_all_free(); }