Commit b7f18015 authored by Marc Gravell's avatar Marc Gravell

include counters from GetOutstandingCount when reporting...

include counters from GetOutstandingCount when reporting WriteResult.TimeoutBeforeWrite; include a "what were you doing?" when reporting certain ProtocolFailure exceptions; also, make the IDE happier
parent 51445c78
......@@ -601,8 +601,10 @@ public async Task<string[]> GetSuggestionsAsync(string prefix, bool fuzzy = fals
/// <param name="query">The query to watch</param>
public AggregationResult Aggregate(AggregationRequest query)
{
var args = new List<object>();
args.Add(_boxedIndexName);
var args = new List<object>
{
_boxedIndexName
};
query.SerializeRedisArgs(args);
var resp = DbSync.Execute("FT.AGGREGATE", args);
......@@ -615,8 +617,10 @@ public AggregationResult Aggregate(AggregationRequest query)
/// <param name="query">The query to watch</param>
public async Task<AggregationResult> AggregateAsync(AggregationRequest query)
{
var args = new List<object>();
args.Add(_boxedIndexName);
var args = new List<object>
{
_boxedIndexName
};
query.SerializeRedisArgs(args);
var resp = await _db.ExecuteAsync("FT.AGGREGATE", args).ConfigureAwait(false);
......
......@@ -21,7 +21,7 @@ public enum FieldType
public class Field
{
public String Name { get; }
public string Name { get; }
public FieldType Type { get; }
public bool Sortable { get; }
public bool NoIndex { get; }
......
......@@ -302,7 +302,7 @@ public void KeyRename()
[Fact]
public void KeyRestore()
{
Byte[] value = new Byte[0];
byte[] value = new byte[0];
TimeSpan expiry = TimeSpan.FromSeconds(123);
wrapper.KeyRestore("key", value, expiry, CommandFlags.HighPriority);
mock.Verify(_ => _.KeyRestore("prefix:key", value, expiry, CommandFlags.HighPriority));
......
......@@ -2066,8 +2066,20 @@ internal Exception GetException(WriteResult result, Message message, ServerEndPo
case WriteResult.NoConnectionAvailable:
return ExceptionFactory.NoConnectionAvailable(IncludeDetailInExceptions, IncludePerformanceCountersInExceptions, message.Command, message, server, GetServerSnapshot());
case WriteResult.TimeoutBeforeWrite:
string counters = null;
try
{
var bridge = server.GetBridge(message.Command, false);
if (bridge != null)
{
bridge.GetOutstandingCount(out var inst, out var qs, out var @in);
counters = $", inst={inst}, qs={qs}, in={@in}";
}
}
catch { }
return ExceptionFactory.Timeout(IncludeDetailInExceptions, "The timeout was reached before the message could be written to the output buffer, and it was not sent ("
+ Format.ToString(TimeoutMilliseconds) + "ms)", message, server);
+ Format.ToString(TimeoutMilliseconds) + "ms" + counters + ")", message, server);
case WriteResult.WriteFailure:
default:
return ExceptionFactory.ConnectionFailure(IncludeDetailInExceptions, ConnectionFailureType.ProtocolFailure, "An unknown error occurred when writing the message", server);
......
......@@ -601,10 +601,10 @@ internal bool ComputeResult(PhysicalConnection connection, RawResult result)
}
}
internal void Fail(ConnectionFailureType failure, Exception innerException)
internal void Fail(ConnectionFailureType failure, Exception innerException, string annotation)
{
PhysicalConnection.IdentifyFailureType(innerException, ref failure);
resultProcessor?.ConnectionFail(this, failure, innerException);
resultProcessor?.ConnectionFail(this, failure, innerException, annotation);
}
internal void SetException(Exception exception)
......@@ -697,7 +697,7 @@ internal void WriteTo(PhysicalConnection physical)
catch (Exception ex)
{
physical?.OnInternalError(ex);
Fail(ConnectionFailureType.InternalFailure, ex);
Fail(ConnectionFailureType.InternalFailure, ex, null);
}
}
......
......@@ -194,7 +194,8 @@ internal void GetOutstandingCount(out int inst, out int qs, out int @in)
var tmp = physical;
if (tmp == null)
{
qs = @in = 0;
qs = 0;
@in = -1;
}
else
{
......@@ -539,7 +540,7 @@ internal WriteResult WriteMessageTakingWriteLock(PhysicalConnection physical, Me
// we screwed up; abort; note that WriteMessageToServer already
// killed the underlying connection
Trace("Unable to write to server");
next.Fail(ConnectionFailureType.ProtocolFailure, null);
next.Fail(ConnectionFailureType.ProtocolFailure, null, "failure before write: " + result.ToString());
CompleteSyncOrAsync(next);
return result;
}
......@@ -739,7 +740,7 @@ private WriteResult WriteMessageToServerInsideWriteLock(PhysicalConnection conne
catch (RedisCommandException ex)
{
Trace("Write failed: " + ex.Message);
message.Fail(ConnectionFailureType.InternalFailure, ex);
message.Fail(ConnectionFailureType.InternalFailure, ex, null);
CompleteSyncOrAsync(message);
// this failed without actually writing; we're OK with that... unless there's a transaction
......@@ -754,7 +755,7 @@ private WriteResult WriteMessageToServerInsideWriteLock(PhysicalConnection conne
catch (Exception ex)
{
Trace("Write failed: " + ex.Message);
message.Fail(ConnectionFailureType.InternalFailure, ex);
message.Fail(ConnectionFailureType.InternalFailure, ex, null);
CompleteSyncOrAsync(message);
// we're not sure *what* happened here; probably an IOException; kill the connection
......
......@@ -1030,7 +1030,7 @@ private static void WriteUnified(PipeWriter writer, long value)
writer.Advance(bytes);
}
internal int GetAvailableInboundBytes() => _socket?.Available ?? 0;
internal int GetAvailableInboundBytes() => _socket?.Available ?? -1;
private RemoteCertificateValidationCallback GetAmbientIssuerCertificateCallback()
{
......
......@@ -98,7 +98,7 @@ private void FailNoServer(List<Message> messages)
var completion = multiplexer.UnprocessableCompletionManager;
foreach(var msg in messages)
{
msg.Fail(ConnectionFailureType.UnableToResolvePhysicalConnection, null);
msg.Fail(ConnectionFailureType.UnableToResolvePhysicalConnection, null, "unable to write batch");
completion.CompleteSyncOrAsync(msg);
}
}
......
......@@ -455,7 +455,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
// the pending tasks
foreach (var op in wrapped)
{
op.Wrapped.Fail(ConnectionFailureType.ProtocolFailure, null);
op.Wrapped.Fail(ConnectionFailureType.ProtocolFailure, null, "transaction failure");
bridge.CompleteSyncOrAsync(op.Wrapped);
}
}
......
......@@ -137,12 +137,14 @@ public static readonly HashEntryArrayProcessor
ASK = Encoding.UTF8.GetBytes("ASK "),
NOAUTH = Encoding.UTF8.GetBytes("NOAUTH ");
public void ConnectionFail(Message message, ConnectionFailureType fail, Exception innerException)
public void ConnectionFail(Message message, ConnectionFailureType fail, Exception innerException, string annotation)
{
PhysicalConnection.IdentifyFailureType(innerException, ref fail);
string exMessage = fail.ToString() + (message == null ? "" : (" on " + (
fail == ConnectionFailureType.ProtocolFailure ? message.ToString() : message.CommandAndKey)));
if (!string.IsNullOrWhiteSpace(annotation)) exMessage += ", " + annotation;
var ex = innerException == null ? new RedisConnectionException(fail, exMessage)
: new RedisConnectionException(fail, exMessage, innerException);
SetException(message, ex);
......@@ -1919,8 +1921,7 @@ private sealed class SentinelArrayOfArraysProcessor : ResultProcessor<KeyValuePa
{
protected override bool SetResultCore(PhysicalConnection connection, Message message, RawResult result)
{
var innerProcessor = StringPairInterleaved as StringPairInterleavedProcessor;
if (innerProcessor == null)
if (!(StringPairInterleaved is StringPairInterleavedProcessor innerProcessor))
{
return false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment