Level / level-rocksdb

A convenience package bundling levelup and rocksdb.
MIT License
145 stars 13 forks source link

Column families #43

Closed adamjabone closed 5 years ago

adamjabone commented 6 years ago

I can't find out how to pass arguments to level(location[, options[, callback]]) so I can open column families. I`am still getting error:

(node:22916) UnhandledPromiseRejectionWarning: OpenError: Invalid argument: You have to open all column families. Column families not opened: col0, col1, col2, col3, col4, col5, col6, col7
    at C:...project\node_modules\levelup\lib\levelup.js:87:23
    at C:...project\node_modules\abstract-leveldown\abstract-leveldown.js:41:14
    at C:...project\node_modules\deferred-leveldown\deferred-leveldown.js:20:21
    at C:...project\node_modules\abstract-leveldown\abstract-leveldown.js:41:14
    at C:...project\node_modules\abstract-leveldown\abstract-leveldown.js:41:14
(node:22916) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:22916) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

How can I open column families?

vweevers commented 6 years ago

Can you share code to reproduce? I didn't know what column families were and would have guessed it's not exposed in the [level-]rocksdb API - but the error message you posted suggests otherwise.

adamjabone commented 6 years ago

Code is very simple:

var level = require('level-rocksdb')
var dbPath = 'C:\\Users\\User\\AppData\\Local\\Parity\\Ethereum\\chains\\ethereum\\db\\906a34e69aec8c0d\\overlayrecent\\db';  // database path
var db = level(dbPath);

And error:

(node:22916) UnhandledPromiseRejectionWarning: OpenError: Invalid argument: You have to open all column families. Column families not opened: col0, col1, col2, col3, col4, col5, col6, col7
at C:...project\node_modules\levelup\lib\levelup.js:87:23
at C:...project\node_modules\abstract-leveldown\abstract-leveldown.js:41:14
at C:...project\node_modules\deferred-leveldown\deferred-leveldown.js:20:21
at C:...project\node_modules\abstract-leveldown\abstract-leveldown.js:41:14
at C:...project\node_modules\abstract-leveldown\abstract-leveldown.js:41:14
(node:22916) UnhandledPromiseRejectionWarning: Unhandled promise rejection.
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:22916) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

It is rocksdb created and used by program Parity. I try to use the database with JavaScript code.

vweevers commented 6 years ago

I see. The database wasn't created by level-rocksdb, but by another program that does support column families? And it wrote data that level-rocksdb can't read.

To support it, we need to pass column family options from JS -> binding -> RocksDB. Would you be up for making a PR?

adamjabone commented 6 years ago

Yes, I will wait for PR. First I have tried to open the database as leveldb with levelup(leveldown(dbpath), hope this didn`t mess anything.

adamjabone commented 6 years ago

I have same error using Java:

import org.rocksdb.RocksDB;
import org.rocksdb.Options;
import org.rocksdb.RocksDBException;

public class Main {
    static String dbPath = "C:/Users/ja1/AppData/Local/Parity/Ethereum/chains/ethereum/db/906a34e69aec8c0d/overlayrecent/db";

    public static void main(String[] args)
    {
        System.out.println("Hello World!");
        // a static method that loads the RocksDB C++ library.
        RocksDB.loadLibrary();

        // the Options class contains a set of configurable DB options
        // that determines the behaviour of the database.
        try (final Options options = new Options().setCreateIfMissing(false)) {

            // a factory method that returns a RocksDB instance
            try (final RocksDB db = RocksDB.open(options, dbPath)) {
                System.out.println("Opened");

                // do something
            }
        } catch (RocksDBException e) {
            // do some error handling
            System.out.println("Did not opened");
            System.out.println(e);

        }
    }
}

Error:

Hello World!
Did not opened
org.rocksdb.RocksDBException: You have to open all column families. Column families not opened: col0, col1, col2, col3, col4, col5, col6, col7

So source of problem can be elsewhere.

vweevers commented 6 years ago

May help you: https://github.com/facebook/rocksdb/wiki/RocksJava-Basics#opening-a-database-with-column-families

adamjabone commented 6 years ago

Thank you, this will help me.

adamjabone commented 6 years ago

It helped, I opened family col0, col1, etc. and it works, do you know how to pass same options in level-rocksdb?

vweevers commented 6 years ago

This is not currently supported. Apologies if that wasn't clear.

adamjabone commented 6 years ago

That was clear, I wanted to assert, thanks.

vweevers commented 5 years ago

See https://github.com/Level/rocksdb/issues/13 for passing options to the RocksDB binding.

Sceat commented 2 months ago

@adamjabone did you manage to use column families in javascript ?