author | Denis Laxalde <denis.laxalde@logilab.fr> |
Tue, 12 Jun 2018 13:58:14 +0200 | |
changeset 3838 | 2808c899bc10 |
parent 3659 | 1e9b535cd9be |
child 3952 | a7794f5abacd |
permissions | -rw-r--r-- |
3403
73920cb25af3
stablerange: add missing licence and copyright header
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3366
diff
changeset
|
1 |
# Code dedicated to the caching of "stable ranges" |
73920cb25af3
stablerange: add missing licence and copyright header
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3366
diff
changeset
|
2 |
# |
73920cb25af3
stablerange: add missing licence and copyright header
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3366
diff
changeset
|
3 |
# These stable ranges are use for obsolescence markers discovery |
73920cb25af3
stablerange: add missing licence and copyright header
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3366
diff
changeset
|
4 |
# |
73920cb25af3
stablerange: add missing licence and copyright header
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3366
diff
changeset
|
5 |
# Copyright 2017 Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
73920cb25af3
stablerange: add missing licence and copyright header
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3366
diff
changeset
|
6 |
# |
73920cb25af3
stablerange: add missing licence and copyright header
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3366
diff
changeset
|
7 |
# This software may be used and distributed according to the terms of the |
73920cb25af3
stablerange: add missing licence and copyright header
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3366
diff
changeset
|
8 |
# GNU General Public License version 2 or any later version. |
73920cb25af3
stablerange: add missing licence and copyright header
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3366
diff
changeset
|
9 |
|
3308
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
10 |
import abc |
3342
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
11 |
import heapq |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
12 |
import sqlite3 |
3342
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
13 |
import time |
2238
aac765e84de3
stablerange: warm cache on transaction (if obshashrange is enabled)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2237
diff
changeset
|
14 |
import weakref |
2130
d784622dd5dc
stablerange: move the range class in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2129
diff
changeset
|
15 |
|
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
16 |
from mercurial import ( |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
17 |
error, |
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
18 |
localrepo, |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
19 |
util, |
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
20 |
) |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
21 |
|
3307
a1ab2588a628
stablerange: split pure algorithm part from the on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3306
diff
changeset
|
22 |
from . import ( |
a1ab2588a628
stablerange: split pure algorithm part from the on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3306
diff
changeset
|
23 |
exthelper, |
3342
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
24 |
genericcaches, |
3307
a1ab2588a628
stablerange: split pure algorithm part from the on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3306
diff
changeset
|
25 |
stablerange, |
3346
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
26 |
utility, |
3307
a1ab2588a628
stablerange: split pure algorithm part from the on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3306
diff
changeset
|
27 |
) |
a1ab2588a628
stablerange: split pure algorithm part from the on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3306
diff
changeset
|
28 |
|
2129
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
29 |
from mercurial.i18n import _ |
d07bb7cbae2f
stablesort: move into the stablerange module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2128
diff
changeset
|
30 |
|
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
31 |
eh = exthelper.exthelper() |
3307
a1ab2588a628
stablerange: split pure algorithm part from the on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3306
diff
changeset
|
32 |
eh.merge(stablerange.eh) |
3342
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
33 |
|
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
34 |
class stablerangeondiskbase(stablerange.stablerangecached, |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
35 |
genericcaches.changelogsourcebase): |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
36 |
"""combine the generic stablerange cache usage with generic changelog one |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
37 |
""" |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
38 |
|
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
39 |
def _updatefrom(self, repo, data): |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
40 |
"""compute the rev of one revision, assert previous revision has an hot cache |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
41 |
""" |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
42 |
repo = repo.unfiltered() |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
43 |
ui = repo.ui |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
44 |
|
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
45 |
rangeheap = [] |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
46 |
for r in data: |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
47 |
rangeheap.append((r, 0)) |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
48 |
total = len(data) |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
49 |
|
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
50 |
heappop = heapq.heappop |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
51 |
heappush = heapq.heappush |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
52 |
heapify = heapq.heapify |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
53 |
|
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
54 |
original = set(rangeheap) |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
55 |
seen = 0 |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
56 |
# progress report is showing up in the profile for small and fast |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
57 |
# repository so we only update it every so often |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
58 |
progress_each = 100 |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
59 |
progress_last = time.time() |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
60 |
heapify(rangeheap) |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
61 |
while rangeheap: |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
62 |
rangeid = heappop(rangeheap) |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
63 |
if rangeid in original: |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
64 |
if not seen % progress_each: |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
65 |
# if a lot of time passed, report more often |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
66 |
progress_new = time.time() |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
67 |
if (1 < progress_each) and (0.1 < progress_new - progress_last): |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
68 |
progress_each /= 10 |
3659
1e9b535cd9be
stablerangecache: include units in ui.progress() calls
Anton Shestakov <av6@dwimlabs.net>
parents:
3646
diff
changeset
|
69 |
ui.progress(_("filling stablerange cache"), seen, |
1e9b535cd9be
stablerangecache: include units in ui.progress() calls
Anton Shestakov <av6@dwimlabs.net>
parents:
3646
diff
changeset
|
70 |
total=total, unit=_("changesets")) |
3342
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
71 |
progress_last = progress_new |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
72 |
seen += 1 |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
73 |
original.remove(rangeid) # might have been added from other source |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
74 |
rangeid = rangeid |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
75 |
if self._getsub(rangeid) is None: |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
76 |
for sub in self.subranges(repo, rangeid): |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
77 |
if self._getsub(sub) is None: |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
78 |
heappush(rangeheap, sub) |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
79 |
ui.progress(_("filling stablerange cache"), None, total=total) |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
80 |
|
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
81 |
def clear(self, reset=False): |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
82 |
super(stablerangeondiskbase, self).clear() |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
83 |
self._subrangescache.clear() |
3194aec207ae
stablerange: add a base class for on disk stored stablerange class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3308
diff
changeset
|
84 |
|
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
85 |
############################# |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
86 |
### simple sqlite caching ### |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
87 |
############################# |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
88 |
|
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
89 |
_sqliteschema = [ |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
90 |
"""CREATE TABLE meta(schemaversion INTEGER NOT NULL, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
91 |
tiprev INTEGER NOT NULL, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
92 |
tipnode BLOB NOT NULL |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
93 |
);""", |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
94 |
"""CREATE TABLE range(rev INTEGER NOT NULL, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
95 |
idx INTEGER NOT NULL, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
96 |
PRIMARY KEY(rev, idx));""", |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
97 |
"""CREATE TABLE subranges(listidx INTEGER NOT NULL, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
98 |
suprev INTEGER NOT NULL, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
99 |
supidx INTEGER NOT NULL, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
100 |
subrev INTEGER NOT NULL, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
101 |
subidx INTEGER NOT NULL, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
102 |
PRIMARY KEY(listidx, suprev, supidx), |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
103 |
FOREIGN KEY (suprev, supidx) REFERENCES range(rev, idx), |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
104 |
FOREIGN KEY (subrev, subidx) REFERENCES range(rev, idx) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
105 |
);""", |
2240
ecb993892c61
stablerange: warm cache before using it server side
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2238
diff
changeset
|
106 |
"CREATE INDEX subranges_index ON subranges (suprev, supidx);", |
3356
24b72cbc486f
stablerange: add an sql index on subranges id too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3355
diff
changeset
|
107 |
"CREATE INDEX superranges_index ON subranges (subrev, subidx);", |
2240
ecb993892c61
stablerange: warm cache before using it server side
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2238
diff
changeset
|
108 |
"CREATE INDEX range_index ON range (rev, idx);", |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
109 |
] |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
110 |
_newmeta = "INSERT INTO meta (schemaversion, tiprev, tipnode) VALUES (?,?,?);" |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
111 |
_updatemeta = "UPDATE meta SET tiprev = ?, tipnode = ?;" |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
112 |
_updaterange = "INSERT INTO range(rev, idx) VALUES (?,?);" |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
113 |
_updatesubranges = """INSERT |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
114 |
INTO subranges(listidx, suprev, supidx, subrev, subidx) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
115 |
VALUES (?,?,?,?,?);""" |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
116 |
_queryexist = "SELECT name FROM sqlite_master WHERE type='table' AND name='meta';" |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
117 |
_querymeta = "SELECT schemaversion, tiprev, tipnode FROM meta;" |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
118 |
_queryrange = "SELECT * FROM range WHERE (rev = ? AND idx = ?);" |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
119 |
_querysubranges = """SELECT subrev, subidx |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
120 |
FROM subranges |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
121 |
WHERE (suprev = ? AND supidx = ?) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
122 |
ORDER BY listidx;""" |
3355
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
123 |
_querysuperranges = """SELECT suprev, supidx |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
124 |
FROM subranges |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
125 |
WHERE (subrev = ? AND subidx = ?) |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
126 |
ORDER BY listidx;""" |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
127 |
|
3308
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
128 |
class stablerangesqlbase(stablerange.stablerangecached): |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
129 |
"""class that can handle all the bits needed to store range into sql |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
130 |
""" |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
131 |
|
3308
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
132 |
__metaclass__ = abc.ABCMeta |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
133 |
|
3308
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
134 |
_schemaversion = None |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
135 |
_cachefile = None |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
136 |
|
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
137 |
def __init__(self, repo, **kwargs): |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
138 |
super(stablerangesqlbase, self).__init__(**kwargs) |
2400
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
139 |
self._vfs = repo.vfs |
3308
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
140 |
self._path = repo.vfs.join(self._cachefile) |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
141 |
self._cl = repo.unfiltered().changelog # (okay to keep an old one) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
142 |
self._ondisktiprev = None |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
143 |
self._ondisktipnode = None |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
144 |
self._unsavedsubranges = {} |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
145 |
|
3355
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
146 |
def contains(self, repo, revs): |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
147 |
new = set() |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
148 |
known = set() |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
149 |
depth = repo.depthcache.get |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
150 |
for r in revs: |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
151 |
new.add((r, depth(r) - 1)) |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
152 |
new.add((r, 0)) |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
153 |
con = self._con |
3364
9df35258e0c5
caches: protect against missing connection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3356
diff
changeset
|
154 |
while new and con is not None: |
3355
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
155 |
# many execute is not efficient |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
156 |
next = new.pop() |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
157 |
known.add(next) |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
158 |
ranges = set(con.execute(_querysuperranges, next).fetchall()) |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
159 |
new.update(ranges) |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
160 |
new -= known |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
161 |
return sorted(known) |
c261eece1eab
obshashrange: less brutal reset when receiving markers on existing node
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3353
diff
changeset
|
162 |
|
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
163 |
def _getsub(self, rangeid): |
3308
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
164 |
# 1) check the in memory cache |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
165 |
# 2) check the sqlcaches (and warm in memory cache we want we find) |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
166 |
cache = self._subrangescache |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
167 |
if rangeid not in cache and rangeid[0] <= self._ondisktiprev and self._con is not None: |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
168 |
value = None |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
169 |
result = self._con.execute(_queryrange, rangeid).fetchone() |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
170 |
if result is not None: # database know about this node (skip in the future?) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
171 |
value = self._con.execute(_querysubranges, rangeid).fetchall() |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
172 |
# in memory caching of the value |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
173 |
cache[rangeid] = value |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
174 |
return cache.get(rangeid) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
175 |
|
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
176 |
def _setsub(self, rangeid, value): |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
177 |
assert rangeid not in self._unsavedsubranges |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
178 |
self._unsavedsubranges[rangeid] = value |
3308
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
179 |
super(stablerangesqlbase, self)._setsub(rangeid, value) |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
180 |
|
2400
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
181 |
def _db(self): |
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
182 |
try: |
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
183 |
util.makedirs(self._vfs.dirname(self._path)) |
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
184 |
except OSError: |
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
185 |
return None |
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
186 |
con = sqlite3.connect(self._path) |
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
187 |
con.text_factory = str |
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
188 |
return con |
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
189 |
|
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
190 |
@util.propertycache |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
191 |
def _con(self): |
2400
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
192 |
con = self._db() |
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
193 |
if con is None: |
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
194 |
return None |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
195 |
cur = con.execute(_queryexist) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
196 |
if cur.fetchone() is None: |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
197 |
return None |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
198 |
meta = con.execute(_querymeta).fetchone() |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
199 |
if meta is None: |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
200 |
return None |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
201 |
if meta[0] != self._schemaversion: |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
202 |
return None |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
203 |
if len(self._cl) <= meta[1]: |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
204 |
return None |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
205 |
if self._cl.node(meta[1]) != meta[2]: |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
206 |
return None |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
207 |
self._ondisktiprev = meta[1] |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
208 |
self._ondisktipnode = meta[2] |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
209 |
if self._tiprev < self._ondisktiprev: |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
210 |
self._tiprev = self._ondisktiprev |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
211 |
self._tipnode = self._ondisktipnode |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
212 |
return con |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
213 |
|
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
214 |
def _save(self, repo): |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
215 |
repo = repo.unfiltered() |
3240
9361149224a7
depthcache: move to a dedicated object and storage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3236
diff
changeset
|
216 |
repo.depthcache.save(repo) |
9361149224a7
depthcache: move to a dedicated object and storage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3236
diff
changeset
|
217 |
if not self._unsavedsubranges: |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
218 |
return # no new data |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
219 |
|
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
220 |
if self._con is None: |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
221 |
util.unlinkpath(self._path, ignoremissing=True) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
222 |
if '_con' in vars(self): |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
223 |
del self._con |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
224 |
|
2400
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
225 |
con = self._db() |
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
226 |
if con is None: |
9a53ed7e5540
stablerangecache: avoid crash when 'cache/' directory is missing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2381
diff
changeset
|
227 |
return |
3347
ab5172ba3c81
stablerange: clarify sql transaction logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3346
diff
changeset
|
228 |
con.execute('BEGIN IMMEDIATE;') |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
229 |
with con: |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
230 |
for req in _sqliteschema: |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
231 |
con.execute(req) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
232 |
|
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
233 |
meta = [self._schemaversion, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
234 |
self._tiprev, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
235 |
self._tipnode, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
236 |
] |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
237 |
con.execute(_newmeta, meta) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
238 |
else: |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
239 |
con = self._con |
3347
ab5172ba3c81
stablerange: clarify sql transaction logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3346
diff
changeset
|
240 |
con.execute('BEGIN IMMEDIATE;') |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
241 |
meta = con.execute(_querymeta).fetchone() |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
242 |
if meta[2] != self._ondisktipnode or meta[1] != self._ondisktiprev: |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
243 |
# drifting is currently an issue because this means another |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
244 |
# process might have already added the cache line we are about |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
245 |
# to add. This will confuse sqlite |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
246 |
msg = _('stable-range cache: skipping write, ' |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
247 |
'database drifted under my feet\n') |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
248 |
hint = _('(disk: %s-%s vs mem: %s%s)\n') |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
249 |
data = (meta[2], meta[1], self._ondisktiprev, self._ondisktipnode) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
250 |
repo.ui.warn(msg) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
251 |
repo.ui.warn(hint % data) |
3347
ab5172ba3c81
stablerange: clarify sql transaction logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3346
diff
changeset
|
252 |
con.execute('ROLLBACK;') |
2237
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
253 |
return |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
254 |
meta = [self._tiprev, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
255 |
self._tipnode, |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
256 |
] |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
257 |
con.execute(_updatemeta, meta) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
258 |
|
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
259 |
self._saverange(con, repo) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
260 |
con.commit() |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
261 |
self._ondisktiprev = self._tiprev |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
262 |
self._ondisktipnode = self._tipnode |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
263 |
self._unsavedsubranges.clear() |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
264 |
|
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
265 |
def _saverange(self, con, repo): |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
266 |
repo = repo.unfiltered() |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
267 |
data = [] |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
268 |
allranges = set() |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
269 |
for key, value in self._unsavedsubranges.items(): |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
270 |
allranges.add(key) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
271 |
for idx, sub in enumerate(value): |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
272 |
data.append((idx, key[0], key[1], sub[0], sub[1])) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
273 |
|
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
274 |
con.executemany(_updaterange, allranges) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
275 |
con.executemany(_updatesubranges, data) |
98e0369b548b
stablerange: introduce ondisk caching through sqlite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2236
diff
changeset
|
276 |
|
3343
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
277 |
class stablerangesql(stablerangesqlbase, stablerangeondiskbase): |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
278 |
"""base clase able to preserve data to disk as sql""" |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
279 |
|
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
280 |
__metaclass__ = abc.ABCMeta |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
281 |
|
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
282 |
# self._cachekey = (tiprev, tipnode) |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
283 |
|
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
284 |
@property |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
285 |
def _tiprev(self): |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
286 |
return self._cachekey[0] |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
287 |
|
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
288 |
@_tiprev.setter |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
289 |
def _tiprev(self, value): |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
290 |
self._cachekey = (value, self._cachekey[1]) |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
291 |
|
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
292 |
@property |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
293 |
def _tipnode(self): |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
294 |
return self._cachekey[1] |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
295 |
|
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
296 |
@_tipnode.setter |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
297 |
def _tipnode(self, value): |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
298 |
self._cachekey = (self._cachekey[0], value) |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
299 |
|
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
300 |
def clear(self, reset=False): |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
301 |
super(stablerangesql, self).clear(reset=reset) |
3348
895e16385a4f
stablerange: be more cautious when deleting the sql connection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3347
diff
changeset
|
302 |
if '_con' in vars(self): |
895e16385a4f
stablerange: be more cautious when deleting the sql connection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3347
diff
changeset
|
303 |
del self._con |
3343
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
304 |
self._subrangescache.clear() |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
305 |
|
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
306 |
def load(self, repo): |
3346
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
307 |
"""load data from disk""" |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
308 |
assert repo.filtername is None |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
309 |
self._cachekey = self.emptykey |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
310 |
|
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
311 |
if self._con is not None: |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
312 |
self._cachekey = (self._ondisktiprev, self._ondisktipnode) |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
313 |
self._ondiskkey = self._cachekey |
3343
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
314 |
|
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
315 |
def save(self, repo): |
3346
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
316 |
if self._cachekey is None or self._cachekey == self._ondiskkey: |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
317 |
return |
3343
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
318 |
self._save(repo) |
86a03229d32d
stablerange: introduce a sql backed version of the generic on disk cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3342
diff
changeset
|
319 |
|
3344
4d054737a79c
stablerange: have a mergepoint based sql backed class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3343
diff
changeset
|
320 |
class mergepointsql(stablerangesql, stablerange.stablerange_mergepoint): |
4d054737a79c
stablerange: have a mergepoint based sql backed class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3343
diff
changeset
|
321 |
|
4d054737a79c
stablerange: have a mergepoint based sql backed class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3343
diff
changeset
|
322 |
_schemaversion = 2 |
4d054737a79c
stablerange: have a mergepoint based sql backed class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3343
diff
changeset
|
323 |
_cachefile = 'cache/evoext_stablerange_v2.sqlite' |
3346
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
324 |
_cachename = 'evo-ext-stablerange-mergepoint' |
3344
4d054737a79c
stablerange: have a mergepoint based sql backed class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3343
diff
changeset
|
325 |
|
3308
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
326 |
class sqlstablerange(stablerangesqlbase, stablerange.stablerange): |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
327 |
|
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
328 |
_schemaversion = 1 |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
329 |
_cachefile = 'cache/evoext_stablerange_v1.sqlite' |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
330 |
|
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
331 |
def warmup(self, repo, upto=None): |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
332 |
self._con # make sure the data base is loaded |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
333 |
try: |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
334 |
# samelessly lock the repo to ensure nobody will update the repo |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
335 |
# concurently. This should not be too much of an issue if we warm |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
336 |
# at the end of the transaction. |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
337 |
# |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
338 |
# XXX However, we lock even if we are up to date so we should check |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
339 |
# before locking |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
340 |
with repo.lock(): |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
341 |
super(sqlstablerange, self).warmup(repo, upto) |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
342 |
self._save(repo) |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
343 |
except error.LockError: |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
344 |
# Exceptionnally we are noisy about it since performance impact is |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
345 |
# large We should address that before using this more widely. |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
346 |
repo.ui.warn('stable-range cache: unable to lock repo while warming\n') |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
347 |
repo.ui.warn('(cache will not be saved)\n') |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
348 |
super(sqlstablerange, self).warmup(repo, upto) |
65af5f9f232b
stablerange: abstract the bit able to store cache into sql
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3307
diff
changeset
|
349 |
|
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
350 |
@eh.reposetup |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
351 |
def setupcache(ui, repo): |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
352 |
|
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
353 |
class stablerangerepo(repo.__class__): |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
354 |
|
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
355 |
@localrepo.unfilteredpropertycache |
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
356 |
def stablerange(self): |
3646
0dd393a32567
stablerangecache: use self instead of repo in stablerangerepo.stablerange()
Anton Shestakov <av6@dwimlabs.net>
parents:
3504
diff
changeset
|
357 |
cache = mergepointsql(self) |
0dd393a32567
stablerangecache: use self instead of repo in stablerangerepo.stablerange()
Anton Shestakov <av6@dwimlabs.net>
parents:
3504
diff
changeset
|
358 |
cache.update(self) |
3346
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
359 |
return cache |
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
360 |
|
2236
c0e2ba85e76a
stablerange: drop the cache on 'destroyed'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2235
diff
changeset
|
361 |
@localrepo.unfilteredmethod |
c0e2ba85e76a
stablerange: drop the cache on 'destroyed'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2235
diff
changeset
|
362 |
def destroyed(self): |
c0e2ba85e76a
stablerange: drop the cache on 'destroyed'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2235
diff
changeset
|
363 |
if 'stablerange' in vars(self): |
3346
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
364 |
self.stablerange.clear() |
2236
c0e2ba85e76a
stablerange: drop the cache on 'destroyed'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2235
diff
changeset
|
365 |
del self.stablerange |
2287
18b8dc058f75
repo: properly progate "destroyed" call to super class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2240
diff
changeset
|
366 |
super(stablerangerepo, self).destroyed() |
2236
c0e2ba85e76a
stablerange: drop the cache on 'destroyed'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2235
diff
changeset
|
367 |
|
3346
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
368 |
if util.safehasattr(repo, 'updatecaches'): |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
369 |
@localrepo.unfilteredmethod |
3504
5dc34b857114
updatecaches: handle any new parameters to the method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3403
diff
changeset
|
370 |
def updatecaches(self, tr=None, **kwargs): |
3366
83b372eceb81
caches: pass the transaction to the "shouldwarncache" logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3364
diff
changeset
|
371 |
if utility.shouldwarmcache(self, tr): |
3353
4635cef9624c
stablerange: cleanup the update logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3348
diff
changeset
|
372 |
self.stablerange.update(self) |
4635cef9624c
stablerange: cleanup the update logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3348
diff
changeset
|
373 |
self.stablerange.save(self) |
3504
5dc34b857114
updatecaches: handle any new parameters to the method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3403
diff
changeset
|
374 |
super(stablerangerepo, self).updatecaches(tr, **kwargs) |
3346
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
375 |
|
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
376 |
else: |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
377 |
def transaction(self, *args, **kwargs): |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
378 |
tr = super(stablerangerepo, self).transaction(*args, **kwargs) |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
379 |
reporef = weakref.ref(self) |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
380 |
|
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
381 |
def _warmcache(tr): |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
382 |
repo = reporef() |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
383 |
if repo is None: |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
384 |
return |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
385 |
repo = repo.unfiltered() |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
386 |
repo.stablerange.update(repo) |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
387 |
repo.stablerange.save(repo) |
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
388 |
|
3366
83b372eceb81
caches: pass the transaction to the "shouldwarncache" logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3364
diff
changeset
|
389 |
if utility.shouldwarmcache(self, tr): |
3346
f4e28b781143
stablerange: use mergepoint based algorithm for the official stable range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3344
diff
changeset
|
390 |
tr.addpostclose('warmcache-10stablerange', _warmcache) |
2551
ecd47c63b6de
obshashrange: add an option to protect from accidental activation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2529
diff
changeset
|
391 |
return tr |
2238
aac765e84de3
stablerange: warm cache on transaction (if obshashrange is enabled)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2237
diff
changeset
|
392 |
|
2125
e0a25339ff17
stablerange: move 'depth' inside a new 'stablerange' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
393 |
repo.__class__ = stablerangerepo |