Python on RocksDB
Looking for potential tool to interact with RocksDB.
If you already have the rocksdb installed on earlier project or setup, the build here will not conflicted with the default RocksDB build where it make its own directory and everything is built within it. Something interesting in this part where a lot of Test Cases where they can be potentially be consumed in the future where the RocksDB needs to be tested.
$ apt-get install build-essential libsnappy-dev zlib1g-dev libbz2-dev libgflags-dev
$ git clone https://github.com/facebook/rocksdb.git
$ cd rocksdb
$ mkdir build && cd build
$ cmake ..
$ make
$ export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:`pwd`/../include
$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:`pwd`
$ export LIBRARY_PATH=${LIBRARY_PATH}:`pwd`
Note: The github project has a typo on the instruction where ". bin/active" should be ". bin/activate"
starting from rocksdb directory
$ cd ../
$ sudo apt-get install python-virtualenv python-dev
$ virtualenv pyrocks_test
$ cd pyrocks_test
$ . bin/activate
$ pip install python-rocksdb
Test RocksDB
>>> import rocksdb
>>> db = rocksdb.DB("test.db", rocksdb.Options(create_if_missing=True))
>>> db.put(b'a', b'data')
>>> print db.get(b'a')
data
The test essentially creating a directory with the contents below. So, the test.db is a database/datafile bundle.
ls -las test.db
total 160
4 drwxr-xr-x 2 rocks rocks 4096 Mar 19 13:40 .
4 drwxrwxr-x 8 rocks rocks 4096 Mar 19 13:40 ..
4 -rw-r--r-- 1 rocks rocks 27 Mar 19 13:41 000003.log
4 -rw-r--r-- 1 rocks rocks 16 Mar 19 13:40 CURRENT
4 -rw-r--r-- 1 rocks rocks 37 Mar 19 13:40 IDENTITY
0 -rw-r--r-- 1 rocks rocks 0 Mar 19 13:40 LOCK
128 -rw-rw-r-- 1 rocks rocks 14869 Mar 19 13:41 LOG
4 -rw-r--r-- 1 rocks rocks 13 Mar 19 13:40 MANIFEST-000001
8 -rw-r--r-- 1 rocks rocks 4571 Mar 19 13:40 OPTIONS-000005
If you are getting missing librocksdb.so.5, you will likely need to rebuild the rocksdb again.
$ apt-get install build-essential libsnappy-dev zlib1g-dev libbz2-dev libgflags-dev
$ git clone https://github.com/facebook/rocksdb.git
$ cd rocksdb
$ mkdir build && cd build
$ cmake ..
$ make
$ export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:`pwd`/../include
$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:`pwd`
$ export LIBRARY_PATH=${LIBRARY_PATH}:`pwd`
$ git clone https://github.com/facebook/rocksdb.git
$ cd rocksdb
$ mkdir build && cd build
$ cmake ..
$ make
$ export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:`pwd`/../include
$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:`pwd`
$ export LIBRARY_PATH=${LIBRARY_PATH}:`pwd`
starting from rocksdb directory
$ cd ../
$ sudo apt-get install python-virtualenv python-dev
$ virtualenv pyrocks_test
$ cd pyrocks_test
$ . bin/activate
$ pip install python-rocksdb
$ sudo apt-get install python-virtualenv python-dev
$ virtualenv pyrocks_test
$ cd pyrocks_test
$ . bin/activate
$ pip install python-rocksdb
>>> import rocksdb
>>> db = rocksdb.DB("test.db", rocksdb.Options(create_if_missing=True))
>>> db.put(b'a', b'data')
>>> print db.get(b'a')
data
>>> db = rocksdb.DB("test.db", rocksdb.Options(create_if_missing=True))
>>> db.put(b'a', b'data')
>>> print db.get(b'a')
data
ls -las test.db
total 160
4 drwxr-xr-x 2 rocks rocks 4096 Mar 19 13:40 .
4 drwxrwxr-x 8 rocks rocks 4096 Mar 19 13:40 ..
4 -rw-r--r-- 1 rocks rocks 27 Mar 19 13:41 000003.log
4 -rw-r--r-- 1 rocks rocks 16 Mar 19 13:40 CURRENT
4 -rw-r--r-- 1 rocks rocks 37 Mar 19 13:40 IDENTITY
0 -rw-r--r-- 1 rocks rocks 0 Mar 19 13:40 LOCK
128 -rw-rw-r-- 1 rocks rocks 14869 Mar 19 13:41 LOG
4 -rw-r--r-- 1 rocks rocks 13 Mar 19 13:40 MANIFEST-000001
8 -rw-r--r-- 1 rocks rocks 4571 Mar 19 13:40 OPTIONS-000005
total 160
4 drwxr-xr-x 2 rocks rocks 4096 Mar 19 13:40 .
4 drwxrwxr-x 8 rocks rocks 4096 Mar 19 13:40 ..
4 -rw-r--r-- 1 rocks rocks 27 Mar 19 13:41 000003.log
4 -rw-r--r-- 1 rocks rocks 16 Mar 19 13:40 CURRENT
4 -rw-r--r-- 1 rocks rocks 37 Mar 19 13:40 IDENTITY
0 -rw-r--r-- 1 rocks rocks 0 Mar 19 13:40 LOCK
128 -rw-rw-r-- 1 rocks rocks 14869 Mar 19 13:41 LOG
4 -rw-r--r-- 1 rocks rocks 13 Mar 19 13:40 MANIFEST-000001
8 -rw-r--r-- 1 rocks rocks 4571 Mar 19 13:40 OPTIONS-000005
No comments:
Post a Comment