Snapshot flags name consistency

Reviewers: buda, mferencevic

Reviewed By: mferencevic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D821
This commit is contained in:
florijan 2017-09-22 09:58:54 +02:00
parent e224199b36
commit ff37c04b38
15 changed files with 54 additions and 56 deletions

View File

@ -21,17 +21,16 @@
--snapshot-cycle-sec=300 --snapshot-cycle-sec=300
# create snapshot disabled on db exit # create snapshot disabled on db exit
--snapshot-on-db-exit=true --snapshot-on-exit=true
# max number of snapshots which will be kept on the disk at some point # max number of snapshots which will be kept on the disk at some point
# if set to -1 the max number of snapshots is unlimited # if set to -1 the max number of snapshots is unlimited
--max-retained-snapshots=3 --snapshot-max-retained=3
# by default query engine runs in interpret mode # by default query engine runs in interpret mode
--interpret=true --interpret=true
# database recovering is disabled by default --snapshot-recover-on-startup=true
--recover-on-startup=true
# use ast caching # use ast caching
--ast-cache=false --ast-cache=false

View File

@ -29,17 +29,17 @@
--query_execution_time_sec=-1 --query_execution_time_sec=-1
# create snapshot disabled on db exit # create snapshot disabled on db exit
--snapshot-on-db-exit=false --snapshot-on-exit=false
# max number of snapshots which will be kept on the disk at some point # max number of snapshots which will be kept on the disk at some point
# if set to -1 the max number of snapshots is unlimited # if set to -1 the max number of snapshots is unlimited
--max-retained-snapshots=-1 --snapshot-max-retained=-1
# by default query engine runs in interpret mode # by default query engine runs in interpret mode
--interpret=true --interpret=true
# database recovering is disabled by default # database recovering is disabled by default
--recover-on-startup=false --snapshot-recover-on-startup=false
# use ast caching # use ast caching
--ast-cache=true --ast-cache=true

View File

@ -21,17 +21,17 @@
--query_execution_time_sec=-1 --query_execution_time_sec=-1
# create snapshot disabled on db exit # create snapshot disabled on db exit
--snapshot-on-db-exit=false --snapshot-on-exit=false
# max number of snapshots which will be kept on the disk at some point # max number of snapshots which will be kept on the disk at some point
# if set to -1 the max number of snapshots is unlimited # if set to -1 the max number of snapshots is unlimited
--max-retained-snapshots=-1 --snapshot-max-retained=-1
# by default query engine runs in interpret mode # by default query engine runs in interpret mode
--interpret=true --interpret=true
# database recovering is disabled by default # database recovering is disabled by default
--recover-on-startup=false --snapshot-recover-on-startup=false
# use ast caching # use ast caching
--ast-cache=true --ast-cache=true

View File

@ -21,17 +21,17 @@
--snapshot-cycle-sec=600 --snapshot-cycle-sec=600
# create snapshot enabled on db exit # create snapshot enabled on db exit
--snapshot-on-db-exit=true --snapshot-on-exit=true
# max number of snapshots which will be kept on the disk at some point # max number of snapshots which will be kept on the disk at some point
# if set to -1 the max number of snapshots is unlimited # if set to -1 the max number of snapshots is unlimited
--max-retained-snapshots=1 --snapshot-max-retained=1
# by default query engine runs in interpret mode # by default query engine runs in interpret mode
--interpret=true --interpret=true
# database recovering is disabled by default # database recovering is disabled by default
--recover-on-startup=false --snapshot-recover-on-startup=false
# use ast caching # use ast caching
--ast-cache=true --ast-cache=true

View File

@ -21,17 +21,17 @@
--snapshot-cycle-sec=-1 --snapshot-cycle-sec=-1
# create snapshot disabled on db exit # create snapshot disabled on db exit
--snapshot-on-db-exit=true --snapshot-on-exit=true
# max number of snapshots which will be kept on the disk at some point # max number of snapshots which will be kept on the disk at some point
# if set to -1 the max number of snapshots is unlimited # if set to -1 the max number of snapshots is unlimited
--max-retained-snapshots=-1 --snapshot-max-retained=-1
# by default query engine runs in interpret mode # by default query engine runs in interpret mode
--interpret=true --interpret=true
# database recovering is disabled by default # database recovering is disabled by default
--recover-on-startup=false --snapshot-recover-on-startup=false
# use ast caching # use ast caching
--ast-cache=true --ast-cache=true

View File

@ -68,9 +68,9 @@ parameters:
--port | integer | 7687 | Communication port on which to listen. --port | integer | 7687 | Communication port on which to listen.
--num-workers | integer | CPU count[^1] | Number of Memgraph worker threads. --num-workers | integer | CPU count[^1] | Number of Memgraph worker threads.
--snapshot-cycle-sec | integer | 300 | Interval (seconds) between database snapshots.<br/>Value of -1 turns taking snapshots off. --snapshot-cycle-sec | integer | 300 | Interval (seconds) between database snapshots.<br/>Value of -1 turns taking snapshots off.
--max-retained-snapshots | integer | 3 | Number of retained snapshots.<br/>Value -1 means without limit. --snapshot-max-retained | integer | 3 | Number of retained snapshots.<br/>Value -1 means without limit.
--snapshot-on-db-exit | bool | false | Make a snapshot when closing Memgraph. --snapshot-on-exit | bool | false | Make a snapshot when closing Memgraph.
--recover-on-startup | bool | false | Recover the database on startup using the last<br/>stored snapshot. --snapshot-recover-on-startup | bool | false | Recover the database on startup using the last<br/>stored snapshot.
--query-execution-time-sec | integer | 180 | Maximum allowed query execution time. <br/>Queries exceeding this limit will be aborted. Value of -1 means no limit. --query-execution-time-sec | integer | 180 | Maximum allowed query execution time. <br/>Queries exceeding this limit will be aborted. Value of -1 means no limit.
[^1]: Maximum number of concurrent executions on the current CPU. [^1]: Maximum number of concurrent executions on the current CPU.

View File

@ -4,7 +4,7 @@
DEFINE_string(snapshot_directory, "snapshots", DEFINE_string(snapshot_directory, "snapshots",
"Relative path to directory in which to save snapshots."); "Relative path to directory in which to save snapshots.");
DEFINE_bool(recover_on_startup, false, "Recover database on startup."); DEFINE_bool(snapshot_recover_on_startup, false, "Recover database on startup.");
std::unique_ptr<GraphDbAccessor> Dbms::active() { std::unique_ptr<GraphDbAccessor> Dbms::active() {
return std::make_unique<GraphDbAccessor>( return std::make_unique<GraphDbAccessor>(

View File

@ -13,7 +13,7 @@
#include "utils/exceptions.hpp" #include "utils/exceptions.hpp"
DECLARE_string(snapshot_directory); DECLARE_string(snapshot_directory);
DECLARE_bool(recover_on_startup); DECLARE_bool(snapshot_recover_on_startup);
namespace fs = std::experimental::filesystem; namespace fs = std::experimental::filesystem;
@ -45,7 +45,7 @@ class Dbms {
throw utils::BasicException("Specified snapshot directory is a file!"); throw utils::BasicException("Specified snapshot directory is a file!");
} }
if (FLAGS_recover_on_startup) { if (FLAGS_snapshot_recover_on_startup) {
if (fs::exists(snapshot_root_dir)) { if (fs::exists(snapshot_root_dir)) {
auto accessor = dbs.access(); auto accessor = dbs.access();
for (auto &snapshot_db_dir : for (auto &snapshot_db_dir :

View File

@ -13,7 +13,7 @@
DEFINE_int32(gc_cycle_sec, 30, DEFINE_int32(gc_cycle_sec, 30,
"Amount of time between starts of two cleaning cycles in seconds. " "Amount of time between starts of two cleaning cycles in seconds. "
"-1 to turn off."); "-1 to turn off.");
DEFINE_int32(max_retained_snapshots, -1, DEFINE_int32(snapshot_max_retained, -1,
"Number of retained snapshots, -1 means without limit."); "Number of retained snapshots, -1 means without limit.");
DEFINE_int32(snapshot_cycle_sec, -1, DEFINE_int32(snapshot_cycle_sec, -1,
"Amount of time between starts of two snapshooters in seconds. -1 " "Amount of time between starts of two snapshooters in seconds. -1 "
@ -22,7 +22,7 @@ DEFINE_int32(query_execution_time_sec, 180,
"Maximum allowed query execution time. Queries exceeding this " "Maximum allowed query execution time. Queries exceeding this "
"limit will be aborted. Value of -1 means no limit."); "limit will be aborted. Value of -1 means no limit.");
DEFINE_bool(snapshot_on_db_exit, false, "Snapshot on exiting the database."); DEFINE_bool(snapshot_on_exit, false, "Snapshot on exiting the database.");
DECLARE_string(snapshot_directory); DECLARE_string(snapshot_directory);
@ -61,7 +61,7 @@ void GraphDb::StartSnapshooting() {
GraphDbAccessor db_accessor(*this); GraphDbAccessor db_accessor(*this);
snapshooter_.MakeSnapshot(db_accessor, snapshooter_.MakeSnapshot(db_accessor,
fs::path(FLAGS_snapshot_directory) / name_, fs::path(FLAGS_snapshot_directory) / name_,
FLAGS_max_retained_snapshots); FLAGS_snapshot_max_retained);
}; };
snapshot_creator_.Run(std::chrono::seconds(FLAGS_snapshot_cycle_sec), snapshot_creator_.Run(std::chrono::seconds(FLAGS_snapshot_cycle_sec),
create_snapshot); create_snapshot);
@ -134,12 +134,12 @@ GraphDb::~GraphDb() {
transaction_killer_.Stop(); transaction_killer_.Stop();
// Create last database snapshot // Create last database snapshot
if (FLAGS_snapshot_on_db_exit == true) { if (FLAGS_snapshot_on_exit == true) {
GraphDbAccessor db_accessor(*this); GraphDbAccessor db_accessor(*this);
LOG(INFO) << "Creating snapshot on shutdown..." << std::endl; LOG(INFO) << "Creating snapshot on shutdown..." << std::endl;
const bool status = snapshooter_.MakeSnapshot( const bool status = snapshooter_.MakeSnapshot(
db_accessor, fs::path(FLAGS_snapshot_directory) / name_, db_accessor, fs::path(FLAGS_snapshot_directory) / name_,
FLAGS_max_retained_snapshots); FLAGS_snapshot_max_retained);
if (status) { if (status) {
std::cout << "Snapshot created successfully." << std::endl; std::cout << "Snapshot created successfully." << std::endl;
} else { } else {

View File

@ -11,7 +11,7 @@
bool Snapshooter::MakeSnapshot(GraphDbAccessor &db_accessor_, bool Snapshooter::MakeSnapshot(GraphDbAccessor &db_accessor_,
const fs::path &snapshot_folder, const fs::path &snapshot_folder,
const int max_retained_snapshots) { const int snapshot_max_retained) {
if (!fs::exists(snapshot_folder) && if (!fs::exists(snapshot_folder) &&
!fs::create_directories(snapshot_folder)) { !fs::create_directories(snapshot_folder)) {
LOG(ERROR) << "Error while creating directory " << snapshot_folder; LOG(ERROR) << "Error while creating directory " << snapshot_folder;
@ -20,7 +20,7 @@ bool Snapshooter::MakeSnapshot(GraphDbAccessor &db_accessor_,
const auto snapshot_file = GetSnapshotFileName(snapshot_folder); const auto snapshot_file = GetSnapshotFileName(snapshot_folder);
if (fs::exists(snapshot_file)) return false; if (fs::exists(snapshot_file)) return false;
if (Encode(snapshot_file, db_accessor_)) { if (Encode(snapshot_file, db_accessor_)) {
MaintainMaxRetainedFiles(snapshot_folder, max_retained_snapshots); MaintainMaxRetainedFiles(snapshot_folder, snapshot_max_retained);
return true; return true;
} }
return false; return false;
@ -80,12 +80,12 @@ std::vector<fs::path> Snapshooter::GetSnapshotFiles(
} }
void Snapshooter::MaintainMaxRetainedFiles(const fs::path &snapshot_folder, void Snapshooter::MaintainMaxRetainedFiles(const fs::path &snapshot_folder,
int max_retained_snapshots) { int snapshot_max_retained) {
if (max_retained_snapshots == -1) return; if (snapshot_max_retained == -1) return;
std::vector<fs::path> files = GetSnapshotFiles(snapshot_folder); std::vector<fs::path> files = GetSnapshotFiles(snapshot_folder);
if (static_cast<int>(files.size()) <= max_retained_snapshots) return; if (static_cast<int>(files.size()) <= snapshot_max_retained) return;
sort(files.begin(), files.end()); sort(files.begin(), files.end());
for (int i = 0; i < static_cast<int>(files.size()) - max_retained_snapshots; for (int i = 0; i < static_cast<int>(files.size()) - snapshot_max_retained;
++i) { ++i) {
if (!fs::remove(files[i])) { if (!fs::remove(files[i])) {
LOG(ERROR) << "Error while removing file: " << files[i]; LOG(ERROR) << "Error while removing file: " << files[i];

View File

@ -21,12 +21,12 @@ class Snapshooter {
* GraphDbAccessor used to access elements of GraphDb. * GraphDbAccessor used to access elements of GraphDb.
* @param snapshot_folder: * @param snapshot_folder:
* folder where snapshots are stored. * folder where snapshots are stored.
* @param max_retained_snapshots: * @param snapshot_max_retained:
* maximum number of snapshots stored in snapshot folder. * maximum number of snapshots stored in snapshot folder.
*/ */
bool MakeSnapshot(GraphDbAccessor &db_accessor, bool MakeSnapshot(GraphDbAccessor &db_accessor,
const fs::path &snapshot_folder, const fs::path &snapshot_folder,
int max_retained_snapshots); int snapshot_max_retained);
private: private:
/** /**

View File

@ -21,17 +21,16 @@
--snapshot-cycle-sec=-1 --snapshot-cycle-sec=-1
# create snapshot disabled on db exit # create snapshot disabled on db exit
--snapshot-on-db-exit=false --snapshot-on-exit=false
# max number of snapshots which will be kept on the disk at some point # max number of snapshots which will be kept on the disk at some point
# if set to -1 the max number of snapshots is unlimited # if set to -1 the max number of snapshots is unlimited
--max-retained-snapshots=-1 --snapshot-max-retained=-1
# by default query engine runs in interpret mode # by default query engine runs in interpret mode
--interpret=true --interpret=true
# database recovering is disabled by default --snapshot-recover-on-startup=true
--recover-on-startup=true
# use ast caching # use ast caching
--ast-cache=true --ast-cache=true

View File

@ -43,7 +43,7 @@ class DbmsRecoveryTest : public ::testing::Test {
}; };
void CreateSnapshot() { void CreateSnapshot() {
FLAGS_recover_on_startup = false; FLAGS_snapshot_recover_on_startup = false;
Dbms dbms; Dbms dbms;
auto dba = dbms.active(); auto dba = dbms.active();
@ -62,7 +62,7 @@ void CreateSnapshot() {
} }
void RecoverDbms() { void RecoverDbms() {
FLAGS_recover_on_startup = true; FLAGS_snapshot_recover_on_startup = true;
Dbms dbms; Dbms dbms;
auto dba = dbms.active(); auto dba = dbms.active();

View File

@ -44,7 +44,7 @@ class RecoveryTest : public ::testing::Test {
CleanDbDir(); CleanDbDir();
FLAGS_snapshot_cycle_sec = -1; FLAGS_snapshot_cycle_sec = -1;
} }
const int max_retained_snapshots_ = 10; const int snapshot_max_retained_ = 10;
}; };
void CreateSmallGraph(Dbms &dbms) { void CreateSmallGraph(Dbms &dbms) {
@ -78,11 +78,11 @@ void CreateBigGraph(Dbms &dbms) {
dba->Commit(); dba->Commit();
} }
void TakeSnapshot(Dbms &dbms, int max_retained_snapshots_) { void TakeSnapshot(Dbms &dbms, int snapshot_max_retained_) {
auto dba = dbms.active(); auto dba = dbms.active();
Snapshooter snapshooter; Snapshooter snapshooter;
snapshooter.MakeSnapshot(*dba.get(), SNAPSHOTS_RECOVERY_DEFAULT_DB_DIR, snapshooter.MakeSnapshot(*dba.get(), SNAPSHOTS_RECOVERY_DEFAULT_DB_DIR,
max_retained_snapshots_); snapshot_max_retained_);
} }
std::string GetLatestSnapshot() { std::string GetLatestSnapshot() {
@ -100,7 +100,7 @@ TEST_F(RecoveryTest, TestEncoding) {
// reading graph is tested. // reading graph is tested.
Dbms dbms; Dbms dbms;
CreateSmallGraph(dbms); CreateSmallGraph(dbms);
TakeSnapshot(dbms, max_retained_snapshots_); TakeSnapshot(dbms, snapshot_max_retained_);
std::string snapshot = GetLatestSnapshot(); std::string snapshot = GetLatestSnapshot();
FileReaderBuffer buffer; FileReaderBuffer buffer;
@ -150,7 +150,7 @@ TEST_F(RecoveryTest, TestEncodingAndDecoding) {
// the snapshot file. After creation graph is tested. // the snapshot file. After creation graph is tested.
Dbms dbms; Dbms dbms;
CreateSmallGraph(dbms); CreateSmallGraph(dbms);
TakeSnapshot(dbms, max_retained_snapshots_); TakeSnapshot(dbms, snapshot_max_retained_);
std::string snapshot = GetLatestSnapshot(); std::string snapshot = GetLatestSnapshot();
// New dbms is needed - old dbms has database "default" // New dbms is needed - old dbms has database "default"
@ -193,7 +193,7 @@ TEST_F(RecoveryTest, TestEncodingAndRecovering) {
// the snapshot file. After creation graph is tested. // the snapshot file. After creation graph is tested.
Dbms dbms; Dbms dbms;
CreateBigGraph(dbms); CreateBigGraph(dbms);
TakeSnapshot(dbms, max_retained_snapshots_); TakeSnapshot(dbms, snapshot_max_retained_);
std::string snapshot = GetLatestSnapshot(); std::string snapshot = GetLatestSnapshot();
// New dbms is needed - old dbms has database "default" // New dbms is needed - old dbms has database "default"
@ -236,7 +236,7 @@ TEST_F(RecoveryTest, TestLabelPropertyIndexRecovery) {
dba->BuildIndex(dba->Label("label"), dba->Property("prop")); dba->BuildIndex(dba->Label("label"), dba->Property("prop"));
dba->Commit(); dba->Commit();
CreateBigGraph(dbms); CreateBigGraph(dbms);
TakeSnapshot(dbms, max_retained_snapshots_); TakeSnapshot(dbms, snapshot_max_retained_);
std::string snapshot = GetLatestSnapshot(); std::string snapshot = GetLatestSnapshot();
Dbms dbms_recover; Dbms dbms_recover;

View File

@ -6,7 +6,7 @@
#include "database/dbms.hpp" #include "database/dbms.hpp"
#include "durability/snapshooter.hpp" #include "durability/snapshooter.hpp"
DECLARE_bool(snapshot_on_db_exit); DECLARE_bool(snapshot_on_exit);
DECLARE_int32(snapshot_cycle_sec); DECLARE_int32(snapshot_cycle_sec);
DECLARE_string(snapshot_directory); DECLARE_string(snapshot_directory);
@ -47,14 +47,14 @@ class SnapshotTest : public ::testing::Test {
}; };
TEST_F(SnapshotTest, CreateLessThanMaxRetainedSnapshotsTests) { TEST_F(SnapshotTest, CreateLessThanMaxRetainedSnapshotsTests) {
const int max_retained_snapshots = 10; const int snapshot_max_retained = 10;
Dbms dbms; Dbms dbms;
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
auto dba = dbms.active(); auto dba = dbms.active();
Snapshooter snapshooter; Snapshooter snapshooter;
snapshooter.MakeSnapshot(*dba.get(), SNAPSHOTS_TEST_DEFAULT_DB_DIR, snapshooter.MakeSnapshot(*dba.get(), SNAPSHOTS_TEST_DEFAULT_DB_DIR,
max_retained_snapshots); snapshot_max_retained);
} }
std::vector<fs::path> files = GetFilesFromDir(SNAPSHOTS_TEST_DEFAULT_DB_DIR); std::vector<fs::path> files = GetFilesFromDir(SNAPSHOTS_TEST_DEFAULT_DB_DIR);
@ -62,7 +62,7 @@ TEST_F(SnapshotTest, CreateLessThanMaxRetainedSnapshotsTests) {
} }
TEST_F(SnapshotTest, CreateMoreThanMaxRetainedSnapshotsTests) { TEST_F(SnapshotTest, CreateMoreThanMaxRetainedSnapshotsTests) {
const int max_retained_snapshots = 2; const int snapshot_max_retained = 2;
Dbms dbms; Dbms dbms;
fs::path first_snapshot; fs::path first_snapshot;
@ -70,7 +70,7 @@ TEST_F(SnapshotTest, CreateMoreThanMaxRetainedSnapshotsTests) {
auto dba = dbms.active(); auto dba = dbms.active();
Snapshooter snapshooter; Snapshooter snapshooter;
snapshooter.MakeSnapshot(*dba.get(), SNAPSHOTS_TEST_DEFAULT_DB_DIR, snapshooter.MakeSnapshot(*dba.get(), SNAPSHOTS_TEST_DEFAULT_DB_DIR,
max_retained_snapshots); snapshot_max_retained);
if (i == 0) { if (i == 0) {
std::vector<fs::path> files_begin = std::vector<fs::path> files_begin =
GetFilesFromDir(SNAPSHOTS_TEST_DEFAULT_DB_DIR); GetFilesFromDir(SNAPSHOTS_TEST_DEFAULT_DB_DIR);
@ -86,14 +86,14 @@ TEST_F(SnapshotTest, CreateMoreThanMaxRetainedSnapshotsTests) {
} }
TEST_F(SnapshotTest, CreateSnapshotWithUnlimitedMaxRetainedSnapshots) { TEST_F(SnapshotTest, CreateSnapshotWithUnlimitedMaxRetainedSnapshots) {
const int max_retained_snapshots = -1; const int snapshot_max_retained = -1;
Dbms dbms; Dbms dbms;
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
auto dba = dbms.active(); auto dba = dbms.active();
Snapshooter snapshooter; Snapshooter snapshooter;
snapshooter.MakeSnapshot(*dba.get(), SNAPSHOTS_TEST_DEFAULT_DB_DIR, snapshooter.MakeSnapshot(*dba.get(), SNAPSHOTS_TEST_DEFAULT_DB_DIR,
max_retained_snapshots); snapshot_max_retained);
} }
std::vector<fs::path> files = GetFilesFromDir(SNAPSHOTS_TEST_DEFAULT_DB_DIR); std::vector<fs::path> files = GetFilesFromDir(SNAPSHOTS_TEST_DEFAULT_DB_DIR);
@ -103,7 +103,7 @@ TEST_F(SnapshotTest, CreateSnapshotWithUnlimitedMaxRetainedSnapshots) {
TEST_F(SnapshotTest, TestSnapshotFileOnDbDestruct) { TEST_F(SnapshotTest, TestSnapshotFileOnDbDestruct) {
{ {
FLAGS_snapshot_directory = SNAPSHOTS_FOLDER_ALL_DB; FLAGS_snapshot_directory = SNAPSHOTS_FOLDER_ALL_DB;
FLAGS_snapshot_on_db_exit = true; FLAGS_snapshot_on_exit = true;
Dbms dbms; Dbms dbms;
auto dba = dbms.active(); auto dba = dbms.active();
} }