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/src/dbintf.cpp | |
parent | 376f5d4859ba96bff4a3c4d7c9622664b9e578d7 (diff) |
initial version of profile compactor for MDBX
Diffstat (limited to 'plugins/Dbx_mdbx/src/dbintf.cpp')
-rw-r--r-- | plugins/Dbx_mdbx/src/dbintf.cpp | 33 |
1 files changed, 33 insertions, 0 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();
|