Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return Accurate Number of Databases #800

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions libs/server/Resp/ArrayCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using Garnet.common;
using Tsavorite.core;

Expand Down Expand Up @@ -237,17 +235,17 @@ private bool NetworkSELECT()
return true;
}

if (storeWrapper.serverOptions.EnableCluster)
if (index < storeWrapper.databaseNum)
{
// Cluster mode does not allow DBID
while (!RespWriteUtils.WriteError(CmdStrings.RESP_ERR_GENERIC_SELECT_CLUSTER_MODE, ref dcurr, dend))
while (!RespWriteUtils.WriteDirect(CmdStrings.RESP_OK, ref dcurr, dend))
SendAndReset();
}
else
{
if (index == 0)
if (storeWrapper.serverOptions.EnableCluster)
{
while (!RespWriteUtils.WriteDirect(CmdStrings.RESP_OK, ref dcurr, dend))
// Cluster mode does not allow DBID
while (!RespWriteUtils.WriteError(CmdStrings.RESP_ERR_GENERIC_SELECT_CLUSTER_MODE, ref dcurr, dend))
SendAndReset();
}
else
Expand Down
8 changes: 7 additions & 1 deletion libs/server/ServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,19 @@ private bool NetworkCONFIG_GET()
ServerConfigType.SAVE => "$4\r\nsave\r\n$0\r\n\r\n"u8,
ServerConfigType.APPENDONLY => storeWrapper.serverOptions.EnableAOF ? "$10\r\nappendonly\r\n$3\r\nyes\r\n"u8 : "$10\r\nappendonly\r\n$2\r\nno\r\n"u8,
ServerConfigType.SLAVE_READ_ONLY => clusterSession == null || clusterSession.ReadWriteSession ? "$15\r\nslave-read-only\r\n$2\r\nno\r\n"u8 : "$15\r\nslave-read-only\r\n$3\r\nyes\r\n"u8,
ServerConfigType.DATABASES => storeWrapper.serverOptions.EnableCluster ? "$9\r\ndatabases\r\n$1\r\n1\r\n"u8 : "$9\r\ndatabases\r\n$2\r\n16\r\n"u8,
ServerConfigType.DATABASES => GetDatabases(),
ServerConfigType.CLUSTER_NODE_TIMEOUT => Encoding.ASCII.GetBytes($"$20\r\ncluster-node-timeout\r\n${storeWrapper.serverOptions.ClusterTimeout.ToString().Length}\r\n{storeWrapper.serverOptions.ClusterTimeout}\r\n"),
ServerConfigType.NONE => throw new NotImplementedException(),
ServerConfigType.ALL => throw new NotImplementedException(),
_ => throw new NotImplementedException()
};

ReadOnlySpan<byte> GetDatabases()
{
var databases = storeWrapper.databaseNum.ToString();
return Encoding.ASCII.GetBytes($"$9\r\ndatabases\r\n${databases.Length}\r\n{databases}\r\n");
}

while (!RespWriteUtils.WriteDirect(parameterValue, ref dcurr, dend))
SendAndReset();
}
Expand Down
5 changes: 5 additions & 0 deletions libs/server/StoreWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public sealed class StoreWrapper

public readonly TimeSpan loggingFrequncy;

/// <summary>
/// NOTE: For now we support only a single database
/// </summary>
public readonly int databaseNum = 1;

/// <summary>
/// Constructor
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion test/Garnet.test/RespAdminCommandsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ public async Task SeFlushDbAndFlushAllTest2([Values(RespCommand.FLUSHALL, RespCo
[TestCase("save", "")]
[TestCase("appendonly", "no")]
[TestCase("slave-read-only", "no")]
[TestCase("databases", "16")]
[TestCase("databases", "1")]
[TestCase("cluster-node-timeout", "60")]
public void SimpleConfigGet(string parameter, string parameterValue)
{
Expand Down