Skip to content

Commit 6b453e9

Browse files
committed
Move CheckpointConfig to its own file
Move CheckpointConfig from checkpoint.{h,cc} to new files checkpoint_config.{h,cc}, reducind the number of files which need to directly include checkpoint.h. Change-Id: I2eadb69604aadcd33526e5a1a50883e1e84347b1 Reviewed-on: http://review.couchbase.org/82687 Reviewed-by: James Harrison <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent 5e08ba2 commit 6b453e9

File tree

8 files changed

+305
-234
lines changed

8 files changed

+305
-234
lines changed

engines/ep/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ ADD_LIBRARY(ep_objs OBJECT
168168
src/bloomfilter.cc
169169
src/callbacks.cc
170170
src/checkpoint.cc
171+
src/checkpoint_config.cc
171172
src/checkpoint_remover.cc
172173
src/conflict_resolution.cc
173174
src/connhandler.cc

engines/ep/src/checkpoint.cc

Lines changed: 0 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,6 @@ const char* to_string(enum checkpoint_state s) {
4141
return "<unknown>";
4242
}
4343

44-
/**
45-
* A listener class to update checkpoint related configs at runtime.
46-
*/
47-
class CheckpointConfigChangeListener : public ValueChangedListener {
48-
public:
49-
CheckpointConfigChangeListener(CheckpointConfig &c) : config(c) { }
50-
virtual ~CheckpointConfigChangeListener() { }
51-
52-
virtual void sizeValueChanged(const std::string &key, size_t value) {
53-
if (key.compare("chk_period") == 0) {
54-
config.setCheckpointPeriod(value);
55-
} else if (key.compare("chk_max_items") == 0) {
56-
config.setCheckpointMaxItems(value);
57-
} else if (key.compare("max_checkpoints") == 0) {
58-
config.setMaxCheckpoints(value);
59-
}
60-
}
61-
62-
virtual void booleanValueChanged(const std::string &key, bool value) {
63-
if (key.compare("item_num_based_new_chk") == 0) {
64-
config.allowItemNumBasedNewCheckpoint(value);
65-
} else if (key.compare("keep_closed_chks") == 0) {
66-
config.allowKeepClosedCheckpoints(value);
67-
} else if (key.compare("enable_chk_merge") == 0) {
68-
config.allowCheckpointMerge(value);
69-
}
70-
}
71-
72-
private:
73-
CheckpointConfig &config;
74-
};
75-
7644
void CheckpointCursor::decrOffset(size_t decr) {
7745
if (offset >= decr) {
7846
offset.fetch_sub(decr);
@@ -1925,99 +1893,6 @@ size_t CheckpointManager::getMemoryUsageOfUnrefCheckpoints() {
19251893
return memUsage;
19261894
}
19271895

1928-
void CheckpointConfig::addConfigChangeListener(
1929-
EventuallyPersistentEngine &engine) {
1930-
Configuration &configuration = engine.getConfiguration();
1931-
configuration.addValueChangedListener("chk_period",
1932-
new CheckpointConfigChangeListener(engine.getCheckpointConfig()));
1933-
configuration.addValueChangedListener("chk_max_items",
1934-
new CheckpointConfigChangeListener(engine.getCheckpointConfig()));
1935-
configuration.addValueChangedListener("max_checkpoints",
1936-
new CheckpointConfigChangeListener(engine.getCheckpointConfig()));
1937-
configuration.addValueChangedListener("item_num_based_new_chk",
1938-
new CheckpointConfigChangeListener(engine.getCheckpointConfig()));
1939-
configuration.addValueChangedListener("keep_closed_chks",
1940-
new CheckpointConfigChangeListener(engine.getCheckpointConfig()));
1941-
configuration.addValueChangedListener("enable_chk_merge",
1942-
new CheckpointConfigChangeListener(engine.getCheckpointConfig()));
1943-
}
1944-
1945-
CheckpointConfig::CheckpointConfig(EventuallyPersistentEngine &e) {
1946-
Configuration &config = e.getConfiguration();
1947-
checkpointPeriod = config.getChkPeriod();
1948-
checkpointMaxItems = config.getChkMaxItems();
1949-
maxCheckpoints = config.getMaxCheckpoints();
1950-
itemNumBasedNewCheckpoint = config.isItemNumBasedNewChk();
1951-
keepClosedCheckpoints = config.isKeepClosedChks();
1952-
enableChkMerge = config.isEnableChkMerge();
1953-
persistenceEnabled = config.getBucketType() == "persistent";
1954-
}
1955-
1956-
bool CheckpointConfig::validateCheckpointMaxItemsParam(size_t
1957-
checkpoint_max_items) {
1958-
if (checkpoint_max_items < MIN_CHECKPOINT_ITEMS ||
1959-
checkpoint_max_items > MAX_CHECKPOINT_ITEMS) {
1960-
std::stringstream ss;
1961-
ss << "New checkpoint_max_items param value " << checkpoint_max_items
1962-
<< " is not ranged between the min allowed value " <<
1963-
MIN_CHECKPOINT_ITEMS
1964-
<< " and max value " << MAX_CHECKPOINT_ITEMS;
1965-
LOG(EXTENSION_LOG_WARNING, "%s", ss.str().c_str());
1966-
return false;
1967-
}
1968-
return true;
1969-
}
1970-
1971-
bool CheckpointConfig::validateCheckpointPeriodParam(
1972-
size_t checkpoint_period) {
1973-
if (checkpoint_period < MIN_CHECKPOINT_PERIOD ||
1974-
checkpoint_period > MAX_CHECKPOINT_PERIOD) {
1975-
std::stringstream ss;
1976-
ss << "New checkpoint_period param value " << checkpoint_period
1977-
<< " is not ranged between the min allowed value " <<
1978-
MIN_CHECKPOINT_PERIOD
1979-
<< " and max value " << MAX_CHECKPOINT_PERIOD;
1980-
LOG(EXTENSION_LOG_WARNING, "%s\n", ss.str().c_str());
1981-
return false;
1982-
}
1983-
return true;
1984-
}
1985-
1986-
bool CheckpointConfig::validateMaxCheckpointsParam(size_t max_checkpoints) {
1987-
if (max_checkpoints < DEFAULT_MAX_CHECKPOINTS ||
1988-
max_checkpoints > MAX_CHECKPOINTS_UPPER_BOUND) {
1989-
std::stringstream ss;
1990-
ss << "New max_checkpoints param value " << max_checkpoints
1991-
<< " is not ranged between the min allowed value " <<
1992-
DEFAULT_MAX_CHECKPOINTS
1993-
<< " and max value " << MAX_CHECKPOINTS_UPPER_BOUND;
1994-
LOG(EXTENSION_LOG_WARNING, "%s\n", ss.str().c_str());
1995-
return false;
1996-
}
1997-
return true;
1998-
}
1999-
2000-
void CheckpointConfig::setCheckpointPeriod(size_t value) {
2001-
if (!validateCheckpointPeriodParam(value)) {
2002-
value = DEFAULT_CHECKPOINT_PERIOD;
2003-
}
2004-
checkpointPeriod = static_cast<rel_time_t>(value);
2005-
}
2006-
2007-
void CheckpointConfig::setCheckpointMaxItems(size_t value) {
2008-
if (!validateCheckpointMaxItemsParam(value)) {
2009-
value = DEFAULT_CHECKPOINT_ITEMS;
2010-
}
2011-
checkpointMaxItems = value;
2012-
}
2013-
2014-
void CheckpointConfig::setMaxCheckpoints(size_t value) {
2015-
if (!validateMaxCheckpointsParam(value)) {
2016-
value = DEFAULT_MAX_CHECKPOINTS;
2017-
}
2018-
maxCheckpoints = value;
2019-
}
2020-
20211896
void CheckpointManager::addStats(ADD_STAT add_stat, const void *cookie) {
20221897
LockHolder lh(queueLock);
20231898
char buf[256];

engines/ep/src/checkpoint.h

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ struct index_entry {
7171
int64_t mutation_id;
7272
};
7373

74-
typedef struct {
75-
uint64_t start;
76-
uint64_t end;
77-
} snapshot_range_t;
78-
7974
typedef struct {
8075
uint64_t start;
8176
snapshot_range_t range;
@@ -993,107 +988,4 @@ class CheckpointManager {
993988
// Outputs a textual description of the CheckpointManager.
994989
std::ostream& operator<<(std::ostream& os, const CheckpointManager& m);
995990

996-
/**
997-
* A class containing the config parameters for checkpoint.
998-
*/
999-
1000-
class CheckpointConfig {
1001-
public:
1002-
CheckpointConfig()
1003-
: checkpointPeriod(DEFAULT_CHECKPOINT_PERIOD),
1004-
checkpointMaxItems(DEFAULT_CHECKPOINT_ITEMS),
1005-
maxCheckpoints(DEFAULT_MAX_CHECKPOINTS),
1006-
itemNumBasedNewCheckpoint(true),
1007-
keepClosedCheckpoints(false),
1008-
enableChkMerge(false),
1009-
persistenceEnabled(true)
1010-
{ /* empty */ }
1011-
1012-
CheckpointConfig(rel_time_t period, size_t max_items, size_t max_ckpts,
1013-
bool item_based_new_ckpt, bool keep_closed_ckpts,
1014-
bool enable_ckpt_merge, bool persistence_enabled)
1015-
: checkpointPeriod(period),
1016-
checkpointMaxItems(max_items),
1017-
maxCheckpoints(max_ckpts),
1018-
itemNumBasedNewCheckpoint(item_based_new_ckpt),
1019-
keepClosedCheckpoints(keep_closed_ckpts),
1020-
enableChkMerge(enable_ckpt_merge),
1021-
persistenceEnabled(persistence_enabled) {}
1022-
1023-
CheckpointConfig(EventuallyPersistentEngine &e);
1024-
1025-
rel_time_t getCheckpointPeriod() const {
1026-
return checkpointPeriod;
1027-
}
1028-
1029-
size_t getCheckpointMaxItems() const {
1030-
return checkpointMaxItems;
1031-
}
1032-
1033-
size_t getMaxCheckpoints() const {
1034-
return maxCheckpoints;
1035-
}
1036-
1037-
bool isItemNumBasedNewCheckpoint() const {
1038-
return itemNumBasedNewCheckpoint;
1039-
}
1040-
1041-
bool canKeepClosedCheckpoints() const {
1042-
return keepClosedCheckpoints;
1043-
}
1044-
1045-
bool isCheckpointMergeSupported() const {
1046-
return enableChkMerge;
1047-
}
1048-
1049-
bool isPersistenceEnabled() const {
1050-
return persistenceEnabled;
1051-
}
1052-
1053-
protected:
1054-
friend class CheckpointConfigChangeListener;
1055-
friend class EventuallyPersistentEngine;
1056-
1057-
bool validateCheckpointMaxItemsParam(size_t checkpoint_max_items);
1058-
bool validateCheckpointPeriodParam(size_t checkpoint_period);
1059-
bool validateMaxCheckpointsParam(size_t max_checkpoints);
1060-
1061-
void setCheckpointPeriod(size_t value);
1062-
void setCheckpointMaxItems(size_t value);
1063-
void setMaxCheckpoints(size_t value);
1064-
1065-
void allowItemNumBasedNewCheckpoint(bool value) {
1066-
itemNumBasedNewCheckpoint = value;
1067-
}
1068-
1069-
void allowKeepClosedCheckpoints(bool value) {
1070-
keepClosedCheckpoints = value;
1071-
}
1072-
1073-
void allowCheckpointMerge(bool value) {
1074-
enableChkMerge = value;
1075-
}
1076-
1077-
static void addConfigChangeListener(EventuallyPersistentEngine &engine);
1078-
1079-
private:
1080-
// Period of a checkpoint in terms of time in sec
1081-
rel_time_t checkpointPeriod;
1082-
// Number of max items allowed in each checkpoint
1083-
size_t checkpointMaxItems;
1084-
// Number of max checkpoints allowed
1085-
size_t maxCheckpoints;
1086-
// Flag indicating if a new checkpoint is created once the number of items in the current
1087-
// checkpoint is greater than the max number allowed.
1088-
bool itemNumBasedNewCheckpoint;
1089-
// Flag indicating if closed checkpoints should be kept in memory if the current memory usage
1090-
// below the high water mark.
1091-
bool keepClosedCheckpoints;
1092-
// Flag indicating if merging closed checkpoints is enabled or not.
1093-
bool enableChkMerge;
1094-
1095-
// Flag indicating if persistence is enabled.
1096-
bool persistenceEnabled;
1097-
};
1098-
1099991
#endif // SRC_CHECKPOINT_H_

0 commit comments

Comments
 (0)