Cassandra-Client

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

dist.ini
encode.c
encode.h
lib/Cassandra/Client.pm
lib/Cassandra/Client/AsyncAnyEvent.pm
lib/Cassandra/Client/AsyncEV.pm
lib/Cassandra/Client/Config.pm
lib/Cassandra/Client/Connection.pm
lib/Cassandra/Client/Error/Base.pm
lib/Cassandra/Client/Error/ClientThrottlingError.pm
lib/Cassandra/Client/Error/ReadTimeoutException.pm
lib/Cassandra/Client/Error/UnavailableException.pm
lib/Cassandra/Client/Error/WriteTimeoutException.pm
lib/Cassandra/Client/Metadata.pm
lib/Cassandra/Client/NetworkStatus.pm
lib/Cassandra/Client/Policy/Auth/Password.pm
lib/Cassandra/Client/Policy/LoadBalancing/Default.pm
lib/Cassandra/Client/Policy/Queue/Default.pm
lib/Cassandra/Client/Policy/Retry.pm
lib/Cassandra/Client/Policy/Retry/Default.pm
lib/Cassandra/Client/Policy/Throttle/Adaptive.pm
lib/Cassandra/Client/Policy/Throttle/Default.pm
lib/Cassandra/Client/Pool.pm

lib/Cassandra/Client.pm  view on Meta::CPAN

    my ($self, $command, $callback, $args, $command_info, $error)= @_;

    if (is_ref($error)) {
        my $retry_decision;
        my $statement = $command eq 'execute_prepared' ? {idempotent => $args->[2]->{idempotent}} : {};

        if ($error->do_retry) {
            $retry_decision= Cassandra::Client::Policy::Retry::retry;
        } elsif ($error->is_request_error) {
            $retry_decision= $self->{retry_policy}->on_request_error($statement, undef, $error, ($command_info->{retries}||0));
        } elsif ($error->isa('Cassandra::Client::Error::WriteTimeoutException')) {
            $retry_decision= $self->{retry_policy}->on_write_timeout($statement, $error->cl, $error->write_type, $error->blockfor, $error->received, ($command_info->{retries}||0));
        } elsif ($error->isa('Cassandra::Client::Error::ReadTimeoutException')) {
            $retry_decision= $self->{retry_policy}->on_read_timeout($statement, $error->cl, $error->blockfor, $error->received, $error->data_retrieved, ($command_info->{retries}||0));
        } elsif ($error->isa('Cassandra::Client::Error::UnavailableException')) {
            $retry_decision= $self->{retry_policy}->on_unavailable($statement, $error->cl, $error->required, $error->alive, ($command_info->{retries}||0));
        } else {
            $retry_decision= Cassandra::Client::Policy::Retry::rethrow;
        }

        if ($retry_decision && $retry_decision eq 'retry') {
            return $self->_command_retry($command, $callback, $args, $command_info);
        }

lib/Cassandra/Client/Error/ReadTimeoutException.pm  view on Meta::CPAN

package Cassandra::Client::Error::ReadTimeoutException;
our $AUTHORITY = 'cpan:TVDW';
$Cassandra::Client::Error::ReadTimeoutException::VERSION = '0.21';
use parent 'Cassandra::Client::Error::Base';
use 5.010;
use strict;
use warnings;

sub is_timeout { 1 }
sub cl { $_[0]{cl} }
sub write_type { $_[0]{write_type} }
sub blockfor { $_[0]{blockfor} }
sub received { $_[0]{received} }
sub data_retrieved { $_[0]{data_retrieved} }

1;

__END__

=pod

=head1 NAME

Cassandra::Client::Error::ReadTimeoutException

=head1 VERSION

version 0.21

=head1 AUTHOR

Tom van der Woerdt <tvdw@cpan.org>

=head1 COPYRIGHT AND LICENSE

lib/Cassandra/Client/Error/WriteTimeoutException.pm  view on Meta::CPAN

package Cassandra::Client::Error::WriteTimeoutException;
our $AUTHORITY = 'cpan:TVDW';
$Cassandra::Client::Error::WriteTimeoutException::VERSION = '0.21';
use parent 'Cassandra::Client::Error::Base';
use 5.010;
use strict;
use warnings;

sub is_timeout { 1 }
sub cl { $_[0]{cl} }
sub write_type { $_[0]{write_type} }
sub blockfor { $_[0]{blockfor} }
sub received { $_[0]{received} }

1;

__END__

=pod

=head1 NAME

Cassandra::Client::Error::WriteTimeoutException

=head1 VERSION

version 0.21

=head1 AUTHOR

Tom van der Woerdt <tvdw@cpan.org>

=head1 COPYRIGHT AND LICENSE

lib/Cassandra/Client/Protocol.pm  view on Meta::CPAN

use 5.010;
use strict;
use warnings;

use Encode;

require Exporter;
our @ISA= qw(Exporter);

use Cassandra::Client::Error::Base;
use Cassandra::Client::Error::ReadTimeoutException;
use Cassandra::Client::Error::WriteTimeoutException;
use Cassandra::Client::Error::UnavailableException;

use constant BIGINT_SUPPORTED => eval { unpack('q>', "\0\0\0\0\0\0\0\1") };
use if !BIGINT_SUPPORTED, 'Math::BigInt';

our (@EXPORT_OK, %EXPORT_TAGS);
our (%consistency_lookup, %batch_type_lookup);
BEGIN {
    my %constants= (
        OPCODE_ERROR => 0,

lib/Cassandra/Client/Protocol.pm  view on Meta::CPAN

        $error{cl}= &unpack_short;
        $error{required}= &unpack_int;
        $error{alive}= &unpack_int;
        return Cassandra::Client::Error::UnavailableException->new(%error);
    } elsif ($code == 0x1100) {
        # Write timeout
        $error{cl}= &unpack_short;
        $error{received}= &unpack_int;
        $error{blockfor}= &unpack_int;
        $error{write_type}= &unpack_string;
        return Cassandra::Client::Error::WriteTimeoutException->new(%error);
    } elsif ($code == 0x1200) {
        # Read timeout
        $error{cl}= &unpack_short;
        $error{received}= &unpack_int;
        $error{blockfor}= &unpack_int;
        $error{data_present}= &unpack_char;
        return Cassandra::Client::Error::ReadTimeoutException->new(%error);
    }

    return Cassandra::Client::Error::Base->new(%error);
}

# Support for 32bit perl
sub bigint_to_bytes {
    my $mb= Math::BigInt->new($_[0]);
    if ($_[0] !~ /^-?[0-9\.E]+$/i) { # Idk, approximate it
        warn "Argument $_[0] isn't numeric";

t/08-retries.t  view on Meta::CPAN

#!perl
use 5.010;
use strict;
use warnings;
use File::Basename qw//; use lib File::Basename::dirname(__FILE__).'/lib';
use Test::More;
use Test::Exception;
use TestCassandra;
use Cassandra::Client::Policy::Retry::Default;
use InstrumentedRetry;
use Cassandra::Client::Error::ReadTimeoutException;

plan skip_all => "Missing Cassandra test environment" unless TestCassandra->is_ok;
plan tests => 10;

my $instrumented_retry = InstrumentedRetry->new(
    Cassandra::Client::Policy::Retry::Default->new(
         max_retries_write_timeout => 2,
    )
);

t/08-retries.t  view on Meta::CPAN

    my $keyspace = 'timeoutspace';
    my $table = 'timeouttable';

    $client->execute("drop keyspace if exists $keyspace");
    $client->execute("CREATE KEYSPACE $keyspace WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': '1'}");
    $client->execute("CREATE TABLE $keyspace.$table (id int, a int, b int, c int, d int, e int, f int, PRIMARY KEY (id,a))");

    $client->execute("INSERT INTO $keyspace.$table (id, a, b, c, d, e, f) VALUES( 1, 1, 1, 1, 1, 1, 1)",{},{});

    $instrumented_retry->reset();
    my $read_error = Cassandra::Client::Error::ReadTimeoutException->new(
        code => 42,
        message => 'Synthetic read error',
        is_timeout => 1,
        received => 0,
        blockfor => 1,
        data_retrieved => 0,
   );

    throws_ok
        { (my $res) = $client->execute("SELECT * FROM $keyspace.$table",{},{_synthetic_error => $read_error}); }



( run in 0.266 second using v1.01-cache-2.11-cpan-4d50c553e7e )