Skip to content

Commit e8ec51a

Browse files
authored
Improve migration logging. (#19667)
<!-- Merging Requirements: - Please give your PR a title that is release-note friendly - In order to be merged, you must add the most appropriate category Label (Added, Changed, Fixed) to your PR --> <!-- Explain why this is an improvement (Does this add missing functionality, improve performance, or reduce complexity?) --> ### Purpose: <!-- Does this PR introduce a breaking change? --> ### Current Behavior: ### New Behavior: <!-- As we aim for complete code coverage, please include details regarding unit, and regression tests --> ### Testing Notes: <!-- Attach any visual examples, or supporting evidence (attach any .gif/video/console output below) -->
2 parents f88a211 + 1444d22 commit e8ec51a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

chia/data_layer/data_store.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,17 @@ async def migrate_db(self, server_files_location: Path) -> None:
427427
await writer.execute("INSERT INTO schema (version_id) VALUES (?)", (version,))
428428
log.info(f"Initialized new DB schema {version}.")
429429

430+
total_generations = 0
431+
synced_generations = 0
430432
for roots in all_roots:
431433
assert len(roots) > 0
434+
total_generations += len(roots)
435+
436+
for roots in all_roots:
432437
store_id = roots[0].store_id
433438
await self.create_tree(store_id=store_id, status=Status.COMMITTED)
434439

440+
expected_synced_generations = synced_generations + len(roots)
435441
for root in roots:
436442
recovery_filename: Optional[Path] = None
437443

@@ -455,10 +461,23 @@ async def migrate_db(self, server_files_location: Path) -> None:
455461

456462
try:
457463
await self.insert_into_data_store_from_file(store_id, root.node_hash, recovery_filename)
464+
synced_generations += 1
465+
log.info(
466+
f"Successfully recovered root from {filename}. "
467+
f"Total roots processed: {(synced_generations / total_generations * 100):.2f}%"
468+
)
458469
except Exception as e:
459470
log.error(f"Cannot recover data from {filename}: {e}")
460471
break
461472

473+
if synced_generations < expected_synced_generations:
474+
log.error(
475+
f"Could not recover {expected_synced_generations - synced_generations} generations. "
476+
f"Consider resyncing the store {store_id} once the migration is complete."
477+
)
478+
# Reset the counter as if we synced correctly, so the percentages add to 100% at the end.
479+
synced_generations = expected_synced_generations
480+
462481
async def get_merkle_blob(
463482
self,
464483
store_id: bytes32,

0 commit comments

Comments
 (0)