Broker: a collection can be followed from /start, its start message comes in the event stream
With a DECTRIS detector the broker starts the writers - and so learned the collection's start message - only when the detector's own start message arrived, after /start had returned. A reader started right after /start found no collection (404) and had to wait for, and race with, the detector. - /start registers the collection in LiveCollection (Expect) as it is accepted, so GET /live/events is accepted from then on. The image pusher fills in the start message when it starts the writers (Begin) - at once on the FPGA path, when the detector's start message arrives on the DECTRIS path. - The event stream's first event is now `start`, carrying that start message (CBOR, base64) with run number, file prefix, image count and images per file; it replaces `collection`. Until it is known the stream only keeps alive. file and end follow as before. - However the measurement thread ends, it ends a collection the pusher did not end (EndIfOpen), so a cancel or a failure before the detector streamed reaches the reader as `end` with an error. The wait is event-driven: it ends with the start message or with the measurement. - GET /live/start.cbor is removed: the stream carries the start message, one route less. - rugnux takes the start message from the stream (BrokerFeed::WaitForStart), so it can be started right after /start; files reported before it attached the reader are replayed to it. Tests: LiveCollection_ExpectedAtStart; BrokerFeed_StartFromEventStream (an event stream whose start message comes late, then a file and the end). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SVmAWnzCmRKAXVUCdc4iNi
This commit is contained in:
1 parent
72c7409327
commit
2981aedd3e
13 files changed
+315
-164
No files matched your search
@@ -5,12 +5,27 @@
|
||||
|
||||
#include "../writer/HDF5NXmx.h"
|
||||
|
||||
void LiveCollection::Begin(const StartMessage &start, std::vector<uint8_t> cbor) {
|
||||
void LiveCollection::Expect() {
|
||||
{
|
||||
std::unique_lock ul(m);
|
||||
const uint64_t generation = state.generation + 1;
|
||||
state = Snapshot{};
|
||||
state.generation = generation;
|
||||
start_cbor.clear();
|
||||
}
|
||||
cv.notify_all();
|
||||
}
|
||||
|
||||
void LiveCollection::Begin(const StartMessage &start, std::vector<uint8_t> cbor) {
|
||||
{
|
||||
std::unique_lock ul(m);
|
||||
// The collection Expect announced, or - when nothing announced it - a new one.
|
||||
if (state.generation == 0 || state.started || state.ended) {
|
||||
const uint64_t generation = state.generation + 1;
|
||||
state = Snapshot{};
|
||||
state.generation = generation;
|
||||
}
|
||||
state.started = true;
|
||||
state.run_number = start.run_number;
|
||||
state.run_name = start.run_name;
|
||||
state.file_prefix = start.file_prefix;
|
||||
@@ -25,7 +40,7 @@ void LiveCollection::Begin(const StartMessage &start, std::vector<uint8_t> cbor)
|
||||
void LiveCollection::FileClosed(uint64_t file_number, uint64_t image_count) {
|
||||
{
|
||||
std::unique_lock ul(m);
|
||||
if (state.generation == 0 || state.ended)
|
||||
if (!state.started || state.ended)
|
||||
return;
|
||||
state.files.push_back(DataFile{
|
||||
.file_number = file_number,
|
||||
@@ -49,18 +64,23 @@ void LiveCollection::End(uint64_t images, const std::string &error) {
|
||||
cv.notify_all();
|
||||
}
|
||||
|
||||
void LiveCollection::EndIfOpen(const std::string &error) {
|
||||
End(0, error);
|
||||
}
|
||||
|
||||
std::optional<std::vector<uint8_t>> LiveCollection::StartCBOR() const {
|
||||
std::unique_lock ul(m);
|
||||
if (state.generation == 0)
|
||||
if (!state.started)
|
||||
return {};
|
||||
return start_cbor;
|
||||
}
|
||||
|
||||
LiveCollection::Snapshot LiveCollection::Wait(uint64_t generation, size_t files_seen,
|
||||
LiveCollection::Snapshot LiveCollection::Wait(uint64_t generation, bool started_seen, size_t files_seen,
|
||||
std::chrono::milliseconds wait) {
|
||||
std::unique_lock ul(m);
|
||||
cv.wait_for(ul, wait, [&] {
|
||||
return state.generation != generation || state.ended || state.files.size() > files_seen;
|
||||
return state.generation != generation || state.ended || state.files.size() > files_seen
|
||||
|| (state.started && !started_seen);
|
||||
});
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user