mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-10 18:05:44 +02:00
In more detail, RdbSaver uses AlignedBuffer that writes into io::Sink in chunks of 4KB. It's great for the direct file I/O, but bad for sockets that receive blocks of 4KB with garbage at the end. I improved the code around this and actually simplified the logic, so now AlignedBuffer is just another Sink that is passed into serializer when writing into files. When sending to sockets a socket sink is passed instead. Also many other unrelated changes grouped into this pretty big cr. 1. dashtable readability improvements. 2. Move methods from facade::ConnectionContext - into facade::Service, make ConnectionContext a dumb object. 3. Optionally allow journal to be memory only (not backed up by a disk) by using a ring buffer to store last k entries in each journal slice. Also renamed journal_shard into journal_slice because journal has presence in each DF thread and not only in its shards. 4. Introduce journal::Entry that will consolidate any store change that happens in the thread. 5. Introduce GetRandomHex utility function. 6. Introduce two hooks: ServerFamily::OnClose that is called when a connection is closed, and ServerFamily::BreakOnShutdown that is called when process exits and any background fibers neet to break early. 7. Pull some noisy info logs out of rdb_load class. 8. Snapshot class now has the ability to subscribe to journal changes, thus it can include concurrent changes into the snapshot. Currently only journal::Op::VAL is supported (it's part of RDB format anyway). Signed-off-by: Roman Gershman <roman@dragonflydb.io>
60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
// Copyright 2022, DragonflyDB authors. All rights reserved.
|
|
// See LICENSE for licensing terms.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include <absl/container/flat_hash_set.h>
|
|
|
|
#include "facade/facade_types.h"
|
|
#include "facade/reply_builder.h"
|
|
|
|
namespace facade {
|
|
|
|
class Connection;
|
|
|
|
class ConnectionContext {
|
|
public:
|
|
ConnectionContext(::io::Sink* stream, Connection* owner);
|
|
|
|
// We won't have any virtual methods, probably. However, since we allocate a derived class,
|
|
// we need to declare a virtual d-tor, so we could properly delete it from Connection code.
|
|
virtual ~ConnectionContext() {}
|
|
|
|
Connection* owner() {
|
|
return owner_;
|
|
}
|
|
|
|
Protocol protocol() const {
|
|
return protocol_;
|
|
}
|
|
|
|
// A convenient proxy for redis interface.
|
|
RedisReplyBuilder* operator->();
|
|
|
|
SinkReplyBuilder* reply_builder() {
|
|
return rbuilder_.get();
|
|
}
|
|
|
|
// Allows receiving the output data from the commands called from scripts.
|
|
SinkReplyBuilder* Inject(SinkReplyBuilder* new_i) {
|
|
SinkReplyBuilder* res = rbuilder_.release();
|
|
rbuilder_.reset(new_i);
|
|
return res;
|
|
}
|
|
|
|
// connection state / properties.
|
|
bool async_dispatch: 1; // whether this connection is currently handled by dispatch fiber.
|
|
bool conn_closing: 1;
|
|
bool req_auth: 1;
|
|
bool replica_conn: 1;
|
|
bool authenticated: 1;
|
|
bool force_dispatch: 1; // whether we should route all requests to the dispatch fiber.
|
|
|
|
private:
|
|
Connection* owner_;
|
|
Protocol protocol_ = Protocol::REDIS;
|
|
std::unique_ptr<SinkReplyBuilder> rbuilder_;
|
|
};
|
|
|
|
} // namespace facade
|