snapshot_and_reset_rpc_counters

Documentation for eth_defi.provider.rpc_counter_maintenance.snapshot_and_reset_rpc_counters function.

snapshot_and_reset_rpc_counters(database_path, backup_dir, reset_id=None, now=None, protected_paths=())

Create a verified dated snapshot and optionally reset physical counters.

Hold wait_other_writers(PIPELINE_DATA_DIR / 'scan-pipeline') throughout. With no reset ID this only snapshots counters. With an ID, a verified backup precedes the transactional reset. Repeating a committed ID verifies its backup and returns its receipt without clearing newly accumulated calls. No other pipeline files are touched. DuckDB’s locking semantics are described at https://duckdb.org/docs/stable/connect/concurrency.html.

The maintenance script selects protected files and owns the pipeline lock; this helper owns only the accounting database. Protected hashes prove those files did not change during maintenance, but are not backups of their data. The dated database copy, pre-reset manifest and transactional reset receipt serve different recovery points: deletion is allowed only after the first two are verified and durable, and the receipt makes a committed reset recoverable even if writing its final JSON acknowledgement fails.

Parameters
  • database_path (pathlib.Path) – Existing accounting database, never created implicitly.

  • backup_dir (pathlib.Path) – Private non-rotating snapshot directory.

  • reset_id (Optional[str]) – Stable identity for an intentional reset, or None for snapshot.

  • now (Optional[datetime.datetime]) – Naive UTC timestamp; defaults to the current UTC time.

  • protected_paths (tuple[pathlib.Path, ...]) – Critical files whose hashes must remain unchanged.

Returns

Verified manifest, including backup path and reset status.

Return type

dict