我对 Berkeley DB 还很陌生,我正在尝试在 Python 中将它与 bsddb3 一起使用,并带有用于电源安全的事务 使用 DB_AUTO_COMMIT 并且没有事务参数读取和写入工作得很好。但是,当我使用手动事务调用 get/put 时,调用会无限期挂起,几乎不使用 CPU(大约 50k 周期/秒)并且不执行磁盘 I/O。
_data_store_env.log_set_config(bdb.DB_LOG_AUTO_REMOVE, True)
_data_store_env.set_lg_max(256 * 2**20)
_data_store_env.set_cachesize(0, 512 * 2**20)
_data_store_env.set_lg_dir(str(_journal_path))
_data_store_env.set_tmp_dir(str(tmp_dir))
_data_store_env.open(str(_bulk_data_path), bdb.DB_CREATE | bdb.DB_INIT_LOCK | bdb.DB_INIT_LOG | bdb.DB_INIT_MPOOL | bdb.DB_INIT_TXN | bdb.DB_RECOVER | bdb.DB_THREAD)
# Originally I simply used DB_AUTO_COMMIT, but I changed it to see if this way would fix the hang. It didn't.
txn = _data_store_env.txn_begin()
_data_store = bdb.DB(_data_store_env)
_data_store.set_flags(bdb.DB_CHKSUM)
_data_store.set_pagesize(65536)
_data_store.open("filestore.db", None, bdb.DB_HASH, bdb.DB_CREATE | bdb.DB_THREAD, 0x660, txn)
_idx_store = bdb.DB(_data_store_env)
_idx_store.set_flags(bdb.DB_CHKSUM | bdb.DB_DUPSORT)
_idx_store.open("idxstore.db", None, bdb.DB_HASH, bdb.DB_CREATE | bdb.DB_THREAD, 0x660, txn)
_data_store.associate(_idx_store, lambda key, data: key[0:9], bdb.DB_IMMUTABLE_KEY, txn)
txn.commit()
...
# It doesn't matter whether this flag is present or not. Both produce the same result.
txn = _data_store_env.txn_begin(None, bdb.DB_TXN_BULK)
...
# Never returns
file_exists = _idx_store.has_key(entry_key, txn)
...
# Also never returns
_data_store.put(file_hash, file_data, txn)
难道我做错了什么?事务甚至可以在 bsddb3 中工作吗?