summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorAlex Gorrod <alexg@wiredtiger.com>2014-06-13 16:47:01 +1000
committerAlex Gorrod <alexg@wiredtiger.com>2014-06-13 16:47:01 +1000
commit63959d67bed4b8d538538f466487bc16d4029a0a (patch)
tree59257e4905822bc1bec3b55e8d11a5cc86cbba81 /api
parentab88b75b7906685876b5c0ea44115746ae2240e8 (diff)
downloadmongo-63959d67bed4b8d538538f466487bc16d4029a0a.tar.gz
Enhance error handling in LevelDB API cursor implementation.
Diffstat (limited to 'api')
-rw-r--r--api/leveldb/leveldb_wt.cc125
1 files changed, 92 insertions, 33 deletions
diff --git a/api/leveldb/leveldb_wt.cc b/api/leveldb/leveldb_wt.cc
index 4cf6f8edf70..69c0b57a497 100644
--- a/api/leveldb/leveldb_wt.cc
+++ b/api/leveldb/leveldb_wt.cc
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2008-2014 WiredTiger, Inc.
- * All rights reserved.
+ * All rights reserved.
*
* See the file LICENSE for redistribution information.
*/
@@ -285,6 +285,11 @@ private:
Status status_;
bool valid_;
+ void SetError(int wiredTigerError) {
+ valid_ = false;
+ status_ = WiredTigerErrorToStatus(wiredTigerError, NULL);
+ }
+
// No copying allowed
IteratorImpl(const IteratorImpl&);
void operator=(const IteratorImpl&);
@@ -663,20 +668,33 @@ DbImpl::ResumeCompactions()
void
IteratorImpl::SeekToFirst()
{
+ int ret;
WT_ITEM item;
- int ret = cursor_->reset(cursor_);
- assert(ret == 0);
+ if (!Status().ok())
+ return;
+
+ if ((ret = cursor_->reset(cursor_)) != 0) {
+ SetError(ret);
+ return;
+ }
ret = cursor_->next(cursor_);
- if (ret != 0) {
+ if (ret == WT_NOTFOUND) {
valid_ = false;
return;
+ } else if (ret != 0) {
+ SetError(ret);
+ return;
+ }
+ if ((ret = cursor_->get_key(cursor_, &item)) != 0) {
+ SetError(ret);
+ return;
}
- ret = cursor_->get_key(cursor_, &item);
- assert(ret == 0);
key_ = Slice((const char *)item.data, item.size);
- ret = cursor_->get_value(cursor_, &item);
- assert(ret == 0);
+ if ((ret = cursor_->get_value(cursor_, &item)) != 0) {
+ SetError(ret);
+ return;
+ }
value_ = Slice((const char *)item.data, item.size);
valid_ = true;
}
@@ -686,20 +704,33 @@ IteratorImpl::SeekToFirst()
void
IteratorImpl::SeekToLast()
{
+ int ret;
WT_ITEM item;
- int ret = cursor_->reset(cursor_);
- assert(ret == 0);
+ if (!Status().ok())
+ return;
+
+ if ((ret = cursor_->reset(cursor_)) != 0) {
+ SetError(ret);
+ return;
+ }
ret = cursor_->prev(cursor_);
- if (ret != 0) {
+ if (ret == WT_NOTFOUND) {
valid_ = false;
return;
+ } else if (ret != 0) {
+ SetError(ret);
+ return;
+ }
+ if ((ret = cursor_->get_key(cursor_, &item)) != 0) {
+ SetError(ret);
+ return;
}
- ret = cursor_->get_key(cursor_, &item);
- assert(ret == 0);
key_ = Slice((const char *)item.data, item.size);
- ret = cursor_->get_value(cursor_, &item);
- assert(ret == 0);
+ if ((ret = cursor_->get_value(cursor_, &item)) != 0) {
+ SetError(ret);
+ return;
+ }
value_ = Slice((const char *)item.data, item.size);
valid_ = true;
}
@@ -712,6 +743,9 @@ IteratorImpl::Seek(const Slice& target)
{
WT_ITEM item;
+ if (!Status().ok())
+ return;
+
item.data = target.data();
item.size = target.size();
cursor_->set_key(cursor_, &item);
@@ -720,15 +754,19 @@ IteratorImpl::Seek(const Slice& target)
ret = cursor_->next(cursor_);
if (ret != 0) {
if (ret != WT_NOTFOUND)
- status_ = Status::IOError(wiredtiger_strerror(ret));
+ SetError(ret);
valid_ = false;
return;
}
- ret = cursor_->get_key(cursor_, &item);
- assert(ret == 0);
+ if ((ret = cursor_->get_key(cursor_, &item)) != 0) {
+ SetError(ret);
+ return;
+ }
key_ = Slice((const char *)item.data, item.size);
- ret = cursor_->get_value(cursor_, &item);
- assert(ret == 0);
+ if ((ret = cursor_->get_value(cursor_, &item)) != 0) {
+ SetError(ret);
+ return;
+ }
value_ = Slice((const char *)item.data, item.size);
valid_ = true;
}
@@ -739,22 +777,33 @@ IteratorImpl::Seek(const Slice& target)
void
IteratorImpl::Next()
{
+ int ret;
WT_ITEM item;
- assert(valid_);
+ if (!Status().ok())
+ return;
+
+ if (!valid_) {
+ SetError(EINVAL);
+ return;
+ }
- int ret = cursor_->next(cursor_);
+ ret = cursor_->next(cursor_);
if (ret != 0) {
if (ret != WT_NOTFOUND)
- status_ = Status::IOError(wiredtiger_strerror(ret));
+ SetError(ret);
valid_ = false;
return;
}
- ret = cursor_->get_key(cursor_, &item);
- assert(ret == 0);
+ if ((ret = cursor_->get_key(cursor_, &item)) != 0) {
+ SetError(ret);
+ return;
+ }
key_ = Slice((const char *)item.data, item.size);
- ret = cursor_->get_value(cursor_, &item);
- assert(ret == 0);
+ if ((ret = cursor_->get_value(cursor_, &item)) != 0) {
+ SetError(ret);
+ return;
+ }
value_ = Slice((const char *)item.data, item.size);
valid_ = true;
}
@@ -767,20 +816,30 @@ IteratorImpl::Prev()
{
WT_ITEM item;
- assert(valid_);
+ if (!Status().ok())
+ return;
+
+ if (!valid_) {
+ SetError(EINVAL);
+ return;
+ }
int ret = cursor_->prev(cursor_);
if (ret != 0) {
if (ret != WT_NOTFOUND)
- status_ = Status::IOError(wiredtiger_strerror(ret));
+ SetError(ret);
valid_ = false;
return;
}
- ret = cursor_->get_key(cursor_, &item);
- assert(ret == 0);
+ if ((ret = cursor_->get_key(cursor_, &item)) != 0) {
+ SetError(ret);
+ return;
+ }
key_ = Slice((const char *)item.data, item.size);
- ret = cursor_->get_value(cursor_, &item);
- assert(ret == 0);
+ if ((ret = cursor_->get_value(cursor_, &item)) != 0) {
+ SetError(ret);
+ return;
+ }
value_ = Slice((const char *)item.data, item.size);
valid_ = true;
}