Class: LogStash::Outputs::S3::TemporaryFileFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/s3/temporary_file_factory.rb

Overview

Since the file can contains dynamic part, we have to handle a more local structure to allow a nice recovery from a crash.

The local structure will look like this.

<TEMPORARY_PATH>/<UUID>/<prefix>/ls.s3.localhost.%Y-%m-%dT%H.%m.tag_es_fb.part1.txt.gz

Since the UUID should be fairly unique I can destroy the whole path when an upload is complete. I do not have to mess around to check if the other directory have file in it before destroying them.

Defined Under Namespace

Classes: IOWrappedGzip

Constant Summary collapse

FILE_MODE =
"a"
STRFTIME =
"%Y-%m-%dT%H.%M"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, tags, encoding, temporary_directory) ⇒ TemporaryFileFactory

Returns a new instance of TemporaryFileFactory.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/logstash/outputs/s3/temporary_file_factory.rb', line 26

def initialize(prefix, tags, encoding, temporary_directory)
  @counter = 0
  @prefix = prefix

  @tags = tags
  @encoding = encoding
  @temporary_directory = temporary_directory
  @lock = Mutex.new

  rotate!
end

Instance Attribute Details

#counterObject

Returns the value of attribute counter.



24
25
26
# File 'lib/logstash/outputs/s3/temporary_file_factory.rb', line 24

def counter
  @counter
end

#currentObject

Returns the value of attribute current.



24
25
26
# File 'lib/logstash/outputs/s3/temporary_file_factory.rb', line 24

def current
  @current
end

#encodingObject

Returns the value of attribute encoding.



24
25
26
# File 'lib/logstash/outputs/s3/temporary_file_factory.rb', line 24

def encoding
  @encoding
end

#prefixObject

Returns the value of attribute prefix.



24
25
26
# File 'lib/logstash/outputs/s3/temporary_file_factory.rb', line 24

def prefix
  @prefix
end

#tagsObject

Returns the value of attribute tags.



24
25
26
# File 'lib/logstash/outputs/s3/temporary_file_factory.rb', line 24

def tags
  @tags
end

#temporary_directoryObject

Returns the value of attribute temporary_directory.



24
25
26
# File 'lib/logstash/outputs/s3/temporary_file_factory.rb', line 24

def temporary_directory
  @temporary_directory
end

Instance Method Details

#rotate!Object



38
39
40
41
42
43
44
# File 'lib/logstash/outputs/s3/temporary_file_factory.rb', line 38

def rotate!
  @lock.synchronize {
    @current = new_file
    increment_counter
    @current
  }
end