mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-10 18:05:44 +02:00
1. Make EngineShardSet to be a process singleton instead of a variable passed everywhere. 2. Implement a heuristic of updating free memory per shard. 3. Make sure that SET command returns OOM when a database reaches its limits.
124 lines
3.4 KiB
C++
124 lines
3.4 KiB
C++
// Copyright 2022, Roman Gershman. All rights reserved.
|
|
// See LICENSE for licensing terms.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include "facade/conn_context.h"
|
|
#include "facade/redis_parser.h"
|
|
#include "server/engine_shard_set.h"
|
|
#include "server/global_state.h"
|
|
#include "util/proactor_pool.h"
|
|
|
|
namespace util {
|
|
class AcceptServer;
|
|
class ListenerInterface;
|
|
} // namespace util
|
|
|
|
namespace dfly {
|
|
|
|
class ConnectionContext;
|
|
class CommandRegistry;
|
|
class Service;
|
|
class Replica;
|
|
class ScriptMgr;
|
|
|
|
struct Metrics {
|
|
std::vector<DbStats> db;
|
|
SliceEvents events;
|
|
TieredStats tiered_stats;
|
|
EngineShard::Stats shard_stats;
|
|
|
|
size_t qps = 0;
|
|
size_t heap_used_bytes = 0;
|
|
size_t heap_comitted_bytes = 0;
|
|
size_t small_string_bytes = 0;
|
|
uint32_t traverse_ttl_per_sec = 0;
|
|
uint32_t delete_ttl_per_sec = 0;
|
|
|
|
facade::ConnectionStats conn_stats;
|
|
};
|
|
|
|
class ServerFamily {
|
|
public:
|
|
ServerFamily(Service* service);
|
|
~ServerFamily();
|
|
|
|
void Init(util::AcceptServer* acceptor, util::ListenerInterface* main_listener);
|
|
void Register(CommandRegistry* registry);
|
|
void Shutdown();
|
|
|
|
Service& service() {
|
|
return service_;
|
|
}
|
|
|
|
Metrics GetMetrics() const;
|
|
|
|
GlobalState* global_state() {
|
|
return &global_state_;
|
|
}
|
|
|
|
ScriptMgr* script_mgr() {
|
|
return script_mgr_.get();
|
|
}
|
|
|
|
void StatsMC(std::string_view section, facade::ConnectionContext* cntx);
|
|
|
|
std::error_code DoSave(Transaction* transaction, std::string* err_details);
|
|
std::error_code DoFlush(Transaction* transaction, DbIndex db_ind);
|
|
|
|
std::string LastSaveFile() const;
|
|
|
|
private:
|
|
uint32_t shard_count() const {
|
|
return shard_set->size();
|
|
}
|
|
|
|
void Auth(CmdArgList args, ConnectionContext* cntx);
|
|
void Client(CmdArgList args, ConnectionContext* cntx);
|
|
void Config(CmdArgList args, ConnectionContext* cntx);
|
|
void DbSize(CmdArgList args, ConnectionContext* cntx);
|
|
void Debug(CmdArgList args, ConnectionContext* cntx);
|
|
void Memory(CmdArgList args, ConnectionContext* cntx);
|
|
void FlushDb(CmdArgList args, ConnectionContext* cntx);
|
|
void FlushAll(CmdArgList args, ConnectionContext* cntx);
|
|
void Info(CmdArgList args, ConnectionContext* cntx);
|
|
void Hello(CmdArgList args, ConnectionContext* cntx);
|
|
void LastSave(CmdArgList args, ConnectionContext* cntx);
|
|
void Latency(CmdArgList args, ConnectionContext* cntx);
|
|
void Psync(CmdArgList args, ConnectionContext* cntx);
|
|
void ReplicaOf(CmdArgList args, ConnectionContext* cntx);
|
|
void Role(CmdArgList args, ConnectionContext* cntx);
|
|
void Save(CmdArgList args, ConnectionContext* cntx);
|
|
void Script(CmdArgList args, ConnectionContext* cntx);
|
|
void Sync(CmdArgList args, ConnectionContext* cntx);
|
|
|
|
void _Shutdown(CmdArgList args, ConnectionContext* cntx);
|
|
|
|
void SyncGeneric(std::string_view repl_master_id, uint64_t offs, ConnectionContext* cntx);
|
|
|
|
uint32_t task_10ms_ = 0;
|
|
Service& service_;
|
|
|
|
util::AcceptServer* acceptor_ = nullptr;
|
|
util::ListenerInterface* main_listener_ = nullptr;
|
|
util::ProactorBase* pb_task_ = nullptr;
|
|
|
|
mutable ::boost::fibers::mutex replicaof_mu_, save_mu_;
|
|
std::shared_ptr<Replica> replica_; // protected by replica_of_mu_
|
|
|
|
std::unique_ptr<ScriptMgr> script_mgr_;
|
|
|
|
GlobalState global_state_;
|
|
time_t start_time_ = 0; // in seconds, epoch time.
|
|
|
|
struct LastSaveInfo {
|
|
time_t save_time; // epoch time in seconds.
|
|
std::string file_name; //
|
|
std::vector<std::pair<std::string_view, size_t>> freq_map; // RDB_TYPE_xxx -> count mapping.
|
|
};
|
|
|
|
LastSaveInfo lsinfo_;
|
|
};
|
|
|
|
} // namespace dfly
|