示例#1
0
void
bdb_remove(uint64_t keyno, int *notfoundp)
{
	DBC *dbc = g.dbc;
	size_t size;
	int ret;

	size = 0;
	key_gen(&keyitem, keyno);
	key.data = (void *)keyitem.data;
	key.size = (u_int32_t)keyitem.size;

	bdb_read(keyno, &value.data, &size, notfoundp);
	value.size = (u_int32_t)size;
	if (*notfoundp)
		return;

	/* Deleting a fixed-length item is the same as setting the bits to 0. */
	if (g.type == FIX)
		bdb_update(key.data, key.size, "", 1);
	else
		if ((ret = dbc->del(dbc, 0)) != 0) {
			if (ret != DB_NOTFOUND)
				bdb_die(ret, "dbc.del: {%.*s}",
				    (int)key.size, (char *)key.data);
			*notfoundp = 1;
		}
}
示例#2
0
文件: bdb.c 项目: qixin/wiredtiger
void
bdb_remove(uint64_t keyno, int *notfoundp)
{
	DBC *dbc = g.dbc;
	int ret;

	key.data = keybuf;
	key_gen(key.data, &key.size, keyno, 0);

	bdb_read(keyno, &value.data, &value.size, notfoundp);
	if (*notfoundp)
		return;

	if ((ret = dbc->del(dbc, 0)) != 0) {
		if (ret != DB_NOTFOUND)
			die(ret, "dbc.del: {%.*s}",
			    (int)key.size, (char *)key.data);
		*notfoundp = 1;
	}
}
示例#3
0
/*
 * read_row --
 *	Read and verify a single element in a row- or column-store file.
 */
static int
read_row(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno)
{
	static int sn = 0;
	WT_ITEM value;
	WT_SESSION *session;
	int exact, ret;
	uint8_t bitfield;

	session = cursor->session;

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

	/* Retrieve the key/value pair by key. */
	switch (g.type) {
	case FIX:
	case VAR:
		cursor->set_key(cursor, keyno);
		break;
	case ROW:
		key_gen((uint8_t *)key->data, &key->size, keyno);
		cursor->set_key(cursor, key);
		break;
	}

	if (sn) {
		ret = cursor->search_near(cursor, &exact);
		if (ret == 0 && exact != 0)
			ret = WT_NOTFOUND;
		sn = 0;
	} else {
		ret = cursor->search(cursor);
		sn = 1;
	}
	if (ret == 0) {
		if (g.type == FIX) {
			ret = cursor->get_value(cursor, &bitfield);
			value.data = &bitfield;
			value.size = 1;
		} else {
			ret = cursor->get_value(cursor, &value);
		}
	}
	if (ret == WT_ROLLBACK)
		return (WT_ROLLBACK);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "read_row: read row %" PRIu64, keyno);

#ifdef HAVE_BERKELEY_DB
	if (!SINGLETHREADED)
		return (0);

	/*
	 * In fixed length stores, zero values at the end of the key space are
	 * returned as not found.  Treat this the same as a zero value in the
	 * key space, to match BDB's behavior.
	 */
	if (ret == WT_NOTFOUND && g.type == FIX) {
		bitfield = 0;
		value.data = &bitfield;
		value.size = 1;
		ret = 0;
	}

	/* Retrieve the BDB value. */
	{
	WT_ITEM bdb_value;
	int notfound;

	bdb_read(keyno, &bdb_value.data, &bdb_value.size, &notfound);

	/* Check for not-found status. */
	if (notfound_chk("read_row", ret, notfound, keyno))
		return (0);

	/* Compare the two. */
	if (value.size != bdb_value.size ||
	    memcmp(value.data, bdb_value.data, value.size) != 0) {
		fprintf(stderr,
		    "read_row: value mismatch %" PRIu64 ":\n", keyno);
		print_item("bdb", &bdb_value);
		print_item(" wt", &value);
		die(0, NULL);
	}
	}
#endif
	return (0);
}
示例#4
0
/*
 * read_row --
 *	Read and verify a single element in a row- or column-store file.
 */
static void
read_row(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno)
{
	WT_ITEM bdb_value, value;
	WT_SESSION *session;
	int notfound, ret;
	uint8_t bitfield;

	session = cursor->session;

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

	/* Retrieve the key/value pair by key. */
	switch (g.c_file_type) {
	case FIX:
	case VAR:
		cursor->set_key(cursor, keyno);
		break;
	case ROW:
		key_gen((uint8_t *)key->data, &key->size, keyno, 0);
		cursor->set_key(cursor, key);
		break;
	}

	if ((ret = cursor->search(cursor)) == 0) {
		if (g.c_file_type == FIX) {
			ret = cursor->get_value(cursor, &bitfield);
			value.data = &bitfield;
			value.size = 1;
		} else {
			memset(&value, 0, sizeof(value));
			ret = cursor->get_value(cursor, &value);
		}
	}
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "read_row: read row %" PRIu64, keyno);

	if (!SINGLETHREADED)
		return;

	/* Retrieve the BDB value. */
	memset(&bdb_value, 0, sizeof(bdb_value));
	bdb_read(keyno, &bdb_value.data, &bdb_value.size, &notfound);

	/*
	 * Check for not-found status.
	 *
	 * In fixed length stores, zero values at the end of the key space
	 * are treated as not found.  Treat this the same as a zero value
	 * in the key space, to match BDB's behavior.
	 */
	if (g.c_file_type == FIX && ret == WT_NOTFOUND) {
		bitfield = 0;
		ret = 0;
	}

	if (notfound_chk("read_row", ret, notfound, keyno))
		return;

	/* Compare the two. */
	if (value.size != bdb_value.size ||
	    memcmp(value.data, bdb_value.data, value.size) != 0) {
		fprintf(stderr,
		    "read_row: read row value mismatch %" PRIu64 ":\n", keyno);
		print_item("bdb", &bdb_value);
		print_item(" wt", &value);
		die(0, NULL);
	}
}