File rotation

34 views
Skip to first unread message

Justin Davis

unread,
Apr 24, 2013, 2:20:50 PM4/24/13
to dendri...@googlegroups.com
Hi!

Question about file rotation -- I was running dendrite last night, left it running and when the log file I was watching rotated. Dendrite stopped processing this file -- any thoughts on how to best handle log rotation?

Thanks!
-Justin

Kyle Maxwell

unread,
Apr 24, 2013, 2:57:51 PM4/24/13
to dendri...@googlegroups.com
Here's the code to handle rotation.  If the tail hits eof, and the file is shorter than last recorded, the tail will start over.


I have an integration test that reads a file, truncates it, and re-writes it.  It verifies that the contents get read twice.


Our production use is so far on files that rotate forwards (e.g. foo.2013.01.01.log), so its possible that there's a bug in this code.  Minimal instructions to reproduce the bug would be greatly appreciated.
--
Cheers,
Kyle Maxwell
Founder, Onemorecloud, Inc
bonsai.io | websolr.com
ky...@onemorecloud.com

Justin Davis

unread,
Apr 24, 2013, 3:41:37 PM4/24/13
to dendri...@googlegroups.com
Got it, I'll try to reproduce and investigate that code some more.

Justin Davis

unread,
Apr 25, 2013, 3:19:32 AM4/25/13
to dendri...@googlegroups.com
Alright, happened again... I'll do some more investigation when I have some free time, but here's a quick data point: I checked out /proc/PID of the dendrite process, and did an ls in the fd folder, and got this:

lr-x------ 1 root root 64 Apr 24 23:49 6 -> /var/log/nginx/access.log.1

(I'm running this on access.log, in case that's unclear, and logrotate moves the file to access.log.1 on rotation)

I'm thinking that because lograte is moving the file, the inode isn't changing and so it just looks like the file isn't being updated anymore, and dendrite waits for more data which never comes. The kernel knows better, and it shows that the file descriptor is pointing to the moved file...

Also worth noting:

ls -hal access.log.1
-rw-r----- 1 justin adm 3694944 Apr 24 23:46 access.log.1

cat offsets/access.log.ptr
3694944

So, perhaps dendrite thinks that it's seen all the data from that file so far, and is awaiting more?

One more theory: perhaps lograte is moving access.log to access.log.1, and dendrite tries to open access.log before it's been recreated?

Anyway, will read through some code and see if anything looks suspicious there.

-J

Kyle Maxwell

unread,
Apr 25, 2013, 11:56:25 AM4/25/13
to dendri...@googlegroups.com
I think its because dendrite has a map of tails keyed by original filename.  Dendrite still has access.log.1 open, but thinks it's access.log, and so prevents a new tail being opened on access.log.

Kyle Maxwell

unread,
Apr 25, 2013, 4:09:31 PM4/25/13
to dendri...@googlegroups.com
This is fixed in master.
Reply all
Reply to author
Forward
0 new messages