diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-11-21 15:28:33 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-11-21 16:24:32 +0100 |
commit | 0aa5b2187dcd7d8c91900dd5cb017481941bfc0f (patch) | |
tree | 4f9440f172b0945381fc3b3c46c45638be1108f1 /common | |
parent | 0d15b4eb0e4ca32072e0e34ea8ffca313de247be (diff) | |
download | sink-0aa5b2187dcd7d8c91900dd5cb017481941bfc0f.tar.gz sink-0aa5b2187dcd7d8c91900dd5cb017481941bfc0f.zip |
Storage debugging code
Diffstat (limited to 'common')
-rw-r--r-- | common/storage.h | 19 | ||||
-rw-r--r-- | common/storage_lmdb.cpp | 81 |
2 files changed, 97 insertions, 3 deletions
diff --git a/common/storage.h b/common/storage.h index c39b904..1967a5e 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -123,6 +123,16 @@ public: | |||
123 | 123 | ||
124 | qint64 getSize(); | 124 | qint64 getSize(); |
125 | 125 | ||
126 | struct Stat { | ||
127 | size_t branchPages; | ||
128 | size_t leafPages; | ||
129 | size_t overflowPages; | ||
130 | size_t numEntries; | ||
131 | }; | ||
132 | Stat stat(); | ||
133 | |||
134 | bool allowsDuplicates() const; | ||
135 | |||
126 | private: | 136 | private: |
127 | friend Transaction; | 137 | friend Transaction; |
128 | NamedDatabase(NamedDatabase &other); | 138 | NamedDatabase(NamedDatabase &other); |
@@ -150,6 +160,15 @@ public: | |||
150 | 160 | ||
151 | operator bool() const; | 161 | operator bool() const; |
152 | 162 | ||
163 | struct Stat { | ||
164 | size_t totalPages; | ||
165 | size_t freePages; | ||
166 | size_t pageSize; | ||
167 | NamedDatabase::Stat mainDbStat; | ||
168 | NamedDatabase::Stat freeDbStat; | ||
169 | }; | ||
170 | Stat stat(); | ||
171 | |||
153 | private: | 172 | private: |
154 | Transaction(Transaction &other); | 173 | Transaction(Transaction &other); |
155 | Transaction &operator=(Transaction &other); | 174 | Transaction &operator=(Transaction &other); |
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 2745a14..392ac0a 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -496,13 +496,39 @@ qint64 DataStore::NamedDatabase::getSize() | |||
496 | if (rc) { | 496 | if (rc) { |
497 | SinkWarning() << "Something went wrong " << QByteArray(mdb_strerror(rc)); | 497 | SinkWarning() << "Something went wrong " << QByteArray(mdb_strerror(rc)); |
498 | } | 498 | } |
499 | // std::cout << "overflow_pages: " << stat.ms_overflow_pages << std::endl; | 499 | return stat.ms_psize * (stat.ms_leaf_pages + stat.ms_branch_pages + stat.ms_overflow_pages); |
500 | } | ||
501 | |||
502 | DataStore::NamedDatabase::Stat DataStore::NamedDatabase::stat() | ||
503 | { | ||
504 | if (!d || !d->transaction) { | ||
505 | return {}; | ||
506 | } | ||
507 | |||
508 | int rc; | ||
509 | MDB_stat stat; | ||
510 | rc = mdb_stat(d->transaction, d->dbi, &stat); | ||
511 | if (rc) { | ||
512 | SinkWarning() << "Something went wrong " << QByteArray(mdb_strerror(rc)); | ||
513 | return {}; | ||
514 | } | ||
515 | return {stat.ms_branch_pages, | ||
516 | stat.ms_leaf_pages, | ||
517 | stat.ms_overflow_pages, | ||
518 | stat.ms_entries}; | ||
500 | // std::cout << "page size: " << stat.ms_psize << std::endl; | 519 | // std::cout << "page size: " << stat.ms_psize << std::endl; |
501 | // std::cout << "branch_pages: " << stat.ms_branch_pages << std::endl; | ||
502 | // std::cout << "leaf_pages: " << stat.ms_leaf_pages << std::endl; | 520 | // std::cout << "leaf_pages: " << stat.ms_leaf_pages << std::endl; |
521 | // std::cout << "branch_pages: " << stat.ms_branch_pages << std::endl; | ||
522 | // std::cout << "overflow_pages: " << stat.ms_overflow_pages << std::endl; | ||
503 | // std::cout << "depth: " << stat.ms_depth << std::endl; | 523 | // std::cout << "depth: " << stat.ms_depth << std::endl; |
504 | // std::cout << "entries: " << stat.ms_entries << std::endl; | 524 | // std::cout << "entries: " << stat.ms_entries << std::endl; |
505 | return stat.ms_psize * (stat.ms_leaf_pages + stat.ms_branch_pages + stat.ms_overflow_pages); | 525 | } |
526 | |||
527 | bool DataStore::NamedDatabase::allowsDuplicates() const | ||
528 | { | ||
529 | unsigned int flags; | ||
530 | mdb_dbi_flags(d->transaction, d->dbi, &flags); | ||
531 | return flags & MDB_DUPSORT; | ||
506 | } | 532 | } |
507 | 533 | ||
508 | 534 | ||
@@ -708,6 +734,55 @@ QList<QByteArray> DataStore::Transaction::getDatabaseNames() const | |||
708 | } | 734 | } |
709 | 735 | ||
710 | 736 | ||
737 | DataStore::Transaction::Stat DataStore::Transaction::stat() | ||
738 | { | ||
739 | const int freeDbi = 0; | ||
740 | const int mainDbi = 1; | ||
741 | |||
742 | MDB_envinfo mei; | ||
743 | mdb_env_info(d->env, &mei); | ||
744 | |||
745 | MDB_stat mst; | ||
746 | mdb_stat(d->transaction, freeDbi, &mst); | ||
747 | auto freeStat = NamedDatabase::Stat{mst.ms_branch_pages, | ||
748 | mst.ms_leaf_pages, | ||
749 | mst.ms_overflow_pages, | ||
750 | mst.ms_entries}; | ||
751 | |||
752 | mdb_stat(d->transaction, mainDbi, &mst); | ||
753 | auto mainStat = NamedDatabase::Stat{mst.ms_branch_pages, | ||
754 | mst.ms_leaf_pages, | ||
755 | mst.ms_overflow_pages, | ||
756 | mst.ms_entries}; | ||
757 | |||
758 | MDB_cursor *cursor; | ||
759 | MDB_val key, data; | ||
760 | size_t freePages = 0, *iptr; | ||
761 | |||
762 | int rc = mdb_cursor_open(d->transaction, freeDbi, &cursor); | ||
763 | if (rc) { | ||
764 | fprintf(stderr, "mdb_cursor_open failed, error %d %s\n", rc, mdb_strerror(rc)); | ||
765 | return {}; | ||
766 | } | ||
767 | |||
768 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { | ||
769 | iptr = static_cast<size_t*>(data.mv_data); | ||
770 | freePages += *iptr; | ||
771 | size_t pg, prev; | ||
772 | ssize_t i, j, span = 0; | ||
773 | j = *iptr++; | ||
774 | for (i = j, prev = 1; --i >= 0; ) { | ||
775 | pg = iptr[i]; | ||
776 | prev = pg; | ||
777 | pg += span; | ||
778 | for (; i >= span && iptr[i-span] == pg; span++, pg++) ; | ||
779 | } | ||
780 | } | ||
781 | mdb_cursor_close(cursor); | ||
782 | return {mei.me_last_pgno + 1, freePages, mst.ms_psize, mainStat, freeStat}; | ||
783 | } | ||
784 | |||
785 | |||
711 | class DataStore::Private | 786 | class DataStore::Private |
712 | { | 787 | { |
713 | public: | 788 | public: |