6f71d3b68b
Summary: copy from task 8196669: 1) Optimistic transactions do not support batching writes from different threads. 2) Pessimistic transactions do not support batching writes if an expiration time is set. In these 2 cases, we currently do not do any write batching in DBImpl::WriteImpl() because there is a WriteCallback that could decide at the last minute to abort the write. But we could support batching write operations with callbacks if we make sure to process the callbacks correctly. To do this, we would first need to modify write_thread.cc to stop preventing writes with callbacks from being batched together. Then we would need to change DBImpl::WriteImpl() to call all WriteCallback's in a batch, only write the batches that succeed, and correctly set the state of each batch's WriteThread::Writer. Test Plan: Added test WriteWithCallbackTest to write_callback_test.cc which creates multiple client threads and verifies that writes are batched and executed properly. Reviewers: hermanlee4, anthony, ngbronson Subscribers: leveldb, dhruba Differential Revision: https://reviews.facebook.net/D52863
28 lines
830 B
C++
28 lines
830 B
C++
// Copyright (c) 2015, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under the BSD-style license found in the
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
#pragma once
|
|
|
|
#include "rocksdb/status.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
class DB;
|
|
|
|
class WriteCallback {
|
|
public:
|
|
virtual ~WriteCallback() {}
|
|
|
|
// Will be called while on the write thread before the write executes. If
|
|
// this function returns a non-OK status, the write will be aborted and this
|
|
// status will be returned to the caller of DB::Write().
|
|
virtual Status Callback(DB* db) = 0;
|
|
|
|
// return true if writes with this callback can be batched with other writes
|
|
virtual bool AllowWriteBatching() = 0;
|
|
};
|
|
|
|
} // namespace rocksdb
|