diff options
author | Ali Akhtarzada <ali.akhtarzada@nokia.com> | 2012-03-20 12:44:27 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-20 15:16:54 +0100 |
commit | 263a7df1c0fd228fe0455387dcd80ac66f1f859b (patch) | |
tree | 49dff61cb5bb953038f4b609bb611430007cd80b | |
parent | ef73d3ebe74c3b4b4121c2a48c62f14c13d18a08 (diff) |
Fixed hbtree cache and got rid of extra sync read
The LRU queue should be updated in getPage, not in cacheFind.
Change-Id: I75f2f4e64a7c6687a7760239490ab7121af50945
Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
-rw-r--r-- | src/hbtree/hbtree.cpp | 23 | ||||
-rw-r--r-- | src/hbtree/hbtree_p.h | 1 | ||||
-rw-r--r-- | tests/auto/hbtree/main.cpp | 1 |
3 files changed, 12 insertions, 13 deletions
diff --git a/src/hbtree/hbtree.cpp b/src/hbtree/hbtree.cpp index 78e9e60..1123dbe 100644 --- a/src/hbtree/hbtree.cpp +++ b/src/hbtree/hbtree.cpp @@ -146,6 +146,7 @@ bool HBtreePrivate::open(int fd) } marker_ = synced0; + synced_ = synced0; lastSyncedId_ = 0; size_ = initSize; @@ -165,6 +166,8 @@ bool HBtreePrivate::open(int fd) return false; } + synced_ = marker_; + if (openMode_ == HBtree::ReadWrite) { off_t currentSize = lseek(fd_, 0, SEEK_END); if (static_cast<off_t>(marker_.meta.size) < currentSize) { @@ -751,13 +754,9 @@ bool HBtreePrivate::sync() MarkerPage synced0(1); MarkerPage synced1(2); - if (!readMarker(1, &synced0)) { - HBTREE_ERROR("failed to read sync marker"); - return false; - } - copy(synced0, &synced1); copy(marker_, &synced0); + copy(marker_, &synced1); if (fsync(fd_) != 0) { HBTREE_ERROR("failed to sync data"); @@ -770,9 +769,9 @@ bool HBtreePrivate::sync() } // Add previous synced marker overflow pages to collectible list - if (synced1.meta.flags & MarkerPage::DataOnOverflow) { + if (synced_.meta.flags & MarkerPage::DataOnOverflow) { QList<quint32> pages; - if (!getOverflowPageNumbers(synced1.overflowPage, &pages)) { + if (!getOverflowPageNumbers(synced_.overflowPage, &pages)) { HBTREE_DEBUG("failed to get overflow pages for" << synced0); return false; } @@ -781,8 +780,9 @@ bool HBtreePrivate::sync() } lastSyncedId_++; + + copy(synced0, &synced_); copy(synced0, &marker_); - copy(synced0, &synced1); // Collect residue pages collectiblePages_.unite(marker_.residueHistory); @@ -1386,11 +1386,8 @@ quint16 HBtreePrivate::collectHistory(NodePage *page) HBtreePrivate::Page *HBtreePrivate::cacheFind(quint32 pgno) const { PageMap::const_iterator it = cache_.find(pgno); - if (it != cache_.constEnd()) { - const_cast<HBtreePrivate *>(this)->lru_.removeOne(it.value()); - const_cast<HBtreePrivate *>(this)->lru_.append(it.value()); + if (it != cache_.constEnd()) return it.value(); - } return 0; } @@ -1634,6 +1631,8 @@ HBtreePrivate::Page *HBtreePrivate::getPage(quint32 pageNumber, bool insertInCac Q_Q(HBtree); q->stats_.hits++; HBTREE_DEBUG("got" << page->info << "from cache"); + lru_.removeOne(page); + lru_.append(page); return page; } } diff --git a/src/hbtree/hbtree_p.h b/src/hbtree/hbtree_p.h index 74a8496..f637c4c 100644 --- a/src/hbtree/hbtree_p.h +++ b/src/hbtree/hbtree_p.h @@ -384,6 +384,7 @@ public: typedef QMap<quint32, Page *> PageMap; Spec spec_; MarkerPage marker_; + MarkerPage synced_; PageMap dirtyPages_; HBtree::CompareFunction compareFunction_; HBtreeTransaction *writeTransaction_; diff --git a/tests/auto/hbtree/main.cpp b/tests/auto/hbtree/main.cpp index 2fb9e0e..7037b1b 100644 --- a/tests/auto/hbtree/main.cpp +++ b/tests/auto/hbtree/main.cpp @@ -934,7 +934,6 @@ void TestHBtree::prev2() QByteArray data = QUuid::createUuid().toRfc4122(); HBtreeTransaction *txn = db->beginTransaction(HBtreeTransaction::ReadWrite); QVERIFY(txn); -// qDebug() << i; QVERIFY(txn->put(data, QByteArray("value_")+QByteArray::number(i))); txn->commit(0); int size = file.size(); |