Skip to content
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

CP-51692: use Event.from instead of Event.next #6125

Merged
merged 5 commits into from
Nov 25, 2024

Conversation

edwintorok
Copy link
Contributor

Event.next can lose events, and we try to encourage our API users to always use Event.from instead.

My understanding (which could be wrong) is that Event.from will give you the events since a given point in time (token), whereas Event.next only gives you even from when you called the API (missing events between API calls).

This PR introduces a feature flag that we can use to switch the interal users of Event.next to Event.from.
Doing so I've discovered a bug in ocaml-rpc, where int32_of_rpc doesn't accept Int32 as input, just Int.
There is a workaround here for now, but I intend to fix this upstream instead, hence the draft PR.

No functional change.

Signed-off-by: Edwin Török <[email protected]>
…n flag

This is more efficient: we can watch a single task, instead of everything in
the DB.

Feature-flag: use-event-next

No functional change.

Signed-off-by: Edwin Török <[email protected]>
int32_of_rpc doesn't accept Int32 as input, just Int because none of the current deserializers actually produce an Int32.
(Int32 is only used by serializers to emit something different).

This is an upstream ocaml-rpc bug that should be fixed, meanwhile convert Rpc.Int32 to Rpc.Int, so that the 'fake_rpc' inside XAPI
can use Event.from.

Otherwise you get this error:
```
Expected int32, got 'I32(0)
```

Signed-off-by: Edwin Török <[email protected]>
…vent.next

This is more efficient: we can watch a single task, instead of everything in
the DB.

Feature-flag: use-event-next

Signed-off-by: Edwin Török <[email protected]>
@robhoes
Copy link
Member

robhoes commented Nov 19, 2024

My understanding (which could be wrong) is that Event.from will give you the events since a given point in time (token), whereas Event.next only gives you even from when you called the API (missing events between API calls).

event.next keeps all events since the last time you called it in a buffer, but this buffer can overflow if you don't call event.next again quickly enough. In that case, you'll get an EVENTS_LOST error. On the other hand, event.from doesn't let a buffer overflow, and solves the problem by effectively eliminating redundant events: where the same field gets updated multiple times, only the last update is kept as an event.

@lindig
Copy link
Contributor

lindig commented Nov 19, 2024

The above comment should go into the API documentation

… of Event.next

Feature flag: use-event-next

Signed-off-by: Edwin Török <[email protected]>
@edwintorok edwintorok force-pushed the pr/CP-51692 branch 2 times, most recently from 6a97fd6 to ace50ae Compare November 19, 2024 14:05
ocaml/xapi/xapi_globs.ml Show resolved Hide resolved
@edwintorok
Copy link
Contributor Author

Upstream bugfix here: mirage/ocaml-rpc#182, though probably still useful to keep the workaround too for now.

@edwintorok edwintorok marked this pull request as ready for review November 21, 2024 18:29
robhoes added a commit that referenced this pull request Nov 21, 2024
Describe EVENTS_LOST in Event.next.
Remove EVENTS_LOST and SESSION_NOT_REGISTERED from Event.from: these are
only raised by Event.next.

Document the actual errors that Event.from can raise.

As requested in
#6125 (comment),
based on
#6125 (comment)
@edwintorok edwintorok merged commit 5f1a59c into xapi-project:feature/perf Nov 25, 2024
15 checks passed
edwintorok added a commit to edwintorok/xen-api that referenced this pull request Dec 3, 2024
Event.next can lose events, and we try to encourage our API users to
always use Event.from instead.

My understanding (which could be wrong) is that Event.from will give you
the events since a given point in time (token), whereas Event.next only
gives you even from when you called the API (missing events between API
calls).

This PR introduces a feature flag that we can use to switch the interal
users of Event.next to Event.from.
Doing so I've discovered a bug in ocaml-rpc, where `int32_of_rpc`
doesn't accept Int32 as input, just Int.
There is a workaround here for now, but I intend to fix this upstream
instead, hence the draft PR.
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