1 |
I'm currently working on solving a strange bug in a daemon like process |
2 |
that uses layman and the portage python module to determine whether or |
3 |
not the daemon requires updates (and if so, self updates). It's highly |
4 |
unlikely that what I'm doing falls under the normal portage usecase, but |
5 |
I would like some help understanding how the caching mechanism works in |
6 |
the portage module. I'm aware that the portage python module uses _some_ |
7 |
kind of caching or lazyness to store queries it makes on the portage |
8 |
tree, but I'm having some trouble figuring out exactly how it works. |
9 |
|
10 |
I'm updating the portage tree in the background while periodically |
11 |
running a check of the most recently available version of a particular |
12 |
package. At some point, portage appears to cache the result of my query |
13 |
and stop hitting the disk, and from that point forward, it never hits it |
14 |
again until the process is killed or something outside that process |
15 |
calls some kind of emerge command. I know from reading portage's source |
16 |
that there is some kind of lazyness or caching going on, but I'm curious |
17 |
why it doesn't seem to happen right away. It seems to me like I can keep |
18 |
querying the disk happily for some amount of time before that process |
19 |
begins to receive the same results per query every time. Since it seems |
20 |
to be happening only after some event that occurs over time, it is |
21 |
basically impossible to reproduce. Can anyone enlighten me? |
22 |
|
23 |
Here is an overview of what the process does: |
24 |
|
25 |
1. daemon spins up |
26 |
2. checks if it needs an update |
27 |
2.1 if it needs an update, do so and restart the daemon goto 1 |
28 |
2.2 if no update is required go to 3 |
29 |
3. do some work, goto 2 |
30 |
|
31 |
Step 2 utilizes layman for syncing an overlay, and then uses the portage |
32 |
python module for checking if the newest version is newer than the |
33 |
installed version with calls like the following: |
34 |
|
35 |
# to get currently installed version of the daemon |
36 |
installed_versions = portage.db[portage.root]['vartree'].dbapi.match(pattern) |
37 |
|
38 |
# to find the most recent version of the daemon |
39 |
available_versions = portage.db[portage.root]['porttree'].dbapi.match(pattern) |
40 |
|
41 |
|
42 |
I've seen a method in the dbapi called flush_cache that sounds |
43 |
promising. If it indeed flushes the cache that I'm running into, it |
44 |
should fix this problem I would imagine. |
45 |
|
46 |
Please let me know if this question is inappropriate for this list, |
47 |
|
48 |
Best Regards, |
49 |
|
50 |
-- |
51 |
Jean-Christophe Petkovich |