diff options
author | George Hazan <ghazan@miranda.im> | 2020-12-01 20:39:34 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-12-01 20:39:34 +0300 |
commit | 505b2f5bd4d5d2442bc0269527b639ec4994b07e (patch) | |
tree | a71aa05b314a60ce1341677cc9c84199fbad9811 /plugins/Dbx_mdbx/src | |
parent | edc0f7b2cb7c3008272aa76ad82644a2cabc94e5 (diff) |
fixes #2634 & #2605 (various problems on startup, caused by transaction isolation), also read-only transactions now use global write transaction
Diffstat (limited to 'plugins/Dbx_mdbx/src')
-rw-r--r-- | plugins/Dbx_mdbx/src/dbcontacts.cpp | 19 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbcrypt.cpp | 41 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbevents.cpp | 92 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbintf.cpp | 14 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbintf.h | 2 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbmodulechain.cpp | 3 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbsettings.cpp | 21 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbutils.cpp | 54 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/stdafx.h | 25 |
9 files changed, 70 insertions, 201 deletions
diff --git a/plugins/Dbx_mdbx/src/dbcontacts.cpp b/plugins/Dbx_mdbx/src/dbcontacts.cpp index 7145bdbfe1..5937865d0d 100644 --- a/plugins/Dbx_mdbx/src/dbcontacts.cpp +++ b/plugins/Dbx_mdbx/src/dbcontacts.cpp @@ -26,8 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. LONG CDbxMDBX::GetContactCount(void)
{
MDBX_stat st;
- txn_ptr_ro trnlck(m_txn_ro);
- mdbx_dbi_stat(trnlck, m_dbContacts, &st, sizeof(st));
+ mdbx_dbi_stat(StartTran(), m_dbContacts, &st, sizeof(st));
return st.ms_entries;
}
@@ -148,8 +147,7 @@ void CDbxMDBX::GatherContactHistory(MCONTACT hContact, OBJLIST<EventItem> &list) DBEventSortingKey keyVal = { hContact, 0, 0 };
MDBX_val key = { &keyVal, sizeof(keyVal) }, data;
- txn_ptr_ro trnlck(m_txn_ro);
- mdbx_cursor_bind(m_txn_ro, m_curEventsSort, m_dbEventsSort);
+ mdbx_cursor_bind(StartTran(), m_curEventsSort, m_dbEventsSort);
for (int res = mdbx_cursor_get(m_curEventsSort, &key, &data, MDBX_SET_RANGE); res == MDBX_SUCCESS; res = mdbx_cursor_get(m_curEventsSort, &key, &data, MDBX_NEXT)) {
const DBEventSortingKey *pKey = (const DBEventSortingKey*)key.iov_base;
@@ -287,15 +285,12 @@ void DBCachedContact::Revert() void CDbxMDBX::FillContacts()
{
- {
- txn_ptr_ro trnlck(m_txn_ro);
- cursor_ptr pCursor(m_txn_ro, m_dbContacts);
+ cursor_ptr pCursor(StartTran(), m_dbContacts);
- MDBX_val key, data;
- while (mdbx_cursor_get(pCursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS) {
- DBCachedContact *cc = m_cache->AddContactToCache(*(MCONTACT*)key.iov_base);
- cc->dbc = *(DBContact*)data.iov_base;
- }
+ MDBX_val key, data;
+ while (mdbx_cursor_get(pCursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS) {
+ DBCachedContact *cc = m_cache->AddContactToCache(*(MCONTACT*)key.iov_base);
+ cc->dbc = *(DBContact*)data.iov_base;
}
for (DBCachedContact *cc = m_cache->GetFirstContact(); cc; cc = m_cache->GetNextContact(cc->contactID)) {
diff --git a/plugins/Dbx_mdbx/src/dbcrypt.cpp b/plugins/Dbx_mdbx/src/dbcrypt.cpp index 1d815c00f9..e88e253b7d 100644 --- a/plugins/Dbx_mdbx/src/dbcrypt.cpp +++ b/plugins/Dbx_mdbx/src/dbcrypt.cpp @@ -203,14 +203,10 @@ int CDbxMDBX::InitCrypt() if (m_crypto != nullptr)
return 0;
- int rc;
+ CRYPTO_PROVIDER *pProvider;
MDBX_val key = { DBKey_Crypto_Provider, sizeof(DBKey_Crypto_Provider) }, value;
- {
- txn_ptr_ro txn(m_txn_ro);
- rc = mdbx_get(txn, m_dbCrypto, &key, &value);
- }
- CRYPTO_PROVIDER *pProvider;
+ int rc = mdbx_get(StartTran(), m_dbCrypto, &key, &value);
if (rc == MDBX_SUCCESS) {
pProvider = Crypto_GetProvider((const char*)value.iov_base);
if (pProvider == nullptr)
@@ -225,11 +221,7 @@ int CDbxMDBX::InitCrypt() return 3;
key.iov_len = sizeof(DBKey_Crypto_Key); key.iov_base = DBKey_Crypto_Key;
- {
- txn_ptr_ro txn(m_txn_ro);
- rc = mdbx_get(txn, m_dbCrypto, &key, &value);
- }
-
+ rc = mdbx_get(StartTran(), m_dbCrypto, &key, &value);
if (rc == MDBX_SUCCESS && (value.iov_len == m_crypto->getKeyLength())) {
if (!m_crypto->setKey((const BYTE*)value.iov_base, value.iov_len)) {
CEnterPasswordDialog dlg(this);
@@ -254,13 +246,10 @@ int CDbxMDBX::InitCrypt() }
key.iov_len = sizeof(DBKey_Crypto_IsEncrypted); key.iov_base = DBKey_Crypto_IsEncrypted;
- {
- txn_ptr_ro txn(m_txn_ro);
- if (mdbx_get(txn, m_dbCrypto, &key, &value) == MDBX_SUCCESS)
- m_bEncrypted = *(const bool *)value.iov_base;
- else
- m_bEncrypted = false;
- }
+ if (mdbx_get(StartTran(), m_dbCrypto, &key, &value) == MDBX_SUCCESS)
+ m_bEncrypted = *(const bool *)value.iov_base;
+ else
+ m_bEncrypted = false;
InitDialogs();
return 0;
@@ -307,19 +296,17 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted) return 0;
std::vector<MEVENT> lstEvents;
- {
- txn_ptr_ro txn(m_txn_ro);
-
- MDBX_stat st;
- mdbx_dbi_stat(txn, m_dbEvents, &st, sizeof(st));
- lstEvents.reserve(st.ms_entries);
-
- cursor_ptr pCursor(txn, m_dbEvents);
+ MDBX_stat st;
+ mdbx_dbi_stat(StartTran(), m_dbEvents, &st, sizeof(st));
+ lstEvents.reserve(st.ms_entries);
+ {
MDBX_val key, data;
+ cursor_ptr pCursor(StartTran(), m_dbEvents);
+
while (mdbx_cursor_get(pCursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS) {
- const MEVENT hDbEvent = *(const MEVENT*)key.iov_base;
+ const MEVENT hDbEvent = *(const MEVENT *)key.iov_base;
lstEvents.push_back(hDbEvent);
}
}
diff --git a/plugins/Dbx_mdbx/src/dbevents.cpp b/plugins/Dbx_mdbx/src/dbevents.cpp index 787b680590..9958301847 100644 --- a/plugins/Dbx_mdbx/src/dbevents.cpp +++ b/plugins/Dbx_mdbx/src/dbevents.cpp @@ -50,13 +50,11 @@ MEVENT CDbxMDBX::AddEvent(MCONTACT contactID, const DBEVENTINFO *dbei) BOOL CDbxMDBX::DeleteEvent(MEVENT hDbEvent)
{
- DBCachedContact *cc, *cc2;
DBEvent dbe;
char *szId = nullptr;
{
- txn_ptr_ro txn(m_txn_ro);
MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data;
- if (mdbx_get(txn, m_dbEvents, &key, &data) != MDBX_SUCCESS)
+ if (mdbx_get(StartTran(), m_dbEvents, &key, &data) != MDBX_SUCCESS)
return 1;
dbe = *(DBEvent*)data.iov_base;
@@ -64,12 +62,12 @@ BOOL CDbxMDBX::DeleteEvent(MEVENT hDbEvent) char *src = (char *)data.iov_base + sizeof(dbe) + dbe.cbBlob + 1;
szId = NEWSTR_ALLOCA(src);
}
-
- cc = (dbe.dwContactID != 0) ? m_cache->GetCachedContact(dbe.dwContactID) : &m_ccDummy;
- if (cc == nullptr || cc->dbc.dwEventCount == 0)
- return 1;
}
+ DBCachedContact *cc2, *cc = (dbe.dwContactID != 0) ? m_cache->GetCachedContact(dbe.dwContactID) : &m_ccDummy;
+ if (cc == nullptr || cc->dbc.dwEventCount == 0)
+ return 1;
+
if (!CheckEvent(cc, &dbe, cc2))
return 1;
{
@@ -148,16 +146,13 @@ BOOL CDbxMDBX::EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO if (dbei->timestamp == 0) return 1;
DBEVENTINFO tmp = *dbei;
- {
- txn_ptr_ro txn(m_txn_ro);
- MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data;
- if (mdbx_get(txn, m_dbEvents, &key, &data) != MDBX_SUCCESS)
- return 1;
- DBEvent *dbe = (DBEvent*)data.iov_base;
- tmp.timestamp = dbe->timestamp;
- }
+ MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data;
+ if (mdbx_get(StartTran(), m_dbEvents, &key, &data) != MDBX_SUCCESS)
+ return 1;
+ DBEvent *dbe = (DBEvent*)data.iov_base;
+ tmp.timestamp = dbe->timestamp;
return !EditEvent(contactID, hDbEvent, &tmp, false);
}
@@ -291,10 +286,8 @@ bool CDbxMDBX::EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO LONG CDbxMDBX::GetBlobSize(MEVENT hDbEvent)
{
- txn_ptr_ro txn(m_txn_ro);
-
MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data;
- if (mdbx_get(txn, m_dbEvents, &key, &data) != MDBX_SUCCESS)
+ if (mdbx_get(StartTran(), m_dbEvents, &key, &data) != MDBX_SUCCESS)
return -1;
return ((const DBEvent*)data.iov_base)->cbBlob;
}
@@ -312,10 +305,8 @@ BOOL CDbxMDBX::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) size_t cbBlob;
const DBEvent *dbe;
{
- txn_ptr_ro txn(m_txn_ro);
-
MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data;
- if (mdbx_get(txn, m_dbEvents, &key, &data) != MDBX_SUCCESS)
+ if (mdbx_get(StartTran(), m_dbEvents, &key, &data) != MDBX_SUCCESS)
return 1;
dbe = (const DBEvent*)data.iov_base;
@@ -469,13 +460,12 @@ MEVENT CDbxMDBX::GetEventById(LPCSTR szModule, LPCSTR szId) strncpy_s(keyId.szEventId, szId, _TRUNCATE);
MDBX_val key = { &keyId, sizeof(MEVENT) + strlen(keyId.szEventId) + 1 }, data;
- txn_ptr_ro txn(m_txn_ro);
- if (mdbx_get(txn, m_dbEventIds, &key, &data) != MDBX_SUCCESS)
+ if (mdbx_get(StartTran(), m_dbEventIds, &key, &data) != MDBX_SUCCESS)
return 0;
MEVENT hDbEvent = *(MEVENT *)data.iov_base;
MDBX_val key2 = { &hDbEvent, sizeof(MEVENT) }, data2;
- if (mdbx_get(txn, m_dbEvents, &key2, &data2) != MDBX_SUCCESS)
+ if (mdbx_get(StartTran(), m_dbEvents, &key2, &data2) != MDBX_SUCCESS)
return 0;
return hDbEvent;
@@ -488,10 +478,8 @@ MCONTACT CDbxMDBX::GetEventContact(MEVENT hDbEvent) if (hDbEvent == 0)
return INVALID_CONTACT_ID;
- txn_ptr_ro txn(m_txn_ro);
-
MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data;
- if (mdbx_get(txn, m_dbEvents, &key, &data) != MDBX_SUCCESS)
+ if (mdbx_get(StartTran(), m_dbEvents, &key, &data) != MDBX_SUCCESS)
return INVALID_CONTACT_ID;
return ((const DBEvent*)data.iov_base)->dwContactID;
@@ -512,9 +500,7 @@ MEVENT CDbxMDBX::FindFirstEvent(MCONTACT contactID) DBEventSortingKey keyVal = { contactID, 0, 0 };
MDBX_val key = { &keyVal, sizeof(keyVal) }, data;
- txn_ptr_ro txn(m_txn_ro);
-
- mdbx_cursor_bind(m_txn_ro, m_curEventsSort, m_dbEventsSort);
+ mdbx_cursor_bind(StartTran(), m_curEventsSort, m_dbEventsSort);
if (mdbx_cursor_get(m_curEventsSort, &key, &data, MDBX_SET_RANGE) != MDBX_SUCCESS)
return cc->t_evLast = 0;
@@ -546,8 +532,7 @@ MEVENT CDbxMDBX::FindLastEvent(MCONTACT contactID) DBEventSortingKey keyVal = { contactID, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF };
MDBX_val key = { &keyVal, sizeof(keyVal) }, data;
- txn_ptr_ro txn(m_txn_ro);
- mdbx_cursor_bind(m_txn_ro, m_curEventsSort, m_dbEventsSort);
+ mdbx_cursor_bind(StartTran(), m_curEventsSort, m_dbEventsSort);
if (mdbx_cursor_get(m_curEventsSort, &key, &data, MDBX_SET_RANGE) != MDBX_SUCCESS) {
if (mdbx_cursor_get(m_curEventsSort, &key, &data, MDBX_LAST) != MDBX_SUCCESS)
@@ -578,11 +563,9 @@ MEVENT CDbxMDBX::FindNextEvent(MCONTACT contactID, MEVENT hDbEvent) if (hDbEvent == 0)
return cc->t_evLast = 0;
- txn_ptr_ro txn(m_txn_ro);
-
if (cc->t_evLast != hDbEvent) {
MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data;
- if (mdbx_get(txn, m_dbEvents, &key, &data) != MDBX_SUCCESS)
+ if (mdbx_get(StartTran(), m_dbEvents, &key, &data) != MDBX_SUCCESS)
return 0;
cc->t_tsLast = ((DBEvent*)data.iov_base)->timestamp;
}
@@ -590,7 +573,7 @@ MEVENT CDbxMDBX::FindNextEvent(MCONTACT contactID, MEVENT hDbEvent) DBEventSortingKey keyVal = { contactID, hDbEvent, cc->t_tsLast };
MDBX_val key = { &keyVal, sizeof(keyVal) }, data;
- mdbx_cursor_bind(m_txn_ro, m_curEventsSort, m_dbEventsSort);
+ mdbx_cursor_bind(StartTran(), m_curEventsSort, m_dbEventsSort);
if (mdbx_cursor_get(m_curEventsSort, &key, nullptr, MDBX_SET) != MDBX_SUCCESS)
return cc->t_evLast = 0;
@@ -619,11 +602,9 @@ MEVENT CDbxMDBX::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent) MDBX_val data;
- txn_ptr_ro txn(m_txn_ro);
-
if (cc->t_evLast != hDbEvent) {
MDBX_val key = { &hDbEvent, sizeof(MEVENT) };
- if (mdbx_get(txn, m_dbEvents, &key, &data) != MDBX_SUCCESS)
+ if (mdbx_get(StartTran(), m_dbEvents, &key, &data) != MDBX_SUCCESS)
return 0;
cc->t_tsLast = ((DBEvent*)data.iov_base)->timestamp;
}
@@ -631,7 +612,7 @@ MEVENT CDbxMDBX::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent) DBEventSortingKey keyVal = { contactID, hDbEvent, cc->t_tsLast };
MDBX_val key = { &keyVal, sizeof(keyVal) };
- mdbx_cursor_bind(m_txn_ro, m_curEventsSort, m_dbEventsSort);
+ mdbx_cursor_bind(StartTran(), m_curEventsSort, m_dbEventsSort);
if (mdbx_cursor_get(m_curEventsSort, &key, nullptr, MDBX_SET) != MDBX_SUCCESS)
return cc->t_evLast = 0;
@@ -675,28 +656,25 @@ public: MEVENT FetchNext() override
{
+ mdbx_cursor_bind(m_pOwner->StartTran(), m_pOwner->m_curEventsSort, m_pOwner->m_dbEventsSort);
+
MDBX_val key = { &m_key, sizeof(m_key) }, data;
DBEventSortingKey dbKey;
- {
- txn_ptr_ro txn(m_pOwner->m_txn_ro);
- mdbx_cursor_bind(m_pOwner->m_txn_ro, m_pOwner->m_curEventsSort, m_pOwner->m_dbEventsSort);
-
- if (m_bFirst) {
- m_bFirst = false;
+ if (m_bFirst) {
+ m_bFirst = false;
- if (mdbx_cursor_get(m_pOwner->m_curEventsSort, &key, &data, MDBX_SET_RANGE) != MDBX_SUCCESS)
- return 0;
- dbKey = *(const DBEventSortingKey *)key.iov_base;
- }
- else {
- if (mdbx_cursor_get(m_pOwner->m_curEventsSort, &key, &data, MDBX_SET) != MDBX_SUCCESS)
- return 0;
+ if (mdbx_cursor_get(m_pOwner->m_curEventsSort, &key, &data, MDBX_SET_RANGE) != MDBX_SUCCESS)
+ return 0;
+ dbKey = *(const DBEventSortingKey *)key.iov_base;
+ }
+ else {
+ if (mdbx_cursor_get(m_pOwner->m_curEventsSort, &key, &data, MDBX_SET) != MDBX_SUCCESS)
+ return 0;
- if (mdbx_cursor_get(m_pOwner->m_curEventsSort, &key, &data, (m_bForward) ? MDBX_NEXT : MDBX_PREV) != MDBX_SUCCESS)
- return 0;
+ if (mdbx_cursor_get(m_pOwner->m_curEventsSort, &key, &data, (m_bForward) ? MDBX_NEXT : MDBX_PREV) != MDBX_SUCCESS)
+ return 0;
- dbKey = *(const DBEventSortingKey *)key.iov_base;
- }
+ dbKey = *(const DBEventSortingKey *)key.iov_base;
}
if (dbKey.hContact != hContact)
diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp index ed8e1fc514..58c037652e 100644 --- a/plugins/Dbx_mdbx/src/dbintf.cpp +++ b/plugins/Dbx_mdbx/src/dbintf.cpp @@ -206,25 +206,22 @@ int CDbxMDBX::Load() if (mdbx_get(m_pWriteTran, m_dbGlobal, &key, &data) == MDBX_SUCCESS)
m_ccDummy.dbc = *(const DBContact *)data.iov_base;
}
- mdbx_txn_commit(m_pWriteTran); m_pWriteTran = nullptr;
- mdbx_txn_begin(m_env, nullptr, MDBX_TXN_RDONLY, &m_txn_ro);
-
m_curEventsSort = mdbx_cursor_create(nullptr);
MDBX_val key, val;
{
- cursor_ptr pCursor(m_txn_ro, m_dbEvents);
+ cursor_ptr pCursor(m_pWriteTran, m_dbEvents);
if (mdbx_cursor_get(pCursor, &key, &val, MDBX_LAST) == MDBX_SUCCESS)
m_dwMaxEventId = *(MEVENT *)key.iov_base;
}
{
- cursor_ptr pCursor(m_txn_ro, m_dbContacts);
+ cursor_ptr pCursor(m_pWriteTran, m_dbContacts);
if (mdbx_cursor_get(pCursor, &key, &val, MDBX_LAST) == MDBX_SUCCESS)
m_maxContactId = *(MCONTACT *)key.iov_base;
}
- mdbx_txn_reset(m_txn_ro);
+ mdbx_txn_commit(m_pWriteTran); m_pWriteTran = nullptr;
if (InitModules()) return EGROKPRF_DAMAGED;
if (InitCrypt()) return EGROKPRF_DAMAGED;
@@ -314,10 +311,7 @@ MDBX_txn* CDbxMDBX::StartTran() _ASSERT(m_dbError == MDBX_SUCCESS);
}
- MDBX_txn *res = nullptr;
- m_dbError = mdbx_txn_begin(m_env, m_pWriteTran, MDBX_TXN_READWRITE, &res);
- _ASSERT(m_dbError == MDBX_SUCCESS);
- return res;
+ return m_pWriteTran;
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h index 126501147b..6cdc48d6d0 100644 --- a/plugins/Dbx_mdbx/src/dbintf.h +++ b/plugins/Dbx_mdbx/src/dbintf.h @@ -140,6 +140,7 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe {
friend class CMdbxEventCursor;
friend class txn_ptr;
+ friend class txn_ptr_ro;
typedef std::map<uint32_t, std::string> TModuleMap;
@@ -178,7 +179,6 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe MDBX_env *m_env;
MDBX_txn *m_pWriteTran;
- CMDBX_txn_ro m_txn_ro;
int m_dbError;
MDBX_dbi m_dbGlobal;
diff --git a/plugins/Dbx_mdbx/src/dbmodulechain.cpp b/plugins/Dbx_mdbx/src/dbmodulechain.cpp index 54e9631c43..10bb0f90e6 100644 --- a/plugins/Dbx_mdbx/src/dbmodulechain.cpp +++ b/plugins/Dbx_mdbx/src/dbmodulechain.cpp @@ -25,8 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. int CDbxMDBX::InitModules()
{
- txn_ptr_ro trnlck(m_txn_ro);
- cursor_ptr pCursor(m_txn_ro, m_dbModules);
+ cursor_ptr pCursor(StartTran(), m_dbModules);
MDBX_val key, data;
while (mdbx_cursor_get(pCursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS) {
diff --git a/plugins/Dbx_mdbx/src/dbsettings.cpp b/plugins/Dbx_mdbx/src/dbsettings.cpp index ee439369e8..1363f987e3 100644 --- a/plugins/Dbx_mdbx/src/dbsettings.cpp +++ b/plugins/Dbx_mdbx/src/dbsettings.cpp @@ -89,15 +89,8 @@ LBL_Seek: keyVal->dwModuleId = GetModuleID(szModule);
memcpy(&keyVal->szSettingName, szSetting, settingNameLen + 1);
- int res;
- const BYTE *pBlob;
- {
- txn_ptr_ro trnlck(m_txn_ro);
- MDBX_val key = { keyVal, sizeof(DBSettingKey) + settingNameLen }, data;
- res = mdbx_get(trnlck, m_dbSettings, &key, &data);
- pBlob = (const BYTE*)data.iov_base;
- }
-
+ MDBX_val key = { keyVal, sizeof(DBSettingKey) + settingNameLen }, data;
+ int res = mdbx_get(StartTran(), m_dbSettings, &key, &data);
if (res != MDBX_SUCCESS) {
// try to get the missing mc setting from the active sub
if (cc && cc->IsMeta() && ValidLookupName(szModule, szSetting)) {
@@ -111,6 +104,7 @@ LBL_Seek: return 1;
}
+ const BYTE *pBlob = (const BYTE*)data.iov_base;
if (isStatic && (pBlob[0] & DBVTF_VARIABLELENGTH) && VLT(dbv->type) != VLT(pBlob[0]))
return 1;
@@ -398,12 +392,11 @@ BOOL CDbxMDBX::DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR BOOL CDbxMDBX::EnumContactSettings(MCONTACT hContact, DBSETTINGENUMPROC pfnEnumProc, const char *szModule, void *param)
{
LIST<char> arKeys(100);
- {
- DBSettingKey keyVal = { hContact, GetModuleID(szModule), 0 };
- MDBX_val key = { &keyVal, sizeof(keyVal) }, data;
- txn_ptr_ro txn(m_txn_ro);
- cursor_ptr pCursor(m_txn_ro, m_dbSettings);
+ DBSettingKey keyVal = { hContact, GetModuleID(szModule), 0 };
+ MDBX_val key = { &keyVal, sizeof(keyVal) }, data;
+ {
+ cursor_ptr pCursor(StartTran(), m_dbSettings);
for (int res = mdbx_cursor_get(pCursor, &key, &data, MDBX_SET_RANGE); res == MDBX_SUCCESS; res = mdbx_cursor_get(pCursor, &key, &data, MDBX_NEXT)) {
const DBSettingKey *pKey = (const DBSettingKey*)key.iov_base;
diff --git a/plugins/Dbx_mdbx/src/dbutils.cpp b/plugins/Dbx_mdbx/src/dbutils.cpp index a1a758a53b..472628bf0a 100644 --- a/plugins/Dbx_mdbx/src/dbutils.cpp +++ b/plugins/Dbx_mdbx/src/dbutils.cpp @@ -55,41 +55,6 @@ int DBSettingKey::Compare(const MDBX_val *ax, const MDBX_val *bx) MDBX_CXX17_NOE }
/////////////////////////////////////////////////////////////////////////////////////////
-// txn_ptr_ro class
-
-txn_ptr_ro::txn_ptr_ro(CMDBX_txn_ro &_txn) :
- txn(_txn),
- lock(txn.cs)
-{
- for (int nRetries = 0; nRetries < 5; nRetries++) {
- int rc = mdbx_txn_renew(txn);
- if (rc == MDBX_SUCCESS)
- break;
-
- #ifdef _DEBUG
- DebugBreak();
- #endif
- Netlib_Logf(nullptr, "txn_ptr_ro::txn_ptr_ro failed with error=%d, retrying...", rc);
- Sleep(0);
- }
-}
-
-txn_ptr_ro::~txn_ptr_ro()
-{
- for (int nRetries = 0; nRetries < 5; nRetries++) {
- int rc = mdbx_txn_reset(txn);
- if (rc == MDBX_SUCCESS)
- break;
-
- #ifdef _DEBUG
- DebugBreak();
- #endif
- Netlib_Logf(nullptr, "txn_ptr_ro::~txn_ptr_ro failed with error=%d, retrying...", rc);
- Sleep(0);
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
// txn_ptr class
txn_ptr::txn_ptr(CDbxMDBX *_db) :
@@ -101,29 +66,10 @@ txn_ptr::txn_ptr(CDbxMDBX *_db) : txn_ptr::~txn_ptr()
{
- if (txn)
- Abort();
-
pDb->m_csDbAccess.Unlock();
}
int txn_ptr::Commit()
{
- int rc = mdbx_txn_commit(txn);
- if (rc != MDBX_SUCCESS) {
- /* FIXME: throw an exception */
- Abort();
- return rc;
- }
- txn = nullptr;
return MDBX_SUCCESS;
}
-
-void txn_ptr::Abort()
-{
- int rc = mdbx_txn_abort(txn);
- /* FIXME: throw an exception */
- _ASSERT(rc == MDBX_SUCCESS);
- UNREFERENCED_PARAMETER(rc);
- txn = nullptr;
-}
diff --git a/plugins/Dbx_mdbx/src/stdafx.h b/plugins/Dbx_mdbx/src/stdafx.h index 82e2e8be53..6904e319d6 100644 --- a/plugins/Dbx_mdbx/src/stdafx.h +++ b/plugins/Dbx_mdbx/src/stdafx.h @@ -58,27 +58,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # define thread_local __declspec(thread)
#endif
-struct CMDBX_txn_ro
-{
- MDBX_txn *txn = nullptr;
- mir_cs cs;
-
- __forceinline operator MDBX_txn* () { return txn; }
- __forceinline MDBX_txn** operator &() { return &txn; }
-};
-
-class txn_ptr_ro
-{
- CMDBX_txn_ro &txn;
- mir_cslock lock;
-
-public:
- txn_ptr_ro(CMDBX_txn_ro &_txn);
- ~txn_ptr_ro();
-
- __forceinline operator MDBX_txn*() const { return txn; }
-};
-
class cursor_ptr
{
MDBX_cursor *m_cursor;
@@ -112,8 +91,7 @@ public: __forceinline operator MDBX_txn*() const { return txn; }
- int Commit();
- void Abort();
+ int Commit();
};
#include "resource.h"
@@ -127,4 +105,3 @@ struct CMPlugin : public PLUGIN<CMPlugin> };
#include "ui.h"
-
|