Skip to content

Commit

Permalink
Fixed client address bug in pool.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmgoncalves committed Sep 5, 2011
1 parent a9997c2 commit 451dad3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
10 changes: 6 additions & 4 deletions README
Expand Up @@ -173,6 +173,12 @@ SYNOPSYS
$validation_class only applies when $column doesn't yet exist, and even
then it is optional (defaults to *BytesType*).

ring
Usage: "ring($keyspace)"

Lists the addresses of all nodes on the cluster associated with the
keyspace "<$keyspace">.

BUGS
Bugs should be reported on github at
<https://github.com/fmgoncalves/p5-cassandra-simple>.
Expand Down Expand Up @@ -215,10 +221,6 @@ TODO

string describe_partitioner()

describe_ring

list<TokenRange> describe_ring(keyspace)

describe_snitch

string describe_snitch()
Expand Down
41 changes: 22 additions & 19 deletions lib/Cassandra/Pool.pm
Expand Up @@ -33,51 +33,54 @@ sub new{
my $keyspace = shift;
my $opt = shift;
my $self={};

my $server_name = $opt->{server_name} // '127.0.0.1';
my $server_port = $opt->{server_port} // 9160;

$self->{username} = $opt->{username} // '';
$self->{password} = $opt->{password} // '';

$self = bless($self, $class);

my $first = $self->create_client({server_name => $server_name, server_port => $server_port});
$first->set_keyspace($keyspace);

$self->{pool} = [];

push @{$self->{pool}}, $first;

foreach( map {$_->{endpoints}->[0]} @{$first->describe_ring($keyspace)} ){

# print Dumper map { split( /\//, $_->{endpoints}->[0]) } @{$first->describe_ring($keyspace)};

foreach( map {split( /\//, $_->{endpoints}->[0])} @{$first->describe_ring($keyspace)} ){
next if $server_name eq $_;
#print $_," ",$keyspace,"\n";
# print ">> ",$_," ",$keyspace,"\n";
my $cl = $self->create_client({server_name => $_, server_port => $server_port});
$cl->set_keyspace($keyspace);
push @{$self->{pool}}, $cl;
}

return $self;
}

sub create_client{

my $self = shift;
my $opt = shift // {};
my $server_name = $opt->{server_name};
my $server_port = $opt->{server_port} // 9160;



my $sock = Thrift::Socket->new( $server_name, $server_port );

my $transport = Thrift::FramedTransport->new( $sock, 1024, 1024 );

my $protocol = Thrift::BinaryProtocol->new( $transport );

my $client = Cassandra::CassandraClient->new( $protocol );

$transport->open;


# print "»opened transport \n";

my $auth = Cassandra::AuthenticationRequest->new;
$auth->{credentials} =
{ username => $self->{username}, password => $self->{password} };
Expand All @@ -92,4 +95,4 @@ sub get{
return $self->{pool}->[rand @{$self->{pool}}];
}

1
1
2 changes: 1 addition & 1 deletion lib/Cassandra/Simple.pm
Expand Up @@ -77,7 +77,7 @@ use warnings;

sub _build_pool {
my $self = shift;
print "BBBBB\n";
#print "BBBBB\n";
return new Cassandra::Pool(
$self->keyspace,
{
Expand Down

0 comments on commit 451dad3

Please sign in to comment.