cirruslabs / orchard

Orchestrator for running Tart Virtual Machines on a cluster of Apple Silicon devices
Other
194 stars 16 forks source link

Change event prefix to preserve order under load #89

Closed fkorotkov closed 1 year ago

fkorotkov commented 1 year ago

When there are a lot of events streamed from a worker, it's possible to have two batches coming for the same timestamp (which is a timestamp of the event on the worker). This way the existing logic would mess up the order because index and the random number doesn't guarantee the order.

To fix this I've changed the format of the prefix for the event to include tro things:

  1. Timestamp in nanoseconds of the injection time on the controller so two sequential batches will have guaranteed order unless they are processed within a nanosecond.
  2. Made the index being fixed length with trailing zeros, so they are properly lexicographically sorted (000001, 000002, ...).

Fixes #88