Skip to content

Instantly share code, notes, and snippets.

@sonots
Created November 21, 2013 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sonots/7586077 to your computer and use it in GitHub Desktop.
Save sonots/7586077 to your computer and use it in GitHub Desktop.
--- /usr/local/fluent-agent-lite/lib/Fluent/AgentLite.pm.orig 2013-11-20 22:56:02.259002703 +0900
+++ /usr/local/fluent-agent-lite/lib/Fluent/AgentLite.pm 2013-11-21 00:08:52.993115865 +0900
@@ -102,22 +102,22 @@
my $primary = $self->choose($self->{servers}->{primary});
my $secondary;
- my $sock = $self->connect($primary) unless $disconnected_primary;
- if (not $sock and $self->{servers}->{secondary}) {
- $secondary = $self->choose($self->{servers}->{secondary});
- $sock = $self->connect($self->choose($self->{servers}->{secondary}));
- }
- $disconnected_primary = 0;
- unless ($sock) {
- # failed to connect both of primary / secondary
- warnf 'failed to connect servers, primary: %s, secondary: %s', $primary, ($secondary || 'none');
- warnf 'waiting %s seconds to reconnect', $reconnect_wait;
-
- Time::HiRes::sleep($reconnect_wait);
- $reconnect_wait *= RECONNECT_WAIT_INCR_RATE;
- $reconnect_wait = RECONNECT_WAIT_MAX if $reconnect_wait > RECONNECT_WAIT_MAX;
- next;
- }
+ #my $sock = $self->connect($primary) unless $disconnected_primary;
+ #if (not $sock and $self->{servers}->{secondary}) {
+ # $secondary = $self->choose($self->{servers}->{secondary});
+ # $sock = $self->connect($self->choose($self->{servers}->{secondary}));
+ #}
+ #$disconnected_primary = 0;
+ #unless ($sock) {
+ # # failed to connect both of primary / secondary
+ # warnf 'failed to connect servers, primary: %s, secondary: %s', $primary, ($secondary || 'none');
+ # warnf 'waiting %s seconds to reconnect', $reconnect_wait;
+
+ # Time::HiRes::sleep($reconnect_wait);
+ # $reconnect_wait *= RECONNECT_WAIT_INCR_RATE;
+ # $reconnect_wait = RECONNECT_WAIT_MAX if $reconnect_wait > RECONNECT_WAIT_MAX;
+ # next;
+ #}
# succeed to connect. set keepalive disconnect time
my $connecting = $secondary || $primary;
@@ -125,7 +125,15 @@
my $expired = time + connection_keepalive_time($keepalive_time) if $expiration_enable;
$reconnect_wait = RECONNECT_WAIT_MIN;
+ my $a_second = time + 1;
+ my $total_lines = 0;
+
while(not $check_reconnect->()) {
+ if (time >= $a_second) {
+ print $total_lines . "\n" if $total_lines > 0;
+ last;
+ }
+
# connection keepalive expired
if ($expiration_enable and time > $expired) {
infof "connection keepalive expired.";
@@ -144,6 +152,7 @@
if (not $pending_packed) {
my $buffered_lines;
($buffered_lines, $continuous_line, $lines) = $self->drain($tailfd, $continuous_line);
+ $total_lines += $lines;
if ($buffered_lines) {
$pending_packed = $self->pack($packer, $fieldname, $buffered_lines);
@@ -161,25 +170,25 @@
}
}
# send
- my $written = $self->send($sock, $pending_packed);
- unless ($written) { # failed to write (socket error).
- $disconnected_primary = 1 unless $secondary;
- last;
- }
+ #my $written = $self->send($sock, $pending_packed);
+ #unless ($written) { # failed to write (socket error).
+ # $disconnected_primary = 1 unless $secondary;
+ # last;
+ #}
$pending_packed = undef;
}
- if ($check_reconnect->()) {
- infof "SIGHUP (or SIGTERM) received";
- $disconnected_primary = 0;
- $check_reconnect->(1); # clear SIGHUP signal
- }
- infof "disconnecting to current server";
- if ($sock) {
- $sock->close;
- $sock = undef;
- }
- infof "disconnected.";
+ #if ($check_reconnect->()) {
+ # infof "SIGHUP (or SIGTERM) received";
+ # $disconnected_primary = 0;
+ # $check_reconnect->(1); # clear SIGHUP signal
+ #}
+ #infof "disconnecting to current server";
+ #if ($sock) {
+ # $sock->close;
+ # $sock = undef;
+ #}
+ #infof "disconnected.";
}
if ($check_terminated->()) {
warnf "SIGTERM received";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment