2014-09-13 01:23:58 +02:00
|
|
|
// Copyright (c) 2013, 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 <stdint.h>
|
|
|
|
#include <deque>
|
|
|
|
#include <limits>
|
|
|
|
#include "rocksdb/status.h"
|
|
|
|
#include "db/write_batch_internal.h"
|
|
|
|
#include "util/autovector.h"
|
|
|
|
#include "port/port.h"
|
2015-02-05 06:39:45 +01:00
|
|
|
#include "util/instrumented_mutex.h"
|
2014-09-13 01:23:58 +02:00
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
|
|
|
|
class WriteThread {
|
|
|
|
public:
|
|
|
|
// Information kept for every waiting writer
|
|
|
|
struct Writer {
|
|
|
|
Status status;
|
|
|
|
WriteBatch* batch;
|
|
|
|
bool sync;
|
|
|
|
bool disableWAL;
|
|
|
|
bool in_batch_group;
|
|
|
|
bool done;
|
2015-05-29 23:36:35 +02:00
|
|
|
bool has_callback;
|
2015-02-05 06:39:45 +01:00
|
|
|
InstrumentedCondVar cv;
|
2014-09-13 01:23:58 +02:00
|
|
|
|
2015-02-05 06:39:45 +01:00
|
|
|
explicit Writer(InstrumentedMutex* mu)
|
2014-09-13 01:23:58 +02:00
|
|
|
: batch(nullptr),
|
|
|
|
sync(false),
|
|
|
|
disableWAL(false),
|
|
|
|
in_batch_group(false),
|
|
|
|
done(false),
|
2015-05-29 23:36:35 +02:00
|
|
|
has_callback(false),
|
2014-09-13 01:23:58 +02:00
|
|
|
cv(mu) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
WriteThread() = default;
|
|
|
|
~WriteThread() = default;
|
|
|
|
|
|
|
|
// Before applying write operation (such as DBImpl::Write, DBImpl::Flush)
|
|
|
|
// thread should grab the mutex_ and be the first on writers queue.
|
|
|
|
// EnterWriteThread is used for it.
|
|
|
|
// Be aware! Writer's job can be done by other thread (see DBImpl::Write
|
|
|
|
// for examples), so check it via w.done before applying changes.
|
|
|
|
//
|
|
|
|
// Writer* w: writer to be placed in the queue
|
|
|
|
// See also: ExitWriteThread
|
|
|
|
// REQUIRES: db mutex held
|
Deprecate WriteOptions::timeout_hint_us
Summary:
In one of our recent meetings, we discussed deprecating features that are not being actively used. One of those features, at least within Facebook, is timeout_hint. The feature is really nicely implemented, but if nobody needs it, we should remove it from our code-base (until we get a valid use-case). Some arguments:
* Less code == better icache hit rate, smaller builds, simpler code
* The motivation for adding timeout_hint_us was to work-around RocksDB's stall issue. However, we're currently addressing the stall issue itself (see @sdong's recent work on stall write_rate), so we should never see sharp lock-ups in the future.
* Nobody is using the feature within Facebook's code-base. Googling for `timeout_hint_us` also doesn't yield any users.
Test Plan: make check
Reviewers: anthony, kradhakrishnan, sdong, yhchiang
Reviewed By: yhchiang
Subscribers: sdong, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D41937
2015-07-14 09:35:48 +02:00
|
|
|
void EnterWriteThread(Writer* w);
|
2014-09-13 01:23:58 +02:00
|
|
|
|
|
|
|
// After doing write job, we need to remove already used writers from
|
|
|
|
// writers_ queue and notify head of the queue about it.
|
|
|
|
// ExitWriteThread is used for this.
|
|
|
|
//
|
|
|
|
// Writer* w: Writer, that was added by EnterWriteThread function
|
|
|
|
// Writer* last_writer: Since we can join a few Writers (as DBImpl::Write
|
|
|
|
// does)
|
|
|
|
// we should pass last_writer as a parameter to
|
|
|
|
// ExitWriteThread
|
|
|
|
// (if you don't touch other writers, just pass w)
|
|
|
|
// Status status: Status of write operation
|
|
|
|
// See also: EnterWriteThread
|
|
|
|
// REQUIRES: db mutex held
|
|
|
|
void ExitWriteThread(Writer* w, Writer* last_writer, Status status);
|
|
|
|
|
2015-05-16 00:52:51 +02:00
|
|
|
// return total batch group size
|
|
|
|
size_t BuildBatchGroup(Writer** last_writer,
|
|
|
|
autovector<WriteBatch*>* write_batch_group);
|
2014-09-13 01:23:58 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Queue of writers.
|
|
|
|
std::deque<Writer*> writers_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace rocksdb
|