From: Michael Opdenacker <michael.opdenacker@bootlin.com>
To: Joshua Watt <jpewhacker@gmail.com>
Cc: bitbake-devel@lists.openembedded.org,
Tim Orling <ticotimo@gmail.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH v5 4/5] prserv: enable database sharing
Date: Tue, 30 Apr 2024 14:58:41 +0200 [thread overview]
Message-ID: <56222882-76c9-44ab-9a20-237a1293489b@bootlin.com> (raw)
In-Reply-To: <CAJdd5GbeJL=Z4-YHYm8eab0x3JD3yynoBE+S0LsuP_E3cCYQPA@mail.gmail.com>
Hi Joshua
Many thanks for the review and guidance. See my comments and questions
below.
On 4/29/24 at 22:34, Joshua Watt wrote:
>> + with closing(self.conn.cursor()) as cursor:
>> + if self.read_only:
>> + table_exists = cursor.execute(
>> + "SELECT count(*) FROM sqlite_master \
>> + WHERE type='table' AND name='%s'" % (self.table))
>> + if not table_exists:
>> + raise prserv.NotFoundError
> This is a race if you run the read-only server first, which seems like
> a bad user experience. I'd probably create the table even if the
> server is read-only (I'm pretty sure hash server works this way also)
Fixed. Thanks.
>
>> + row = data.fetchone()
>> + if row is not None:
>> + val=row[0]
>> + else:
>> + #no value found, try to insert
>> + try:
>> + cursor.execute("INSERT INTO %s VALUES (?, ?, ?, ?);" % (self.table),
>> + (version, pkgarch, checksum, value))
>> + except sqlite3.IntegrityError as exc:
>> + logger.error(str(exc))
> You probably want to make this whole SELECT / INSERT block a loop, and
> instead of repeating the SELECT below, retry the loop on an integrity
> error. The only reason you should be getting an integrity error is if
> you have a race between multiple servers accessing the database at
> once. In that case, looping back and trying to fall out in the
> previous SELECT is better.
>
> This is especially important if you delete entries in the database, as
> in pathological cases you might have to loop several times before you
> fall out of the loop (although typically, you would only need to retry
> once).
>
> I'd recommend this paradigm any other places you do SELECT / INSERT
> where the INSERT depends on the SELECT.
This is actually coming from the prserv legacy code, which I haven't
really touched yet.
Is this kind of event really expected to happen with sqlite3? I see that
hashserve only checks for "sqlite3.IntegrityError" once, so maybe it's
too pessimistic to anticipate errors here... Do we also want to support
multiple builders accessing the same PR database?
Anyway, if I really have to do it, I guess I'd also have to do it in the
store_value() function which currently just logs an error without
retrying. But if we loop, doesn't it add the risk to create an endless
loop?
Cheers,
Michael.
--
Michael Opdenacker, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2024-04-30 12:58 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-29 20:14 [PATCH v5 0/5] prserv: add support for an "upstream" server michael.opdenacker
2024-04-29 20:14 ` [PATCH v5 1/5] prserv: declare "max_package_pr" client hook michael.opdenacker
2024-04-29 20:14 ` [PATCH v5 2/5] prserv: move code from __init__ to bitbake-prserv michael.opdenacker
2024-05-02 16:57 ` [bitbake-devel] " Khem Raj
2024-05-03 8:04 ` Michael Opdenacker
2024-05-03 14:14 ` Khem Raj
2024-05-08 13:35 ` Richard Purdie
2024-05-08 15:13 ` Khem Raj
2024-05-08 17:40 ` Michael Opdenacker
2024-05-14 17:03 ` Khem Raj
2024-04-29 20:14 ` [PATCH v5 3/5] prserv: add "upstream" server support michael.opdenacker
2024-04-29 20:14 ` [PATCH v5 4/5] prserv: enable database sharing michael.opdenacker
2024-04-29 20:34 ` Joshua Watt
2024-04-30 12:58 ` Michael Opdenacker [this message]
2024-04-30 13:23 ` Joshua Watt
2024-04-30 13:55 ` Joshua Watt
2024-04-30 14:38 ` Michael Opdenacker
2024-04-29 20:14 ` [PATCH v5 5/5] prserv: add bitbake selftests michael.opdenacker
2024-04-29 21:08 ` Joshua Watt
2024-04-30 8:29 ` Michael Opdenacker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56222882-76c9-44ab-9a20-237a1293489b@bootlin.com \
--to=michael.opdenacker@bootlin.com \
--cc=bitbake-devel@lists.openembedded.org \
--cc=jpewhacker@gmail.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=ticotimo@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.