1
1
# Summary
2
2
3
3
This RFC proposes moving away from the current model of fetching new releases
4
- to build, moving from running [ crates-index-diff] in a thread to using webhooks
5
- and the [ crates-index] crate.
4
+ to build, moving from using a timer to receiving webhooks.
6
5
7
6
# Motivation
8
7
9
8
While the current approach has worked well for us so far, it has some problems:
10
9
11
- * Running the update in a cronjob every 2 minutes is wasteful, as there is
10
+ * Running the update in a timer every 2 minutes is wasteful, as there is
12
11
often a greater delay between two publishes.
13
- * Running the update in a crobjob every 2 minutes adds delay to getting the
12
+ * Running the update in a timer every 2 minutes adds delay to getting the
14
13
documentation built if the queue is empty, as the release might potentially
15
14
have to wait those extra two minutes.
16
- * The approach doesn't scale, if we want to move to a setup where there is more
17
- than a single frontend server we'd have to elect which server runs the fetch.
18
15
* The way crates-index-diff stores its state (a branch in the local repo) is
19
16
fragile, as it might become out of sync causing the loss of a publish.
20
17
* The way crates-index-diff stores its state makes it hard to move the server
@@ -27,34 +24,29 @@ endpoint, `/_/index-webhook`, which starts a index sync in the background. The
27
24
payload of the webhook is ignored, but the webhook signature is validated if a
28
25
secret key is provided to the application through an environment variable.
29
26
30
- When an index synchronization starts, the [ crates-index] crate is used to load
31
- in memory a list of all crates, their versions and whether each version is
32
- yanked. Then, the full list of releases and queued crates is fetched from the
33
- database, and it's compared with the contents of the index. Finally, idempotent
34
- queries are sent to the database to update its state (queueing crates and
35
- changing the yanked status) where needed.
27
+ We also change [ crate-index-diff] to store the hash of the last visited commit
28
+ in the database instead of a local branch in the index repository: this will
29
+ allow new instances to catch up immediately without the need of copying over
30
+ the git repository.
31
+
32
+ For this proposal to work we need to make the updates to the queue idempotent,
33
+ and add a lock on the index repository in each machine to prevent the same
34
+ machine from updating the same repository multiple times.
36
35
37
36
# Rationale of the proposal
38
37
39
- This proposal removes the cronjob and implements realtime updates of the index,
38
+ This proposal removes the timer and implements realtime updates of the index,
40
39
which does not have to happen on a specific machine if we ever move to multiple
41
40
frontend servers.
42
41
43
- This proposal also works if multiple index synchronizations start at the
44
- same time (for example, if two requests are received at the same time) without
45
- having to implement a job queue: since all the updates to the database are
46
- idempotent multiple syncs at the same time would not affect each other
47
- (provided we structure the SQL queries the right way). A single mutex on each
48
- host to lock ` git fetch ` es on the index might be needed though.
49
-
50
42
# Alternatives
51
43
52
- We could implement only the webhook or the index synchronization, keeping the
53
- old code for the part we don't replace. While it would improve the status quo,
54
- it wouldn't address all the problems noted in the motivation.
44
+ We could also switch from [ crates-index-diff] to doing a full synchronization
45
+ every time a new crate is published. While it would decrease the chances of an
46
+ inconsistency between crates.io and docs.rs, it would impact performance every
47
+ time a new crate is published.
55
48
56
49
We could also do nothing: while the current system is not perfect it works
57
50
without much trouble.
58
51
59
52
[ crates-index-diff ] : https://crates.io/crates/crates-index-diff
60
- [ crates-index ] : https://crates.io/crates/crates-index
0 commit comments