[jcifs] Files seem stale, no modifications seen.

CifsCifsCifs apguerlain at gmail.com
Thu Mar 6 10:40:29 MST 2014


Hey all,

I'm working on a tool which uses JCIFS for tailing DNS and DHCP records so
that they can be analyzed in real time.  I have several Windows domain
controllers which all have the consistent behavior for the two types of
logs.  For DNS it rolls over at a certain file size limit, which happens to
be every 3-5 hours or so under normal load, and DHCP files which are
enumerated like:

DhcpSrvLog-Sun.log
DhcpSrvLog-Mon.log
...
DhcpSrvLog-Sat.log

These DHCP files are generally small, and therefore are replaced once a week
as the DC replaces the file to write a new one.  My issue is primarily
tailing the DHCP files on only one of my four Domain Controllers.  My
strategy is thus:

My program is given the UNC path to the directory containing the DHCP logs
and the credentials in order to create an SmbFile for the directory, which
works.  Each child file of the given directory is baselined with it's
current length in bytes so that the program can logically determine when the
files are written to or replaced.  For each child file of the given
directory it determines changes with the following algorithm:

1. Create SmbRandomAccessFile with the SmbFile.
2. Determine if the file has been replaced.
    a. Seek to the last file length - 1.
    b. Read 1 byte.
        i. If the read was successful, the file has not been replaced.
        ii. If the read was unsuccessful, the file has been replaced.
3. Create a new SmbRandomAccessFile in the same way as step 1.
4. Seek to either the last file length if the file wasn't replaced, or seek
to 0 if the file was replaced.
5. Enter loop
    i. Attempt to read into a byte array the next 4096 bytes with a read
(SmbRandomAccessFile.read(buffer, 0, buffer.length))
    ii. If the read was successful, write the read bytes out to a local file
so that another program can process it, otherwise exit the loop.
6. Set the file length to SmbRandomAccessFile.getFilePointer() so that on
the next iteration the program knows where to start reading.

I'm running one of these programs for each of the four DC's.  The issue I'm
seeing is that it works flawlessly on three of the DC's and fails on the
fourth.  The instance that is malfunctioning is reading the file fine upon
startup and until rotation occurs.  When a new day starts, the DC replaces
one of the DHCP files and starts writing a new one in its place.  If I've
been running the program for a few hours at least, the JCIFS reads do not
see that the file has been replaced and still see the file as it was at the
end of the day before.  This stale file is never read unless I go ahead and
open it in vim or gedit, in which case it for some reason is suddenly seen
as changed by my program.  (Note: I am loading the file for reading on a
different machine that the one running my program.)  Somehow the file
metadata is being updated when I load it, but otherwise JCIFS sees no
change.  I'm trying to determine if it is a JCIFs issue or some type of
caching issue which is causing the stale files.

Any and all help is welcome and I'd be grateful for it.
-CifsCifsCifs



--
View this message in context: http://samba.2283325.n4.nabble.com/Files-seem-stale-no-modifications-seen-tp4662168.html
Sent from the Samba - jcifs mailing list archive at Nabble.com.


More information about the jCIFS mailing list