Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
enyim committed Sep 16, 2010
1 parent d61a616 commit 98b412c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 49 deletions.
6 changes: 3 additions & 3 deletions Northscale.Store/NorthScaleClient.cs
Expand Up @@ -161,7 +161,7 @@ private bool ExecuteWithRedirect(IMemcachedNode startNode, ISingleItemOperation
{
if (startNode.Execute(op)) return true;

var iows = (IOpWithState)op;
var iows = (IOperationWithState)op;

#if HAS_FORWARD_MAP
// node responded with invalid vbucket
Expand All @@ -183,7 +183,7 @@ private bool ExecuteWithRedirect(IMemcachedNode startNode, ISingleItemOperation
}
#endif
// still invalid vbucket, try all nodes in sequence
if (iows.State == OpState.InvalidVBucket)
if (iows.State == OperationState.InvalidVBucket)
{
var nodes = this.Pool.GetWorkingNodes();

Expand All @@ -193,7 +193,7 @@ private bool ExecuteWithRedirect(IMemcachedNode startNode, ISingleItemOperation
return true;

// the node accepted our request so quit
if (iows.State != OpState.InvalidVBucket)
if (iows.State != OperationState.InvalidVBucket)
break;
}
}
Expand Down
80 changes: 34 additions & 46 deletions Northscale.Store/VBucketAwareOperationFactory.cs
Expand Up @@ -61,27 +61,15 @@ IFlushOperation IOperationFactory.Flush()
return new FlushOperation();
}

[Serializable]
public class InvalidVBucketException : Exception
{
public InvalidVBucketException() { }
public InvalidVBucketException(string message) : base(message) { }
public InvalidVBucketException(string message, Exception inner) : base(message, inner) { }
protected InvalidVBucketException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}

#region [ Custom operations ]

private const string NotMyVBucket = "I'm not responsible for this vbucket";

private class VBStore : StoreOperation, IOpWithState
private class VBStore : StoreOperation, IOperationWithState
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(VBStore).FullName.Replace('+', '.'));
private VBucketNodeLocator locator;
private OpState state;
private OperationState state;

public VBStore(VBucketNodeLocator locator, StoreMode mode, string key, CacheItem value, uint expires)
: base(mode, key, value, expires)
Expand All @@ -102,32 +90,32 @@ protected override BinaryRequest Build()
protected override bool ReadResponse(PooledSocket socket)
{
var r = base.ReadResponse(socket);
this.state = r ? OpState.Success : OpState.Failure;
this.state = r ? OperationState.Success : OperationState.Failure;

if (!r)
{
if (this.CurrentResponse.GetResponseMessage() == NotMyVBucket)
this.state = OpState.InvalidVBucket;
this.state = OperationState.InvalidVBucket;
}

return r;
}

#region IOpWithState Members
#region [ IOperationWithState ]

OpState IOpWithState.State
OperationState IOperationWithState.State
{
get { return this.state; }
}

#endregion
}

private class VBDelete : DeleteOperation, IOpWithState
private class VBDelete : DeleteOperation, IOperationWithState
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(VBDelete).FullName.Replace('+', '.'));
private VBucketNodeLocator locator;
private OpState state;
private OperationState state;

public VBDelete(VBucketNodeLocator locator, string key)
: base(key)
Expand All @@ -148,32 +136,32 @@ protected override BinaryRequest Build()
protected override bool ReadResponse(PooledSocket socket)
{
var r = base.ReadResponse(socket);
this.state = r ? OpState.Success : OpState.Failure;
this.state = r ? OperationState.Success : OperationState.Failure;

if (!r)
{
if (this.CurrentResponse.GetResponseMessage() == NotMyVBucket)
this.state = OpState.InvalidVBucket;
this.state = OperationState.InvalidVBucket;
}

return r;
}

#region IOpWithState Members
#region [ IOperationWithState ]

OpState IOpWithState.State
OperationState IOperationWithState.State
{
get { return this.state; }
}

#endregion
}

private class VBMutator : MutatorOperation, IOpWithState
private class VBMutator : MutatorOperation, IOperationWithState
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(VBMutator).FullName.Replace('+', '.'));
private VBucketNodeLocator locator;
private OpState state;
private OperationState state;

public VBMutator(VBucketNodeLocator locator, MutationMode mode, string key, ulong defaultValue, ulong delta, uint expires)
: base(mode, key, defaultValue, delta, expires)
Expand All @@ -194,20 +182,20 @@ protected override BinaryRequest Build()
protected override bool ReadResponse(PooledSocket socket)
{
var r = base.ReadResponse(socket);
this.state = r ? OpState.Success : OpState.Failure;
this.state = r ? OperationState.Success : OperationState.Failure;

if (!r)
{
if (this.CurrentResponse.GetResponseMessage() == NotMyVBucket)
this.state = OpState.InvalidVBucket;
this.state = OperationState.InvalidVBucket;
}

return r;
}

#region IOpWithState Members
#region [ IOperationWithState ]

OpState IOpWithState.State
OperationState IOperationWithState.State
{
get { return this.state; }
}
Expand Down Expand Up @@ -237,11 +225,11 @@ protected override BinaryRequest Build(string key)
}
}

private class VBConcat : ConcatOperation, IOpWithState
private class VBConcat : ConcatOperation, IOperationWithState
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(VBConcat).FullName.Replace('+', '.'));
private VBucketNodeLocator locator;
private OpState state;
private OperationState state;

public VBConcat(VBucketNodeLocator locator, ConcatenationMode mode, string key, ArraySegment<byte> data)
: base(mode, key, data)
Expand All @@ -262,38 +250,38 @@ protected override BinaryRequest Build()
protected override bool ReadResponse(PooledSocket socket)
{
var r = base.ReadResponse(socket);
this.state = r ? OpState.Success : OpState.Failure;
this.state = r ? OperationState.Success : OperationState.Failure;

if (!r)
{
if (this.CurrentResponse.GetResponseMessage() == NotMyVBucket)
this.state = OpState.InvalidVBucket;
this.state = OperationState.InvalidVBucket;
}

return r;
}

#region IOpWithState Members
#region [ IOperationWithState ]

OpState IOpWithState.State
OperationState IOperationWithState.State
{
get { return this.state; }
}

#endregion
}

private class VBGet : GetOperation, IOpWithState
private class VBGet : GetOperation, IOperationWithState
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(VBGet).FullName.Replace('+', '.'));
private VBucketNodeLocator locator;
private OpState state;
private OperationState state;

public VBGet(VBucketNodeLocator locator, string key)
: base(key)
{
this.locator = locator;
this.state = OpState.Unspecified;
this.state = OperationState.Unspecified;
}

protected override BinaryRequest Build()
Expand All @@ -309,20 +297,20 @@ protected override BinaryRequest Build()
protected override bool ReadResponse(PooledSocket socket)
{
var r = base.ReadResponse(socket);
this.state = r ? OpState.Success : OpState.Failure;
this.state = r ? OperationState.Success : OperationState.Failure;

if (!r)
{
if (this.CurrentResponse.GetResponseMessage() == NotMyVBucket)
this.state = OpState.InvalidVBucket;
this.state = OperationState.InvalidVBucket;
}

return r;
}

#region IOpWithState Members
#region [ IOperationWithState ]

OpState IOpWithState.State
OperationState IOperationWithState.State
{
get { return this.state; }
}
Expand All @@ -333,12 +321,12 @@ OpState IOpWithState.State
#endregion
}

interface IOpWithState
internal interface IOperationWithState
{
OpState State { get; }
OperationState State { get; }
}

enum OpState { Unspecified, Success, Failure, InvalidVBucket }
internal enum OperationState { Unspecified, Success, Failure, InvalidVBucket }
}

#region [ License information ]
Expand Down

0 comments on commit 98b412c

Please sign in to comment.