summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-04-12 20:55:18 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-04-12 20:55:18 +0300
commitcdf4c110510a39c162b469ecbd6f69571019cf69 (patch)
treef7e47d684c94d877a141fc64ade0ca471aa1fce1 /plugins
parent376f5d4859ba96bff4a3c4d7c9622664b9e578d7 (diff)
initial version of profile compactor for MDBX
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Db3x_mmap/src/init.cpp2
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.cpp33
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.h2
-rw-r--r--plugins/Dbx_mdbx/src/init.cpp2
-rw-r--r--plugins/Dbx_mdbx/src/stdafx.h1
-rw-r--r--plugins/Import/src/dbrw/dbrw.cpp2
6 files changed, 39 insertions, 3 deletions
diff --git a/plugins/Db3x_mmap/src/init.cpp b/plugins/Db3x_mmap/src/init.cpp
index aea65a0ddf..587b79253b 100644
--- a/plugins/Db3x_mmap/src/init.cpp
+++ b/plugins/Db3x_mmap/src/init.cpp
@@ -121,7 +121,7 @@ LBL_Error:
static DATABASELINK dblink =
{
- sizeof(DATABASELINK),
+ 0,
"dbx_mmap",
L"dbx mmap driver",
makeDatabase,
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>
diff --git a/plugins/Import/src/dbrw/dbrw.cpp b/plugins/Import/src/dbrw/dbrw.cpp
index b5ed672bdb..00bf079c05 100644
--- a/plugins/Import/src/dbrw/dbrw.cpp
+++ b/plugins/Import/src/dbrw/dbrw.cpp
@@ -86,7 +86,7 @@ static MDatabaseCommon* dbrw_Load(const wchar_t *profile, BOOL)
static DATABASELINK dblink =
{
- sizeof(DATABASELINK),
+ 0,
"dbrw",
L"dbx SQLite driver",
dbrw_makeDatabase,