Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Issue 115 #10

Open
wants to merge 1 commit into from

1 participant

@rrmayer

Added a StatusCodeEnum consistent with the Memcached protocol (and SASL auth extensions). Added code throughout to convert int status codes to the enum. Added a NodeNotFound status code, and return it when a node cannot be located.

ref Issue #115

Signed-off-by: Rob Mayer rmayer@stewartstrategy.com

Rob Mayer Added a StatusCodeEnum consistent with the Memcached protocol (and SA…
…SL auth extensions). Added code throughout to convert int status codes to the enum. Added a NodeNotFound status code, and return it when a node cannot be located.

Signed-off-by: Rob Mayer <rmayer@stewartstrategy.com>
fab11d9
@rrmayer rrmayer referenced this pull request in couchbase/couchbase-net-client
Closed

Memcached Issues 115 & 96 #3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 18, 2013
  1. Added a StatusCodeEnum consistent with the Memcached protocol (and SA…

    Rob Mayer authored
    …SL auth extensions). Added code throughout to convert int status codes to the enum. Added a NodeNotFound status code, and return it when a node cannot be located.
    
    Signed-off-by: Rob Mayer <rmayer@stewartstrategy.com>
This page is out of date. Refresh to see the latest.
View
2  Enyim.Caching/Enyim.Caching.csproj
@@ -274,7 +274,6 @@
<Compile Include="Memcached\Results\IStoreOperationResult.cs" />
<Compile Include="Memcached\Results\MutateOperationResult.cs" />
<Compile Include="Memcached\Results\OperationResultBase.cs" />
- <Compile Include="Memcached\Results\StatusCodes\StatusCodeEnums.cs" />
<Compile Include="Memcached\Results\StatusCodes\StatusCodeMessages.cs" />
<Compile Include="Memcached\Results\StoreOperationResult.cs" />
<Compile Include="Memcached\Results\TextOperationResult.cs" />
@@ -295,6 +294,7 @@
<Compile Include="Memcached\Transcoders\ITranscoder.cs">
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Memcached\Results\StatusCodes\StatusCodeEnum.cs" />
<Compile Include="TigerHash.cs" />
<Compile Include="UIntEqualityComparer.cs" />
</ItemGroup>
View
2  Enyim.Caching/Memcached/MemcachedNode.cs
@@ -4,6 +4,7 @@
using System.Net;
using System.Threading;
using Enyim.Caching.Configuration;
+using Enyim.Caching.Memcached.Results.StatusCodes;
using Enyim.Collections;
using System.Security;
using Enyim.Caching.Memcached.Protocol.Binary;
@@ -565,6 +566,7 @@ protected virtual IPooledSocketResult ExecuteOperation(IOperation op)
{
log.Error(e);
+ result.StatusCode = StatusCode.UnspecifiedError;
result.Fail("Exception reading response", e);
return result;
}
View
7 Enyim.Caching/Memcached/OperationInterfaces.cs
@@ -1,8 +1,7 @@
using System;
-using System.Net;
using System.Collections.Generic;
-using Enyim.Caching.Memcached.Protocol;
using Enyim.Caching.Memcached.Results;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching.Memcached
{
@@ -11,7 +10,7 @@ public interface IOperation
IList<ArraySegment<byte>> GetBuffer();
IOperationResult ReadResponse(PooledSocket socket);
- int StatusCode { get; }
+ StatusCode StatusCode { get; }
/// <summary>
/// 'next' is called when the operation completes. The bool parameter indicates the success of the operation.
@@ -81,7 +80,7 @@ public struct CasResult<T>
{
public T Result { get; set; }
public ulong Cas { get; set; }
- public int StatusCode { get; set; }
+ public StatusCode StatusCode { get; set; }
}
}
View
5 Enyim.Caching/Memcached/Protocol/Binary/BinaryNode.cs
@@ -4,6 +4,7 @@
using System.Net;
using System.Threading;
using Enyim.Caching.Configuration;
+using Enyim.Caching.Memcached.Results.StatusCodes;
using Enyim.Collections;
using System.Security;
@@ -55,7 +56,7 @@ private bool Auth(PooledSocket socket)
while (!currentStep.ReadResponse(socket).Success)
{
// challenge-response authentication
- if (currentStep.StatusCode == 0x21)
+ if (currentStep.StatusCode == StatusCode.ContinueAuthentication)
{
currentStep = new SaslContinue(this.authenticationProvider, currentStep.Data);
socket.Write(currentStep.GetBuffer());
@@ -63,7 +64,7 @@ private bool Auth(PooledSocket socket)
else
{
if (log.IsWarnEnabled)
- log.WarnFormat("Authentication failed, return code: 0x{0:x}", currentStep.StatusCode);
+ log.WarnFormat("Authentication failed, return code: ", currentStep.StatusCode);
// invalid credentials or other error
return false;
View
3  Enyim.Caching/Memcached/Protocol/Binary/BinarySingleItemOperation.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using Enyim.Caching.Memcached.Results;
using Enyim.Caching.Memcached.Results.Extensions;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching.Memcached.Protocol.Binary
{
@@ -24,7 +25,7 @@ protected internal override IOperationResult ReadResponse(PooledSocket socket)
var retval = response.Read(socket);
this.Cas = response.CAS;
- this.StatusCode = response.StatusCode;
+ this.StatusCode = response.StatusCode.ToStatusCode();
var result = new BinaryOperationResult()
{
View
3  Enyim.Caching/Memcached/Protocol/Binary/GetOperation.cs
@@ -3,6 +3,7 @@
using Enyim.Caching.Memcached.Results;
using Enyim.Caching.Memcached.Results.Extensions;
using Enyim.Caching.Memcached.Results.Helpers;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching.Memcached.Protocol.Binary
{
@@ -29,7 +30,7 @@ protected override IOperationResult ProcessResponse(BinaryResponse response)
var status = response.StatusCode;
var result = new BinaryOperationResult();
- this.StatusCode = status;
+ this.StatusCode = status.ToStatusCode();
if (status == 0)
{
View
5 Enyim.Caching/Memcached/Protocol/Binary/MultiGetOperation.cs
@@ -5,6 +5,7 @@
using System.Threading;
using Enyim.Caching.Memcached.Results;
using Enyim.Caching.Memcached.Results.Extensions;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching.Memcached.Protocol.Binary
{
@@ -96,7 +97,7 @@ private bool DoReadAsync()
while (this.asyncLoopState == null)
{
var readSuccess = reader.ReadAsync(this.currentSocket, this.EndReadAsync, out ioPending);
- this.StatusCode = reader.StatusCode;
+ this.StatusCode = reader.StatusCode.ToStatusCode();
if (ioPending) return readSuccess;
@@ -157,7 +158,7 @@ protected internal override IOperationResult ReadResponse(PooledSocket socket)
while (response.Read(socket))
{
- this.StatusCode = response.StatusCode;
+ this.StatusCode = response.StatusCode.ToStatusCode();
// found the noop, quit
if (response.CorrelationId == this.noopId)
View
3  Enyim.Caching/Memcached/Protocol/Binary/MutatorOperation.cs
@@ -2,6 +2,7 @@
using Enyim.Caching.Memcached.Results.Extensions;
using Enyim.Caching.Memcached.Results.Helpers;
using Enyim.Caching.Memcached.Results;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching.Memcached.Protocol.Binary
{
@@ -56,7 +57,7 @@ protected override IOperationResult ProcessResponse(BinaryResponse response)
{
var result = new BinaryOperationResult();
var status = response.StatusCode;
- this.StatusCode = status;
+ this.StatusCode = status.ToStatusCode();
if (status == 0)
{
View
3  Enyim.Caching/Memcached/Protocol/Binary/SaslStep.cs
@@ -3,6 +3,7 @@
using System.Text;
using Enyim.Caching.Memcached.Results;
using Enyim.Caching.Memcached.Results.Extensions;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching.Memcached.Protocol.Binary
{
@@ -21,7 +22,7 @@ protected internal override IOperationResult ReadResponse(PooledSocket socket)
var retval = response.Read(socket);
- this.StatusCode = response.StatusCode;
+ this.StatusCode = response.StatusCode.ToStatusCode();
this.Data = response.Data.Array;
var result = new BinaryOperationResult
View
3  Enyim.Caching/Memcached/Protocol/Binary/StatsOperation.cs
@@ -4,6 +4,7 @@
using System.Net;
using Enyim.Caching.Memcached.Results;
using Enyim.Caching.Memcached.Results.Extensions;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching.Memcached.Protocol.Binary
{
@@ -46,7 +47,7 @@ protected internal override IOperationResult ReadResponse(PooledSocket socket)
}
this.result = serverData;
- this.StatusCode = response.StatusCode;
+ this.StatusCode = response.StatusCode.ToStatusCode();
var result = new BinaryOperationResult()
{
View
3  Enyim.Caching/Memcached/Protocol/Binary/StoreOperation.cs
@@ -3,6 +3,7 @@
using Enyim.Caching.Memcached.Results;
using Enyim.Caching.Memcached.Results.Helpers;
using Enyim.Caching.Memcached.Results.Extensions;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching.Memcached.Protocol.Binary
{
@@ -62,7 +63,7 @@ protected override IOperationResult ProcessResponse(BinaryResponse response)
log.DebugFormat("Store failed for key '{0}'. Reason: {1}", this.Key, Encoding.ASCII.GetString(response.Data.Array, response.Data.Offset, response.Data.Count));
}
#endif
- this.StatusCode = response.StatusCode;
+ this.StatusCode = response.StatusCode.ToStatusCode();
if (response.StatusCode == 0)
{
return result.Pass();
View
5 Enyim.Caching/Memcached/Protocol/Operation.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Enyim.Caching.Memcached.Results;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching.Memcached.Protocol
{
@@ -32,12 +33,12 @@ bool IOperation.ReadResponseAsync(PooledSocket socket, Action<bool> next)
return this.ReadResponseAsync(socket, next);
}
- int IOperation.StatusCode
+ StatusCode IOperation.StatusCode
{
get { return this.StatusCode; }
}
- public int StatusCode { get; protected set; }
+ public StatusCode StatusCode { get; protected set; }
}
}
View
3  Enyim.Caching/Memcached/Results/IOperationResult.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching.Memcached.Results
{
@@ -27,7 +28,7 @@ public interface IOperationResult
/// <summary>
/// The StatusCode returned from the server
/// </summary>
- int? StatusCode { get; set; }
+ StatusCode? StatusCode { get; set; }
/// <summary>
/// A result that influenced the current result
View
6 Enyim.Caching/Memcached/Results/OperationResultBase.cs
@@ -1,7 +1,5 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching.Memcached.Results
{
@@ -13,7 +11,7 @@ public abstract class OperationResultBase : IOperationResult
public Exception Exception { get; set; }
- public int? StatusCode { get; set; }
+ public StatusCode? StatusCode { get; set; }
public IOperationResult InnerResult { get; set; }
View
38 ...ed/Results/StatusCodes/StatusCodeEnums.cs → ...hed/Results/StatusCodes/StatusCodeEnum.cs
@@ -1,16 +1,34 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
namespace Enyim.Caching.Memcached.Results.StatusCodes
{
- public enum StatusCodeEnums
- {
- Success = 0,
- NotFound,
- DataExistsForKey
- }
+ public enum StatusCode
+ {
+ NodeNotFound = -2,
+ UnspecifiedError = -1,
+ NoError = 0,
+ KeyNotFound = 1,
+ KeyExists = 2,
+ ValueTooLarge = 3,
+ InvalidArguments = 4,
+ ItemNotStored = 5,
+ IncrDecrOnNonNumericValue = 6,
+ Unauthorized = 0x20,
+ ContinueAuthentication = 0x21,
+ UnknownCommand = 0x81,
+ OutOfMemory = 0x82
+ }
+
+ public static class Converter
+ {
+ public static StatusCode ToStatusCode(this int input)
+ {
+ if (input >= -2 && input <= 6 || input == 0x20 || input == 0x21 || input == 0x81 || input == 0x82)
+ return (StatusCode)input;
+
+ return StatusCode.UnspecifiedError;
+ }
+ }
}
#region [ License information ]
@@ -33,4 +51,4 @@ public enum StatusCodeEnums
* limitations under the License.
*
* ************************************************************/
-#endregion
+#endregion
View
8 Enyim.Caching/MemcachedClient.Results.cs
@@ -6,6 +6,7 @@
using Enyim.Caching.Memcached.Results;
using Enyim.Caching.Memcached.Results.Extensions;
using Enyim.Caching.Memcached.Results.Factories;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching
{
@@ -24,7 +25,7 @@ public partial class MemcachedClient : IMemcachedClient, IMemcachedResultsClient
public IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value)
{
ulong tmp = 0;
- int status;
+ StatusCode status;
return this.PerformStore(mode, key, value, 0, ref tmp, out status);
}
@@ -40,7 +41,7 @@ public IStoreOperationResult ExecuteStore(StoreMode mode, string key, object val
public IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, TimeSpan validFor)
{
ulong tmp = 0;
- int status;
+ StatusCode status;
return this.PerformStore(mode, key, value, MemcachedClient.GetExpiration(validFor, null), ref tmp, out status);
}
@@ -56,7 +57,7 @@ public IStoreOperationResult ExecuteStore(StoreMode mode, string key, object val
public IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, DateTime expiresAt)
{
ulong tmp = 0;
- int status;
+ StatusCode status;
return this.PerformStore(mode, key, value, MemcachedClient.GetExpiration(null, expiresAt), ref tmp, out status);
}
@@ -474,6 +475,7 @@ protected IRemoveOperationResult PerformRemove(string key, ulong cas = 0)
return result;
}
+ result.StatusCode = StatusCode.NodeNotFound;
result.Fail("Unable to locate node");
return result;
}
View
28 Enyim.Caching/MemcachedClient.cs
@@ -10,6 +10,7 @@
using Enyim.Caching.Memcached.Results;
using Enyim.Caching.Memcached.Results.Factories;
using Enyim.Caching.Memcached.Results.Extensions;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching
{
@@ -209,7 +210,7 @@ protected virtual IGetOperationResult PerformTryGet(string key, out ulong cas, o
result.Value = value;
result.Cas = cas;
-
+ result.StatusCode = StatusCode.NodeNotFound;
if (this.performanceMonitor != null) this.performanceMonitor.Get(1, false);
result.Fail("Unable to locate node");
@@ -229,7 +230,7 @@ protected virtual IGetOperationResult PerformTryGet(string key, out ulong cas, o
public bool Store(StoreMode mode, string key, object value)
{
ulong tmp = 0;
- int status;
+ StatusCode status;
return this.PerformStore(mode, key, value, 0, ref tmp, out status).Success;
}
@@ -245,7 +246,7 @@ public bool Store(StoreMode mode, string key, object value)
public bool Store(StoreMode mode, string key, object value, TimeSpan validFor)
{
ulong tmp = 0;
- int status;
+ StatusCode status;
return this.PerformStore(mode, key, value, MemcachedClient.GetExpiration(validFor, null), ref tmp, out status).Success;
}
@@ -261,7 +262,7 @@ public bool Store(StoreMode mode, string key, object value, TimeSpan validFor)
public bool Store(StoreMode mode, string key, object value, DateTime expiresAt)
{
ulong tmp = 0;
- int status;
+ StatusCode status;
return this.PerformStore(mode, key, value, MemcachedClient.GetExpiration(null, expiresAt), ref tmp, out status).Success;
}
@@ -277,7 +278,7 @@ public bool Store(StoreMode mode, string key, object value, DateTime expiresAt)
public CasResult<bool> Cas(StoreMode mode, string key, object value, ulong cas)
{
var result = this.PerformStore(mode, key, value, 0, cas);
- return new CasResult<bool> { Cas = result.Cas, Result = result.Success, StatusCode = result.StatusCode.Value };
+ return new CasResult<bool> { Cas = result.Cas, Result = result.Success, StatusCode = result.StatusCode.Value };
}
@@ -328,10 +329,10 @@ public CasResult<bool> Cas(StoreMode mode, string key, object value)
private IStoreOperationResult PerformStore(StoreMode mode, string key, object value, uint expires, ulong cas)
{
ulong tmp = cas;
- int status;
+ StatusCode status;
var retval = this.PerformStore(mode, key, value, expires, ref tmp, out status);
- retval.StatusCode = status;
+ retval.StatusCode = status;
if (retval.Success)
{
@@ -340,13 +341,13 @@ private IStoreOperationResult PerformStore(StoreMode mode, string key, object va
return retval;
}
- protected virtual IStoreOperationResult PerformStore(StoreMode mode, string key, object value, uint expires, ref ulong cas, out int statusCode)
+ protected virtual IStoreOperationResult PerformStore(StoreMode mode, string key, object value, uint expires, ref ulong cas, out StatusCode statusCode)
{
var hashedKey = this.keyTransformer.Transform(key);
var node = this.pool.Locate(hashedKey);
var result = StoreOperationResultFactory.Create();
- statusCode = -1;
+ statusCode = StatusCode.UnspecifiedError;
if (node != null)
{
@@ -367,7 +368,7 @@ protected virtual IStoreOperationResult PerformStore(StoreMode mode, string key,
var commandResult = node.Execute(command);
result.Cas = cas = command.CasValue;
- result.StatusCode = statusCode = command.StatusCode;
+ result.StatusCode = statusCode = command.StatusCode;
if (commandResult.Success)
{
@@ -381,7 +382,7 @@ protected virtual IStoreOperationResult PerformStore(StoreMode mode, string key,
}
if (this.performanceMonitor != null) this.performanceMonitor.Store(mode, 1, false);
-
+ result.StatusCode = StatusCode.NodeNotFound;
result.Fail("Unable to locate node");
return result;
}
@@ -619,7 +620,8 @@ protected virtual IMutateOperationResult PerformMutate(MutationMode mode, string
if (this.performanceMonitor != null) this.performanceMonitor.Mutate(mode, 1, false);
// TODO not sure about the return value when the command fails
- result.Fail("Unable to locate node");
+ result.StatusCode = StatusCode.NodeNotFound;
+ result.Fail("Unable to locate node");
return result;
}
@@ -709,7 +711,7 @@ protected virtual IConcatOperationResult PerformConcatenate(ConcatenationMode mo
}
if (this.performanceMonitor != null) this.performanceMonitor.Concatenate(mode, 1, false);
-
+ result.StatusCode = StatusCode.NodeNotFound;
result.Fail("Unable to locate node");
return result;
}
Something went wrong with that request. Please try again.