Skip to content

Commit

Permalink
instead of using node count, use explicit tracking of the DB count
Browse files Browse the repository at this point in the history
  • Loading branch information
mgravell committed Feb 12, 2024
1 parent ba2e05a commit 42ce0b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/StackExchange.Redis/PhysicalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public PhysicalConnection(PhysicalBridge bridge)
OnCreateEcho();
}

// *definitely* multi-database; this can help identify some unusual config scenarios
internal bool MultiDatabasesOverride { get; set; } // switch to flags-enum if more needed later

internal async Task BeginConnectAsync(ILogger? log)
{
var bridge = BridgeCouldBeNull;
Expand Down Expand Up @@ -262,6 +265,7 @@ private enum ReadMode : byte

private RedisProtocol _protocol; // note starts at **zero**, not RESP2
public RedisProtocol? Protocol => _protocol == 0 ? null : _protocol;

internal void SetProtocol(RedisProtocol value) => _protocol = value;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
Expand Down
11 changes: 6 additions & 5 deletions src/StackExchange.Redis/ResultProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,10 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
int dbCount = checked((int)i64);
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (CONFIG) databases: " + dbCount);
server.Databases = dbCount;
if (dbCount > 1)
{
connection.MultiDatabasesOverride = true;
}
}
else if (key.IsEqual(CommonReplies.slave_read_only) || key.IsEqual(CommonReplies.replica_read_only))
{
Expand Down Expand Up @@ -1110,11 +1114,8 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
var bridge = connection.BridgeCouldBeNull;
var config = Parse(connection, nodes);

// note: some setups self-report as a cluster with a single
// endpoint (in two pieces - replica+primary, same path);
// don't treat that as a real cluster; see
// https://github.com/StackExchange/StackExchange.Redis/issues/2642
if (bridge != null && config.Nodes.Count >= 2)
// re multi-db: https://github.com/StackExchange/StackExchange.Redis/issues/2642
if (bridge != null && !connection.MultiDatabasesOverride)
{
bridge.ServerEndPoint.ServerType = ServerType.Cluster;
}
Expand Down
4 changes: 4 additions & 0 deletions src/StackExchange.Redis/ServerEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ internal async Task AutoConfigureAsync(PhysicalConnection? connection, ILogger?
lastInfoReplicationCheckTicks = Environment.TickCount;
if (features.InfoSections)
{
// note: Redis 7.0 has a multi-section usage, but we don't know
// the server version at this point; we *could* use the optional
// value on the config, but let's keep things simple: these
// commands are suitably cheap
msg = Message.Create(-1, flags, RedisCommand.INFO, RedisLiterals.replication);
msg.SetInternalCall();
await WriteDirectOrQueueFireAndForgetAsync(connection, msg, autoConfigProcessor).ForAwait();
Expand Down

0 comments on commit 42ce0b8

Please sign in to comment.