Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #109 from nathannis/master
Browse files Browse the repository at this point in the history
Excessive Blacklisting when using a load balancer to access nodes
  • Loading branch information
nberardi committed Jan 25, 2013
2 parents 9ced334 + f575b66 commit f83865b
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Connections/ConnectionBuilder.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ConnectionBuilder : FluentCassandra.Connections.IConnectionBuilder
/// <param name="host"></param> /// <param name="host"></param>
/// <param name="port"></param> /// <param name="port"></param>
/// <param name="timeout"></param> /// <param name="timeout"></param>
public ConnectionBuilder(string keyspace, string host, int port = Server.DefaultPort, int connectionTimeout = Server.DefaultTimeout, bool pooling = false, int minPoolSize = 0, int maxPoolSize = 100, int maxRetries = 0, int serverPollingInterval = 30, int connectionLifetime = 0, ConnectionType connectionType = ConnectionType.Framed, int bufferSize = 1024, ConsistencyLevel read = ConsistencyLevel.QUORUM, ConsistencyLevel write = ConsistencyLevel.QUORUM, string cqlVersion = FluentCassandra.Connections.CqlVersion.ServerDefault, bool compressCqlQueries = true, string username = null, string password = null) public ConnectionBuilder(string keyspace, string host, int port = Server.DefaultPort, int connectionTimeout = Server.DefaultTimeout, bool pooling = false, int minPoolSize = 0, int maxPoolSize = 100, int maxRetries = 0, int serverPollingInterval = 30, int connectionLifetime = 0, ConnectionType connectionType = ConnectionType.Framed, int bufferSize = 1024, ConsistencyLevel read = ConsistencyLevel.QUORUM, ConsistencyLevel write = ConsistencyLevel.QUORUM, string cqlVersion = FluentCassandra.Connections.CqlVersion.ConnectionDefault , bool compressCqlQueries = true, string username = null, string password = null)
{ {
Keyspace = keyspace; Keyspace = keyspace;
Servers = new List<Server>() { new Server(host, port) }; Servers = new List<Server>() { new Server(host, port) };
Expand Down
2 changes: 1 addition & 1 deletion src/Connections/ConnectionProvider.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class ConnectionProvider : IConnectionProvider
protected ConnectionProvider(IConnectionBuilder builder) protected ConnectionProvider(IConnectionBuilder builder)
{ {
ConnectionBuilder = builder; ConnectionBuilder = builder;
Servers = new RoundRobinServerManager(builder); Servers = new SingleServerManager(builder);
} }


/// <summary> /// <summary>
Expand Down
63 changes: 63 additions & 0 deletions src/Connections/SingleServerManager.cs
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace FluentCassandra.Connections
{
public class SingleServerManager : IServerManager
{
private readonly object _lock = new object();
private Server _server;

public SingleServerManager(IConnectionBuilder builder)
{
_server = builder.Servers[0];
}

#region IServerManager Members

public bool HasNext
{
get { return true; }
}

public Server Next()
{
return _server;
}

public void ErrorOccurred(Server server, Exception exc = null)
{
Debug.WriteLineIf(exc != null, exc, "connection");
}

public void Add(Server server)
{
_server = server;
}
public void Remove(Server server)
{
throw new NotImplementedException ("SingleServerManager does not implement Remove(server)");
}
#endregion
#region IEnumerable<Server> Members

public IEnumerator<Server> GetEnumerator()
{
throw new NotImplementedException("SingleServerManager does not implement Enumerable(server)");
}

#endregion

#region IEnumerable Members

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

#endregion
}
}
7 changes: 4 additions & 3 deletions src/FluentCassandra.csproj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<SignAssembly>false</SignAssembly> <SignAssembly>true</SignAssembly>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>fluentCassandra-me.snk</AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
Expand Down Expand Up @@ -115,6 +114,7 @@
<Compile Include="Connections\ConnectionType.cs" /> <Compile Include="Connections\ConnectionType.cs" />
<Compile Include="Connections\CqlVersion.cs" /> <Compile Include="Connections\CqlVersion.cs" />
<Compile Include="Connections\IConnectionBuilder.cs" /> <Compile Include="Connections\IConnectionBuilder.cs" />
<Compile Include="Connections\SingleServerManager.cs" />
<Compile Include="Connections\NormalConnectionProvider.cs" /> <Compile Include="Connections\NormalConnectionProvider.cs" />
<Compile Include="Connections\IConnection.cs" /> <Compile Include="Connections\IConnection.cs" />
<Compile Include="Connections\IConnectionProvider.cs" /> <Compile Include="Connections\IConnectionProvider.cs" />
Expand Down Expand Up @@ -312,6 +312,7 @@
<Compile Include="Types\VoidType.cs" /> <Compile Include="Types\VoidType.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="fluentCassandra-me.snk" />
<None Include="FluentCassandra.nuspec"> <None Include="FluentCassandra.nuspec">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</None> </None>
Expand Down
4 changes: 2 additions & 2 deletions test/FluentCassandra.StressTest/Main.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@


namespace FluentCassandra.StressTest namespace FluentCassandra.StressTest
{ {
class Program class Program1
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
Console.Error.WriteLine("Stress Test 1"); Console.Error.WriteLine("Stress Test 1");
try try
{ {
StressTest.StressTest1.Test(); //tressTest1.Test();
} }
catch (Exception ex) catch (Exception ex)
{ {
Expand Down
2 changes: 1 addition & 1 deletion test/FluentCassandra.StressTest/StressTest1.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using FluentCassandra.Types; using FluentCassandra.Types;
using FluentCassandra.Connections; using FluentCassandra.Connections;
using Apache.Cassandra; using FluentCassandra.Apache.Cassandra;


namespace FluentCassandra.StressTest namespace FluentCassandra.StressTest
{ {
Expand Down
27 changes: 27 additions & 0 deletions test/FluentCassandra.Tests/Connections/SingleServerManagerTests.cs
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using Xunit;

namespace FluentCassandra.Connections.Tests
{
public class SingleServerManagerTests
{
[Fact]
public void CanGetServerAfterError()
{
SingleServerManager target = new SingleServerManager(new ConnectionBuilder("Server=unit-test-1"));

Server original = target.Next();

for (int i = 0; i < 10; i++)
{
Assert.True(target.HasNext, "SingleServerManager should always have another server available.");
Server next = target.Next();
Assert.True(original.ToString().Equals(next.ToString(), StringComparison.OrdinalIgnoreCase),
"SingleServerManager always returns the same server.");
//mark the server as failing to set up the next test iteration.
target.ErrorOccurred(next);
}
}
}
}
1 change: 1 addition & 0 deletions test/FluentCassandra.Tests/FluentCassandra.Tests.csproj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<Compile Include="CassandraQueryTest.cs" /> <Compile Include="CassandraQueryTest.cs" />
<Compile Include="Connections\ConnectionBuilderTests.cs" /> <Compile Include="Connections\ConnectionBuilderTests.cs" />
<Compile Include="Connections\ConnectionProviderTests.cs" /> <Compile Include="Connections\ConnectionProviderTests.cs" />
<Compile Include="Connections\SingleServerManagerTests.cs" />
<Compile Include="Connections\NormalConnectionProviderTests.cs" /> <Compile Include="Connections\NormalConnectionProviderTests.cs" />
<Compile Include="Connections\RoundRobinServerManagerTests.cs" /> <Compile Include="Connections\RoundRobinServerManagerTests.cs" />
<Compile Include="CqlHelperTest.cs" /> <Compile Include="CqlHelperTest.cs" />
Expand Down
2 changes: 1 addition & 1 deletion test/FluentCassandra.Tests/app.config
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<configuration> <configuration>
<appSettings> <appSettings>
<add key="TestServer" value="localhost"></add> <add key="TestServer" value="dev-Cassandra"></add>
<add key="TestPort" value="9160"></add> <add key="TestPort" value="9160"></add>
<add key="TestKeySpace" value="Testing"></add> <add key="TestKeySpace" value="Testing"></add>
</appSettings> </appSettings>
Expand Down

0 comments on commit f83865b

Please sign in to comment.