Skip to content

Commit

Permalink
In cluster-mode enabled, override the databases config at startup to 1 (
Browse files Browse the repository at this point in the history
#11555)

In cluster-mode, only DB0 is supported so all data must reside in that database. There is a single check that validates that data loaded from an RDB all resides in DB0. This check is performed after all the data is loaded which makes it difficult to identify where the non DB0 data resides as well as does a bunch of unnecessary work to load incompatible data. This change override the database config at startup to 1 to throw an error when attempting to add data to a database other than DB0.

Co-authored-by: Eran Liberty <eranl@amazon.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
  • Loading branch information
4 people committed Jan 5, 2023
1 parent a2e75a7 commit cb1fff3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,12 @@ void loadServerConfigFromString(char *config) {
goto loaderr;
}

/* in case cluster mode is enabled dbnum must be 1 */
if (server.cluster_enabled && server.dbnum > 1) {
serverLog(LL_WARNING, "WARNING: Changing databases number from %d to 1 since we are in cluster mode", server.dbnum);
server.dbnum = 1;
}

/* To ensure backward compatibility and work while hz is out of range */
if (server.config_hz < CONFIG_MIN_HZ) server.config_hz = CONFIG_MIN_HZ;
if (server.config_hz > CONFIG_MAX_HZ) server.config_hz = CONFIG_MAX_HZ;
Expand Down
7 changes: 1 addition & 6 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -7202,12 +7202,7 @@ int main(int argc, char **argv) {
aofOpenIfNeededOnServerStart();
aofDelHistoryFiles();
if (server.cluster_enabled) {
if (verifyClusterConfigWithData() == C_ERR) {
serverLog(LL_WARNING,
"You can't have keys in a DB different than DB 0 when in "
"Cluster mode. Exiting.");
exit(1);
}
serverAssert(verifyClusterConfigWithData() == C_OK);
}

for (j = 0; j < CONN_TYPE_MAX; j++) {
Expand Down

0 comments on commit cb1fff3

Please sign in to comment.