Esempio n. 1
0
/*
 * col_remove --
 *	Remove a row from a column-store file.
 */
static void
col_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp)
{
	WT_SESSION *session;
	int notfound, ret;

	session = cursor->session;

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

	cursor->set_key(cursor, keyno);
	ret = cursor->remove(cursor);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "col_remove: remove %" PRIu64 " by key", keyno);
	*notfoundp = ret == WT_NOTFOUND;

	if (!SINGLETHREADED)
		return;

	/*
	 * Deleting a fixed-length item is the same as setting the bits to 0;
	 * do the same thing for the BDB store.
	 */
	if (g.c_file_type == FIX) {
		key_gen((uint8_t *)key->data, &key->size, keyno, 0);
		bdb_update(key->data, key->size, "\0", 1, &notfound);
	} else
		bdb_remove(keyno, &notfound);

	(void)notfound_chk("col_remove", ret, notfound, keyno);
}
Esempio n. 2
0
/*
 * row_remove --
 *	Remove an row from a row-store file.
 */
static void
row_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp)
{
	WT_SESSION *session;
	int notfound, ret;

	session = cursor->session;

	key_gen((uint8_t *)key->data, &key->size, keyno, 0);

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

	cursor->set_key(cursor, key);
	ret = cursor->remove(cursor);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "row_remove: remove %" PRIu64 " by key", keyno);
	*notfoundp = ret == WT_NOTFOUND;

	if (!SINGLETHREADED)
		return;

	bdb_remove(keyno, &notfound);
	(void)notfound_chk("row_remove", ret, notfound, keyno);
}
Esempio n. 3
0
/*
 * row_remove --
 *	Remove an row from a row-store file.
 */
static int
row_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp)
{
	WT_SESSION *session;
	int notfound, ret;

	session = cursor->session;

	key_gen((uint8_t *)key->data, &key->size, keyno, 0);

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

	cursor->set_key(cursor, key);
	/* We use the cursor in overwrite mode, check for existence. */
	if ((ret = cursor->search(cursor)) == 0)
		ret = cursor->remove(cursor);
	if (ret == WT_DEADLOCK)
		return (WT_DEADLOCK);
	if (ret != 0 && ret != WT_NOTFOUND)
		die(ret, "row_remove: remove %" PRIu64 " by key", keyno);
	*notfoundp = (ret == WT_NOTFOUND);

	if (!SINGLETHREADED)
		return (0);

	bdb_remove(keyno, &notfound);
	(void)notfound_chk("row_remove", ret, notfound, keyno);
	return (0);
}
/*
 * col_remove --
 *	Remove a row from a column-store file.
 */
static int
col_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp)
{
    WT_SESSION *session;
    int ret;

    session = cursor->session;

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

    cursor->set_key(cursor, keyno);
    /* We use the cursor in overwrite mode, check for existence. */
    if ((ret = cursor->search(cursor)) == 0)
        ret = cursor->remove(cursor);
    if (ret == WT_ROLLBACK)
        return (WT_ROLLBACK);
    if (ret != 0 && ret != WT_NOTFOUND)
        testutil_die(ret,
                     "col_remove: remove %" PRIu64 " by key", keyno);
    *notfoundp = (ret == WT_NOTFOUND);

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

    {
        int notfound;

        /*
         * Deleting a fixed-length item is the same as setting the bits to 0;
         * do the same thing for the BDB store.
         */
        if (g.type == FIX) {
            key_gen((uint8_t *)key->data, &key->size, keyno);
            bdb_update(key->data, key->size, "\0", 1, &notfound);
        } else
            bdb_remove(keyno, &notfound);
        (void)notfound_chk("col_remove", ret, notfound, keyno);
    }
#else
    (void)key;				/* [-Wunused-variable] */
#endif
    return (0);
}
Esempio n. 5
0
void
bdb_truncate(uint64_t start, uint64_t stop)
{
	DBC *dbc = g.dbc;
	size_t len;
	int cmp, ret, notfound;

	/* Deleting a fixed-length item is the same as setting the bits to 0. */
	if (g.type == FIX) {
		/*
		 * If we're deleting from/to the start/end of the database,
		 * correct for the number of records we have.
		 */
		if (start == 0)
			start = 1;
		if (stop == 0)
			stop = g.rows;
		for (; start <= stop; ++start)
			bdb_remove(start, &notfound);
		return;
	}

	if (start == 0) {
		ret = dbc->get(dbc, &key, &value, DB_FIRST);
		if (ret != 0 && ret != DB_NOTFOUND)
			bdb_die(ret, "%s", "dbc.get: DB_FIRST");
	} else {
		key_gen(&keyitem, start);
		key.data = (void *)keyitem.data;
		key.size = (u_int32_t)keyitem.size;
		ret = dbc->get(dbc, &key, &value, DB_SET_RANGE);
		if (ret != 0 && ret != DB_NOTFOUND)
			bdb_die(ret, "dbc.get: DB_SET: {%.*s}",
			    (int)key.size, (char *)key.data);
	}
	if (ret == DB_NOTFOUND)
		return;

	if (stop == 0) {
		do {
			ret = dbc->del(dbc, 0);
			if (ret != 0 && ret != DB_NOTFOUND)
				bdb_die(ret, "dbc.del: {%.*s}",
				    (int)key.size, (char *)key.data);
		} while ((ret = dbc->get(dbc, &key, &value, DB_NEXT)) == 0);
	} else {
		key_gen(&keyitem, stop);
		do {
			len = WT_MIN(key.size, keyitem.size);
			cmp = memcmp(key.data, keyitem.data, len);
			if (g.c_reverse) {
				if (cmp < 0 ||
				    (cmp == 0 && key.size < keyitem.size))
					break;
			} else
				if (cmp > 0 ||
				    (cmp == 0 && key.size > keyitem.size))
					break;
			ret = dbc->del(dbc, 0);
			if (ret != 0 && ret != DB_NOTFOUND)
				bdb_die(ret, "dbc.del: {%.*s}",
				    (int)key.size, (char *)key.data);
		} while ((ret = dbc->get(dbc, &key, &value, DB_NEXT)) == 0);
	}
	if (ret != 0 && ret != DB_NOTFOUND)
		bdb_die(ret, "%s", "dbc.get: DB_NEXT");
}