23std::string labelOf(Replica
const&
r)
25 return r.label.empty() ?
r.url.substr(0,
r.url.find(
'?')) :
r.label;
30 : mReplicas(
std::move(replicas)), mOptions(options), mOpener(
std::move(opener)), mLog(
std::move(log))
32 if (mReplicas.empty()) {
33 throw IoError(
"(no replica)",
"no replica to open");
35 for (mIndex = 0; mIndex < mReplicas.size(); ++mIndex) {
37 mSource = openReplica(mIndex);
38 mSize = mSource->size();
39 mRemote = mSource->isRemote();
42 report(
"Could not open replica on " + labelOf(mReplicas[mIndex]) +
": " +
e.what());
43 mErrors +=
" " + labelOf(mReplicas[mIndex]) +
": " +
e.what() +
";";
46 throw IoError(labelOf(mReplicas.front()),
"no replica could be opened:" + mErrors);
49std::shared_ptr<ByteSource> FailoverByteSource::openReplica(
size_t index)
51 std::shared_ptr<ByteSource>
source = mOpener(mReplicas[
index].
url, mOptions);
52 if (mSource &&
source->size() != mSize) {
58std::shared_ptr<ByteSource> FailoverByteSource::current()
const
60 std::lock_guard lock{mMutex};
66 std::lock_guard lock{mMutex};
67 return mReplicas[mIndex].label;
72 return mRetiredBytes.load(std::memory_order_relaxed) + current()->bytesRead();
77 return mRetiredCalls.load(std::memory_order_relaxed) + current()->readCalls();
80void FailoverByteSource::report(std::string
const&
message)
const
94 withFailover([&](
ByteSource&
s) {
s.readvInto(requests); });
97void FailoverByteSource::withFailover(std::function<
void(
ByteSource&)>
const& read)
100 std::shared_ptr<ByteSource>
source;
103 std::lock_guard lock{mMutex};
105 generation = mGeneration;
110 }
catch (IoError
const&
e) {
111 std::lock_guard lock{mMutex};
112 if (generation != mGeneration) {
115 mRetiredBytes.fetch_add(
source->bytesRead(), std::memory_order_relaxed);
116 mRetiredCalls.fetch_add(
source->readCalls(), std::memory_order_relaxed);
117 std::string
error =
e.what();
122 double delay = mOptions.
retryDelay * std::pow(2., mAttempts);
124 report(
"Read error on " + labelOf(mReplicas[mIndex]) +
", retry " +
std::to_string(mAttempts) +
" of " +
126 std::this_thread::sleep_for(std::chrono::duration<double>(delay));
128 mErrors +=
" " + labelOf(mReplicas[mIndex]) +
": " +
error +
";";
129 if (mIndex + 1 >= mReplicas.size()) {
130 throw IoError(labelOf(mReplicas.front()),
"no replica left to read from:" + mErrors);
134 report(
"Moving to replica on " + labelOf(mReplicas[mIndex]) +
" after: " +
error);
137 mSource = openReplica(mIndex);
140 }
catch (IoError
const& reopen) {
141 error = reopen.what();
142 if (mAttempts == 0) {
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 s
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
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 e
char error[CURL_ERROR_SIZE]
std::function< void(std::string const &)> Log
std::function< std::unique_ptr< ByteSource >(std::string const &url, Options const &)> Opener
void readvInto(std::span< ReadRequest > requests) override
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.
uint64_t bytesRead() const override
std::string url() const override
FailoverByteSource(std::vector< Replica > replicas, Options const &options, Opener opener, Log log)
Throws IoError when no replica opens.
std::string replicaLabel() const override
The label of the replica being read, for a source opened with openReplicas().
uint64_t readCalls() const override
GLsizei GLsizei GLchar * source
GLuint GLsizei const GLchar * message
GLenum GLenum GLsizei len
std::string to_string(gsl::span< T, Size > span)
Failure of the underlying transport.