Commit f29f4bdb authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Implement COMMAND-STATS to expose total number of reads/writes since startup

parent 1fb3c40f
Pipeline #878558 passed with stages
in 38 minutes and 26 seconds
......@@ -35,6 +35,7 @@ struct cmdMapInit {
redis_cmd_map["debug"] = {RedisCommand::DEBUG, CommandType::CONTROL};
redis_cmd_map["monitor"] = {RedisCommand::MONITOR, CommandType::CONTROL};
redis_cmd_map["client_id"] = {RedisCommand::CLIENT_ID, CommandType::CONTROL};
redis_cmd_map["command_stats"] = {RedisCommand::COMMAND_STATS, CommandType::CONTROL};
redis_cmd_map["auth"] = {RedisCommand::AUTH, CommandType::AUTHENTICATION};
redis_cmd_map["hmac_auth_generate_challenge"] = {RedisCommand::HMAC_AUTH_GENERATE_CHALLENGE, CommandType::AUTHENTICATION};
......
......@@ -35,6 +35,7 @@ enum class RedisCommand {
DEBUG,
MONITOR,
CLIENT_ID,
COMMAND_STATS,
FLUSHALL,
......
......@@ -27,6 +27,7 @@
#include "Formatter.hh"
#include "redis/ArrayResponseBuilder.hh"
#include "redis/Transaction.hh"
#include "utils/Statistics.hh"
using namespace quarkdb;
RedisEncodedResponse Formatter::moved(int64_t shardId, const RaftServer &location) {
......@@ -191,6 +192,14 @@ RedisEncodedResponse Formatter::multiply(const RedisEncodedResponse &resp, size_
return RedisEncodedResponse(ss.str());
}
RedisEncodedResponse Formatter::stats(const Statistics &stats) {
std::vector<std::string> arr;
arr.emplace_back(SSTR("TOTAL-READS " << stats.reads));
arr.emplace_back(SSTR("TOTAL-WRITES " << stats.writes));
arr.emplace_back(SSTR("TOTAL-BATCHES " << stats.batches));
return statusVector(arr);
}
RedisEncodedResponse Formatter::subscribe(std::string_view channel, size_t active) {
return strstrint("subscribe", channel, active);
}
......
......@@ -32,6 +32,7 @@ namespace quarkdb {
struct RaftEntry;
class RedisRequest;
struct Statistics;
class Formatter {
public:
......@@ -64,6 +65,7 @@ public:
static RedisEncodedResponse redisRequest(const RedisRequest &req);
static RedisEncodedResponse multiply(const RedisEncodedResponse &resp, size_t factor);
static RedisEncodedResponse stats(const Statistics &stats);
private:
static RedisEncodedResponse strstrint(std::string_view str1, std::string_view str2, int num);
......
......@@ -220,6 +220,15 @@ LinkStatus Shard::dispatch(Connection *conn, RedisRequest &req) {
return conn->status(ss.str());
}
case RedisCommand::COMMAND_STATS: {
if(req.size() != 1) return conn->errArgs(req[0]);
InFlightRegistration registration(inFlightTracker);
if(!registration.ok()) {
return conn->err("unavailable");
}
return conn->raw(Formatter::stats(stateMachine->commandStats()));
}
default: {
if(req.getCommandType() == CommandType::QUARKDB) {
qdb_critical("Unable to dispatch command '" << req[0] << "' of type QUARKDB");
......
......@@ -1786,12 +1786,18 @@ std::string StateMachine::statistics() {
return stats;
}
//------------------------------------------------------------------------------
// Get level stats
//------------------------------------------------------------------------------
std::string StateMachine::levelStats() {
std::string stats;
db->GetProperty(rocksdb::DB::Properties::kLevelStats, &stats);
return stats;
}
//------------------------------------------------------------------------------
// Get compression stats
//------------------------------------------------------------------------------
std::vector<std::string> StateMachine::compressionStats() {
std::vector<std::string> results;
......@@ -1804,6 +1810,13 @@ std::vector<std::string> StateMachine::compressionStats() {
return results;
}
//------------------------------------------------------------------------------
// Get command stats
//------------------------------------------------------------------------------
Statistics StateMachine::commandStats() {
return requestCounter.getOverallStats();
}
rocksdb::Status StateMachine::noop(LogIndex index) {
StagingArea stagingArea(*this);
return stagingArea.commit(index);
......
......@@ -243,6 +243,11 @@ public:
//----------------------------------------------------------------------------
std::vector<std::string> compressionStats();
//----------------------------------------------------------------------------
// Get command stats
//----------------------------------------------------------------------------
Statistics commandStats();
bool inBulkLoad() const {
return bulkLoad;
}
......
......@@ -65,6 +65,10 @@ void RequestCounter::setReportingStatus(bool val) {
activated = val;
}
Statistics RequestCounter::getOverallStats() {
return aggregator.getOverallStats();
}
void RequestCounter::mainThread(ThreadAssistant &assistant) {
while(!assistant.terminationRequested()) {
......
......@@ -48,6 +48,8 @@ public:
void setReportingStatus(bool val);
void account(const RedisRequest &req);
Statistics getOverallStats();
private:
void account(const RedisRequest &req, Statistics *stats);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment