Skip to content

Keep the highest _id given out in Fbe.fb so a deleted one is never reused - #1331

Open
Thayorns wants to merge 1 commit into
zerocracy:masterfrom
Thayorns:1245
Open

Thayorns wants to merge 1 commit into
zerocracy:masterfrom
Thayorns:1245

Conversation

@Thayorns

@Thayorns Thayorns commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Fbe.fb numbered every new fact from (max _id) of the facts that were still in the factbase. Once the fact with the highest _id was deleted, the next insert got its number again, so anything that kept that _id from earlier in the run, such as Fbe.overwrite, Fbe.delete or the log lines, pointed at a different fact.

The Pre block now remembers, in a local it closes over, the highest _id it has given out while the cached factbase lives, and takes the larger of that and (max _id), so a number is never handed out twice. The (max _id) part stays, so a factbase that arrives with facts already numbered still continues after its highest one.

The tests delete the last fact, delete every fact, and delete then insert inside one transaction, and each checks the next _id. One more test makes sure numbering still follows the highest _id of the origin factbase.

This covers one run. An _id deleted in a previous run and not saved into the factbase can still come back in the next one, because nothing records it; that would need the counter persisted somewhere, which is a bigger change than this issue.

Closes #1245

@Thayorns

Copy link
Copy Markdown
Contributor Author

@yegor256 take a look please, happy to clarify anything about the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fbe.fb gives a new fact the _id of a deleted one, because it numbers facts from (max _id)

1 participant