diff options
author | George Hazan <ghazan@miranda.im> | 2020-11-16 20:17:27 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-11-16 20:17:27 +0300 |
commit | 7bb7189d67da6f916bbc9f4076d1319cd03f65d2 (patch) | |
tree | b12a5ada678447adcbe9ed82faafa5aa69794c81 /plugins | |
parent | efe255d24291ca83efa9caee3696a8f1451b3b11 (diff) |
Dbx_mdbx: global cursors replaced with mdbx_cursor_bind() and temporary cursors
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Dbx_mdbx/src/dbcontacts.cpp | 8 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbcrypt.cpp | 18 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbevents.cpp | 32 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbintf.cpp | 267 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbintf.h | 18 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbmodulechain.cpp | 6 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbsettings.cpp | 6 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/stdafx.h | 14 |
8 files changed, 187 insertions, 182 deletions
diff --git a/plugins/Dbx_mdbx/src/dbcontacts.cpp b/plugins/Dbx_mdbx/src/dbcontacts.cpp index 67e5d2be6f..0236a3ea08 100644 --- a/plugins/Dbx_mdbx/src/dbcontacts.cpp +++ b/plugins/Dbx_mdbx/src/dbcontacts.cpp @@ -149,9 +149,9 @@ void CDbxMDBX::GatherContactHistory(MCONTACT hContact, OBJLIST<EventItem> &list) MDBX_val key = { &keyVal, sizeof(keyVal) }, data;
txn_ptr_ro trnlck(m_txn_ro);
- cursor_ptr_ro cursor(m_curEventsSort);
+ mdbx_cursor_bind(m_txn_ro, m_curEventsSort, m_dbEventsSort);
- for (int res = mdbx_cursor_get(cursor, &key, &data, MDBX_SET_RANGE); res == MDBX_SUCCESS; res = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) {
+ 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;
if (pKey->hContact != hContact)
return;
@@ -286,10 +286,10 @@ void CDbxMDBX::FillContacts() {
{
txn_ptr_ro trnlck(m_txn_ro);
- cursor_ptr_ro cursor(m_curContacts);
+ cursor_ptr pCursor(m_txn_ro, m_dbContacts);
MDBX_val key, data;
- while (mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS) {
+ 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;
}
diff --git a/plugins/Dbx_mdbx/src/dbcrypt.cpp b/plugins/Dbx_mdbx/src/dbcrypt.cpp index 1d86211318..7fd002cf00 100644 --- a/plugins/Dbx_mdbx/src/dbcrypt.cpp +++ b/plugins/Dbx_mdbx/src/dbcrypt.cpp @@ -308,19 +308,19 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted) std::vector<MEVENT> lstEvents;
{
- txn_ptr_ro txnro(m_txn_ro);
+ txn_ptr_ro txn(m_txn_ro);
MDBX_stat st;
- mdbx_dbi_stat(txnro, m_dbEvents, &st, sizeof(st));
+ mdbx_dbi_stat(txn, m_dbEvents, &st, sizeof(st));
lstEvents.reserve(st.ms_entries);
- {
- cursor_ptr_ro cursor(m_curEvents);
- MDBX_val key, data;
- while (mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS) {
- const MEVENT hDbEvent = *(const MEVENT*)key.iov_base;
- lstEvents.push_back(hDbEvent);
- }
+
+ cursor_ptr pCursor(txn, m_dbEvents);
+
+ MDBX_val key, data;
+ while (mdbx_cursor_get(pCursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS) {
+ 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 ff94225bed..e0ce827049 100644 --- a/plugins/Dbx_mdbx/src/dbevents.cpp +++ b/plugins/Dbx_mdbx/src/dbevents.cpp @@ -514,8 +514,8 @@ MEVENT CDbxMDBX::FindFirstEvent(MCONTACT contactID) txn_ptr_ro txn(m_txn_ro);
- cursor_ptr_ro cursor(m_curEventsSort);
- if (mdbx_cursor_get(cursor, &key, &data, MDBX_SET_RANGE) != MDBX_SUCCESS)
+ mdbx_cursor_bind(m_txn_ro, m_curEventsSort, m_dbEventsSort);
+ if (mdbx_cursor_get(m_curEventsSort, &key, &data, MDBX_SET_RANGE) != MDBX_SUCCESS)
return cc->t_evLast = 0;
const DBEventSortingKey *pKey = (const DBEventSortingKey*)key.iov_base;
@@ -547,14 +547,14 @@ MEVENT CDbxMDBX::FindLastEvent(MCONTACT contactID) MDBX_val key = { &keyVal, sizeof(keyVal) }, data;
txn_ptr_ro txn(m_txn_ro);
- cursor_ptr_ro cursor(m_curEventsSort);
+ mdbx_cursor_bind(m_txn_ro, m_curEventsSort, m_dbEventsSort);
- if (mdbx_cursor_get(cursor, &key, &data, MDBX_SET_RANGE) != MDBX_SUCCESS) {
- if (mdbx_cursor_get(cursor, &key, &data, MDBX_LAST) != MDBX_SUCCESS)
+ 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)
return cc->t_evLast = 0;
}
else {
- if (mdbx_cursor_get(cursor, &key, &data, MDBX_PREV) != MDBX_SUCCESS)
+ if (mdbx_cursor_get(m_curEventsSort, &key, &data, MDBX_PREV) != MDBX_SUCCESS)
return cc->t_evLast = 0;
}
@@ -590,11 +590,11 @@ MEVENT CDbxMDBX::FindNextEvent(MCONTACT contactID, MEVENT hDbEvent) DBEventSortingKey keyVal = { contactID, hDbEvent, cc->t_tsLast };
MDBX_val key = { &keyVal, sizeof(keyVal) }, data;
- cursor_ptr_ro cursor(m_curEventsSort);
- if (mdbx_cursor_get(cursor, &key, nullptr, MDBX_SET) != MDBX_SUCCESS)
+ mdbx_cursor_bind(m_txn_ro, m_curEventsSort, m_dbEventsSort);
+ if (mdbx_cursor_get(m_curEventsSort, &key, nullptr, MDBX_SET) != MDBX_SUCCESS)
return cc->t_evLast = 0;
- if (mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT) != MDBX_SUCCESS)
+ if (mdbx_cursor_get(m_curEventsSort, &key, &data, MDBX_NEXT) != MDBX_SUCCESS)
return cc->t_evLast = 0;
const DBEventSortingKey *pKey = (const DBEventSortingKey*)key.iov_base;
@@ -631,11 +631,11 @@ MEVENT CDbxMDBX::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent) DBEventSortingKey keyVal = { contactID, hDbEvent, cc->t_tsLast };
MDBX_val key = { &keyVal, sizeof(keyVal) };
- cursor_ptr_ro cursor(m_curEventsSort);
- if (mdbx_cursor_get(cursor, &key, nullptr, MDBX_SET) != MDBX_SUCCESS)
+ mdbx_cursor_bind(m_txn_ro, m_curEventsSort, m_dbEventsSort);
+ if (mdbx_cursor_get(m_curEventsSort, &key, nullptr, MDBX_SET) != MDBX_SUCCESS)
return cc->t_evLast = 0;
- if (mdbx_cursor_get(cursor, &key, &data, MDBX_PREV) != MDBX_SUCCESS)
+ if (mdbx_cursor_get(m_curEventsSort, &key, &data, MDBX_PREV) != MDBX_SUCCESS)
return cc->t_evLast = 0;
const DBEventSortingKey *pKey = (const DBEventSortingKey*)key.iov_base;
@@ -679,20 +679,20 @@ public: DBEventSortingKey dbKey;
{
txn_ptr_ro txn(m_pOwner->m_txn_ro);
- cursor_ptr_ro cursor(m_pOwner->m_curEventsSort);
+ mdbx_cursor_bind(m_pOwner->m_txn_ro, m_pOwner->m_curEventsSort, m_pOwner->m_dbEventsSort);
if (m_bFirst) {
m_bFirst = false;
- if (mdbx_cursor_get(cursor, &key, &data, MDBX_SET_RANGE) != MDBX_SUCCESS)
+ 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(cursor, &key, &data, MDBX_SET) != MDBX_SUCCESS)
+ if (mdbx_cursor_get(m_pOwner->m_curEventsSort, &key, &data, MDBX_SET) != MDBX_SUCCESS)
return 0;
- if (mdbx_cursor_get(cursor, &key, &data, (m_bForward) ? MDBX_NEXT : MDBX_PREV) != MDBX_SUCCESS)
+ 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;
diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp index 7faf1328eb..d03d0ab498 100644 --- a/plugins/Dbx_mdbx/src/dbintf.cpp +++ b/plugins/Dbx_mdbx/src/dbintf.cpp @@ -36,6 +36,9 @@ CDbxMDBX::CDbxMDBX(const wchar_t *tszFileName, int iMode) : CDbxMDBX::~CDbxMDBX()
{
+ if (m_curEventsSort)
+ mdbx_cursor_close(m_curEventsSort);
+
mdbx_env_close(m_env);
if (!m_bReadOnly)
@@ -51,6 +54,93 @@ CDbxMDBX::~CDbxMDBX() /////////////////////////////////////////////////////////////////////////////////////////
+BOOL CDbxMDBX::Backup(const wchar_t *pwszPath)
+{
+ HANDLE pFile = ::CreateFile(pwszPath, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (pFile == nullptr) {
+ Netlib_Logf(0, "Backup file <%S> cannot be created", pwszPath);
+ return 1;
+ }
+
+ int res = mdbx_env_copy2fd(m_env, pFile, MDBX_CP_COMPACT);
+ if (res != MDBX_SUCCESS) {
+ Netlib_Logf(0, "CDbxMDBX::Backup: mdbx_env_copy2fd failed with error code %d", res);
+LBL_Fail:
+ CloseHandle(pFile);
+ DeleteFileW(pwszPath);
+ return res;
+ }
+
+ res = FlushFileBuffers(pFile);
+ if (res == 0) {
+ Netlib_Logf(0, "CDbxMDBX::Backup: FlushFileBuffers failed with error code %d", GetLastError());
+ goto LBL_Fail;
+ }
+
+ CloseHandle(pFile);
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+size_t iDefHeaderOffset = 0;
+BYTE bDefHeader[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+
+int CDbxMDBX::Check(void)
+{
+ FILE *pFile = _wfopen(m_pwszProfileName, L"rb");
+ if (pFile == nullptr)
+ return EGROKPRF_CANTREAD;
+
+ fseek(pFile, (LONG)iDefHeaderOffset, SEEK_SET);
+ BYTE buf[_countof(bDefHeader)];
+ size_t cbRead = fread(buf, 1, _countof(buf), pFile);
+ fclose(pFile);
+ if (cbRead != _countof(buf))
+ return EGROKPRF_DAMAGED;
+
+ return (memcmp(buf, bDefHeader, _countof(bDefHeader))) ? EGROKPRF_UNKHEADER : 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+BOOL CDbxMDBX::Compact()
+{
+ CMStringW wszTmpFile(FORMAT, L"%s.tmp", m_pwszProfileName.get());
+
+ mir_cslock lck(m_csDbAccess);
+ int res = Backup(wszTmpFile);
+ if (res)
+ return res;
+
+ mdbx_env_close(m_env);
+
+ DeleteFileW(m_pwszProfileName);
+ MoveFileW(wszTmpFile, m_pwszProfileName);
+
+ Map();
+ Load();
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void CDbxMDBX::DBFlush(bool bForce)
+{
+ if (bForce) {
+ mir_cslock lck(m_csDbAccess);
+
+ if (m_pWriteTran) {
+ mdbx_txn_commit(m_pWriteTran);
+ m_pWriteTran = nullptr;
+ }
+ }
+ else if (m_safetyMode)
+ m_impl.m_timer.Start(50);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
int CDbxMDBX::Load()
{
MDBX_db_flags_t defFlags = MDBX_CREATE;
@@ -64,7 +154,7 @@ int CDbxMDBX::Load() }
return EGROKPRF_DAMAGED;
}
-
+
mdbx_dbi_open(trnlck, "global", defFlags | MDBX_INTEGERKEY, &m_dbGlobal);
mdbx_dbi_open(trnlck, "crypto", defFlags, &m_dbCrypto);
mdbx_dbi_open(trnlck, "contacts", defFlags | MDBX_INTEGERKEY, &m_dbContacts);
@@ -102,18 +192,20 @@ int CDbxMDBX::Load() }
mdbx_txn_begin(m_env, nullptr, MDBX_TXN_RDONLY, &m_txn_ro);
- mdbx_cursor_open(m_txn_ro, m_dbEvents, &m_curEvents);
- mdbx_cursor_open(m_txn_ro, m_dbEventIds, &m_curEventIds);
- mdbx_cursor_open(m_txn_ro, m_dbEventsSort, &m_curEventsSort);
- mdbx_cursor_open(m_txn_ro, m_dbSettings, &m_curSettings);
- mdbx_cursor_open(m_txn_ro, m_dbModules, &m_curModules);
- mdbx_cursor_open(m_txn_ro, m_dbContacts, &m_curContacts);
+
+ m_curEventsSort = mdbx_cursor_create(nullptr);
MDBX_val key, val;
- if (mdbx_cursor_get(m_curEvents, &key, &val, MDBX_LAST) == MDBX_SUCCESS)
- m_dwMaxEventId = *(MEVENT*)key.iov_base;
- if (mdbx_cursor_get(m_curContacts, &key, &val, MDBX_LAST) == MDBX_SUCCESS)
- m_maxContactId = *(MCONTACT*)key.iov_base;
+ {
+ cursor_ptr pCursor(m_txn_ro, 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);
+ if (mdbx_cursor_get(pCursor, &key, &val, MDBX_LAST) == MDBX_SUCCESS)
+ m_maxContactId = *(MCONTACT *)key.iov_base;
+ }
mdbx_txn_reset(m_txn_ro);
@@ -127,71 +219,51 @@ int CDbxMDBX::Load() /////////////////////////////////////////////////////////////////////////////////////////
-size_t iDefHeaderOffset = 0;
-BYTE bDefHeader[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
-
-int CDbxMDBX::Check(void)
+static void assert_func(const MDBX_env*, const char *msg, const char *function, unsigned line) MDBX_CXX17_NOEXCEPT
{
- FILE *pFile = _wfopen(m_pwszProfileName, L"rb");
- if (pFile == nullptr)
- return EGROKPRF_CANTREAD;
-
- fseek(pFile, (LONG)iDefHeaderOffset, SEEK_SET);
- BYTE buf[_countof(bDefHeader)];
- size_t cbRead = fread(buf, 1, _countof(buf), pFile);
- fclose(pFile);
- if (cbRead != _countof(buf))
- return EGROKPRF_DAMAGED;
+ Netlib_Logf(nullptr, "MDBX: assertion failed (%s, %d): %s", function, line, msg);
- return (memcmp(buf, bDefHeader, _countof(bDefHeader))) ? EGROKPRF_UNKHEADER : 0;
+ #if defined(_DEBUG)
+ _wassert(_A2T(msg).get(), _A2T(function).get(), line);
+ #endif
}
-/////////////////////////////////////////////////////////////////////////////////////////
-
-BOOL CDbxMDBX::Compact()
+int CDbxMDBX::Map()
{
- CMStringW wszTmpFile(FORMAT, L"%s.tmp", m_pwszProfileName.get());
-
- mir_cslock lck(m_csDbAccess);
- int res = Backup(wszTmpFile);
- if (res)
- return res;
+ if (!LockName(m_pwszProfileName))
+ return EGROKPRF_CANTREAD;
- mdbx_env_close(m_env);
+ mdbx_env_create(&m_env);
+ mdbx_env_set_maxdbs(m_env, 10);
+ mdbx_env_set_userctx(m_env, this);
+ mdbx_env_set_assert(m_env, assert_func);
- DeleteFileW(m_pwszProfileName);
- MoveFileW(wszTmpFile, m_pwszProfileName);
+#ifdef _WIN64
+ mdbx_env_set_maxreaders(m_env, 1024);
+ __int64 upperLimit = 0x400000000ul;
+#else
+ mdbx_env_set_maxreaders(m_env, 244);
+ intptr_t upperLimit = 512ul << 20;
+#endif
- Map();
- Load();
- return 0;
-}
-
-BOOL CDbxMDBX::Backup(const wchar_t *pwszPath)
-{
- HANDLE pFile = ::CreateFile(pwszPath, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
- if (pFile == nullptr) {
- Netlib_Logf(0, "Backup file <%S> cannot be created", pwszPath);
- return 1;
- }
+ int rc = mdbx_env_set_geometry(m_env,
+ -1, // minimal lower limit
+ 1ul << 20, // at least 1M for now
+ upperLimit, // 512M upper size
+ 1ul << 20, // 1M growth step
+ 512ul << 10, // 512K shrink threshold
+ -1); // default page size
+ if (rc != MDBX_SUCCESS)
+ return EGROKPRF_CANTREAD;
- int res = mdbx_env_copy2fd(m_env, pFile, MDBX_CP_COMPACT);
- if (res != MDBX_SUCCESS) {
- Netlib_Logf(0, "CDbxMDBX::Backup: mdbx_env_copy2fd failed with error code %d", res);
-LBL_Fail:
- CloseHandle(pFile);
- DeleteFileW(pwszPath);
- return res;
- }
+ MDBX_env_flags_t mode = MDBX_NOSUBDIR | MDBX_MAPASYNC | MDBX_WRITEMAP | MDBX_SAFE_NOSYNC | MDBX_COALESCE | MDBX_EXCLUSIVE;
+ if (m_bReadOnly)
+ mode |= MDBX_RDONLY;
- res = FlushFileBuffers(pFile);
- if (res == 0) {
- Netlib_Logf(0, "CDbxMDBX::Backup: FlushFileBuffers failed with error code %d", GetLastError());
- goto LBL_Fail;
- }
+ if (mdbx_env_open(m_env, _T2A(m_pwszProfileName), mode, 0664) != MDBX_SUCCESS)
+ return EGROKPRF_CANTREAD;
- CloseHandle(pFile);
- return 0;
+ return EGROKPRF_NOERROR;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -212,51 +284,21 @@ void CDbxMDBX::SetCacheSafetyMode(BOOL bIsSet) /////////////////////////////////////////////////////////////////////////////////////////
-static void assert_func(const MDBX_env*, const char *msg, const char *function, unsigned line) MDBX_CXX17_NOEXCEPT
+MDBX_txn* CDbxMDBX::StartTran()
{
- Netlib_Logf(nullptr, "MDBX: assertion failed (%s, %d): %s", function, line, msg);
-
- #if defined(_DEBUG)
- _wassert(_A2T(msg), _A2T(function), line);
- #endif
-}
-
-int CDbxMDBX::Map()
-{
- if (!LockName(m_pwszProfileName))
- return EGROKPRF_CANTREAD;
-
- mdbx_env_create(&m_env);
- mdbx_env_set_maxdbs(m_env, 10);
- mdbx_env_set_userctx(m_env, this);
- mdbx_env_set_assert(m_env, assert_func);
-
- #ifdef _WIN64
- mdbx_env_set_maxreaders(m_env, 1024);
- __int64 upperLimit = 0x400000000ul;
- #else
- mdbx_env_set_maxreaders(m_env, 244);
- intptr_t upperLimit = 512ul << 20;
- #endif
-
- int rc = mdbx_env_set_geometry(m_env,
- -1, // minimal lower limit
- 1ul << 20, // at least 1M for now
- upperLimit, // 512M upper size
- 1ul << 20, // 1M growth step
- 512ul << 10, // 512K shrink threshold
- -1); // default page size
- if (rc != MDBX_SUCCESS)
- return EGROKPRF_CANTREAD;
+ /*
+ mir_cslock lck(m_csDbAccess);
- MDBX_env_flags_t mode = MDBX_NOSUBDIR | MDBX_MAPASYNC | MDBX_WRITEMAP | MDBX_SAFE_NOSYNC | MDBX_COALESCE | MDBX_EXCLUSIVE;
- if (m_bReadOnly)
- mode |= MDBX_RDONLY;
+ if (m_pWriteTran == nullptr) {
+ m_dbError = mdbx_txn_begin(m_env, nullptr, (m_bReadOnly) ? MDBX_TXN_RDONLY : MDBX_TXN_READWRITE, &m_pWriteTran);
+ // FIXME: throw an exception
+ _ASSERT(m_dbError == MDBX_SUCCESS);
+ }*/
- if (mdbx_env_open(m_env, _T2A(m_pwszProfileName), mode, 0664) != MDBX_SUCCESS)
- return EGROKPRF_CANTREAD;
-
- return EGROKPRF_NOERROR;
+ MDBX_txn *res = nullptr;
+ m_dbError = mdbx_txn_begin(m_env, m_pWriteTran, (m_bReadOnly) ? MDBX_TXN_RDONLY : MDBX_TXN_READWRITE, &res);
+ _ASSERT(m_dbError == MDBX_SUCCESS);
+ return res;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -276,17 +318,6 @@ void CDbxMDBX::TouchFile() }
}
-/////////////////////////////////////////////////////////////////////////////////////////
-
-void CDbxMDBX::DBFlush(bool bForce)
-{
- if (bForce)
- mdbx_env_sync(m_env);
-
- else if (m_safetyMode)
- m_impl.m_timer.Start(50);
-}
-
///////////////////////////////////////////////////////////////////////////////
// MIDatabaseChecker
diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h index f8c94750c1..5d6e35aa5c 100644 --- a/plugins/Dbx_mdbx/src/dbintf.h +++ b/plugins/Dbx_mdbx/src/dbintf.h @@ -159,14 +159,7 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe }
} m_impl;
- __forceinline MDBX_txn* StartTran()
- {
- MDBX_txn *res = 0;
- m_dbError = mdbx_txn_begin(m_env, nullptr, (m_bReadOnly) ? MDBX_TXN_RDONLY : MDBX_TXN_READWRITE, &res);
- /* FIXME: throw an exception */
- _ASSERT(m_dbError == MDBX_SUCCESS);
- return res;
- }
+ MDBX_txn* StartTran();
bool CheckEvent(DBCachedContact *cc, const DBEvent *dbe, DBCachedContact *&cc2);
bool EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO *dbe, bool bNew);
@@ -182,6 +175,7 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe bool m_safetyMode = true, m_bReadOnly, m_bEncrypted, m_bUsesPassword;
MDBX_env *m_env;
+ MDBX_txn *m_pWriteTran;
CMDBX_txn_ro m_txn_ro;
int m_dbError;
@@ -194,16 +188,12 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe // settings
MDBX_dbi m_dbSettings;
- MDBX_cursor *m_curSettings;
-
HANDLE hService[2], hHook;
////////////////////////////////////////////////////////////////////////////
// contacts
MDBX_dbi m_dbContacts;
- MDBX_cursor *m_curContacts;
-
MCONTACT m_maxContactId = 0;
void GatherContactHistory(MCONTACT hContact, OBJLIST<EventItem> &items);
@@ -212,7 +202,7 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe // events
MDBX_dbi m_dbEvents, m_dbEventsSort, m_dbEventIds;
- MDBX_cursor *m_curEvents, *m_curEventsSort, *m_curEventIds;
+ MDBX_cursor *m_curEventsSort;
MEVENT m_dwMaxEventId;
void FindNextUnread(const txn_ptr &_txn, DBCachedContact *cc, DBEventSortingKey &key2);
@@ -221,8 +211,6 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe // modules
MDBX_dbi m_dbModules;
- MDBX_cursor *m_curModules;
-
TModuleMap m_Modules;
int InitModules();
diff --git a/plugins/Dbx_mdbx/src/dbmodulechain.cpp b/plugins/Dbx_mdbx/src/dbmodulechain.cpp index 4799b1e6f9..fd41acd623 100644 --- a/plugins/Dbx_mdbx/src/dbmodulechain.cpp +++ b/plugins/Dbx_mdbx/src/dbmodulechain.cpp @@ -26,10 +26,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. int CDbxMDBX::InitModules()
{
txn_ptr_ro trnlck(m_txn_ro);
- cursor_ptr_ro cursor(m_curModules);
-
+ cursor_ptr pCursor(m_txn_ro, m_dbModules);
+
MDBX_val key, data;
- while (mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS) {
+ while (mdbx_cursor_get(pCursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS) {
uint32_t iMod = *(uint32_t*)key.iov_base;
const char *szMod = (const char*)data.iov_base;
m_Modules[iMod] = szMod;
diff --git a/plugins/Dbx_mdbx/src/dbsettings.cpp b/plugins/Dbx_mdbx/src/dbsettings.cpp index 0387b69ad6..9d1f32fc5d 100644 --- a/plugins/Dbx_mdbx/src/dbsettings.cpp +++ b/plugins/Dbx_mdbx/src/dbsettings.cpp @@ -399,13 +399,13 @@ BOOL CDbxMDBX::EnumContactSettings(MCONTACT hContact, DBSETTINGENUMPROC pfnEnumP {
LIST<char> arKeys(100);
{
- DBSettingKey keyVal = { hContact, GetModuleID(szModule), 0 };
txn_ptr_ro txn(m_txn_ro);
- cursor_ptr_ro cursor(m_curSettings);
+ cursor_ptr pCursor(m_txn_ro, m_dbSettings);
+ DBSettingKey keyVal = { hContact, GetModuleID(szModule), 0 };
MDBX_val key = { &keyVal, sizeof(keyVal) }, data;
- for (int res = mdbx_cursor_get(cursor, &key, &data, MDBX_SET_RANGE); res == MDBX_SUCCESS; res = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) {
+ 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;
if (pKey->hContact != hContact || pKey->dwModuleId != keyVal.dwModuleId)
break;
diff --git a/plugins/Dbx_mdbx/src/stdafx.h b/plugins/Dbx_mdbx/src/stdafx.h index a8918e9b80..0dcad889ed 100644 --- a/plugins/Dbx_mdbx/src/stdafx.h +++ b/plugins/Dbx_mdbx/src/stdafx.h @@ -139,20 +139,6 @@ public: __forceinline operator MDBX_cursor*() const { return m_cursor; }
};
-class cursor_ptr_ro
-{
- MDBX_cursor *m_cursor;
-public:
- __forceinline cursor_ptr_ro(MDBX_cursor *cursor) : m_cursor(cursor)
- {
- int rc = mdbx_cursor_renew(mdbx_cursor_txn(m_cursor), m_cursor);
- /* FIXME: throw an exception */
- _ASSERT(rc == MDBX_SUCCESS);
- UNREFERENCED_PARAMETER(rc);
- }
- __forceinline operator MDBX_cursor*() const { return m_cursor; }
-};
-
#include "dbintf.h"
#include "resource.h"
#include "version.h"
|