summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAli Akhtarzada <ali.akhtarzada@nokia.com>2012-04-10 11:22:56 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-10 12:52:55 +0200
commit20549eedb5b5e852c0e384cd76bfbff14168dbda (patch)
treeec1c784bd95187ada816f2f36f937e65d5113c69 /src
parentdaed60aea68c5adbfacabb7472463d5d4d2b7b3d (diff)
hbtree ensure only one transaction active at any time
Disable support for concurrent read and write transactions since they dont make sense with current implementations Change-Id: I57125d94b71af3cba6322b428bcb0cde297443cc Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/hbtree/hbtree.cpp17
-rw-r--r--src/hbtree/hbtree_p.h1
2 files changed, 17 insertions, 1 deletions
diff --git a/src/hbtree/hbtree.cpp b/src/hbtree/hbtree.cpp
index 5e8f0810..46b3585c 100644
--- a/src/hbtree/hbtree.cpp
+++ b/src/hbtree/hbtree.cpp
@@ -91,7 +91,7 @@ const quint32 HBtreePrivate::PageInfo::INVALID_PAGE = 0xFFFFFFFF;
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), lastPage_(PageInfo::INVALID_PAGE), cursorDisrupted_(false)
+ writeTransaction_(0), readTransaction_(0), lastPage_(PageInfo::INVALID_PAGE), cursorDisrupted_(false)
{
}
@@ -209,6 +209,8 @@ bool HBtreePrivate::open(int fd)
void HBtreePrivate::close(bool doSync)
{
+ HBTREE_ASSERT(!readTransaction_ && !writeTransaction_);
+
if (fd_ != -1) {
HBTREE_DEBUG("closing btree with fd:" << fd_);
if (doSync)
@@ -931,9 +933,13 @@ void HBtreePrivate::abort(HBtreeTransaction *transaction)
}
dirtyPages_.clear();
if (transaction->isReadWrite()) {
+ HBTREE_ASSERT(transaction == writeTransaction_);
if (::flock(fd_, LOCK_UN) != 0)
HBTREE_ERROR("failed to unlock file with transaction @" << transaction);
writeTransaction_ = 0;
+ } else {
+ HBTREE_ASSERT(transaction == readTransaction_);
+ readTransaction_ = 0;
}
delete transaction;
cachePrune();
@@ -998,6 +1004,13 @@ HBtreeTransaction *HBtreePrivate::beginTransaction(HBtreeTransaction::Type type)
{
Q_Q(HBtree);
+ HBTREE_ASSERT(!writeTransaction_ && !readTransaction_);
+
+ if (writeTransaction_ || readTransaction_) {
+ HBTREE_ERROR("Only one transaction type supported at a time");
+ return 0;
+ }
+
if (type == HBtreeTransaction::ReadWrite && writeTransaction_) {
HBTREE_ERROR("cannot open write transaction when one in progress");
return 0;
@@ -1031,6 +1044,8 @@ HBtreeTransaction *HBtreePrivate::beginTransaction(HBtreeTransaction::Type type)
transaction->revision_ = marker_.meta.revision;
if (type == HBtreeTransaction::ReadWrite)
writeTransaction_ = transaction;
+ else
+ readTransaction_ = transaction;
HBTREE_DEBUG("began" << (transaction->isReadOnly() ? "read" : "write")
<< "transaction @" << transaction
<< "[root:" << transaction->rootPage_
diff --git a/src/hbtree/hbtree_p.h b/src/hbtree/hbtree_p.h
index ab529797..8575db31 100644
--- a/src/hbtree/hbtree_p.h
+++ b/src/hbtree/hbtree_p.h
@@ -388,6 +388,7 @@ public:
PageMap dirtyPages_;
HBtree::CompareFunction compareFunction_;
HBtreeTransaction *writeTransaction_;
+ HBtreeTransaction *readTransaction_;
QSet<quint32> collectiblePages_;
PageMap cache_;
quint32 lastPage_;