iz
Clone
https://git.tahinli.com/Tahinli/iz.git
0 watching0 forksRustAGPL-3.0567.3 KiB3950aceTahinli27 days ago34 commits
| 1 | //! The deleter: the attachments' disk and Files-service work that runs outside a request. A deleted |
| 2 | //! attachment's row is gone at once (the transaction in `iz-core` records the copies it owes in |
| 3 | //! `blob_deletions`, one record per place); this worker removes them and retries with a backoff until they are |
| 4 | //! gone, then clears the record. It runs until the stop flag is set, like every worker |
| 5 | //! (`docs/architecture.md` section 8). |
| 6 | //! |
| 7 | //! The rules that keep a live copy safe are the same ones the mover follows (`mover.rs`). Every step that |
| 8 | //! touches a copy, or the row that says where the bytes are, holds `AppState::blob_lock`. Under that lock, a |
| 9 | //! record is judged against the row as it is then: |
| 10 | //! - the row is `moving`: a move is under way, so the record waits; |
| 11 | //! - the row is in the record's own place: the record is stale, and the copy is the live one, so nothing is removed; |
| 12 | //! - the row is gone, or is in the other place: the owed copy is removed. |
| 13 | //! |
| 14 | //! Local copies are removed only through `iz_core::staging::remove_blob`, which builds the path from the validated |
| 15 | //! attachment id. Files-service copies are removed with `DELETE`, which counts a missing object as done. |
| 16 | |
| 17 | use Duration; |
| 18 | |
| 19 | use remove_blob; |
| 20 | use ; |
| 21 | use watch; |
| 22 | |
| 23 | use crateAppState; |
| 24 | |
| 25 | /// The largest body of one upload request, in bytes. Reason: several files may come in one form, each up to the |
| 26 | /// per-file limit (at most 500 MiB), and this bounds the whole request. |
| 27 | pub const UPLOAD_REQUEST_MAX_BYTES: usize = 1024 * 1024 * 1024; |
| 28 | /// How often the deleter looks for due deletions. Reason: a deleted file should be gone within seconds. |
| 29 | const SWEEP_EVERY: Duration = from_secs; |
| 30 | /// Most deletions one sweep handles. Reason: bounds one sweep when many files are deleted at once. |
| 31 | const SWEEP_BATCH: i64 = 50; |
| 32 | /// The first retry delay, in seconds. Doubles with each failed attempt. |
| 33 | const RETRY_BASE_SECS: u64 = 5; |
| 34 | /// The longest retry delay, in seconds. Reason: a copy that cannot be removed is looked at every ten minutes. |
| 35 | const RETRY_CAP_SECS: u64 = 600; |
| 36 | |
| 37 | /// The delay before the next attempt after `attempts` failures. |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | /// Starts the deleter. It sweeps at once, then every [`SWEEP_EVERY`], until `stop` is set. |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | /// What one owed copy came to on this pass. |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | /// One pass over the due deletions. A failure is logged and retried later; it never stops the worker. Also |
| 68 | /// run by the sweeper as a backstop. |
| 69 | pub async |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | /// Removes one owed copy, judged against the row under the blob lock (see the module comment). |
| 118 | async |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 |