This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Tarantool -- an efficient key/value data store".
The branch perl-iproto-async has been updated
via 54611269f1628e23c451cfa0f165f51528264e5b (commit)
from f9593d2377c9eabea88087909a99cb2e611ac9cf (commit)
Summary of changes:
mod/silverbox/client/perl/lib/MR/IProto.pm | 21 ++++----
.../client/perl/lib/MR/IProto/Cluster/Server.pm | 4 +-
.../client/perl/lib/MR/IProto/Connection/Async.pm | 13 ++++-
.../client/perl/lib/MR/IProto/Connection/Sync.pm | 55 +++++++++++---------
.../client/perl/lib/MR/IProto/NoResponse.pm | 23 ++++++++
5 files changed, 75 insertions(+), 41 deletions(-)
create mode 100644 mod/silverbox/client/perl/lib/MR/IProto/NoResponse.pm
commit 54611269f1628e23c451cfa0f165f51528264e5b
Author: Aleksey Mashanov <[email protected]>
Date: Tue Nov 30 18:47:33 2010 +0300
https://sys.mail.ru/task_viewer.php?id=761758
no_reply means no reply at all, not reply with empty data
diff --git a/mod/silverbox/client/perl/lib/MR/IProto.pm
b/mod/silverbox/client/perl/lib/MR/IProto.pm
index 4ef70aa..0d5f293 100644
--- a/mod/silverbox/client/perl/lib/MR/IProto.pm
+++ b/mod/silverbox/client/perl/lib/MR/IProto.pm
@@ -36,7 +36,7 @@ but requires some more CPU):
);
my $response = $client->send($request);
# $response isa My::Project::Message::MyOperation::Response.
- # Of cource, both message classes (request and reply) must
+ # Of course, both message classes (request and reply) must
# be implemented by user.
Or without them (not recommended because of unclean architecture):
@@ -457,12 +457,15 @@ sub _send {
die "Callback must be specified" unless $callback;
die "Method must be called in void context" if defined wantarray;
- my ($req_msg, $key, $body, $unpack, $retry);
+ my ($req_msg, $key, $body, $unpack, $retry, $response_class, $no_reply);
# MR::IProto::Message OO-API
if( blessed($message) ) {
$req_msg = $message->msg;
$key = $message->key;
$body = $message->data;
+ $response_class = $self->_reply_class->{$req_msg};
+ die sprintf "Cannot find response class for message code $req_msg\n"
unless $response_class;
+ $no_reply = $response_class->isa('MR::IProto::NoResponse');
$retry = $message->retry ? $self->max_request_retries : 1;
}
# Old-style compatible API
@@ -471,7 +474,8 @@ sub _send {
$body = exists $message->{payload} ? $message->{payload}
: ref $message->{data} ? pack delete $message->{pack} || 'L*',
@{$message->{data}}
: $message->{data};
- $unpack = $message->{no_reply} ? sub { 0 } : $message->{unpack} or die
"unpack or no_reply must be specified";
+ $no_reply = $message->{no_reply};
+ $unpack = $no_reply ? sub { 0 } : $message->{unpack} or die "unpack or
no_reply must be specified";
$retry = $message->{retry} ? $self->max_request_retries : 1;
}
@@ -483,7 +487,7 @@ sub _send {
my ($by_resp) = @_;
$self->_debug(2, sprintf "send msg=%d try %d of %d total", $req_msg,
$try, $by_resp ? $self->max_request_retries : $retry );
$server = $self->cluster->server( $key );
- $server->$xsync->send($req_msg, $body, $sub);
+ $server->$xsync->send($req_msg, $body, $sub, $no_reply);
};
my $next_try = $sync
? sub {
@@ -524,17 +528,12 @@ sub _send {
else {
my $ok = eval {
die "Request and reply message code is different: $resp_msg !=
$req_msg\n"
- unless $resp_msg == $req_msg;
+ unless $no_reply || $resp_msg == $req_msg;
if ($unpack) {
$data = [ $unpack->($data) ];
}
else {
- if( my $data_class = $self->_reply_class->{$resp_msg} ) {
- $data = $data_class->new( data => $data, request =>
$message );
- }
- else {
- die sprintf "Unknown message code $resp_msg\n";
- }
+ $data = $response_class->new( data => $data, request =>
$message );
}
1;
};
diff --git a/mod/silverbox/client/perl/lib/MR/IProto/Cluster/Server.pm
b/mod/silverbox/client/perl/lib/MR/IProto/Cluster/Server.pm
index 86a949a..375ca01 100644
--- a/mod/silverbox/client/perl/lib/MR/IProto/Cluster/Server.pm
+++ b/mod/silverbox/client/perl/lib/MR/IProto/Cluster/Server.pm
@@ -63,7 +63,7 @@ Timeout of connect operation.
has connect_timeout => (
is => 'rw',
isa => 'Num',
- default => 5,
+ default => 2,
);
=item timeout
@@ -75,7 +75,7 @@ Timeout of read and write operations.
has timeout => (
is => 'rw',
isa => 'Num',
- default => 5,
+ default => 2,
trigger => sub {
my ($self, $new) = @_;
$self->async->set_timeout($new) if $self->has_async();
diff --git a/mod/silverbox/client/perl/lib/MR/IProto/Connection/Async.pm
b/mod/silverbox/client/perl/lib/MR/IProto/Connection/Async.pm
index 8626595..af1a2e9 100644
--- a/mod/silverbox/client/perl/lib/MR/IProto/Connection/Async.pm
+++ b/mod/silverbox/client/perl/lib/MR/IProto/Connection/Async.pm
@@ -82,14 +82,14 @@ sub set_timeout {
=over
-=item _send( $msg, $payload, $callback )
+=item _send( $msg, $payload, $callback, $no_reply )
Send message to server.
=cut
sub _send {
- my ($self, $msg, $payload, $callback) = @_;
+ my ($self, $msg, $payload, $callback, $no_reply) = @_;
my $sync = $self->_choose_sync();
my $header = $self->_pack_header($msg, length $payload, $sync);
$self->_callbacks->{$sync} = $callback;
@@ -97,7 +97,14 @@ sub _send {
$self->_debug_dump(5, 'send header: ', $header);
$self->_debug_dump(5, 'send payload: ', $payload);
$self->_handle->push_write( $header . $payload );
- $self->_handle->push_read( chunk => 12, $self->_read_reply );
+ if( $no_reply ) {
+ $self->_recv_finished($sync, undef, undef);
+ $self->_try_to_send();
+ delete($self->_callbacks->{$sync})->(undef, undef);
+ }
+ else {
+ $self->_handle->push_read( chunk => 12, $self->_read_reply );
+ }
return;
}
diff --git a/mod/silverbox/client/perl/lib/MR/IProto/Connection/Sync.pm
b/mod/silverbox/client/perl/lib/MR/IProto/Connection/Sync.pm
index 825f64a..a95e321 100644
--- a/mod/silverbox/client/perl/lib/MR/IProto/Connection/Sync.pm
+++ b/mod/silverbox/client/perl/lib/MR/IProto/Connection/Sync.pm
@@ -34,10 +34,10 @@ See L<MR::IProto::Connection/send> for more information.
=cut
sub send {
- my ($self, $msg, $payload, $callback) = @_;
- my ($resp_msg, $resp_payload);
+ my ($self, $msg, $payload, $callback, $no_reply) = @_;
+ my ($sync, $resp_msg, $resp_payload);
my $ok = eval {
- my $sync = $self->_choose_sync();
+ $sync = $self->_choose_sync();
my $header = $self->_pack_header($msg, length $payload, $sync);
$self->_send_started($sync, $msg, $payload);
$self->_debug_dump(5, 'send header: ', $header);
@@ -50,31 +50,34 @@ sub send {
substr $write, 0, $written, '';
}
- my $resp_header;
- my $to_read = 12;
- while( $to_read ) {
- my $read = sysread($self->_socket, my $buf, $to_read);
- die $! unless defined $read;
- die "EOF during read of header" if $read == 0;
- $resp_header .= $buf;
- $to_read -= $read;
+ unless( $no_reply ) {
+ my $resp_header;
+ my $to_read = 12;
+ while( $to_read ) {
+ my $read = sysread($self->_socket, my $buf, $to_read);
+ die $! unless defined $read;
+ die "EOF during read of header" if $read == 0;
+ $resp_header .= $buf;
+ $to_read -= $read;
+ }
+ $self->_debug_dump(6, 'recv header: ', $resp_header);
+ ($resp_msg, my $resp_length, my $resp_sync) =
$self->_unpack_header($resp_header);
+ die "Request and reply sync is different: $resp_sync != $sync"
unless $resp_sync == $sync;
+
+ $to_read = $resp_length;
+ while( $to_read ) {
+ my $read = sysread($self->_socket, my $buf, $to_read);
+ die $! unless defined $read;
+ die "EOF during read of payload" if $read == 0;
+ $resp_payload .= $buf;
+ $to_read -= $read;
+ }
+ $self->_debug_dump(6, 'recv payload: ', $resp_payload);
}
- $self->_debug_dump(6, 'recv header: ', $resp_header);
- ($resp_msg, my $resp_length, my $resp_sync) =
$self->_unpack_header($resp_header);
- die "Request and reply sync is different: $resp_msg != $msg" unless
$resp_msg == $msg;
-
- $to_read = $resp_length;
- while( $to_read ) {
- my $read = sysread($self->_socket, my $buf, $to_read);
- die $! unless defined $read;
- die "EOF during read of payload" if $read == 0;
- $resp_payload .= $buf;
- $to_read -= $read;
- }
- $self->_debug_dump(6, 'recv payload: ', $resp_payload);
1;
};
if($ok) {
+ $self->_recv_finished($sync, $resp_msg, $resp_payload);
$callback->($resp_msg, $resp_payload);
}
else {
@@ -84,7 +87,9 @@ sub send {
$self->_clear_socket();
}
$self->server->active(0);
- $callback->(undef, undef, $@);
+ my $error = $@;
+ $self->_recv_finished($sync, undef, undef, $error);
+ $callback->(undef, undef, $error);
}
return;
}
diff --git a/mod/silverbox/client/perl/lib/MR/IProto/NoResponse.pm
b/mod/silverbox/client/perl/lib/MR/IProto/NoResponse.pm
new file mode 100644
index 0000000..e3a5be5
--- /dev/null
+++ b/mod/silverbox/client/perl/lib/MR/IProto/NoResponse.pm
@@ -0,0 +1,23 @@
+package MR::IProto::NoResponse;
+
+=head1 NAME
+
+MR::IProto::NoResponse - no response
+
+=head1 DESCRIPTION
+
+Base class used to mark messages with no response.
+
+=cut
+
+use Mouse;
+extends 'MR::IProto::Response';
+
+has '+data' => (
+ isa => 'Undef',
+);
+
+no Mouse;
+__PACKAGE__->meta->make_immutable();
+
+1;
--
Tarantool -- an efficient key/value data store
_______________________________________________
Mailing list: https://launchpad.net/~tarantool-developers
Post to : [email protected]
Unsubscribe : https://launchpad.net/~tarantool-developers
More help : https://help.launchpad.net/ListHelp