diff options
author | George Hazan <ghazan@miranda.im> | 2018-04-12 20:55:18 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-04-12 20:55:18 +0300 |
commit | cdf4c110510a39c162b469ecbd6f69571019cf69 (patch) | |
tree | f7e47d684c94d877a141fc64ade0ca471aa1fce1 /plugins/Dbx_mdbx | |
parent | 376f5d4859ba96bff4a3c4d7c9622664b9e578d7 (diff) |
initial version of profile compactor for MDBX
Diffstat (limited to 'plugins/Dbx_mdbx')
-rw-r--r-- | plugins/Dbx_mdbx/src/dbintf.cpp | 33 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbintf.h | 2 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/init.cpp | 2 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/stdafx.h | 1 |
4 files changed, 37 insertions, 1 deletions
diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp index 230a01920e..2c3f8907b8 100644 --- a/plugins/Dbx_mdbx/src/dbintf.cpp +++ b/plugins/Dbx_mdbx/src/dbintf.cpp @@ -167,6 +167,39 @@ int CDbxMDBX::Check(void) return (memcmp(buf, bDefHeader, _countof(bDefHeader))) ? EGROKPRF_UNKHEADER : 0;
}
+BOOL CDbxMDBX::Compact()
+{
+ CMStringW wszTmpFile(FORMAT, L"%s.tmp", m_tszProfileName);
+
+ HANDLE pFile = ::CreateFile(wszTmpFile, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (pFile == nullptr) {
+ Netlib_Logf(0, "Temporary file <%S> cannot be created", wszTmpFile.c_str());
+ return 1;
+ }
+
+ mir_cslock lck(m_csDbAccess);
+ int res = mdbx_env_copy2fd(m_env, pFile, MDBX_CP_COMPACT);
+ CloseHandle(pFile);
+
+ if (res == MDBX_SUCCESS) {
+ mdbx_env_close(m_env);
+
+ DeleteFileW(m_tszProfileName);
+ MoveFileW(wszTmpFile, m_tszProfileName);
+
+ mdbx_env_create(&m_env);
+ mdbx_env_set_maxdbs(m_env, 10);
+ mdbx_env_set_maxreaders(m_env, 244);
+ mdbx_env_set_userctx(m_env, this);
+
+ Map();
+ Load();
+ }
+ else DeleteFileW(wszTmpFile);
+
+ return 0;
+}
+
int CDbxMDBX::PrepareCheck()
{
InitModules();
diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h index 0b616916ed..6d998f7d77 100644 --- a/plugins/Dbx_mdbx/src/dbintf.h +++ b/plugins/Dbx_mdbx/src/dbintf.h @@ -267,6 +267,8 @@ public: STDMETHODIMP_(BOOL) MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub);
STDMETHODIMP_(BOOL) MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub);
+ STDMETHODIMP_(BOOL) Compact();
+
public:
MICryptoEngine *m_crypto;
};
diff --git a/plugins/Dbx_mdbx/src/init.cpp b/plugins/Dbx_mdbx/src/init.cpp index 6efe170cb5..2500cd30ad 100644 --- a/plugins/Dbx_mdbx/src/init.cpp +++ b/plugins/Dbx_mdbx/src/init.cpp @@ -93,7 +93,7 @@ static MDatabaseCommon* loadDatabase(const TCHAR *profile, BOOL bReadOnly) static DATABASELINK dblink =
{
- sizeof(DATABASELINK),
+ MDB_CAPS_COMPACT,
"dbx_mdbx",
L"MDBX database driver",
makeDatabase,
diff --git a/plugins/Dbx_mdbx/src/stdafx.h b/plugins/Dbx_mdbx/src/stdafx.h index 243756e39a..5e00445dba 100644 --- a/plugins/Dbx_mdbx/src/stdafx.h +++ b/plugins/Dbx_mdbx/src/stdafx.h @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #pragma once
#include <windows.h>
+#include <io.h>
#include <time.h>
#include <process.h>
|