Esempio n. 1
0
int ftfs_directory_is_empty(DB *meta_db, struct ftfs_meta_key *meta_key,
                            DB_TXN *txn, int *is_empty)
{
	int ret, r;
	struct ftfs_meta_key *start_meta_key;
	struct ftfs_die_cb_info info;
	DBT key;
	DBC *cursor;

	start_meta_key = alloc_child_meta_key_from_meta_key(meta_key, "");
	if (!start_meta_key)
		return -ENOMEM;

	dbt_init(&key, start_meta_key, SIZEOF_KEY(*start_meta_key));

	ret = meta_db->cursor(meta_db, txn, &cursor, DB_CURSOR_FLAGS);
	if (ret)
		goto out;

	info.meta_key = meta_key;
	info.is_empty = is_empty;
	ret = cursor->c_getf_set_range(cursor, 0, &key, ftfs_die_cb, &info);
	if (ret == DB_NOTFOUND) {
		ret = 0;
		*is_empty = 1;
	}

	r = cursor->c_close(cursor);
	BUG_ON(r);
out:
	meta_key_free(start_meta_key);

	return ret;
}
Esempio n. 2
0
int ftfs_bstore_scan_pages(DB *data_db, struct ftfs_meta_key *meta_key,
                           DB_TXN *txn, struct ftio *ftio)
{
	int ret, r;
	uint64_t block_num;
	struct ftfs_scan_pages_cb_info info;
	struct ftfs_data_key *data_key, *prefetch_data_key;
	DBT key_dbt, prefetch_key_dbt;
	DBC *cursor;

	if (ftio_job_done(ftio))
		return 0;
	block_num = ftio_current_page(ftio)->index;
	data_key = alloc_data_key_from_meta_key(meta_key, block_num);
	if (!data_key)
		return -ENOMEM;
	block_num = ftio_last_page(ftio)->index;
	prefetch_data_key = alloc_data_key_from_meta_key(meta_key, block_num);
	if (!prefetch_data_key) {
		ret = -ENOMEM;
		goto out;
	}

	dbt_init(&key_dbt, data_key, SIZEOF_KEY(*data_key));
	dbt_init(&prefetch_key_dbt, prefetch_data_key, SIZEOF_KEY(*prefetch_data_key));

	ret = data_db->cursor(data_db, txn, &cursor, DB_CURSOR_FLAGS);
	if (ret)
		goto free_out;

	ret = cursor->c_set_bounds(cursor, &key_dbt, &prefetch_key_dbt, true, 0);
	if (ret)
		goto close_cursor;

	info.meta_key = meta_key;
	info.ftio = ftio;

	r = cursor->c_getf_set_range(cursor, 0, &key_dbt, ftfs_scan_pages_cb, &info);
	while (info.do_continue && !r)
		r = cursor->c_getf_next(cursor, 0, ftfs_scan_pages_cb, &info);
	if (r && r != DB_NOTFOUND)
		ret = r;
	if (!ret)
		ftfs_bstore_fill_rest_page(ftio);

close_cursor:
	r = cursor->c_close(cursor);
	BUG_ON(r);
free_out:
	data_key_free(prefetch_data_key);
out:
	data_key_free(data_key);

	return ret;
}
Esempio n. 3
0
    void IndexCursor::setPosition(const BSONObj &key, const BSONObj &pk) {
        TOKULOG(3) << toString() << ": setPosition(): getf " << key << ", pk " << pk << ", direction " << _direction << endl;

        // Empty row buffer, reset fetch iteration, go get more rows.
        _buffer.empty();
        _getf_iteration = 0;

        storage::Key sKey( key, !pk.isEmpty() ? &pk : NULL );
        DBT key_dbt = sKey.dbt();;

        int r;
        const int rows_to_fetch = getf_fetch_count();
        struct cursor_getf_extra extra(&_buffer, rows_to_fetch);
        DBC *cursor = _cursor.dbc();
        if ( forward() ) {
            r = cursor->c_getf_set_range(cursor, getf_flags(), &key_dbt, cursor_getf, &extra);
        } else {
            r = cursor->c_getf_set_range_reverse(cursor, getf_flags(), &key_dbt, cursor_getf, &extra);
        }
        if ( extra.ex != NULL ) {
            throw *extra.ex;
        }
        if (r == TOKUDB_INTERRUPTED) {
            _interrupt_extra.throwException();
        }
        if ( r != 0 && r != DB_NOTFOUND ) {
            extra.throwException();
            storage::handle_ydb_error(r);
        }

        _getf_iteration++;
        _ok = extra.rows_fetched > 0 ? true : false;
        if ( ok() ) {
            getCurrentFromBuffer();
        }

        TOKULOG(3) << "setPosition hit K, PK, Obj " << _currKey << _currPK << _currObj << endl;
    }