Project
Loading...
Searching...
No Matches
FailoverByteSource.h
Go to the documentation of this file.
1// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_FRAMEWORK_AODNATIVE_FAILOVERBYTESOURCE_H_
13#define O2_FRAMEWORK_AODNATIVE_FAILOVERBYTESOURCE_H_
14
16#include <atomic>
17#include <functional>
18#include <mutex>
19
20namespace o2::aod::native
21{
22
29{
30 public:
31 using Opener = std::function<std::unique_ptr<ByteSource>(std::string const& url, Options const&)>;
32 using Log = std::function<void(std::string const&)>;
33
35 FailoverByteSource(std::vector<Replica> replicas, Options const& options, Opener opener, Log log);
36
37 uint64_t size() const override { return mSize; }
38 void readInto(uint64_t off, size_t len, void* dst) override;
39 void readvInto(std::span<ReadRequest> requests) override;
40 std::span<const uint8_t> tryMap(uint64_t off, size_t len) override { return current()->tryMap(off, len); }
41 bool canMap() const override { return current()->canMap(); }
42 bool isRemote() const override { return mRemote; }
43 void willNeed(uint64_t off, size_t len) override { current()->willNeed(off, len); }
44 void dontNeed(uint64_t off, size_t len) override { current()->dontNeed(off, len); }
45 uint64_t bytesRead() const override;
46 uint64_t readCalls() const override;
47 std::string url() const override { return current()->url(); }
48 std::string replicaLabel() const override;
49
50 private:
51 std::shared_ptr<ByteSource> current() const;
53 void withFailover(std::function<void(ByteSource&)> const& read);
55 std::shared_ptr<ByteSource> openReplica(size_t index);
56 void report(std::string const& message) const;
57
58 std::vector<Replica> mReplicas;
59 Options mOptions;
60 Opener mOpener;
61 Log mLog;
62
63 mutable std::mutex mMutex;
64 std::shared_ptr<ByteSource> mSource; // guarded by mMutex
65 size_t mIndex = 0; // guarded by mMutex
66 uint64_t mGeneration = 0; // guarded by mMutex, bumped at every reopen
67 int mAttempts = 0; // retries done on the current replica, guarded by mMutex
68 std::string mErrors; // what went wrong on the replicas left behind
69
70 uint64_t mSize = 0;
71 bool mRemote = false;
72 std::atomic<uint64_t> mRetiredBytes = 0;
73 std::atomic<uint64_t> mRetiredCalls = 0;
74};
75
76} // namespace o2::aod::native
77
78#endif // O2_FRAMEWORK_AODNATIVE_FAILOVERBYTESOURCE_H_
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
std::function< void(std::string const &)> Log
std::function< std::unique_ptr< ByteSource >(std::string const &url, Options const &)> Opener
bool canMap() const override
Whether tryMap() provides every range, so that nothing needs reading.
void readvInto(std::span< ReadRequest > requests) override
bool isRemote() const override
Whether each read is a network round trip, worth hiding behind decoding.
void readInto(uint64_t off, size_t len, void *dst) override
Throws IoError, or CorruptData when the range is past the end of the file.
std::string url() const override
std::string replicaLabel() const override
The label of the replica being read, for a source opened with openReplicas().
void willNeed(uint64_t off, size_t len) override
Hints that a range will be needed soon, or is no longer needed.
std::span< const uint8_t > tryMap(uint64_t off, size_t len) override
A view of the bytes without copying them, if the backend can provide it.
void dontNeed(uint64_t off, size_t len) override
GLenum GLenum dst
Definition glcorearb.h:1767
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLsizei const GLchar * message
Definition glcorearb.h:2517
GLenum GLenum GLsizei len
Definition glcorearb.h:4232