Esempio n. 1
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. 2
0
    void IndexCursor::_prelockRange(const BSONObj &startKey, const BSONObj &endKey) {
        const bool isSecondary = !_cl->isPKIndex(_idx);

        // The ydb requires that we only lock ranges such that the left
        // endpoint is less than or equal to the right endpoint.
        // Reverse cursors describe the start and end key as the two
        // keys where they start and end iteration, which is backwards
        // in the key space (because they iterate in reverse).
        const BSONObj &leftKey = forward() ? startKey : endKey; 
        const BSONObj &rightKey = forward() ? endKey : startKey; 
        dassert(leftKey.woCompare(rightKey, _ordering) <= 0);

        storage::Key sKey(leftKey, isSecondary ? &minKey : NULL);
        storage::Key eKey(rightKey, isSecondary ? &maxKey : NULL);
        DBT start = sKey.dbt();
        DBT end = eKey.dbt();

        DBC *cursor = _cursor.dbc();
        const int r = cursor->c_set_bounds( cursor, &start, &end, true, 0 );
        if ( r != 0 ) {
            storage::handle_ydb_error(r);
        }
    }