MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / Commit

Method Commit

rtpose_wrapper/src/caffe/util/db_lmdb.cpp:57–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57void LMDBTransaction::Commit() {
58 MDB_dbi mdb_dbi;
59 MDB_val mdb_key, mdb_data;
60 MDB_txn *mdb_txn;
61
62 // Initialize MDB variables
63 MDB_CHECK(mdb_txn_begin(mdb_env_, NULL, 0, &mdb_txn));
64 MDB_CHECK(mdb_dbi_open(mdb_txn, NULL, 0, &mdb_dbi));
65
66 for (int i = 0; i < keys.size(); i++) {
67 mdb_key.mv_size = keys[i].size();
68 mdb_key.mv_data = const_cast<char*>(keys[i].data());
69 mdb_data.mv_size = values[i].size();
70 mdb_data.mv_data = const_cast<char*>(values[i].data());
71
72 // Add data to the transaction
73 int put_rc = mdb_put(mdb_txn, mdb_dbi, &mdb_key, &mdb_data, 0);
74 if (put_rc == MDB_MAP_FULL) {
75 // Out of memory - double the map size and retry
76 mdb_txn_abort(mdb_txn);
77 mdb_dbi_close(mdb_env_, mdb_dbi);
78 DoubleMapSize();
79 Commit();
80 return;
81 }
82 // May have failed for some other reason
83 MDB_CHECK(put_rc);
84 }
85
86 // Commit the transaction
87 int commit_rc = mdb_txn_commit(mdb_txn);
88 if (commit_rc == MDB_MAP_FULL) {
89 // Out of memory - double the map size and retry
90 mdb_dbi_close(mdb_env_, mdb_dbi);
91 DoubleMapSize();
92 Commit();
93 return;
94 }
95 // May have failed for some other reason
96 MDB_CHECK(commit_rc);
97
98 // Cleanup after successful commit
99 mdb_dbi_close(mdb_env_, mdb_dbi);
100 keys.clear();
101 values.clear();
102}
103
104void LMDBTransaction::DoubleMapSize() {
105 struct MDB_envinfo current_info;

Callers 6

mainFunction · 0.45
FillMethod · 0.45
TestReshapeMethod · 0.45
SetUpMethod · 0.45
TYPED_TESTFunction · 0.45

Calls 4

MDB_CHECKFunction · 0.85
dataMethod · 0.80
clearMethod · 0.80
sizeMethod · 0.45

Tested by 4

FillMethod · 0.36
TestReshapeMethod · 0.36
SetUpMethod · 0.36
TYPED_TESTFunction · 0.36