summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdbx/src/dbcheck.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Dbx_mdbx/src/dbcheck.cpp')
-rw-r--r--plugins/Dbx_mdbx/src/dbcheck.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/plugins/Dbx_mdbx/src/dbcheck.cpp b/plugins/Dbx_mdbx/src/dbcheck.cpp
index e636e196c4..f32469c6c4 100644
--- a/plugins/Dbx_mdbx/src/dbcheck.cpp
+++ b/plugins/Dbx_mdbx/src/dbcheck.cpp
@@ -23,7 +23,57 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
+/////////////////////////////////////////////////////////////////////////////////////////
+// we are tracing EventsSort table to verify that they have correct event ids
+
int CDbxMDBX::CheckEvents1(void)
{
+ txn_ptr trnlck(StartTran());
+ cursor_ptr cursor(trnlck, m_dbEventsSort);
+
+ MDBX_val key, data;
+ for (int ret = mdbx_cursor_get(cursor, &key, &data, MDBX_FIRST); ret == MDBX_SUCCESS; ret = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) {
+ auto *pData = (DBEventSortingKey *)key.iov_base;
+
+ // if that's not a member of system event, check contact's existence first
+ if (pData->hContact != 0) {
+ auto *cc = m_cache->GetCachedContact(pData->hContact);
+ if (cc == nullptr) {
+ mdbx_cursor_del(cursor, 0);
+ cb->pfnAddLogMessage(STATUS_ERROR, CMStringW(FORMAT, TranslateT("Orphaned sorting event with wrong contact ID %d, deleting"), pData->hContact));
+ continue;
+ }
+ }
+
+ if (GetBlobSize(pData->hEvent) == -1) {
+ mdbx_cursor_del(cursor, 0);
+ cb->pfnAddLogMessage(STATUS_ERROR, CMStringW(FORMAT, TranslateT("Orphaned sorting event with wrong event ID %d:%08X, deleting"), pData->hContact, pData->hEvent));
+ continue;
+ }
+ }
+
+ trnlck.commit();
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// we are tracing EventId tables to verify that they have correct event ids
+
+int CDbxMDBX::CheckEvents2(void)
+{
+ txn_ptr trnlck(StartTran());
+ cursor_ptr cursor(trnlck, m_dbEventIds);
+
+ MDBX_val key, data;
+ for (int ret = mdbx_cursor_get(cursor, &key, &data, MDBX_FIRST); ret == MDBX_SUCCESS; ret = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) {
+ MEVENT hDbEvent = *(MEVENT *)data.iov_base;
+ if (GetBlobSize(hDbEvent) == -1) {
+ mdbx_cursor_del(cursor, 0);
+ cb->pfnAddLogMessage(STATUS_ERROR, CMStringW(FORMAT, TranslateT("Orphaned event id with wrong event ID %08X, deleting"), hDbEvent));
+ continue;
+ }
+ }
+
+ trnlck.commit();
return 0;
}