diff options
author | Carlos Manuel Duclos Vergara <carlos.duclos@nokia.com> | 2012-05-10 12:56:41 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-11 10:25:35 +0200 |
commit | f27b4a598755e4359ff202bb698ea38a3740e78b (patch) | |
tree | e173950c2caafc95e9967e936c52e1256c9962e3 | |
parent | 829bd1fb2df20c6785a2554c4eb4b44304093a86 (diff) |
Adding error report to HBTree.
After a pwrite failure, I copy the errno value. It can then be queried
via JsonDbBtree::lastWriteError().
After a pread failure I do the same and the result can be queried via
JsonDbBtree::lastReadError().
I haven't modified AOB since I'm not familiar with it.
Change-Id: I76b6e7b4bbc2dd621eb716107a4e7a0aff38686c
Reviewed-by: Ali Akhtarzada <ali.akhtarzada@nokia.com>
-rw-r--r-- | src/hbtree/hbtree.cpp | 25 | ||||
-rw-r--r-- | src/hbtree/hbtree.h | 2 | ||||
-rw-r--r-- | src/hbtree/hbtree_p.h | 3 | ||||
-rw-r--r-- | src/partition/jsondbbtree.h | 4 |
4 files changed, 30 insertions, 4 deletions
diff --git a/src/hbtree/hbtree.cpp b/src/hbtree/hbtree.cpp index 4c9ff2d..3d86392 100644 --- a/src/hbtree/hbtree.cpp +++ b/src/hbtree/hbtree.cpp @@ -44,6 +44,7 @@ #include <sys/file.h> #include <sys/stat.h> #include <stddef.h> +#include <errno.h> #include <QDebug> @@ -95,7 +96,7 @@ HBtreePrivate::HBtreePrivate(HBtree *q, const QString &name) : q_ptr(q), fileName_(name), fd_(-1), openMode_(HBtree::ReadOnly), size_(0), lastSyncedId_(0), cacheSize_(20), compareFunction_(0), writeTransaction_(0), readTransaction_(0), lastPage_(PageInfo::INVALID_PAGE), cursorDisrupted_(false), - forceCommitFail_(0) + forceCommitFail_(0), lastWriteError_(0), lastReadError_(0) { } @@ -154,6 +155,7 @@ bool HBtreePrivate::open(int fd) lastSyncedId_ = 0; size_ = initSize; } else { + lastReadError_ = errno; HBTREE_ERROR("failed to read spec page - rc:" << rc); return false; } @@ -202,7 +204,7 @@ bool HBtreePrivate::open(int fd) << ", residueHistory_:" << residueHistory_ << ", size_:" << size_ << "]"); - + lastReadError_ = 0; return true; } @@ -265,9 +267,11 @@ bool HBtreePrivate::readSpec(const QByteArray &binaryData) int rc = pread(fd_, (void *)buffer.data(), spec.pageSize, 0); if (rc != spec.pageSize) { + lastReadError_ = errno; HBTREE_DEBUG("failed to read" << spec.pageSize << "bytes for spec page. Spec:" << spec); return false; } + lastReadError_ = 0; } quint32 crc = calculateChecksum(buffer); @@ -730,9 +734,11 @@ QByteArray HBtreePrivate::readPage(quint32 pageNumber) ssize_t rc = read(fd_, (void *)pageBuffer_.data(), spec_.pageSize); if (rc != spec_.pageSize) { + lastReadError_ = errno; HBTREE_DEBUG("failed to read @" << offset << "for page" << pageNumber << "- rc:" << rc); return QByteArray(); } + lastReadError_ = 0; PageInfo pageInfo = deserializePageInfo(pageBuffer_); @@ -781,10 +787,11 @@ bool HBtreePrivate::writePage(QByteArray *buffer) const const off_t offset = pageNumber * spec_.pageSize; ssize_t rc = pwrite(fd_, (const void *)buffer->constData(), spec_.pageSize, offset); if (rc != spec_.pageSize) { + lastWriteError_ = errno; HBTREE_DEBUG("failed pwrite. Expected page size" << spec_.pageSize << "- rc:" << rc); return false; } - + lastWriteError_ = 0; HBTREE_DEBUG("wrote page" << deserializePageInfo(*buffer)); const Q_Q(HBtree); @@ -2832,6 +2839,18 @@ bool HBtree::isOpen() const return d->fd_ != -1; } +int HBtree::lastWriteError() const +{ + Q_D(const HBtree); + return d->lastWriteError_; +} + +int HBtree::lastReadError() const +{ + Q_D(const HBtree); + return d->lastReadError_; +} + size_t HBtree::size() const { Q_D(const HBtree); diff --git a/src/hbtree/hbtree.h b/src/hbtree/hbtree.h index 997c5b1..f791404 100644 --- a/src/hbtree/hbtree.h +++ b/src/hbtree/hbtree.h @@ -134,6 +134,8 @@ public: bool open(); void close(); bool isOpen() const; + int lastWriteError() const; + int lastReadError() const; bool open(OpenMode mode) { setOpenMode(mode); return open(); } diff --git a/src/hbtree/hbtree_p.h b/src/hbtree/hbtree_p.h index c0efc4d..0686409 100644 --- a/src/hbtree/hbtree_p.h +++ b/src/hbtree/hbtree_p.h @@ -398,9 +398,10 @@ public: QList<Page *> lru_; bool cursorDisrupted_; mutable QByteArray pageBuffer_; - bool verifyIntegrity(const Page *pPage) const; int forceCommitFail_; + mutable int lastWriteError_; + int lastReadError_; }; QT_BEGIN_NAMESPACE diff --git a/src/partition/jsondbbtree.h b/src/partition/jsondbbtree.h index 6a64840..d05ffdc 100644 --- a/src/partition/jsondbbtree.h +++ b/src/partition/jsondbbtree.h @@ -119,6 +119,10 @@ public: Stat stats() const; bool sync() { Q_ASSERT(mBtree); return mBtree->sync(); } + int lastWriteError() const + { Q_ASSERT(mBtree); return mBtree->lastWriteError(); } + int lastReadError() const + { Q_ASSERT(mBtree); return mBtree->lastReadError(); } bool putOne(const QByteArray &key, const QByteArray &value); bool getOne(const QByteArray &key, QByteArray *value); |