8000 Only allow to create replication2 database in MaintainerMode (#20619) · 0ArtemBabaev/arangodb@7512660 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7512660

Browse files
authored
Only allow to create replication2 database in MaintainerMode (arangodb#20619)
* Only allow to create replication2 database in MaintainerMode * Also made the FeatureFlag maintainer only * Revert "Only allow to create replication2 database in MaintainerMode" This reverts commit 47036e1. * Removed unused function * Prohibit start of Coordinators if --database.default-replication-version is changed * FATAL exit if Replication2 is found for non-maintainer build * Fatal crash a Coordinator if it sees a rep2 database that it cannot handle * Let DBServers persist the ReplicationVersion of their database. This is not strictly required but is cleaner * Throw an error when we try to use replication2 in a non-replication2 binary * Fixed clang-format
1 parent b0081ff commit 7512660

File tree

6 files changed

+90
-35
lines changed

6 files changed

+90
-35
lines changed

arangod/Cluster/ClusterInfo.cpp

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "Agency/Supervision.h"
3232
#include "ApplicationFeatures/ApplicationServer.h"
3333
#include "Basics/Exceptions.h"
34+
#include "Basics/FeatureFlags.h"
3435
#include "Basics/GlobalResourceMonitor.h"
3536
#include "Basics/GlobalSerialization.h"
3637
#include "Basics/NumberUtils.h"
@@ -1067,6 +1068,24 @@ void ClusterInfo::loadPlan() {
10671068
// the startup once the extended names option is turned off.
10681069
info.validateNames(false);
10691070

1071+
if (!arangodb::replication2::EnableReplication2) {
1072+
// We right now cannot run a replication2 database on a coordinator
1073+
// that has replication2 disabled
1074+
if (info.replicationVersion() == arangodb::replication::Version::TWO) {
1075+
LOG_TOPIC("8fdd8", FATAL, Logger::REPLICATION2)
1076+
<< "Replication version 2 is disabled in this binary, but "
1077+
"loading a "
1078+
"version 2 database "
1079+
<< "(named '" << info.getName() << "'). "
1080+
<< "Creating such databases is disabled. Please dump the data, "
1081+
"and "
1082+
"recreate the database with replication version 1 (the "
1083+
"default), "
1084+
"and then restore the data.";
1085+
FATAL_ERROR_EXIT();
1086+
}
1087+
}
1088+
10701089
Result res = info.load(dbSlice, VPackSlice::emptyArraySlice());
10711090

10721091
if (res.fail()) {
@@ -1731,18 +1750,56 @@ void ClusterInfo::loadPlan() {
17311750
}
17321751
}
17331752

1734-
// The systemDB does initially set the sharding attribute. Therefore,
1735-
// we need to set it here.
1753+
// The systemDB does initially set default values.
1754+
// As they can change with startup parameters we need
1755+
// to overwrite hem here to align with existing properties
1756+
// and all participants in the cluster agree on
1757+
// same definition.
17361758
if (newPlan.contains(StaticStrings::SystemDatabase)) {
17371759
auto planSlice = newPlan[StaticStrings::SystemDatabase]->slice();
17381760
if (planSlice.isArray() && planSlice.length() == 1) {
17391761
if (planSlice.at(0).isObject()) {
17401762
auto entrySlice = planSlice.at(0);
1741-
auto path = std::vector<std::string>{
1742-
"arango", "Plan", "Databases", StaticStrings::SystemDatabase,
1743-
StaticStrings::Sharding};
1744-
if (entrySlice.hasKey(path) && entrySlice.get(path).isString()) {
1745-
systemDB->setSharding(entrySlice.get(path).copyString());
1763+
{
1764+
// Add sharding Attribute
1765+
auto path = std::vector<std::string>{
1766+
"arango", "Plan", "Databases",
1767+
StaticStrings::SystemDatabase, StaticStrings::Sharding};
1768+
if (auto value = entrySlice.get(path); value.isString()) {
1769+
systemDB->setSharding(value.copyString());
1770+
}
1771+
}
1772+
{
1773+
// Add replication version
1774+
auto path =
1775+
std::vector<std::string>{"arango", "Plan", "Databases",
1776+
StaticStrings::SystemDatabase,
1777+
StaticStrings::ReplicationVersion};
1778+
if (auto value = entrySlice.get(path); value.isString()) {
1779+
auto res = replication::parseVersion(value.stringView());
1780+
// Just care for valid Replication versions now
1781+
if (res.ok() && res.get() != systemDB->replicationVersion()) {
1782+
// We cannot change the replication version of the system
1783+
// database The system database is created during startup,
1784+
// using the default option There is a timeframe where new
1785+
// collections are already created for this database, and
1786+
// use the "wrong" replicationVersion. This crashes on the
1787+
// way before this codepoint is reached and could repair the
1788+
// system Database.
1789+
LOG_TOPIC("50b83", FATAL, arangodb::Logger::STARTUP)
1790+
<< "Changed option "
1791+
"'--database.default-replication-version' between "
1792+
"startups. (Was "
1793+
<< value.stringView() << ", is now set to "
1794+
<< replication::versionToString(
1795+
systemDB->replicationVersion())
1796+
<< "). This would break the _system database. If you "
1797+
"want your _system database to use a different "
1798+
"replication version you need to start with an "
1799+
"empty cluster and restore data.";
1800+
FATAL_ERROR_EXIT();
1801+
}
1802+
}
17461803
}
17471804
}
17481805
}

arangod/Replication2/Version.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ namespace arangodb::replication {
4141

4242
enum class Version { ONE = 1, TWO = 2 };
4343

44+
// We disable Replication2 in Production environments for now
45+
// This we only allow to use Version one.
46+
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
4447
constexpr inline auto allowedVersions = {Version::ONE, Version::TWO};
48+
#else
49+
constexpr inline auto allowedVersions = {Version::ONE};
50+
#endif
4551

4652
auto parseVersion(std::string_view version) -> ResultT<replication::Version>;
4753
auto parseVersion(velocypack::Slice version) -> ResultT<replication::Version>;

arangod/RocksDBEngine/RocksDBEngine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,6 +3010,11 @@ void RocksDBEngine::addSystemDatabase() {
30103010
builder.add(StaticStrings::DatabaseName,
30113011
VPackValue(StaticStrings::SystemDatabase));
30123012
builder.add("deleted", VPackValue(false));
3013+
// Also store the ReplicationVersion when creating the Database
3014+
auto& df = server().getFeature<DatabaseFeature>();
3015+
builder.add(
3016+
StaticStrings::ReplicationVersion,
3017+
VPackValue(replication::versionToString(df.defaultReplicationVersion())));
30133018
builder.close();
30143019

30153020
RocksDBLogValue log = RocksDBLogValue::DatabaseCreate(id);

arangod/VocBase/VocbaseInfo.cpp

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "VocbaseInfo.h"
2525

2626
#include "ApplicationFeatures/ApplicationServer.h"
27+
#include "Basics/application-exit.h"
2728
#include "Basics/FeatureFlags.h"
2829
#include "Basics/StaticStrings.h"
2930
#include "Basics/StringUtils.h"
@@ -35,7 +36,6 @@
3536
#include "RestServer/DatabaseFeature.h"
3637
#include "Utils/Events.h"
3738
#include "Utilities/NameValidator.h"
38-
#include "VocBase/Methods/Databases.h"
3939

4040
#include <absl/strings/str_cat.h>
4141

@@ -117,26 +117,6 @@ Result CreateDatabaseInfo::load(std::string_view name, VPackSlice options,
117117
return checkOptions();
118118
}
119119

120-
Result CreateDatabaseInfo::load(std::string_view name, uint64_t id,
121-
VPackSlice options, VPackSlice users) {
122-
_name = name;
123-
_id = id;
124-
125-
Result res = extractOptions(options, false /*getId*/, false /*getUser*/);
126-
if (res.ok()) {
127-
res = extractUsers(users);
128-
}
129-
if (!res.ok()) {
130-
return res;
131-
}
132-
133-
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
134-
_valid = true;
135-
#endif
136-
137-
return checkOptions();
138-
}
139-
140120
void CreateDatabaseInfo::toVelocyPack(VPackBuilder& builder,
141121
bool withUsers) const {
142122
TRI_ASSERT(_validId);
@@ -255,6 +235,13 @@ Result CreateDatabaseInfo::extractOptions(VPackSlice options, bool extractId,
255235
_writeConcern = vocopts.writeConcern;
256236
_sharding = vocopts.sharding;
257237
if (!ServerState::instance()->isSingleServer()) {
238+
if (!arangodb::replication2::EnableReplication2) {
239+
if (vocopts.replicationVersion == replication::Version::TWO) {
240+
return Result(TRI_ERROR_NOT_IMPLEMENTED,
241+
"Replication version 2 is disabled in this binary, "
242+
"cannot create replication version 2 databases.");
243+
}
244+
}
258245
// Just ignore Replication2 for SingleServers
259246
_replicationVersion = vocopts.replicationVersion;
260247
}
@@ -297,15 +284,14 @@ Result CreateDatabaseInfo::checkOptions() {
297284

298285
if (_replicationVersion == replication::Version::TWO &&
299286
!replication2::EnableReplication2) {
300-
LOG_TOPIC("8fdd7", ERR, Logger::REPLICATION2)
287+
LOG_TOPIC("8fdd7", FATAL, Logger::REPLICATION2)
301288
<< "Replication version 2 is disabled in this binary, but loading a "
302289
"version 2 database "
303290
<< "(named '" << _name << "'). "
304-
<< "Creating such databases is disabled. Loading a version 2 database "
305-
"that was created with another binary will work, but it is strongly "
306-
"discouraged to use it in production. Please dump the data, and "
291+
<< "Creating such databases is disabled. Please dump the data, and "
307292
"recreate the database with replication version 1 (the default), "
308293
"and then restore the data.";
294+
FATAL_ERROR_EXIT();
309295
}
310296

311297
if (_validateNames) {

arangod/VocBase/VocbaseInfo.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ class CreateDatabaseInfo {
8080
Result load(std::string_view name, VPackSlice options,
8181
VPackSlice users = VPackSlice::emptyArraySlice());
8282

83-
Result load(std::string_view name, uint64_t id, VPackSlice options,
84-
VPackSlice users);
85-
8683
Result load(VPackSlice options, VPackSlice users);
8784

8885
void toVelocyPack(VPackBuilder& builder, bool withUsers = false) const;

lib/Basics/FeatureFlags.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@
2323

2424
#include "FeatureFlags.h"
2525

26+
#if ARANGODB_ENABLE_MAINTAINER_MODE
2627
bool const ::arangodb::replication2::EnableReplication2 = true;
28+
#else
29+
bool const ::arangodb::replication2::EnableReplication2 = false;
30+
#endif

0 commit comments

Comments
 (0)
0