fix: keep cold Cell reads outside native mutation deadline
This commit is contained in:
1 parent
4d1b825e4a
commit
ec75445f44
7 files changed
+179
-13
No files matched your search
@@ -172,7 +172,8 @@ def _dispose_clone(root):
|
||||
_write_json(root / 'clone-cleanup.json', {'path': str(target), 'removed': not target.exists()})
|
||||
|
||||
|
||||
def read_library_cell_catalog(library_path: Path, part_number: str, evidence_root: Path, *, partition: str | None = None) -> CellCatalog:
|
||||
def read_library_cell_catalog(library_path: Path, part_number: str, evidence_root: Path, *,
|
||||
partition: str | None = None, allow_cold_read: bool = True) -> CellCatalog:
|
||||
library = Path(library_path).resolve()
|
||||
if not isinstance(part_number, str) or not part_number.strip() or (partition is not None and not partition):
|
||||
_fail('part number and optional partition must be nonempty')
|
||||
@@ -191,12 +192,18 @@ def read_library_cell_catalog(library_path: Path, part_number: str, evidence_roo
|
||||
if _hash(path) != cache['sha256']:
|
||||
raise ValueError('evidence digest changed')
|
||||
value = _catalog_from_evidence(json.loads(path.read_text(encoding='utf-8')), library, part_number, partition, fingerprint, path)
|
||||
except (ValueError, KeyError, OSError, TypeError):
|
||||
pass # Re-read through an owned clone; never return damaged proof.
|
||||
except (ValueError, KeyError, OSError, TypeError, AttributeError):
|
||||
pass # Only an explicitly permitted cold read may replace damaged proof.
|
||||
else:
|
||||
if _library_manifest(library) != manifest:
|
||||
if not allow_cold_read:
|
||||
_fail('源库在缓存核验期间发生变化,请在料号规则中重新读取目标封装后再执行。')
|
||||
_fail('source library changed during cache validation')
|
||||
return value
|
||||
if not allow_cold_read:
|
||||
# Native mutation has its own hard deadline: never wait for the reader
|
||||
# mutex or create a clone/process inside that budget.
|
||||
_fail('目标封装缓存缺失或已失效,请在料号规则中重新读取目标封装后再执行。')
|
||||
root = evidence_root / 'reads' / uuid.uuid4().hex
|
||||
root.mkdir(parents=True)
|
||||
evidence_path = root / 'catalog.json'
|
||||
|
||||
@@ -86,13 +86,14 @@ def target_cell_catalog(app, snapshot, metadata, selected):
|
||||
library = Path(raw_path)
|
||||
if not raw_path.strip() or not library.is_absolute():
|
||||
raise ValueError("Active project has no absolute central library path for Cell validation")
|
||||
return cell_catalog_binding(library, metadata[3], selected, cell_catalog_evidence_root(snapshot))
|
||||
return cell_catalog_binding(library, metadata[3], selected, cell_catalog_evidence_root(snapshot),
|
||||
allow_cold_read=False)
|
||||
|
||||
|
||||
def cell_catalog_binding(library, part_number, selected, evidence_root):
|
||||
def cell_catalog_binding(library, part_number, selected, evidence_root, *, allow_cold_read=False):
|
||||
from .cell_catalog import read_library_cell_catalog
|
||||
|
||||
catalog = read_library_cell_catalog(library, part_number, evidence_root)
|
||||
catalog = read_library_cell_catalog(library, part_number, evidence_root, allow_cold_read=allow_cold_read)
|
||||
if catalog.library_path.resolve() != library.resolve() or catalog.part_number != part_number:
|
||||
raise ValueError("Cell catalog does not match the active project and target part")
|
||||
names = [cell.name for cell in catalog.cells]
|
||||
|
||||
@@ -91,7 +91,11 @@ def require_current_cell_binding(snapshot, binding, project, metadata):
|
||||
raise ValueError('Recovery has no bound target Cell catalog')
|
||||
from .cell_catalog import project_library_path
|
||||
library = project_library_path(project)
|
||||
current = cell_catalog_binding(library, metadata[3], cell, cell_catalog_evidence_root(snapshot))
|
||||
# Standalone preflight runs before the recovery CAD worker and outside the
|
||||
# native helper deadline. Rebuild lost cache while interruption protection
|
||||
# still locks the rule editor, then require the original exact binding.
|
||||
current = cell_catalog_binding(library, metadata[3], cell, cell_catalog_evidence_root(snapshot),
|
||||
allow_cold_read=True)
|
||||
if current != binding['cell_catalog']:
|
||||
raise ValueError('Recovery target Cell catalog has changed')
|
||||
return current
|
||||
|
||||
Reference in new issue
Block a user