mirror of
https://github.com/meineerde/rackstash.git
synced 2025-10-17 14:01:01 +00:00
Do not lock files with flock by default anymore
Newer Windows versions (i.e. >= 10.0.14393) apparently follow POSIX more strictly. With current Windows and Linux versions, we can thus get away with just writing to the file and depending on the OS to properly serialize those writes. On older versions or with some network filesystems, the user might still have to enable file locking if they are writing to the same log file from multiple processes.
This commit is contained in:
parent
a8911dbbd7
commit
f231d226d0
@ -24,7 +24,8 @@ module Rackstash
|
|||||||
# concurrent writes of multiple processes (e.g. multiple worker processes of
|
# concurrent writes of multiple processes (e.g. multiple worker processes of
|
||||||
# an application server) don't produce interleaved log lines.
|
# an application server) don't produce interleaved log lines.
|
||||||
#
|
#
|
||||||
# When using Windows, we can only guarantee writes up to the underlying
|
# When using some older versions of Windows (< 10.0.14393) or Linux
|
||||||
|
# (< 4.2.6), we likely can only guarantee writes up to the underlying
|
||||||
# drive's sector size to be atomic (usually either 512 Bytes or 4 KiByte).
|
# drive's sector size to be atomic (usually either 512 Bytes or 4 KiByte).
|
||||||
# Larger log lines might be interleaved or partially lost.
|
# Larger log lines might be interleaved or partially lost.
|
||||||
#
|
#
|
||||||
@ -36,10 +37,10 @@ module Rackstash
|
|||||||
# applies to NFS and most FUSE filesystems like sshfs. However, SMB/CIFS is
|
# applies to NFS and most FUSE filesystems like sshfs. However, SMB/CIFS is
|
||||||
# likely safe to use here.
|
# likely safe to use here.
|
||||||
#
|
#
|
||||||
# When reading the log file, the reader might still see incomplete writes
|
# In any case, when reading the log file, the reader might still see
|
||||||
# depending on the OS and filesystem. Since we are only writing complete
|
# incomplete writes depending on the OS and filesystem. Since we are only
|
||||||
# lines, it should be safe to continue reading until you observe a newline
|
# writing complete lines, it should be safe to continue reading until you
|
||||||
# (`\n`) character.
|
# observe a newline (`\n`) character.
|
||||||
#
|
#
|
||||||
# Assuming you are creating the log adapter like this
|
# Assuming you are creating the log adapter like this
|
||||||
#
|
#
|
||||||
@ -116,7 +117,7 @@ module Rackstash
|
|||||||
# @param auto_reopen (see #auto_reopen=)
|
# @param auto_reopen (see #auto_reopen=)
|
||||||
# @param rotate (see #rotate=)
|
# @param rotate (see #rotate=)
|
||||||
# @param lock (see #lock=)
|
# @param lock (see #lock=)
|
||||||
def initialize(path, auto_reopen: true, rotate: nil, lock: Gem.win_platform?)
|
def initialize(path, auto_reopen: true, rotate: nil, lock: false)
|
||||||
@base_path = ::File.expand_path(path).freeze
|
@base_path = ::File.expand_path(path).freeze
|
||||||
|
|
||||||
self.auto_reopen = auto_reopen
|
self.auto_reopen = auto_reopen
|
||||||
@ -135,8 +136,9 @@ module Rackstash
|
|||||||
|
|
||||||
# @param lock [Boolean] set to `true` to aquire an exclusive write lock
|
# @param lock [Boolean] set to `true` to aquire an exclusive write lock
|
||||||
# for each write to the log file. This can ensure more consistent writes
|
# for each write to the log file. This can ensure more consistent writes
|
||||||
# from multiple processes on some filesystems. We enable this by default
|
# from multiple processes on some filesystems. This might be required
|
||||||
# on Windows only since it can be quite expensive.
|
# for older Windows or Linux or with some filesystems not implementing
|
||||||
|
# strict POSIX compatibility (such as NFS or most FUSE filesystems)
|
||||||
def lock=(lock)
|
def lock=(lock)
|
||||||
@lock = !!lock
|
@lock = !!lock
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user