/* * Copyright (C) 2015 ScyllaDB */ /* * This file is part of Scylla. * * Scylla is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Scylla 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 Scylla. If not, see . */ #include "commitlog.hh" #include #include "api/api-doc/commitlog.json.hh" #include namespace api { template static auto acquire_cl_metric(http_context& ctx, Func&& func) { typedef std::result_of_t ret_type; return ctx.db.map_reduce0([func = std::forward(func)](database& db) { if (db.commitlog() == nullptr) { return make_ready_future(); } return make_ready_future(func(db.commitlog())); }, ret_type(), std::plus()).then([](ret_type res) { return make_ready_future(res); }); } void set_commitlog(http_context& ctx, routes& r) { httpd::commitlog_json::get_active_segment_names.set(r, [&ctx](std::unique_ptr req) { auto res = make_shared>(); return ctx.db.map_reduce([res](std::vector names) { res->insert(res->end(), names.begin(), names.end()); }, [](database& db) { if (db.commitlog() == nullptr) { return make_ready_future>(std::vector()); } return make_ready_future>(db.commitlog()->get_active_segment_names()); }).then([res] { return make_ready_future(*res.get()); }); }); // We currently do not support archive segments httpd::commitlog_json::get_archiving_segment_names.set(r, [](const_req req) { std::vector res; return res; }); httpd::commitlog_json::get_completed_tasks.set(r, [&ctx](std::unique_ptr req) { return acquire_cl_metric(ctx, std::bind(&db::commitlog::get_completed_tasks, std::placeholders::_1)); }); httpd::commitlog_json::get_pending_tasks.set(r, [&ctx](std::unique_ptr req) { return acquire_cl_metric(ctx, std::bind(&db::commitlog::get_pending_tasks, std::placeholders::_1)); }); httpd::commitlog_json::get_total_commit_log_size.set(r, [&ctx](std::unique_ptr req) { return acquire_cl_metric(ctx, std::bind(&db::commitlog::get_total_size, std::placeholders::_1)); }); } }