summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-02-04 18:38:40 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-02-04 18:38:40 +0300
commit3c8113e543388f8c29fdc4e5b311d60a8a0a8302 (patch)
tree1377f71b3eb6ea3e3957b4c5205348d0329e8a86 /plugins
parent32cd89f64ef0449eac0ceea2ba9bc1aa36c5759b (diff)
checker for MDBX, first version
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Dbx_mdbx/src/dbevents.cpp56
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.cpp15
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.h6
-rw-r--r--plugins/Dbx_mdbx/src/dbmodulechain.cpp5
-rw-r--r--plugins/Dbx_mdbx/src/init.cpp5
5 files changed, 77 insertions, 10 deletions
diff --git a/plugins/Dbx_mdbx/src/dbevents.cpp b/plugins/Dbx_mdbx/src/dbevents.cpp
index 71a9a44353..711dd58598 100644
--- a/plugins/Dbx_mdbx/src/dbevents.cpp
+++ b/plugins/Dbx_mdbx/src/dbevents.cpp
@@ -29,6 +29,8 @@ STDMETHODIMP_(LONG) CDbxMDBX::GetEventCount(MCONTACT contactID)
return (cc == nullptr) ? 0 : cc->dbc.dwEventCount;
}
+///////////////////////////////////////////////////////////////////////////////
+
STDMETHODIMP_(MEVENT) CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
{
if (dbei == nullptr) return 0;
@@ -125,6 +127,8 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
return dwEventId;
}
+///////////////////////////////////////////////////////////////////////////////
+
STDMETHODIMP_(BOOL) CDbxMDBX::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent)
{
DBCachedContact *cc = m_cache->GetCachedContact(contactID), *cc2 = nullptr;
@@ -190,6 +194,8 @@ STDMETHODIMP_(BOOL) CDbxMDBX::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent)
return 0;
}
+///////////////////////////////////////////////////////////////////////////////
+
STDMETHODIMP_(LONG) CDbxMDBX::GetBlobSize(MEVENT hDbEvent)
{
txn_ptr_ro txn(m_txn_ro);
@@ -200,6 +206,8 @@ STDMETHODIMP_(LONG) CDbxMDBX::GetBlobSize(MEVENT hDbEvent)
return ((const DBEvent*)data.iov_base)->cbBlob;
}
+///////////////////////////////////////////////////////////////////////////////
+
STDMETHODIMP_(BOOL) CDbxMDBX::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
{
if (dbei == nullptr) return 1;
@@ -244,6 +252,8 @@ STDMETHODIMP_(BOOL) CDbxMDBX::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
return 0;
}
+///////////////////////////////////////////////////////////////////////////////
+
void CDbxMDBX::FindNextUnread(const txn_ptr &txn, DBCachedContact *cc, DBEventSortingKey &key2)
{
cursor_ptr cursor(txn, m_dbEventsSort);
@@ -264,6 +274,8 @@ void CDbxMDBX::FindNextUnread(const txn_ptr &txn, DBCachedContact *cc, DBEventSo
cc->dbc.evFirstUnread = cc->dbc.tsFirstUnread = 0;
}
+///////////////////////////////////////////////////////////////////////////////
+
STDMETHODIMP_(BOOL) CDbxMDBX::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent)
{
if (hDbEvent == 0) return -1;
@@ -306,6 +318,8 @@ STDMETHODIMP_(BOOL) CDbxMDBX::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent)
return wRetVal;
}
+///////////////////////////////////////////////////////////////////////////////
+
STDMETHODIMP_(MCONTACT) CDbxMDBX::GetEventContact(MEVENT hDbEvent)
{
if (hDbEvent == 0)
@@ -320,6 +334,8 @@ STDMETHODIMP_(MCONTACT) CDbxMDBX::GetEventContact(MEVENT hDbEvent)
return ((const DBEvent*)data.iov_base)->contactID;
}
+///////////////////////////////////////////////////////////////////////////////
+
thread_local uint64_t t_tsLast = 0;
thread_local MEVENT t_evLast = 0;
@@ -339,12 +355,16 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::FindFirstEvent(MCONTACT contactID)
return t_evLast = (pKey->hContact == contactID) ? pKey->hEvent : 0;
}
+///////////////////////////////////////////////////////////////////////////////
+
STDMETHODIMP_(MEVENT) CDbxMDBX::FindFirstUnreadEvent(MCONTACT contactID)
{
DBCachedContact *cc = m_cache->GetCachedContact(contactID);
return (cc == nullptr) ? 0 : cc->dbc.evFirstUnread;
}
+///////////////////////////////////////////////////////////////////////////////
+
STDMETHODIMP_(MEVENT) CDbxMDBX::FindLastEvent(MCONTACT contactID)
{
DBEventSortingKey keyVal = { contactID, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF };
@@ -367,6 +387,8 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::FindLastEvent(MCONTACT contactID)
return t_evLast = (pKey->hContact == contactID) ? pKey->hEvent : 0;
}
+///////////////////////////////////////////////////////////////////////////////
+
STDMETHODIMP_(MEVENT) CDbxMDBX::FindNextEvent(MCONTACT contactID, MEVENT hDbEvent)
{
if (hDbEvent == 0)
@@ -396,6 +418,8 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::FindNextEvent(MCONTACT contactID, MEVENT hDbEven
return t_evLast = (pKey->hContact == contactID) ? pKey->hEvent : 0;
}
+///////////////////////////////////////////////////////////////////////////////
+
STDMETHODIMP_(MEVENT) CDbxMDBX::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent)
{
if (hDbEvent == 0)
@@ -426,3 +450,35 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::FindPrevEvent(MCONTACT contactID, MEVENT hDbEven
t_tsLast = pKey->ts;
return t_evLast = (pKey->hContact == contactID) ? pKey->hEvent : 0;
}
+
+///////////////////////////////////////////////////////////////////////////////
+// checker
+
+int CDbxMDBX::CheckEvents1()
+{
+/* txn_ptr_ro trnlck(m_txn_ro);
+ cursor_ptr_ro cursor(m_curEvents);
+
+ uint32_t eventID = 0;
+ MDBX_val key = { &eventID, sizeof(eventID) }, data;
+
+ while (mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS) {
+ const DBEvent *dbe = (const DBEvent*)data.iov_base;
+
+ DBEventSortingKey lookupkey = { dbe->contactID, eventID, dbe->timestamp };
+ MDBX_val key2 = { &lookupkey, sizeof(lookupkey) }, data2;
+ if (!mdbx_get(m_txn_ro, m_dbEventsSort, &key, nullptr))
+ continue;
+
+ txn_ptr txn(m_env);
+ if (mdbx_del(txn, m_dbEvents, &key, nullptr) == MDBX_SUCCESS)
+ txn.commit();
+ }
+ */
+ return ERROR_NO_MORE_ITEMS;
+}
+
+int CDbxMDBX::CheckEvents2()
+{
+ return ERROR_NO_MORE_ITEMS;
+}
diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp
index 679141dc79..93d6a7db09 100644
--- a/plugins/Dbx_mdbx/src/dbintf.cpp
+++ b/plugins/Dbx_mdbx/src/dbintf.cpp
@@ -201,7 +201,7 @@ int CDbxMDBX::Map()
///////////////////////////////////////////////////////////////////////////////
// MIDatabaseChecker
-typedef int (CDbxMDBX::*CheckWorker)(int);
+typedef int (CDbxMDBX::*CheckWorker)(void);
int CDbxMDBX::Start(DBCHeckCallback *callback)
{
@@ -209,9 +209,18 @@ int CDbxMDBX::Start(DBCHeckCallback *callback)
return ERROR_SUCCESS;
}
-int CDbxMDBX::CheckDb(int, int)
+static CheckWorker Workers[6] =
{
- return ERROR_OUT_OF_PAPER;
+ &CDbxMDBX::CheckEvents1,
+ &CDbxMDBX::CheckEvents2,
+};
+
+int CDbxMDBX::CheckDb(int phase, int)
+{
+ if (phase >= _countof(Workers))
+ return ERROR_OUT_OF_PAPER;
+
+ return (this->*Workers[phase])();
}
void CDbxMDBX::Destroy()
diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h
index a68e8ab4bc..bbab8b2d1e 100644
--- a/plugins/Dbx_mdbx/src/dbintf.h
+++ b/plugins/Dbx_mdbx/src/dbintf.h
@@ -199,6 +199,12 @@ protected:
public:
MICryptoEngine *m_crypto;
+ ////////////////////////////////////////////////////////////////////////////
+ // checker
+
+ int CheckEvents1();
+ int CheckEvents2();
+
protected:
MDBX_env *m_env;
CMDBX_txn_ro m_txn_ro;
diff --git a/plugins/Dbx_mdbx/src/dbmodulechain.cpp b/plugins/Dbx_mdbx/src/dbmodulechain.cpp
index aa2427348a..e25c85a0b3 100644
--- a/plugins/Dbx_mdbx/src/dbmodulechain.cpp
+++ b/plugins/Dbx_mdbx/src/dbmodulechain.cpp
@@ -27,8 +27,9 @@ int CDbxMDBX::InitModules()
{
txn_ptr_ro trnlck(m_txn_ro);
cursor_ptr_ro cursor(m_curModules);
-
- MDBX_val key, data;
+
+ uint32_t iHash = 0;
+ MDBX_val key = { &iHash, sizeof(iHash) }, data;
while (mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS) {
uint32_t iMod = *(uint32_t*)key.iov_base;
const char *szMod = (const char*)data.iov_base;
diff --git a/plugins/Dbx_mdbx/src/init.cpp b/plugins/Dbx_mdbx/src/init.cpp
index 75b5585924..bfb04f23ae 100644
--- a/plugins/Dbx_mdbx/src/init.cpp
+++ b/plugins/Dbx_mdbx/src/init.cpp
@@ -90,11 +90,6 @@ MIDatabaseChecker* CheckDb(const TCHAR *profile, int *error)
return nullptr;
}
- if (db->PrepareCheck()) {
- *error = ERROR_BAD_FORMAT;
- return nullptr;
- }
-
return db.release();
}