1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
|
# File 'lib/fluent/plugin/output.rb', line 1445
def enqueue_thread_run
value_for_interval = nil
if @flush_mode == :interval
value_for_interval = @buffer_config.flush_interval
end
if @chunk_key_time
if !value_for_interval || @buffer_config.timekey < value_for_interval
value_for_interval = [@buffer_config.timekey, @buffer_config.timekey_wait].min
end
end
unless value_for_interval
raise "BUG: both of flush_interval and timekey are disabled"
end
interval = value_for_interval / 11.0
if interval < @buffer_config.flush_thread_interval
interval = @buffer_config.flush_thread_interval
end
while !self.after_started? && !self.stopped?
sleep 0.5
end
log.debug "enqueue_thread actually running"
begin
while @output_enqueue_thread_running
now_int = Time.now.to_i
if @output_flush_interrupted
sleep interval
next
end
@output_enqueue_thread_mutex.lock
begin
if @flush_mode == :interval
flush_interval = @buffer_config.flush_interval.to_i
@buffer.enqueue_all{ |metadata, chunk| chunk.raw_create_at + flush_interval <= now_int }
end
if @chunk_key_time
timekey_unit = @buffer_config.timekey
timekey_wait = @buffer_config.timekey_wait
current_timekey = now_int - now_int % timekey_unit
@buffer.enqueue_all{ |metadata, chunk| metadata.timekey < current_timekey && metadata.timekey + timekey_unit + timekey_wait <= now_int }
end
rescue => e
raise if @under_plugin_development
log.error "unexpected error while checking flushed chunks. ignored.", error: e
log.error_backtrace
ensure
@output_enqueue_thread_waiting = false
@output_enqueue_thread_mutex.unlock
end
sleep interval
end
rescue => e
log.error "error on enqueue thread", error: e
log.error_backtrace
raise
end
end
|