PythiloLesson 8 of 12 · progress kept in this browser

Practice in Lab: Project: apply atomic versioned index updates and revocations →

Project: apply atomic versioned index updates and revocations

An index update is an authority change as well as a content change. Deletion must leave enough revision information to prevent an old delivery from resurrecting revoked text. This project applies a complete event batch to a copied index state, checks compare-and-swap ownership and deduplicates canonical event identities. A conflict aborts the batch before the caller publishes the returned value. The local value transformation is executable, but durable atomic publication, concurrent writers, event retention and a real search backend remain explicit production work.

document = {'revision':2,'deleted':True,'text':''}
incoming_revision = 1
print(incoming_revision > document['revision'])
print('retain the tombstone revision')
Your task

State has tenant,integer version,documents mapping and seen event-digest mapping. Require expected_version==state.version. Work on a deep copy. Events contain tenant,event,id,positive integer revision,op=upsert/delete; upsert also needs string text and list of string roles. Reject unknown event fields and cross-tenant events. Canonical JSON SHA-256 identifies an event: identical event replay is ignored, changed replay rejected. Every new document revision must exceed the previous revision, including tombstones. Store revision,deleted,text,sorted unique roles; deletion clears text/roles but retains revision. Advance state version once if any new event applied. Errors leave the original state unchanged.