From ce4551ad398479c92f89a41bf6a10e1bdf33c926 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Thu, 3 Dec 2026 10:38:48 +0100 Subject: [PATCH] DPL: do not let a completed input channel hold back the others A time-pipelined source whose lane ends early, e.g. an AOD reader lane with no files left with --readers 2, leaves a completed input channel in its consumers whose oldest possible timeslice never advances again. Before, that stale value was still used: - as the reference of the channel balancing in doPrepare: the channel of the live lane was suspended once it was ahead of it, and, as no polled channel was still running, the consumer went to EndOfStream with data still in flight; - in the minimum of TimesliceIndex::setOldestPossibleInput: the oldest possible output stopped advancing, so the dummy sink stopped reporting consumed timeslices and the rate limiting stopped offering them. Either way the remaining reader lane starved forever on its shared memory or timeslice offers, and the workflow hung. Completed channels are now ignored for both. The timeslices of the ended lane are then skipped by ordered consumers (e.g. the AOD writer) through the oldest possible timeslice, which happens asynchronously: at end of stream, when nothing can arrive anymore, skip to the oldest pending timeslice directly, or the last pending ones are dropped. Add a workflow test where one of two pipelined source lanes ends at once: before, its consumer got 10 of 100 timeframes. --- Framework/Core/CMakeLists.txt | 1 + Framework/Core/src/DataProcessingDevice.cxx | 21 +++++- Framework/Core/src/TimesliceIndex.cxx | 4 +- .../test/test_PipelinedSourceEndOfStream.cxx | 66 +++++++++++++++++++ 4 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 Framework/Core/test/test_PipelinedSourceEndOfStream.cxx diff --git a/Framework/Core/CMakeLists.txt b/Framework/Core/CMakeLists.txt index b31e951bb7ec1..fa22f4434fb19 100644 --- a/Framework/Core/CMakeLists.txt +++ b/Framework/Core/CMakeLists.txt @@ -394,6 +394,7 @@ foreach(w Forwarding ParallelPipeline ParallelProducer + PipelinedSourceEndOfStream SlowConsumer SlowProducerWithWildCard SimpleDataProcessingDevice01 diff --git a/Framework/Core/src/DataProcessingDevice.cxx b/Framework/Core/src/DataProcessingDevice.cxx index b181eda458056..2661819b955bb 100644 --- a/Framework/Core/src/DataProcessingDevice.cxx +++ b/Framework/Core/src/DataProcessingDevice.cxx @@ -1550,7 +1550,9 @@ void DataProcessingDevice::doPrepare(ServiceRegistryRef ref) O2_SIGNPOST_END(device, dpid, "do_prepare", "Nothing to poll. Waiting for next iteration."); return; } - auto currentOldest = state.inputChannelInfos[pollOrder.front()].oldestForChannel; + // A completed channel will not send anything anymore, so it must not hold back the others. + auto oldestRunning = std::ranges::find_if(pollOrder, [&infos = state.inputChannelInfos](int a) { return infos[a].state != InputChannelState::Completed; }); + auto currentOldest = state.inputChannelInfos[oldestRunning != pollOrder.end() ? *oldestRunning : pollOrder.front()].oldestForChannel; auto currentNewest = state.inputChannelInfos[pollOrder.back()].oldestForChannel; auto delta = currentNewest.value - currentOldest.value; O2_SIGNPOST_EVENT_EMIT(device, dpid, "do_prepare", "Oldest possible timeframe range %" PRIu64 " => %" PRIu64 " delta %" PRIu64, @@ -1729,8 +1731,21 @@ void DataProcessingDevice::doRun(ServiceRegistryRef ref) bool shouldProcess = DataProcessingHelpers::hasOnlyGenerated(spec) == false; - while (DataProcessingDevice::tryDispatchComputation(ref, streamContext.completed) && shouldProcess) { - relayer.processDanglingInputs(context.expirationHandlers, *context.registry, false); + auto& decongestion = ref.get(); + while (true) { + while (DataProcessingDevice::tryDispatchComputation(ref, streamContext.completed) && shouldProcess) { + relayer.processDanglingInputs(context.expirationHandlers, *context.registry, false); + } + // No input can arrive anymore, so an ordered consumer must not wait for the timeslices it misses. + if (!shouldProcess || !decongestion.orderedCompletionPolicyActive) { + break; + } + auto oldest = (int64_t)ref.get().updateOldestPossibleOutput(false).timeslice.value; + if (oldest <= decongestion.nextTimeslice) { + break; + } + decongestion.nextTimeslice = oldest; + ref.get().rescan(); } auto& timingInfo = ref.get(); diff --git a/Framework/Core/src/TimesliceIndex.cxx b/Framework/Core/src/TimesliceIndex.cxx index df98eea3cc9d0..d9b223334290a 100644 --- a/Framework/Core/src/TimesliceIndex.cxx +++ b/Framework/Core/src/TimesliceIndex.cxx @@ -151,9 +151,9 @@ TimesliceIndex::OldestInputInfo TimesliceIndex::setOldestPossibleInput(Timeslice OldestInputInfo result{timestamp, channel}; bool changed = false; for (int ci = 0; ci < mChannels.size(); ci++) { - // Check if this is a real channel. Skip otherwise. + // Check if this is a real channel which can still send data. Skip otherwise. auto& channelRef = mChannels[ci]; - if (channelRef.channelType != ChannelAccountingType::DPL) { + if (channelRef.channelType != ChannelAccountingType::DPL || channelRef.state == InputChannelState::Completed) { continue; } auto& a = channelRef.oldestForChannel; diff --git a/Framework/Core/test/test_PipelinedSourceEndOfStream.cxx b/Framework/Core/test/test_PipelinedSourceEndOfStream.cxx new file mode 100644 index 0000000000000..8f5f8fa712899 --- /dev/null +++ b/Framework/Core/test/test_PipelinedSourceEndOfStream.cxx @@ -0,0 +1,66 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +#include "Framework/CompletionPolicyHelpers.h" + +void customize(std::vector& policies) +{ + policies.push_back(o2::framework::CompletionPolicyHelpers::consumeWhenAllOrdered("ordered-consumer")); +} + +#include "Framework/CallbackService.h" +#include "Framework/ControlService.h" +#include "Framework/DeviceSpec.h" +#include "Framework/EndOfStreamContext.h" +#include "Framework/Logger.h" +#include "Framework/runDataProcessing.h" + +using namespace o2::framework; + +// A source with two time-pipelined lanes, like the AOD reader with --readers 2, +// where one lane has nothing to read and ends immediately. The other lane must +// still deliver all its data: the completed channel must hold back neither the +// polling of the other channel nor the oldest possible timeslice. +constexpr int nTimeframes = 100; + +DataProcessorSpec consumer(std::string name) +{ + return DataProcessorSpec{ + .name = name, + .inputs = {InputSpec{"data", "TST", "PIPELINED"}}, + .algorithm = adaptStateful([](CallbackService& callbacks) { + static int received = 0; + callbacks.set([](EndOfStreamContext&) { + if (received != nTimeframes) { + LOGP(fatal, "Received {} timeframes, expected {}", received, nTimeframes); + } + }); + return adaptStateless([]() { received++; }); + })}; +} + +WorkflowSpec defineDataProcessing(ConfigContext const&) +{ + return WorkflowSpec{ + timePipeline(DataProcessorSpec{ + .name = "producer", + .outputs = {OutputSpec{{"data"}, "TST", "PIPELINED"}}, + .algorithm = adaptStateless([](DataAllocator& outputs, ControlService& control, DeviceSpec const& spec) { + static int sent = 0; + if (spec.inputTimesliceId == 1 || sent == nTimeframes) { + control.endOfStream(); + control.readyToQuit(QuitRequest::Me); + return; + } + outputs.make(Output{"TST", "PIPELINED", 0}) = sent++; + })}, + 2), + consumer("consumer"), consumer("ordered-consumer")}; +}