Skip to content

Refactor Xapi_event (redux) #6370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 20, 2025

Conversation

contificate
Copy link
Contributor

Same as #6306 but retaining the suppression of potential snapshot-related exceptions. Now, there is commentary, a citation of the internal CA ticket (from 2012), and a commit hash citing the introduction of the try-with.


Clean BVT+BST (214804) and works as expected under the internal error reproduction script.

These commits were cherry picked back to the top, but I am happy to squash them.

Colin James added 2 commits March 19, 2025 09:13
In Xapi_event, events are accumulated by folding over the set of tables
associated with a subscriber's subscription record. These events are
mostly accumulated as lists within a tuple.

There is no analogue of functional record update for tuples in OCaml.
This means that the separate accumulations have to cite values they will
not update. By introducing records, we can only cite the fields we
actually change.

Signed-off-by: Colin James <colin.barr@cloud.com>
In event accumulation for event.from, the code uses a mutable variable
to thread a value through event accumulation. However, this value itself
is accumulated in the fold: it gets larger for each matching database
event that matches a subscription.

To avoid the complexity in effectively having a global, mutable
variable, we drop it and make it more evident when it changes: it is
changed when no events are accumulated (by grab_range). In the case that
no events are accumulated, but the deadline hasn't been reached, the
code tries to collect events again. It is during a retry that the
last_generation needs to be bumped, as it defines the starting point by
which to query the database for recent and deleted objects. In short, if
no suitable events were gleaned from matching database object records
since a given point, there's no point starting from there again.

Signed-off-by: Colin James <colin.barr@cloud.com>
@contificate contificate force-pushed the private/cbarr/event-redux branch from d1554c6 to 4488c68 Compare March 19, 2025 13:49
Colin James added 2 commits March 19, 2025 13:57
In order to provide event records to subscribers, we must convert the
accumulated events of the form (table, objref, time) into event records.

The process of doing this is simple for objects in the database. The
only difference is that deletion events do not provide a snapshot (as
the object has been deleted). To avoid repeating ourselves, we define an
"events_of" function that accumulates event records. The function takes
an argument that specifies whether an attempt to provide a snapshot
should be performed.

The reification of events associated with messages - which are not
stored in the database - is untouched. This relies on a callback
instated elsewhere.

Signed-off-by: Colin James <colin.barr@cloud.com>
Further changes to turn tuples into records.

Also partially uncurries `collect_events` to make its intended use as a
fold more apparent.

Signed-off-by: Colin James <colin.barr@cloud.com>
@contificate contificate force-pushed the private/cbarr/event-redux branch from 4488c68 to cf8ff83 Compare March 19, 2025 13:57
Copy link
Contributor

@lindig lindig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this code is subtle; I trust the extended testing.

else
events
with _ ->
(* CA-91931: An exception may be raised here if an object's
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be safe to match specific exceptions to avoid swallowing unexpected exceptions?

@psafont psafont added this pull request to the merge queue Mar 20, 2025
Merged via the queue into xapi-project:master with commit 5ddf28c Mar 20, 2025
17 checks passed
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.

3 participants