0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-19 00:10:59 +01:00

ircd::db: Add WAL information interface w/ console cmd.

This commit is contained in:
Jason Volk 2018-12-10 14:04:30 -08:00
parent c3560d4890
commit 8d6c7e3576
6 changed files with 184 additions and 0 deletions

View file

@ -26,6 +26,7 @@ namespace ircd::db
const std::vector<std::string> &errors(const database &);
std::vector<std::string> files(const database &, uint64_t &msz);
std::vector<std::string> files(const database &);
std::vector<std::string> wals(const database &);
size_t file_count(const database &);
size_t bytes(const database &);
@ -86,6 +87,7 @@ struct ircd::db::database
struct env;
struct cache;
struct sst;
struct wal;
std::string name;
uint64_t checkpoint;

View file

@ -37,6 +37,7 @@ namespace rocksdb
struct SstFileMetaData;
struct SstFileWriter;
struct TableProperties;
struct LogFile;
}
//

View file

@ -0,0 +1,42 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_DB_DATABASE_WAL_H
struct ircd::db::database::wal
{
struct info;
};
/// Get info about a WAL file
///
struct ircd::db::database::wal::info
{
struct vector;
std::string name;
uint64_t number {0};
uint64_t seq {0};
size_t size {0};
bool alive {false};
info(const database &, const string_view &filename);
info() = default;
info &operator=(const rocksdb::LogFile &);
};
struct ircd::db::database::wal::info::vector
:std::vector<info>
{
vector() = default;
explicit vector(const database &);
};

View file

@ -70,6 +70,7 @@ namespace ircd::db
#include "database/options.h"
#include "database/snapshot.h"
#include "database/sst.h"
#include "database/wal.h"
#include "cache.h"
#include "opts.h"
#include "column.h"

View file

@ -594,6 +594,31 @@ ircd::db::file_count(const database &d)
});
}
/// Get the list of WAL (Write Ahead Log) files.
std::vector<std::string>
ircd::db::wals(const database &cd)
{
auto &d
{
const_cast<database &>(cd)
};
std::vector<std::unique_ptr<rocksdb::LogFile>> vec;
throw_on_error
{
d.d->GetSortedWalFiles(vec)
};
std::vector<std::string> ret(vec.size());
std::transform(begin(vec), end(vec), begin(ret), []
(const auto &file)
{
return file->PathName();
});
return ret;
}
/// Get the live file list for db; see overlord documentation.
std::vector<std::string>
ircd::db::files(const database &d)
@ -3204,6 +3229,70 @@ ircd::db::database::sst::info::operator=(rocksdb::TableProperties &&tp)
return *this;
}
///////////////////////////////////////////////////////////////////////////////
//
// database::wal
//
//
// wal::info::vector
//
ircd::db::database::wal::info::vector::vector(const database &d_)
{
auto &d{const_cast<database &>(d_)};
std::vector<std::unique_ptr<rocksdb::LogFile>> vec;
throw_on_error
{
d.d->GetSortedWalFiles(vec)
};
this->resize(vec.size());
for(size_t i(0); i < vec.size(); ++i)
this->at(i).operator=(*vec.at(i));
}
//
// wal::info::info
//
ircd::db::database::wal::info::info(const database &d_,
const string_view &filename)
{
auto &d{const_cast<database &>(d_)};
std::vector<std::unique_ptr<rocksdb::LogFile>> vec;
throw_on_error
{
d.d->GetSortedWalFiles(vec)
};
for(const auto &ptr : vec)
if(ptr->PathName() == filename)
{
this->operator=(*ptr);
return;
}
throw not_found
{
"No file named '%s' is live in database '%s'",
filename,
d.name
};
}
ircd::db::database::wal::info &
ircd::db::database::wal::info::operator=(const rocksdb::LogFile &lf)
{
name = lf.PathName();
number = lf.LogNumber();
seq = lf.StartSequence();
size = lf.SizeFileBytes();
alive = lf.Type() == rocksdb::WalFileType::kAliveLogFile;
return *this;
}
///////////////////////////////////////////////////////////////////////////////
//
// database::env

View file

@ -2581,6 +2581,55 @@ console_cmd__db__sst__dump(opt &out, const string_view &line)
return true;
}
bool
console_cmd__db__wal(opt &out, const string_view &line)
try
{
const params param{line, " ",
{
"dbname",
}};
const auto dbname
{
param.at("dbname")
};
auto &database
{
db::database::get(dbname)
};
const db::database::wal::info::vector vec
{
database
};
out
<< std::setw(12) << std::left << "PATH" << " "
<< std::setw(8) << std::left << "ID" << " "
<< std::setw(12) << std::right << "START SEQ" << " "
<< std::setw(20) << std::left << "SIZE" << " "
<< std::setw(8) << std::left << "STATUS" << " "
<< std::endl;
for(const auto &info : vec)
out
<< std::setw(12) << std::left << info.name << " "
<< std::setw(8) << std::left << info.number << " "
<< std::setw(12) << std::right << info.seq << " "
<< std::setw(20) << std::left << pretty(iec(info.size)) << " "
<< std::setw(8) << std::left << (info.alive? "LIVE"_sv : "ARCHIVE"_sv) << " "
<< std::endl;
return true;
}
catch(const std::out_of_range &e)
{
out << "No open database by that name" << std::endl;
return true;
}
bool
console_cmd__db__files(opt &out, const string_view &line)
try