mrfakename commited on
Commit
4b5f8e4
·
verified ·
1 Parent(s): e69ff42

Resume shards from first unmirrored file

Browse files
Files changed (1) hide show
  1. mirror_worker.py +21 -4
mirror_worker.py CHANGED
@@ -143,7 +143,24 @@ def main() -> None:
143
  if number % WORKER_COUNT == WORKER_INDEX
144
  and (item.get("Type") or item.get("type")) != "tree"
145
  ]
146
- print(f"worker {WORKER_INDEX}/{WORKER_COUNT}: {len(selected)} files")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  pending: list[tuple[str, Path]] = []
148
  pending_bytes = 0
149
 
@@ -157,12 +174,12 @@ def main() -> None:
157
  pending = []
158
  pending_bytes = 0
159
 
160
- for number, item in enumerate(selected, start=1):
161
  path = item.get("Path") or item.get("path") or item.get("Name")
162
  if not path:
163
  continue
164
  if path in uploaded:
165
- print(f"skip {number}/{len(selected)} {path}", flush=True)
166
  continue
167
  local = WORKDIR / path
168
  local.parent.mkdir(parents=True, exist_ok=True)
@@ -183,7 +200,7 @@ def main() -> None:
183
  uploaded.add(path)
184
  if len(pending) >= 200 or pending_bytes >= 5_000_000_000:
185
  flush()
186
- print(f"done {number}/{len(selected)} {path}", flush=True)
187
  finally:
188
  # Staged files remain until their batch commit succeeds.
189
  if path not in uploaded:
 
143
  if number % WORKER_COUNT == WORKER_INDEX
144
  and (item.get("Type") or item.get("type")) != "tree"
145
  ]
146
+ # Each shard is processed in deterministic manifest order. Resume at its
147
+ # first absent path instead of walking tens of thousands of committed files
148
+ # after every hourly job restart.
149
+ shard_total = len(selected)
150
+ resume_at = next(
151
+ (
152
+ index
153
+ for index, item in enumerate(selected)
154
+ if (item.get("Path") or item.get("path") or item.get("Name")) not in uploaded
155
+ ),
156
+ len(selected),
157
+ )
158
+ print(
159
+ f"worker {WORKER_INDEX}/{WORKER_COUNT}: "
160
+ f"{resume_at}/{shard_total} complete; {shard_total - resume_at} remaining",
161
+ flush=True,
162
+ )
163
+ selected = selected[resume_at:]
164
  pending: list[tuple[str, Path]] = []
165
  pending_bytes = 0
166
 
 
174
  pending = []
175
  pending_bytes = 0
176
 
177
+ for number, item in enumerate(selected, start=resume_at + 1):
178
  path = item.get("Path") or item.get("path") or item.get("Name")
179
  if not path:
180
  continue
181
  if path in uploaded:
182
+ print(f"skip {number}/{shard_total} {path}", flush=True)
183
  continue
184
  local = WORKDIR / path
185
  local.parent.mkdir(parents=True, exist_ok=True)
 
200
  uploaded.add(path)
201
  if len(pending) >= 200 or pending_bytes >= 5_000_000_000:
202
  flush()
203
+ print(f"done {number}/{shard_total} {path}", flush=True)
204
  finally:
205
  # Staged files remain until their batch commit succeeds.
206
  if path not in uploaded: