Commit db8b3c6c authored by Nick Craver's avatar Nick Craver

Cleanup: Message.Flags

parent 36f5a354
...@@ -23,7 +23,7 @@ private LoggingMessage(TextWriter log, Message tail) : base(tail.Db, tail.Flags, ...@@ -23,7 +23,7 @@ private LoggingMessage(TextWriter log, Message tail) : base(tail.Db, tail.Flags,
{ {
this.log = log; this.log = log;
this.tail = tail; this.tail = tail;
FlagsRaw = tail.FlagsRaw; Flags = tail.Flags;
} }
public override string CommandAndKey => tail.CommandAndKey; public override string CommandAndKey => tail.CommandAndKey;
...@@ -75,9 +75,6 @@ internal abstract class Message : ICompletable ...@@ -75,9 +75,6 @@ internal abstract class Message : ICompletable
| CommandFlags.FireAndForget | CommandFlags.FireAndForget
| CommandFlags.NoRedirect | CommandFlags.NoRedirect
| CommandFlags.NoScriptCache; | CommandFlags.NoScriptCache;
private CommandFlags flags;
internal CommandFlags FlagsRaw { get { return flags; } set { flags = value; } }
private ResultBox resultBox; private ResultBox resultBox;
private ResultProcessor resultProcessor; private ResultProcessor resultProcessor;
...@@ -112,7 +109,7 @@ protected Message(int db, CommandFlags flags, RedisCommand command) ...@@ -112,7 +109,7 @@ protected Message(int db, CommandFlags flags, RedisCommand command)
bool masterOnly = IsMasterOnly(command); bool masterOnly = IsMasterOnly(command);
Db = db; Db = db;
this.command = command; this.command = command;
this.flags = flags & UserSelectableFlags; Flags = flags & UserSelectableFlags;
if (masterOnly) SetMasterOnly(); if (masterOnly) SetMasterOnly();
createdDateTime = DateTime.UtcNow; createdDateTime = DateTime.UtcNow;
...@@ -122,7 +119,7 @@ protected Message(int db, CommandFlags flags, RedisCommand command) ...@@ -122,7 +119,7 @@ protected Message(int db, CommandFlags flags, RedisCommand command)
internal void SetMasterOnly() internal void SetMasterOnly()
{ {
switch (GetMasterSlaveFlags(flags)) switch (GetMasterSlaveFlags(Flags))
{ {
case CommandFlags.DemandSlave: case CommandFlags.DemandSlave:
throw ExceptionFactory.MasterOnly(false, command, null, null); throw ExceptionFactory.MasterOnly(false, command, null, null);
...@@ -132,7 +129,7 @@ internal void SetMasterOnly() ...@@ -132,7 +129,7 @@ internal void SetMasterOnly()
case CommandFlags.PreferMaster: case CommandFlags.PreferMaster:
case CommandFlags.PreferSlave: case CommandFlags.PreferSlave:
default: // we will run this on the master, then default: // we will run this on the master, then
flags = SetMasterSlaveFlags(flags, CommandFlags.DemandMaster); Flags = SetMasterSlaveFlags(Flags, CommandFlags.DemandMaster);
break; break;
} }
} }
...@@ -159,14 +156,11 @@ internal void PrepareToResend(ServerEndPoint resendTo, bool isMoved) ...@@ -159,14 +156,11 @@ internal void PrepareToResend(ServerEndPoint resendTo, bool isMoved)
Status = CommandStatus.WaitingToBeSent; Status = CommandStatus.WaitingToBeSent;
} }
public CommandFlags Flags { get; internal set; }
internal CommandStatus Status { get; private set; } internal CommandStatus Status { get; private set; }
public RedisCommand Command => command; public RedisCommand Command => command;
public virtual string CommandAndKey => Command.ToString(); public virtual string CommandAndKey => Command.ToString();
public CommandFlags Flags => flags;
/// <summary> /// <summary>
/// Things with the potential to cause harm, or to reveal configuration information /// Things with the potential to cause harm, or to reveal configuration information
/// </summary> /// </summary>
...@@ -200,17 +194,17 @@ public bool IsAdmin ...@@ -200,17 +194,17 @@ public bool IsAdmin
} }
} }
public bool IsAsking => (flags & AskingFlag) != 0; public bool IsAsking => (Flags & AskingFlag) != 0;
internal bool IsScriptUnavailable => (flags & ScriptUnavailableFlag) != 0; internal bool IsScriptUnavailable => (Flags & ScriptUnavailableFlag) != 0;
internal void SetScriptUnavailable() internal void SetScriptUnavailable()
{ {
flags |= ScriptUnavailableFlag; Flags |= ScriptUnavailableFlag;
} }
public bool IsFireAndForget => (flags & CommandFlags.FireAndForget) != 0; public bool IsFireAndForget => (Flags & CommandFlags.FireAndForget) != 0;
public bool IsInternalCall => (flags & InternalCallFlag) != 0; public bool IsInternalCall => (Flags & InternalCallFlag) != 0;
public ResultBox ResultBox => resultBox; public ResultBox ResultBox => resultBox;
...@@ -420,7 +414,7 @@ public bool IsMasterOnly() ...@@ -420,7 +414,7 @@ public bool IsMasterOnly()
// note that the constructor runs the switch statement above, so // note that the constructor runs the switch statement above, so
// this will alread be true for master-only commands, even if the // this will alread be true for master-only commands, even if the
// user specified PreferMaster etc // user specified PreferMaster etc
return GetMasterSlaveFlags(flags) == CommandFlags.DemandMaster; return GetMasterSlaveFlags(Flags) == CommandFlags.DemandMaster;
} }
/// <summary> /// <summary>
...@@ -434,7 +428,7 @@ public bool IsMasterOnly() ...@@ -434,7 +428,7 @@ public bool IsMasterOnly()
/// </summary> /// </summary>
public void SetInternalCall() public void SetInternalCall()
{ {
flags |= InternalCallFlag; Flags |= InternalCallFlag;
} }
public override string ToString() public override string ToString()
...@@ -619,7 +613,7 @@ internal void SetException(Exception exception) ...@@ -619,7 +613,7 @@ internal void SetException(Exception exception)
internal void SetRequestSent() internal void SetRequestSent()
{ {
Status = CommandStatus.Sent; Status = CommandStatus.Sent;
if ((flags & NeedsAsyncTimeoutCheckFlag) != 0) if ((Flags & NeedsAsyncTimeoutCheckFlag) != 0)
{ {
_writeTickCount = Environment.TickCount; // note this might be reset if we resend a message, cluster-moved etc; I'm OK with that _writeTickCount = Environment.TickCount; // note this might be reset if we resend a message, cluster-moved etc; I'm OK with that
} }
...@@ -628,15 +622,15 @@ internal void SetRequestSent() ...@@ -628,15 +622,15 @@ internal void SetRequestSent()
// the time (ticks) at which this message was considered written // the time (ticks) at which this message was considered written
private int _writeTickCount; private int _writeTickCount;
private void SetNeedsTimeoutCheck() => flags |= NeedsAsyncTimeoutCheckFlag; private void SetNeedsTimeoutCheck() => Flags |= NeedsAsyncTimeoutCheckFlag;
internal bool HasAsyncTimedOut(int now, int timeoutMilliseconds, out int millisecondsTaken) internal bool HasAsyncTimedOut(int now, int timeoutMilliseconds, out int millisecondsTaken)
{ {
if ((flags & NeedsAsyncTimeoutCheckFlag) != 0) if ((Flags & NeedsAsyncTimeoutCheckFlag) != 0)
{ {
millisecondsTaken = unchecked(now - _writeTickCount); // note: we can't just check "if sent < cutoff" because of wrap-aro millisecondsTaken = unchecked(now - _writeTickCount); // note: we can't just check "if sent < cutoff" because of wrap-aro
if (millisecondsTaken >= timeoutMilliseconds) if (millisecondsTaken >= timeoutMilliseconds)
{ {
flags &= ~NeedsAsyncTimeoutCheckFlag; // note: we don't remove it from the queue - still might need to marry it up; but: it is toast Flags &= ~NeedsAsyncTimeoutCheckFlag; // note: we don't remove it from the queue - still might need to marry it up; but: it is toast
return true; return true;
} }
} }
...@@ -649,23 +643,23 @@ internal bool HasAsyncTimedOut(int now, int timeoutMilliseconds, out int millise ...@@ -649,23 +643,23 @@ internal bool HasAsyncTimedOut(int now, int timeoutMilliseconds, out int millise
internal void SetAsking(bool value) internal void SetAsking(bool value)
{ {
if (value) flags |= AskingFlag; // the bits giveth if (value) Flags |= AskingFlag; // the bits giveth
else flags &= ~AskingFlag; // and the bits taketh away else Flags &= ~AskingFlag; // and the bits taketh away
} }
internal void SetNoRedirect() internal void SetNoRedirect()
{ {
flags |= CommandFlags.NoRedirect; Flags |= CommandFlags.NoRedirect;
} }
internal void SetPreferMaster() internal void SetPreferMaster()
{ {
flags = (flags & ~MaskMasterServerPreference) | CommandFlags.PreferMaster; Flags = (Flags & ~MaskMasterServerPreference) | CommandFlags.PreferMaster;
} }
internal void SetPreferSlave() internal void SetPreferSlave()
{ {
flags = (flags & ~MaskMasterServerPreference) | CommandFlags.PreferSlave; Flags = (Flags & ~MaskMasterServerPreference) | CommandFlags.PreferSlave;
} }
internal void SetSource(ResultProcessor resultProcessor, ResultBox resultBox) internal void SetSource(ResultProcessor resultProcessor, ResultBox resultBox)
......
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