From 451dad33f8c9d68a96899fc506667bcc9cefce18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20Gon=C3=A7alves?= Date: Mon, 5 Sep 2011 18:56:20 +0100 Subject: [PATCH] Fixed client address bug in pool. --- README | 10 ++++++---- lib/Cassandra/Pool.pm | 41 ++++++++++++++++++++++------------------- lib/Cassandra/Simple.pm | 2 +- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/README b/README index 34ad4bd..09787d6 100644 --- a/README +++ b/README @@ -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 . @@ -215,10 +221,6 @@ TODO string describe_partitioner() - describe_ring - - list describe_ring(keyspace) - describe_snitch string describe_snitch() diff --git a/lib/Cassandra/Pool.pm b/lib/Cassandra/Pool.pm index c318087..cbea715 100644 --- a/lib/Cassandra/Pool.pm +++ b/lib/Cassandra/Pool.pm @@ -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} }; @@ -92,4 +95,4 @@ sub get{ return $self->{pool}->[rand @{$self->{pool}}]; } -1 \ No newline at end of file +1 diff --git a/lib/Cassandra/Simple.pm b/lib/Cassandra/Simple.pm index c73235b..d31e217 100644 --- a/lib/Cassandra/Simple.pm +++ b/lib/Cassandra/Simple.pm @@ -77,7 +77,7 @@ use warnings; sub _build_pool { my $self = shift; - print "BBBBB\n"; + #print "BBBBB\n"; return new Cassandra::Pool( $self->keyspace, {