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")}; +}