我有一个简单的rocksdb
程序,在其中创建一个数据库,并使用事务在其中添加一些值。
using namespace rocksdb;
std::string kDBPath = "D:\\Newdata";
int main() {
// open DB
Options options;
TransactionDBOptions txn_db_options;
options.create_if_missing = true;
TransactionDB* txn_db;
Status s = TransactionDB::Open(options, txn_db_options, kDBPath, &txn_db);
assert(s.ok());
WriteOptions write_options;
ReadOptions read_options;
TransactionOptions txn_options;
std::string value;
////////////////////////////////////////////////////////
//
// Simple Transaction Example ("Read Committed")
//
////////////////////////////////////////////////////////
// Start a transaction
Transaction* txn = txn_db->BeginTransaction(write_options);
assert(txn);
// Read a key in this transaction
//s = txn->Get(read_options, "abc", &value);
//assert(s.IsNotFound());
// Write a key in this transaction
s = txn->Put("abc", "def");
assert(s.ok());
// Read a key OUTSIDE this transaction. Does not affect txn.
s = txn_db->Get(read_options, "abc", &value);
assert(s.IsNotFound());
// Write a key OUTSIDE of this transaction.
// Does not affect txn since this is an unrelated key.
s = txn_db->Put(write_options, "xyz", "zzz");
assert(s.ok());
// Write a key OUTSIDE of this transaction.
// Fail because the key conflicts with the key written in txn.
s = txn_db->Put(write_options, "abc", "def");
assert(s.subcode() == Status::kLockTimeout);
// Value for key "xyz" has been committed, can be read in txn.
s = txn->Get(read_options, "xyz", &value);
assert(s.ok());
assert(value == "zzz");
// Commit transaction
s = txn->Commit();
assert(s.ok());
std::cout << "End program";
return 0;
}
首先失败Put
。
错误:
Exception thrown at 0x00007FF7FCAD0D84 in Rocksdbtest.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
Unhandled exception thrown: read access violation.
txn->**** was 0xFFFFFFFFFFFFFF27.
使用VS进行调试会显示<Unable to read memory>
的{{1}}字段的name
。
VS更新之前,同一程序运行良好。