Implementing xLock/xUnlock VFS methods...

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Implementing xLock/xUnlock VFS methods...

J Decker
The documentation isn't very clear on what the intent of an xUnlock(
SQLITE_LOCK_NONE ) is intended to do.  Is it unlock everything? Is it the
same as remove a shared lock?

The first few operations are xLock( SQLITE_LOCK_SHARED ) followed by
xUnlock(SQLITE_LOCK_NONE)...

sqlite.h.in
https://github.com/mackyle/sqlite/blob/master/src/sqlite.h.in#L627
where the constants are defined... says 'one of these are used...'

and describing locking levels...
https://github.com/mackyle/sqlite/blob/master/src/sqlite.h.in#L708-L720


https://www.sqlite.org/c3ref/io_methods.html
xLock() increases the lock. xUnlock() decreases the lock. The
xCheckReservedLock() method checks whether any database connection, either
in this process or in some other process, is holding a RESERVED, PENDING,
or EXCLUSIVE lock on the file. It returns true if such a lock exists and
false otherwise.

https://www.sqlite.org/lockingv3.html
has description of what locking states are intended to be... there's
'UNLOCKED' but not LOCK_NONE

I did find another page that had lock state transitions, and information
about when the busy callback would be called... but that also didn't say
anything about the transition to unlock states...

There was a note around the .C code in the pager unlocking using LOCK_NONE,
but I cna't find that, it just says, see note above... and that didn't
really say what the intent was.

I searched the nabble mailing list archive for 'SQLITE_LOCK_NONE' and found
0 hits.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Implementing xLock/xUnlock VFS methods...

Dan Kennedy-4

On 8/1/63 20:29, J Decker wrote:
> The documentation isn't very clear on what the intent of an xUnlock(
> SQLITE_LOCK_NONE ) is intended to do.  Is it unlock everything? Is it the
> same as remove a shared lock?

That's right. xUnlock(fd, SQLITE_LOCK_NONE) should completely unlock the
file. xUnlock(fd, SQLITE_LOCK_SHARED) should fall back to a SHARED lock
from RESERVED/PENDING/EXCLUSIVE.

Dan.



>
> The first few operations are xLock( SQLITE_LOCK_SHARED ) followed by
> xUnlock(SQLITE_LOCK_NONE)...
>
> sqlite.h.in
> https://github.com/mackyle/sqlite/blob/master/src/sqlite.h.in#L627
> where the constants are defined... says 'one of these are used...'
>
> and describing locking levels...
> https://github.com/mackyle/sqlite/blob/master/src/sqlite.h.in#L708-L720
>
>
> https://www.sqlite.org/c3ref/io_methods.html
> xLock() increases the lock. xUnlock() decreases the lock. The
> xCheckReservedLock() method checks whether any database connection, either
> in this process or in some other process, is holding a RESERVED, PENDING,
> or EXCLUSIVE lock on the file. It returns true if such a lock exists and
> false otherwise.
>
> https://www.sqlite.org/lockingv3.html
> has description of what locking states are intended to be... there's
> 'UNLOCKED' but not LOCK_NONE
>
> I did find another page that had lock state transitions, and information
> about when the busy callback would be called... but that also didn't say
> anything about the transition to unlock states...
>
> There was a note around the .C code in the pager unlocking using LOCK_NONE,
> but I cna't find that, it just says, see note above... and that didn't
> really say what the intent was.
>
> I searched the nabble mailing list archive for 'SQLITE_LOCK_NONE' and found
> 0 hits.
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Implementing xLock/xUnlock VFS methods...

J Decker
On Wed, Jan 8, 2020 at 7:10 AM Dan Kennedy <[hidden email]> wrote:

>
> On 8/1/63 20:29, J Decker wrote:
> > The documentation isn't very clear on what the intent of an xUnlock(
> > SQLITE_LOCK_NONE ) is intended to do.  Is it unlock everything? Is it the
> > same as remove a shared lock?
>
> That's right. xUnlock(fd, SQLITE_LOCK_NONE) should completely unlock the
> file. xUnlock(fd, SQLITE_LOCK_SHARED) should fall back to a SHARED lock
> from RESERVED/PENDING/EXCLUSIVE.
>
> Thank you... the second thing there confuses me...
xLock(SHARED)  xLock(SHARED) xLock(PENDING)
xUnlock( SHARED) - clear pending, and add a shared for total of 3?  or is
xUnlock always remove (this file handle's) locks?
I haven't finished implementing the first part to get a 'real' sequence...
Also; I suppose I should return SQLITE_BUSY instead of waiting on the lock
myself?  expected return values aren't covered well either.

Dan.

>
>
>
> >
> > The first few operations are xLock( SQLITE_LOCK_SHARED ) followed by
> > xUnlock(SQLITE_LOCK_NONE)...
> >
> > sqlite.h.in
> > https://github.com/mackyle/sqlite/blob/master/src/sqlite.h.in#L627
> > where the constants are defined... says 'one of these are used...'
> >
> > and describing locking levels...
> > https://github.com/mackyle/sqlite/blob/master/src/sqlite.h.in#L708-L720
> >
> >
> > https://www.sqlite.org/c3ref/io_methods.html
> > xLock() increases the lock. xUnlock() decreases the lock. The
> > xCheckReservedLock() method checks whether any database connection,
> either
> > in this process or in some other process, is holding a RESERVED, PENDING,
> > or EXCLUSIVE lock on the file. It returns true if such a lock exists and
> > false otherwise.
> >
> > https://www.sqlite.org/lockingv3.html
> > has description of what locking states are intended to be... there's
> > 'UNLOCKED' but not LOCK_NONE
> >
> > I did find another page that had lock state transitions, and information
> > about when the busy callback would be called... but that also didn't say
> > anything about the transition to unlock states...
> >
> > There was a note around the .C code in the pager unlocking using
> LOCK_NONE,
> > but I cna't find that, it just says, see note above... and that didn't
> > really say what the intent was.
> >
> > I searched the nabble mailing list archive for 'SQLITE_LOCK_NONE' and
> found
> > 0 hits.
> > _______________________________________________
> > sqlite-users mailing list
> > [hidden email]
> > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Implementing xLock/xUnlock VFS methods...

Dan Kennedy-4

On 8/1/63 22:41, J Decker wrote:

> On Wed, Jan 8, 2020 at 7:10 AM Dan Kennedy <[hidden email]> wrote:
>
>> On 8/1/63 20:29, J Decker wrote:
>>> The documentation isn't very clear on what the intent of an xUnlock(
>>> SQLITE_LOCK_NONE ) is intended to do.  Is it unlock everything? Is it the
>>> same as remove a shared lock?
>> That's right. xUnlock(fd, SQLITE_LOCK_NONE) should completely unlock the
>> file. xUnlock(fd, SQLITE_LOCK_SHARED) should fall back to a SHARED lock
>> from RESERVED/PENDING/EXCLUSIVE.
>>
>> Thank you... the second thing there confuses me...
> xLock(SHARED)  xLock(SHARED) xLock(PENDING)
> xUnlock( SHARED) - clear pending, and add a shared for total of 3?  or is
> xUnlock always remove (this file handle's) locks?

You don't have to count SHARED locks. A connection is either in SHARED
lock state or it is not. For your sequence:

   xLock(SHARED); // Take SHARED lock
   xLock(SHARED); // No-op, we already have SHARED
   xLock(PENDING); // Upgrade to PENDING lock
   xUnlock(SHARED); // Drop back down to SHARED lock

then

   xUnlock(NONE); // Completely unlock file

If you can't obtain a requested lock, return SQLITE_BUSY. SQLite may
retry or may abandon the operation, depending on the configured
busy-handler or busy-timeout.

Dan.






> I haven't finished implementing the first part to get a 'real' sequence...
> Also; I suppose I should return SQLITE_BUSY instead of waiting on the lock
> myself?  expected return values aren't covered well either.
>
> Dan.
>>
>>
>>> The first few operations are xLock( SQLITE_LOCK_SHARED ) followed by
>>> xUnlock(SQLITE_LOCK_NONE)...
>>>
>>> sqlite.h.in
>>> https://github.com/mackyle/sqlite/blob/master/src/sqlite.h.in#L627
>>> where the constants are defined... says 'one of these are used...'
>>>
>>> and describing locking levels...
>>> https://github.com/mackyle/sqlite/blob/master/src/sqlite.h.in#L708-L720
>>>
>>>
>>> https://www.sqlite.org/c3ref/io_methods.html
>>> xLock() increases the lock. xUnlock() decreases the lock. The
>>> xCheckReservedLock() method checks whether any database connection,
>> either
>>> in this process or in some other process, is holding a RESERVED, PENDING,
>>> or EXCLUSIVE lock on the file. It returns true if such a lock exists and
>>> false otherwise.
>>>
>>> https://www.sqlite.org/lockingv3.html
>>> has description of what locking states are intended to be... there's
>>> 'UNLOCKED' but not LOCK_NONE
>>>
>>> I did find another page that had lock state transitions, and information
>>> about when the busy callback would be called... but that also didn't say
>>> anything about the transition to unlock states...
>>>
>>> There was a note around the .C code in the pager unlocking using
>> LOCK_NONE,
>>> but I cna't find that, it just says, see note above... and that didn't
>>> really say what the intent was.
>>>
>>> I searched the nabble mailing list archive for 'SQLITE_LOCK_NONE' and
>> found
>>> 0 hits.
>>> _______________________________________________
>>> sqlite-users mailing list
>>> [hidden email]
>>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>> _______________________________________________
>> sqlite-users mailing list
>> [hidden email]
>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users