From e5f124fe68b78d3c4aeca39f9aca914c91cc4124 Mon Sep 17 00:00:00 2001 From: Roy Lee Date: Mon, 8 Nov 2021 16:37:58 -0800 Subject: [PATCH] add a rocksdb setup sanity check --- test_rocksdb.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 test_rocksdb.py diff --git a/test_rocksdb.py b/test_rocksdb.py new file mode 100755 index 000000000..39470457e --- /dev/null +++ b/test_rocksdb.py @@ -0,0 +1,47 @@ +#! python + +import os +import shutil +import rocksdb +import tempfile +import logging + +log = logging.getLogger() +log.addHandler(logging.StreamHandler()) +log.setLevel(logging.INFO) + +def _main(db_loc): + opts = rocksdb.Options(create_if_missing=True) + db = rocksdb.DB(os.path.join(db_loc, "test"), opts) + secondary_location = os.path.join(db_loc, "secondary") + secondary = rocksdb.DB( + os.path.join(db_loc, "test"), + rocksdb.Options(create_if_missing=True, max_open_files=-1), + secondary_name=secondary_location + ) + try: + assert secondary.get(b"a") is None + db.put(b"a", b"b") + assert db.get(b"a") == b"b" + assert secondary.get(b"a") is None + + secondary.try_catch_up_with_primary() + assert secondary.get(b"a") == b"b" + finally: + secondary.close() + db.close() + + +def main(): + db_dir = tempfile.mkdtemp() + try: + _main(db_dir) + log.info("rocksdb %s (%s) works!", rocksdb.__version__, rocksdb.ROCKSDB_VERSION) + except: + log.exception("boom") + finally: + shutil.rmtree(db_dir) + + +if __name__ == "__main__": + main()