// ----------------------------------------------------------------------
// File: Shard.hh
// Author: Georgios Bitzes - CERN
// ----------------------------------------------------------------------
/************************************************************************
* quarkdb - a redis-like highly available key-value store *
* Copyright (C) 2016 CERN/Switzerland *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see .*
************************************************************************/
#ifndef QUARKDB_SHARD_H
#define QUARKDB_SHARD_H
#include "raft/RaftTimeouts.hh"
#include "Dispatcher.hh"
#include "Configuration.hh"
#include "redis/CommandMonitor.hh"
#include "utils/InFlightTracker.hh"
#include "health/HealthIndicator.hh"
namespace quarkdb {
class RaftGroup; class ShardDirectory; class StandaloneGroup;
class Shard : public Dispatcher {
public:
Shard(ShardDirectory *shardDir, const RaftServer &me, Mode mode, const RaftTimeouts &t, const std::string &password);
~Shard();
RaftGroup* getRaftGroup();
void spinup();
void spindown();
virtual LinkStatus dispatch(Connection *conn, RedisRequest &req) override final;
virtual LinkStatus dispatch(Connection *conn, Transaction &transaction) override final;
virtual void notifyDisconnect(Connection *conn) override final {}
size_t monitors() { return commandMonitor.size(); }
NodeHealth getHealth();
private:
void detach();
void attach();
void start();
void stopAcceptingRequests();
CommandMonitor commandMonitor;
ShardDirectory *shardDirectory;
std::unique_ptr raftGroup;
std::unique_ptr standaloneGroup;
StateMachine *stateMachine = nullptr;
Dispatcher *dispatcher = nullptr;
RaftServer myself;
Mode mode;
RaftTimeouts timeouts;
std::string password;
InFlightTracker inFlightTracker;
std::mutex raftGroupMtx;
};
}
#endif