Make trace files lexicographically ordered

This resolves #1825

The basic idea is that we prefix every sequence number with its with,
separated by a dot. That way the filename length isn't increased
drastically (unlike using a fixed whidth number with 0-padding)
and the file names will be lexicographically ordered.
This commit is contained in:
mpilman 2019-07-10 20:37:59 -07:00
parent c70e762f0e
commit a66dc937fc
1 changed files with 12 additions and 1 deletions

View File

@ -87,7 +87,18 @@ void FileTraceLogWriter::write(const std::string& str) {
void FileTraceLogWriter::open() {
cleanupTraceFiles();
auto finalname = format("%s.%d.%s", basename.c_str(), ++index, extension.c_str());
++index;
int indexWidth = -1;
while (index > 0) {
index /= 10;
++indexWidth;
}
// this allows one process to write 10 billion log files
// this should be enough - if not we could make the base larger...
ASSERT(index >= 0 && index < 10);
auto finalname = format("%s.%d.%d.%s", basename.c_str(), indexWidth, ++index, extension.c_str());
while ( (traceFileFD = __open( finalname.c_str(), TRACEFILE_FLAGS, TRACEFILE_MODE )) == -1 ) {
lastError(errno);
if (errno == EEXIST)