Clemens Ladisch <clem...@ladisch.de> schrieb am Mi., 3. Aug. 2016 um 14:42 Uhr:
> Wolfgang Haupt wrote: > > I've been playing around recently at home with mysql > > Oh? > Sorry, of course that should be SQLite :) > > I was interested why smb breaks the oplock and found that every time I > > execute my command: > > SQLiteDataReader reader = command.ExecuteReader(); // C# code > > wireshark shows me 3 lock requests/responses to/from smb: > > > > 1. exclusive lock, fail immediately > > 2. shared lock, fail immediately > > 3. unlock > > > > I wonder if SQLite needs an exclusive lock (which obviously is an > exclusive > > lock in smb language, maybe not in ntfs/fat language) for select's on the > > database, or if the translation of file-locks is broken within windows' > smb > > protocol implementation. > > Different SQLite locks are implemented by taking an exclusive lock on > different bytes in the file. > > This is what the source code says about it: > > ** LockFile() prevents not just writing but also reading by other > processes. > ** A SHARED_LOCK is obtained by locking a single randomly-chosen > ** byte out of a specific range of bytes. The lock byte is obtained at > ** random so two separate readers can probably access the file at the > ** same time, unless they are unlucky and choose the same lock byte. > ** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range. > ** There can only be one writer. A RESERVED_LOCK is obtained by locking > ** a single byte of the file that is designated as the reserved lock byte. > ** A PENDING_LOCK is obtained by locking a designated byte different from > ** the RESERVED_LOCK byte. > ** > ** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available, > ** which means we can use reader/writer locks. When reader/writer locks > ** are used, the lock is placed on the same range of bytes that is used > ** for probabilistic locking in Win95/98/ME. Hence, the locking scheme > ** will support two or more Win95 readers or two or more WinNT readers. > ** But a single Win95 reader will lock out all WinNT readers and a single > ** WinNT reader will lock out all other Win95 readers. > Thanks for this insight. > > I only see those lock requests when a second user is connected to the db > > (another smb detail I guess). > > > > It's not that there's any problem here, I just want to understand what's > > going on, as I've been assuming that a read only file access will not > break > > an smb oplock. > > Reading will not break an oplock, but when two programs take R/W locks, > Windows assumes that at least one of them is about to write something. All together this means: To obtain a SHARED_LOCK SQLite takes an exclusive lock on a single random byte. I guess Win10 is considered WinNT/2K/XP so SQLite takes a R/W lock -> Windows will assume that at least one of them is about to write something and thus SMB breaks my oplock. Does this make sense? If yes - thanks a lot for your detailed answer. > > Regards, > Clemens > _______________________________________________ > sqlite-users mailing list > sqlite-users@mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users Best Regards, Wolfgang _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users