summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@wiredtiger.com>2014-07-09 16:25:58 +1000
committerMichael Cahill <michael.cahill@wiredtiger.com>2014-07-09 16:25:58 +1000
commit5e9075f7babe22a77900c127280bdbfc7dcb6e40 (patch)
treea91a0b397d7b6a8cb7163cc81574a15dd2b05b3a /api
parentb48469701568ca0211110c9d8f7d360cbdde309c (diff)
downloadmongo-5e9075f7babe22a77900c127280bdbfc7dcb6e40.tar.gz
Add a fast path for write batches that are either empty or have a single entry. The problem is that begin/commit causes cursors to be reset, and in this workload there are quite a few cursors. Only do that if needed to execute the write batch correctly.
This optimization is currently only implemented in RocksDB -- stock LevelDB has no way to figure out the number of entries in a write batch.
Diffstat (limited to 'api')
-rw-r--r--api/leveldb/leveldb_wt.cc19
1 files changed, 13 insertions, 6 deletions
diff --git a/api/leveldb/leveldb_wt.cc b/api/leveldb/leveldb_wt.cc
index bb42ca90254..e126b47469c 100644
--- a/api/leveldb/leveldb_wt.cc
+++ b/api/leveldb/leveldb_wt.cc
@@ -365,10 +365,16 @@ DbImpl::Write(const WriteOptions& options, WriteBatch* updates)
Status status = Status::OK();
OperationContext *context = GetContext();
WT_SESSION *session = context->GetSession();
- int ret, t_ret;
+ int ret = 0, t_ret;
+
+#ifdef HAVE_ROCKSDB
+ int need_txn = (updates->Count() > 1);
+#else
+ int need_txn = 1;
+#endif
for (;;) {
- if ((ret = session->begin_transaction(session, NULL)) != 0) {
+ if (need_txn && (ret = session->begin_transaction(session, NULL)) != 0) {
errmsg = "Begin transaction failed in Write batch";
goto err;
}
@@ -380,22 +386,23 @@ DbImpl::Write(const WriteOptions& options, WriteBatch* updates)
try {
status = updates->Iterate(&handler);
} catch(...) {
- (void)session->rollback_transaction(session, NULL);
+ if (need_txn)
+ (void)session->rollback_transaction(session, NULL);
throw;
}
#endif
if (!status.ok() || (ret = handler.GetWiredTigerStatus()) != WT_DEADLOCK)
break;
// Roll back the transaction on deadlock so we can try again
- if ((ret = session->rollback_transaction(session, NULL)) != 0) {
+ if (need_txn && (ret = session->rollback_transaction(session, NULL)) != 0) {
errmsg = "Rollback transaction failed in Write batch";
goto err;
}
}
- if (status.ok() && ret == 0) {
+ if (need_txn && status.ok() && ret == 0) {
ret = session->commit_transaction(session, NULL);
- } else {
+ } else if (need_txn) {
t_ret = session->rollback_transaction(session, NULL);
if (ret == 0)
ret = t_ret;