mirror of
https://github.com/apple/foundationdb.git
synced 2026-01-25 04:18:18 +00:00
Minor changes from reading code (#12297)
* ensure workload names are not duplicated * improve system call failure handling; improve internal interface * fix return value semantics * simplify WorkloadFactory(); address review comment * simplify it correctly this time
This commit is contained in:
@@ -259,7 +259,10 @@ struct WorkloadFactory : IWorkloadFactory {
|
||||
bool runInUntrustedClient;
|
||||
WorkloadFactory(UntrustedMode runInUntrustedClient = UntrustedMode::False)
|
||||
: runInUntrustedClient(runInUntrustedClient) {
|
||||
factories()[WorkloadType::NAME] = Reference<IWorkloadFactory>::addRef(this);
|
||||
auto& f = factories();
|
||||
std::string name = WorkloadType::NAME;
|
||||
ASSERT(!f.contains(name));
|
||||
f[name] = Reference<IWorkloadFactory>::addRef(this);
|
||||
}
|
||||
Reference<TestWorkload> create(WorkloadContext const& wcx) override {
|
||||
if (g_network->isSimulated() && runInUntrustedClient) {
|
||||
|
||||
@@ -142,7 +142,7 @@ void FileTraceLogWriter::write(const char* str, size_t len) {
|
||||
} else {
|
||||
issues->addIssue("trace_log_file_write_error");
|
||||
needsResolve = true;
|
||||
fprintf(stderr, "Unexpected error [%d] when flushing trace log.\n", errno);
|
||||
fprintf(stderr, "Unexpected error [%d] (%s) when writing to trace file.\n", errno, strerror(errno));
|
||||
lastError(errno);
|
||||
threadSleep(0.1);
|
||||
}
|
||||
@@ -180,20 +180,23 @@ void FileTraceLogWriter::open() {
|
||||
extension.c_str(),
|
||||
tracePartialFileSuffix.c_str());
|
||||
} else {
|
||||
// Save errno before issuing subsequent system calls,
|
||||
// such as write(2) via fprintf, in case that fails for
|
||||
// some other reason.
|
||||
int saveErrno = errno;
|
||||
fprintf(stderr,
|
||||
"ERROR: could not create trace log file `%s' (%d: %s)\n",
|
||||
finalname.c_str(),
|
||||
errno,
|
||||
strerror(errno));
|
||||
saveErrno,
|
||||
strerror(saveErrno));
|
||||
issues->addIssue("trace_log_could_not_create_file");
|
||||
needsResolve = true;
|
||||
|
||||
int errorNum = errno;
|
||||
onMainThreadVoid([finalname = finalname, errorNum] {
|
||||
onMainThreadVoid([finalname = finalname, saveErrno] {
|
||||
TraceEvent(SevWarnAlways, "TraceFileOpenError")
|
||||
.detail("Filename", finalname)
|
||||
.detail("ErrorCode", errorNum)
|
||||
.detail("Error", strerror(errorNum))
|
||||
.detail("ErrorCode", saveErrno)
|
||||
.detail("Error", strerror(saveErrno))
|
||||
.trackLatest("TraceFileOpenError");
|
||||
});
|
||||
threadSleep(FLOW_KNOBS->TRACE_RETRY_OPEN_INTERVAL);
|
||||
@@ -224,7 +227,9 @@ void FileTraceLogWriter::roll() {
|
||||
}
|
||||
|
||||
void FileTraceLogWriter::sync() {
|
||||
__fsync(traceFileFD);
|
||||
if (__fsync(traceFileFD) != 0) {
|
||||
fprintf(stderr, "ERROR: fsync(%s): %d, %s\n", finalname.c_str(), errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
void FileTraceLogWriter::cleanupTraceFiles() {
|
||||
|
||||
@@ -76,8 +76,7 @@ struct SuppressionMap {
|
||||
|
||||
std::map<std::string, SuppressionInfo> suppressionMap;
|
||||
|
||||
// Returns -1 if this event is suppressed
|
||||
int64_t checkAndInsertSuppression(std::string type, double duration) {
|
||||
int64_t checkAndInsertSuppression(std::string type, double duration, bool& suppress) {
|
||||
ASSERT(g_network);
|
||||
if (suppressionMap.size() >= FLOW_KNOBS->MAX_TRACE_SUPPRESSIONS) {
|
||||
TraceEvent(SevWarnAlways, "ClearingTraceSuppressionMap").log();
|
||||
@@ -85,15 +84,17 @@ struct SuppressionMap {
|
||||
}
|
||||
|
||||
auto insertion = suppressionMap.insert(std::make_pair(type, SuppressionInfo()));
|
||||
int64_t suppressedEventCount;
|
||||
if (insertion.second || insertion.first->second.endTime <= now()) {
|
||||
int64_t suppressedEventCount = insertion.first->second.suppressedEventCount;
|
||||
suppress = false;
|
||||
suppressedEventCount = insertion.first->second.suppressedEventCount;
|
||||
insertion.first->second.endTime = now() + duration;
|
||||
insertion.first->second.suppressedEventCount = 0;
|
||||
return suppressedEventCount;
|
||||
} else {
|
||||
++insertion.first->second.suppressedEventCount;
|
||||
return -1;
|
||||
suppress = true;
|
||||
suppressedEventCount = ++insertion.first->second.suppressedEventCount;
|
||||
}
|
||||
return suppressedEventCount;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1225,8 +1226,9 @@ BaseTraceEvent& TraceEvent::suppressFor(double duration, bool logSuppressedEvent
|
||||
|
||||
if (g_network) {
|
||||
if (isNetworkThread()) {
|
||||
int64_t suppressedEventCount = suppressedEvents.checkAndInsertSuppression(type, duration);
|
||||
if (suppressedEventCount < 0)
|
||||
bool suppress = false;
|
||||
int64_t suppressedEventCount = suppressedEvents.checkAndInsertSuppression(type, duration, suppress);
|
||||
if (suppress)
|
||||
enabled.suppress();
|
||||
if (enabled && logSuppressedEventCount) {
|
||||
detail("SuppressedEventCount", suppressedEventCount);
|
||||
|
||||
Reference in New Issue
Block a user