lockfile but using db table row instead of file

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

lockfile but using db table row instead of file

Peng Yu
The command line program `lockfile` locks based on files. I wants to do the
same thing but based on a row in a table. For example (this is just one
example feature, but all other features should also be preserved), if a
given row is there, the process will hang unless some other process delete
the given row. Multiple processes can compete for the same row. Because
program like this should deal with concurrency, I am not clear how to make
it bug free. Does anybody has a ready-to-use solution? Thanks.
--
Regards,
Peng
_______________________________________________
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: lockfile but using db table row instead of file

Keith Medcalf

On Wednesday, 4 September, 2019 04:40, Peng Yu <[hidden email]> wrote:

>The command line program `lockfile` locks based on files. I wants to do the
>same thing but based on a row in a table. For example (this is just one
>example feature, but all other features should also be preserved), if a
>given row is there, the process will hang unless some other process delete
>the given row. Multiple processes can compete for the same row. Because
>program like this should deal with concurrency, I am not clear how to make
>it bug free. Does anybody has a ready-to-use solution? Thanks.

Lockfile is a program that implements lockfiles for *nix shell scripts.  Why would you want to re-create that?  If you want to co-ordinate access to something between processes and/or threads in programs written in C then why not just use the OS provided named semaphore interface and skip all the extra complication (and let the OS do all the work, that’s why it was written)?

--
The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume.




_______________________________________________
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: lockfile but using db table row instead of file

Stephen Chrzanowski
In reply to this post by Peng Yu
What Keith said, plus, SQLite does not do row locking, period.  It's a full
file lock when required.  SQLite has some embedded functionality to deal
with locking things like this, and your program will  need to be written to
be aware of how to deal with locking.

If you're attempting to fix race conditions, then you need to look at how
your programs are working with each other, either by communicating with
each other through FIFO files (If linux) or through DDE (Dynamic Data
Exchange) if Windows, or rely on the OS and SQLite provisions already out
there.  I've done some LIGHT work with DDE back in the Delphi 5 days, and
from what I remember, it was pretty interesting.

Work with the tools you have, and don't go reinvent the wheel.  (Unless the
purpose is to reinvent the wheel just for fun.)

On Wed, Sep 4, 2019 at 6:40 AM Peng Yu <[hidden email]> wrote:

> The command line program `lockfile` locks based on files. I wants to do the
> same thing but based on a row in a table. For example (this is just one
> example feature, but all other features should also be preserved), if a
> given row is there, the process will hang unless some other process delete
> the given row. Multiple processes can compete for the same row. Because
> program like this should deal with concurrency, I am not clear how to make
> it bug free. Does anybody has a ready-to-use solution? Thanks.
> --
> Regards,
> Peng
> _______________________________________________
> 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: lockfile but using db table row instead of file

Peng Yu
In reply to this post by Keith Medcalf
On 9/4/19, Keith Medcalf <[hidden email]> wrote:

>
> On Wednesday, 4 September, 2019 04:40, Peng Yu <[hidden email]> wrote:
>
>>The command line program `lockfile` locks based on files. I wants to do the
>>same thing but based on a row in a table. For example (this is just one
>>example feature, but all other features should also be preserved), if a
>>given row is there, the process will hang unless some other process delete
>>the given row. Multiple processes can compete for the same row. Because
>>program like this should deal with concurrency, I am not clear how to make
>>it bug free. Does anybody has a ready-to-use solution? Thanks.
>
> Lockfile is a program that implements lockfiles for *nix shell scripts.  Why
> would you want to re-create that?  If you want to co-ordinate access to
> something between processes and/or threads in programs written in C then why
> not just use the OS provided named semaphore interface and skip all the
> extra complication (and let the OS do all the work, that’s why it was
> written)?

I use lockfile to ensuring one process runs when dealing with file
dependencies (as in build systems such as make which takes care of
file dependencies). Now I put some files in sqlar. Therefore, I'd like
to have something as a natural extension of lockfile's feature to deal
with files in sqlar. However, since sqlite db is locked per file,
there is no way to concurrently change two files in sqlar anyway. In
this sense, my question seems not to matter anymore.

--
Regards,
Peng
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users