mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-14 18:02:31 +08:00
Add trace_partial_file_suffix network option
This commit is contained in:
parent
5301e1a865
commit
39eff8c569
@ -53,12 +53,11 @@ int main(int argc, char** argv) {
|
|||||||
fdb_check(fdb_select_api_version(710));
|
fdb_check(fdb_select_api_version(710));
|
||||||
|
|
||||||
std::string file_identifier = "trace_partial_file_suffix_test" + std::to_string(std::random_device{}());
|
std::string file_identifier = "trace_partial_file_suffix_test" + std::to_string(std::random_device{}());
|
||||||
// std::string trace_partial_file_suffix = ".tmp";
|
std::string trace_partial_file_suffix = ".tmp";
|
||||||
std::string trace_partial_file_suffix = "";
|
|
||||||
|
|
||||||
set_net_opt(FDBNetworkOption::FDB_NET_OPTION_TRACE_ENABLE, "");
|
set_net_opt(FDBNetworkOption::FDB_NET_OPTION_TRACE_ENABLE, "");
|
||||||
set_net_opt(FDBNetworkOption::FDB_NET_OPTION_TRACE_FILE_IDENTIFIER, file_identifier);
|
set_net_opt(FDBNetworkOption::FDB_NET_OPTION_TRACE_FILE_IDENTIFIER, file_identifier);
|
||||||
// set_net_opt(FDBNetworkOption::FDB_NET_OPTION_TRACE_PARTIAL_FILE_SUFFIX, trace_partial_file_suffix);
|
set_net_opt(FDBNetworkOption::FDB_NET_OPTION_TRACE_PARTIAL_FILE_SUFFIX, trace_partial_file_suffix);
|
||||||
|
|
||||||
fdb_check(fdb_setup_network());
|
fdb_check(fdb_setup_network());
|
||||||
std::thread network_thread{ &fdb_run_network };
|
std::thread network_thread{ &fdb_run_network };
|
||||||
|
@ -1698,7 +1698,8 @@ Database Database::createDatabase(Reference<ClusterConnectionFile> connFile,
|
|||||||
networkOptions.traceDirectory.get(),
|
networkOptions.traceDirectory.get(),
|
||||||
"trace",
|
"trace",
|
||||||
networkOptions.traceLogGroup,
|
networkOptions.traceLogGroup,
|
||||||
networkOptions.traceFileIdentifier);
|
networkOptions.traceFileIdentifier,
|
||||||
|
networkOptions.tracePartialFileSuffix);
|
||||||
|
|
||||||
TraceEvent("ClientStart")
|
TraceEvent("ClientStart")
|
||||||
.detail("SourceVersion", getSourceVersion())
|
.detail("SourceVersion", getSourceVersion())
|
||||||
@ -1856,6 +1857,10 @@ void setNetworkOption(FDBNetworkOptions::Option option, Optional<StringRef> valu
|
|||||||
throw invalid_option_value();
|
throw invalid_option_value();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case FDBNetworkOptions::TRACE_PARTIAL_FILE_SUFFIX:
|
||||||
|
validateOptionValuePresent(value);
|
||||||
|
networkOptions.tracePartialFileSuffix = value.get().toString();
|
||||||
|
break;
|
||||||
case FDBNetworkOptions::KNOB: {
|
case FDBNetworkOptions::KNOB: {
|
||||||
validateOptionValuePresent(value);
|
validateOptionValuePresent(value);
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ struct NetworkOptions {
|
|||||||
std::string traceFormat;
|
std::string traceFormat;
|
||||||
std::string traceClockSource;
|
std::string traceClockSource;
|
||||||
std::string traceFileIdentifier;
|
std::string traceFileIdentifier;
|
||||||
|
std::string tracePartialFileSuffix;
|
||||||
Optional<bool> logClientInfo;
|
Optional<bool> logClientInfo;
|
||||||
Reference<ReferencedObject<Standalone<VectorRef<ClientVersionRef>>>> supportedVersions;
|
Reference<ReferencedObject<Standalone<VectorRef<ClientVersionRef>>>> supportedVersions;
|
||||||
bool runLoopProfilingEnabled;
|
bool runLoopProfilingEnabled;
|
||||||
|
@ -57,6 +57,9 @@ description is not currently required but encouraged.
|
|||||||
<Option name="trace_file_identifier" code="36"
|
<Option name="trace_file_identifier" code="36"
|
||||||
paramType="String" paramDescription="The identifier that will be part of all trace file names"
|
paramType="String" paramDescription="The identifier that will be part of all trace file names"
|
||||||
description="Once provided, this string will be used to replace the port/PID in the log file names." />
|
description="Once provided, this string will be used to replace the port/PID in the log file names." />
|
||||||
|
<Option name="trace_partial_file_suffix" code="39"
|
||||||
|
paramType="String" paramDesciption="Append this suffix to partially written log files. When a log file is complete, rename it to remove the suffix."
|
||||||
|
description="" />
|
||||||
<Option name="knob" code="40"
|
<Option name="knob" code="40"
|
||||||
paramType="String" paramDescription="knob_name=knob_value"
|
paramType="String" paramDescription="knob_name=knob_value"
|
||||||
description="Set internal tuning or debugging knobs"/>
|
description="Set internal tuning or debugging knobs"/>
|
||||||
|
@ -87,11 +87,13 @@ FileTraceLogWriter::FileTraceLogWriter(std::string const& directory,
|
|||||||
std::string const& processName,
|
std::string const& processName,
|
||||||
std::string const& basename,
|
std::string const& basename,
|
||||||
std::string const& extension,
|
std::string const& extension,
|
||||||
|
std::string const& tracePartialFileSuffix,
|
||||||
uint64_t maxLogsSize,
|
uint64_t maxLogsSize,
|
||||||
std::function<void()> const& onError,
|
std::function<void()> const& onError,
|
||||||
Reference<ITraceLogIssuesReporter> const& issues)
|
Reference<ITraceLogIssuesReporter> const& issues)
|
||||||
: directory(directory), processName(processName), basename(basename), extension(extension), maxLogsSize(maxLogsSize),
|
: directory(directory), processName(processName), basename(basename), extension(extension),
|
||||||
traceFileFD(-1), index(0), issues(issues), onError(onError) {}
|
tracePartialFileSuffix(tracePartialFileSuffix), maxLogsSize(maxLogsSize), traceFileFD(-1), index(0), issues(issues),
|
||||||
|
onError(onError) {}
|
||||||
|
|
||||||
void FileTraceLogWriter::addref() {
|
void FileTraceLogWriter::addref() {
|
||||||
ReferenceCounted<FileTraceLogWriter>::addref();
|
ReferenceCounted<FileTraceLogWriter>::addref();
|
||||||
@ -158,7 +160,8 @@ void FileTraceLogWriter::open() {
|
|||||||
// log10(index) < 10
|
// log10(index) < 10
|
||||||
UNSTOPPABLE_ASSERT(indexWidth < 10);
|
UNSTOPPABLE_ASSERT(indexWidth < 10);
|
||||||
|
|
||||||
auto finalname = format("%s.%d.%d.%s", basename.c_str(), indexWidth, index, extension.c_str());
|
finalname =
|
||||||
|
format("%s.%d.%d.%s%s", basename.c_str(), indexWidth, index, extension.c_str(), tracePartialFileSuffix.c_str());
|
||||||
while ((traceFileFD = __open(finalname.c_str(), TRACEFILE_FLAGS, TRACEFILE_MODE)) == -1) {
|
while ((traceFileFD = __open(finalname.c_str(), TRACEFILE_FLAGS, TRACEFILE_MODE)) == -1) {
|
||||||
lastError(errno);
|
lastError(errno);
|
||||||
if (errno == EEXIST) {
|
if (errno == EEXIST) {
|
||||||
@ -166,7 +169,12 @@ void FileTraceLogWriter::open() {
|
|||||||
indexWidth = unsigned(::floor(log10f(float(index))));
|
indexWidth = unsigned(::floor(log10f(float(index))));
|
||||||
|
|
||||||
UNSTOPPABLE_ASSERT(indexWidth < 10);
|
UNSTOPPABLE_ASSERT(indexWidth < 10);
|
||||||
finalname = format("%s.%d.%d.%s", basename.c_str(), indexWidth, index, extension.c_str());
|
finalname = format("%s.%d.%d.%s%s",
|
||||||
|
basename.c_str(),
|
||||||
|
indexWidth,
|
||||||
|
index,
|
||||||
|
extension.c_str(),
|
||||||
|
tracePartialFileSuffix.c_str());
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ERROR: could not create trace log file `%s' (%d: %s)\n",
|
"ERROR: could not create trace log file `%s' (%d: %s)\n",
|
||||||
@ -178,7 +186,7 @@ void FileTraceLogWriter::open() {
|
|||||||
|
|
||||||
int errorNum = errno;
|
int errorNum = errno;
|
||||||
onMainThreadVoid(
|
onMainThreadVoid(
|
||||||
[finalname, errorNum] {
|
[finalname = finalname, errorNum] {
|
||||||
TraceEvent(SevWarnAlways, "TraceFileOpenError")
|
TraceEvent(SevWarnAlways, "TraceFileOpenError")
|
||||||
.detail("Filename", finalname)
|
.detail("Filename", finalname)
|
||||||
.detail("ErrorCode", errorNum)
|
.detail("ErrorCode", errorNum)
|
||||||
@ -201,6 +209,11 @@ void FileTraceLogWriter::close() {
|
|||||||
while (__close(traceFileFD))
|
while (__close(traceFileFD))
|
||||||
threadSleep(0.1);
|
threadSleep(0.1);
|
||||||
}
|
}
|
||||||
|
traceFileFD = -1;
|
||||||
|
if (!tracePartialFileSuffix.empty()) {
|
||||||
|
renameFile(finalname, finalname.substr(0, finalname.size() - tracePartialFileSuffix.size()));
|
||||||
|
}
|
||||||
|
finalname = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileTraceLogWriter::roll() {
|
void FileTraceLogWriter::roll() {
|
||||||
|
@ -51,6 +51,8 @@ private:
|
|||||||
std::string processName;
|
std::string processName;
|
||||||
std::string basename;
|
std::string basename;
|
||||||
std::string extension;
|
std::string extension;
|
||||||
|
std::string finalname;
|
||||||
|
std::string tracePartialFileSuffix;
|
||||||
|
|
||||||
uint64_t maxLogsSize;
|
uint64_t maxLogsSize;
|
||||||
int traceFileFD;
|
int traceFileFD;
|
||||||
@ -66,6 +68,7 @@ public:
|
|||||||
std::string const& processName,
|
std::string const& processName,
|
||||||
std::string const& basename,
|
std::string const& basename,
|
||||||
std::string const& extension,
|
std::string const& extension,
|
||||||
|
std::string const& tracePartialFileSuffix,
|
||||||
uint64_t maxLogsSize,
|
uint64_t maxLogsSize,
|
||||||
std::function<void()> const& onError,
|
std::function<void()> const& onError,
|
||||||
Reference<ITraceLogIssuesReporter> const& issues);
|
Reference<ITraceLogIssuesReporter> const& issues);
|
||||||
|
@ -115,6 +115,7 @@ private:
|
|||||||
std::string directory;
|
std::string directory;
|
||||||
std::string processName;
|
std::string processName;
|
||||||
Optional<NetworkAddress> localAddress;
|
Optional<NetworkAddress> localAddress;
|
||||||
|
std::string tracePartialFileSuffix;
|
||||||
|
|
||||||
Reference<IThreadPool> writer;
|
Reference<IThreadPool> writer;
|
||||||
uint64_t rollsize;
|
uint64_t rollsize;
|
||||||
@ -288,13 +289,15 @@ public:
|
|||||||
std::string const& timestamp,
|
std::string const& timestamp,
|
||||||
uint64_t rs,
|
uint64_t rs,
|
||||||
uint64_t maxLogsSize,
|
uint64_t maxLogsSize,
|
||||||
Optional<NetworkAddress> na) {
|
Optional<NetworkAddress> na,
|
||||||
|
std::string const& tracePartialFileSuffix) {
|
||||||
ASSERT(!writer && !opened);
|
ASSERT(!writer && !opened);
|
||||||
|
|
||||||
this->directory = directory;
|
this->directory = directory;
|
||||||
this->processName = processName;
|
this->processName = processName;
|
||||||
this->logGroup = logGroup;
|
this->logGroup = logGroup;
|
||||||
this->localAddress = na;
|
this->localAddress = na;
|
||||||
|
this->tracePartialFileSuffix = tracePartialFileSuffix;
|
||||||
|
|
||||||
basename = format("%s/%s.%s.%s",
|
basename = format("%s/%s.%s.%s",
|
||||||
directory.c_str(),
|
directory.c_str(),
|
||||||
@ -306,6 +309,7 @@ public:
|
|||||||
processName,
|
processName,
|
||||||
basename,
|
basename,
|
||||||
formatter->getExtension(),
|
formatter->getExtension(),
|
||||||
|
tracePartialFileSuffix,
|
||||||
maxLogsSize,
|
maxLogsSize,
|
||||||
[this]() { barriers->triggerAll(); },
|
[this]() { barriers->triggerAll(); },
|
||||||
issues));
|
issues));
|
||||||
@ -715,7 +719,8 @@ void openTraceFile(const NetworkAddress& na,
|
|||||||
std::string directory,
|
std::string directory,
|
||||||
std::string baseOfBase,
|
std::string baseOfBase,
|
||||||
std::string logGroup,
|
std::string logGroup,
|
||||||
std::string identifier) {
|
std::string identifier,
|
||||||
|
std::string tracePartialFileSuffix) {
|
||||||
if (g_traceLog.isOpen())
|
if (g_traceLog.isOpen())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -739,7 +744,8 @@ void openTraceFile(const NetworkAddress& na,
|
|||||||
format("%lld", time(nullptr)),
|
format("%lld", time(nullptr)),
|
||||||
rollsize,
|
rollsize,
|
||||||
maxLogsSize,
|
maxLogsSize,
|
||||||
!g_network->isSimulated() ? na : Optional<NetworkAddress>());
|
!g_network->isSimulated() ? na : Optional<NetworkAddress>(),
|
||||||
|
tracePartialFileSuffix);
|
||||||
|
|
||||||
uncancellable(recurring(&flushTraceFile, FLOW_KNOBS->TRACE_FLUSH_INTERVAL, TaskPriority::FlushTrace));
|
uncancellable(recurring(&flushTraceFile, FLOW_KNOBS->TRACE_FLUSH_INTERVAL, TaskPriority::FlushTrace));
|
||||||
g_traceBatch.dump();
|
g_traceBatch.dump();
|
||||||
|
@ -564,7 +564,8 @@ void openTraceFile(const NetworkAddress& na,
|
|||||||
std::string directory = ".",
|
std::string directory = ".",
|
||||||
std::string baseOfBase = "trace",
|
std::string baseOfBase = "trace",
|
||||||
std::string logGroup = "default",
|
std::string logGroup = "default",
|
||||||
std::string identifier = "");
|
std::string identifier = "",
|
||||||
|
std::string tracePartialFileSuffix = "");
|
||||||
void initTraceEventMetrics();
|
void initTraceEventMetrics();
|
||||||
void closeTraceFile();
|
void closeTraceFile();
|
||||||
bool traceFileIsOpen();
|
bool traceFileIsOpen();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user