class Kafkat::Interface::KafkaLogs

Constants

UNTRUNCATED_SIZE

Attributes

log_path[R]

Public Class Methods

new(config) click to toggle source
# File lib/kafkat/interface/kafka_logs.rb, line 11
def initialize(config)
  @log_path = config.log_path
end

Public Instance Methods

clean_indexes!() click to toggle source
# File lib/kafkat/interface/kafka_logs.rb, line 15
def clean_indexes!
  check_exists

  to_remove = []
  lock_for_write do
    index_glob = File.join(log_path, '**/*.index')
    Dir[index_glob].each do |index_path|
      size = File.size(index_path)
      to_remove << index_path if size == UNTRUNCATED_SIZE
    end
  end

  to_remove.each do |path|
    print "Removing #{path}.\n"
    File.unlink(path)
  end

  to_remove.size
end

Private Instance Methods

check_exists() click to toggle source
# File lib/kafkat/interface/kafka_logs.rb, line 37
def check_exists
  raise NoLogsError unless File.exists?(log_path)
end
lock_for_write() { || ... } click to toggle source
# File lib/kafkat/interface/kafka_logs.rb, line 41
def lock_for_write
  File.open(lockfile_path, File::CREAT) do |lockfile|
    locked = lockfile.flock(File::LOCK_EX | File::LOCK_NB)
    raise KafkaRunningError unless locked
    yield
  end
end
lockfile_path() click to toggle source
# File lib/kafkat/interface/kafka_logs.rb, line 49
def lockfile_path
  File.join(log_path, '.lock')
end