Allow the user to provide a custome trace log file identifier that will be used as the prefix of all trace log files created at the client side.

This commit is contained in:
Xin Dong 2020-03-26 11:24:53 -07:00
parent 0547cf2b4c
commit a0177a9335
5 changed files with 22 additions and 5 deletions

View File

@ -792,7 +792,9 @@ Database Database::createDatabase( Reference<ClusterConnectionFile> connFile, in
auto publicIP = determinePublicIPAutomatically( connFile->getConnectionString() ); auto publicIP = determinePublicIPAutomatically( connFile->getConnectionString() );
selectTraceFormatter(networkOptions.traceFormat); selectTraceFormatter(networkOptions.traceFormat);
selectTraceClockSource(networkOptions.traceClockSource); selectTraceClockSource(networkOptions.traceClockSource);
openTraceFile(NetworkAddress(publicIP, ::getpid()), networkOptions.traceRollSize, networkOptions.traceMaxLogsSize, networkOptions.traceDirectory.get(), "trace", networkOptions.traceLogGroup); openTraceFile(NetworkAddress(publicIP, ::getpid()), networkOptions.traceRollSize,
networkOptions.traceMaxLogsSize, networkOptions.traceDirectory.get(), "trace",
networkOptions.traceLogGroup, networkOptions.traceFileIdentifier);
TraceEvent("ClientStart") TraceEvent("ClientStart")
.detail("SourceVersion", getSourceVersion()) .detail("SourceVersion", getSourceVersion())
@ -874,6 +876,10 @@ void setNetworkOption(FDBNetworkOptions::Option option, Optional<StringRef> valu
throw invalid_option_value(); throw invalid_option_value();
} }
break; break;
case FDBNetworkOptions::TRACE_FILE_IDENTIFIER:
validateOptionValue(value, true);
networkOptions.traceFileIdentifier = value.get().toString();
break;
case FDBNetworkOptions::KNOB: { case FDBNetworkOptions::KNOB: {
validateOptionValue(value, true); validateOptionValue(value, true);

View File

@ -58,6 +58,7 @@ struct NetworkOptions {
std::string traceLogGroup; std::string traceLogGroup;
std::string traceFormat; std::string traceFormat;
std::string traceClockSource; std::string traceClockSource;
std::string traceFileIdentifier;
Optional<bool> logClientInfo; Optional<bool> logClientInfo;
Reference<ReferencedObject<Standalone<VectorRef<ClientVersionRef>>>> supportedVersions; Reference<ReferencedObject<Standalone<VectorRef<ClientVersionRef>>>> supportedVersions;
bool slowTaskProfilingEnabled; bool slowTaskProfilingEnabled;

View File

@ -54,6 +54,9 @@ description is not currently required but encouraged.
<Option name="trace_clock_source" code="35" <Option name="trace_clock_source" code="35"
paramType="String" paramDescription="Trace clock source" paramType="String" paramDescription="Trace clock source"
description="Select clock source for trace files. now (the default) or realtime are supported." /> description="Select clock source for trace files. now (the default) or realtime are supported." />
<Option name="trace_file_identifier" code="36"
paramType="String" paramDescription="The identifier that will be part of all trace file names"
description="Once provided, all trace log file names will use this string as the prefix." />
<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"/>

View File

@ -711,7 +711,8 @@ void flushTraceFileVoid() {
} }
} }
void openTraceFile(const NetworkAddress& na, uint64_t rollsize, uint64_t maxLogsSize, std::string directory, std::string baseOfBase, std::string logGroup) { void openTraceFile(const NetworkAddress& na, uint64_t rollsize, uint64_t maxLogsSize, std::string directory,
std::string baseOfBase, std::string logGroup, std::string identifier) {
if(g_traceLog.isOpen()) if(g_traceLog.isOpen())
return; return;
@ -723,7 +724,12 @@ void openTraceFile(const NetworkAddress& na, uint64_t rollsize, uint64_t maxLogs
std::string ip = na.ip.toString(); std::string ip = na.ip.toString();
std::replace(ip.begin(), ip.end(), ':', '_'); // For IPv6, Windows doesn't accept ':' in filenames. std::replace(ip.begin(), ip.end(), ':', '_'); // For IPv6, Windows doesn't accept ':' in filenames.
std::string baseName = format("%s.%s.%d", baseOfBase.c_str(), ip.c_str(), na.port); std::string baseName;
if (identifier.size() > 0) {
baseName = format("%s.%s.%s.%d", identifier, baseOfBase.c_str(), ip.c_str(), na.port);
} else {
baseName = format("%s.%s.%d", baseOfBase.c_str(), ip.c_str(), na.port);
}
g_traceLog.open( directory, baseName, logGroup, format("%lld", time(NULL)), rollsize, maxLogsSize, !g_network->isSimulated() ? na : Optional<NetworkAddress>()); g_traceLog.open( directory, baseName, logGroup, format("%lld", time(NULL)), rollsize, maxLogsSize, !g_network->isSimulated() ? na : Optional<NetworkAddress>());
uncancellable(recurring(&flushTraceFile, FLOW_KNOBS->TRACE_FLUSH_INTERVAL, TaskPriority::FlushTrace)); uncancellable(recurring(&flushTraceFile, FLOW_KNOBS->TRACE_FLUSH_INTERVAL, TaskPriority::FlushTrace));

View File

@ -587,7 +587,8 @@ struct EventCacheHolder : public ReferenceCounted<EventCacheHolder> {
#endif #endif
struct NetworkAddress; struct NetworkAddress;
void openTraceFile(const NetworkAddress& na, uint64_t rollsize, uint64_t maxLogsSize, std::string directory = ".", std::string baseOfBase = "trace", std::string logGroup = "default"); void openTraceFile(const NetworkAddress& na, uint64_t rollsize, uint64_t maxLogsSize, std::string directory = ".",
std::string baseOfBase = "trace", std::string logGroup = "default", std::string identifier = "");
void initTraceEventMetrics(); void initTraceEventMetrics();
void closeTraceFile(); void closeTraceFile();
bool traceFileIsOpen(); bool traceFileIsOpen();