Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-anoyes committed Jan 28, 2022
1 parent 4a8e2a8 commit 134f07a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion bindings/c/test/unit/trace_partial_file_suffix_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int main(int argc, char** argv) {

// Apparently you need to open a database to initialize logging
FDBDatabase* out;
fdb_check(fdb_create_database(nullptr, &out));
fdb_check(fdb_create_database(argv[1], &out));
fdb_database_destroy(out);

// Eventually there's a new trace file for this test ending in .tmp
Expand Down
4 changes: 4 additions & 0 deletions bindings/python/tests/fdbcli_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import sys
import shutil
import os
import subprocess
import logging
Expand Down Expand Up @@ -216,6 +217,9 @@ def kill(logger):

@enable_logging()
def suspend(logger):
if not shutil.which("pidof"):
logger.debug("Skipping suspend test. Pidof not available")
return
output1 = run_fdbcli_command('suspend')
lines = output1.split('\n')
assert len(lines) == 2
Expand Down
49 changes: 28 additions & 21 deletions flow/FileTraceLogWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ void FileTraceLogWriter::write(const StringRef& str) {
}

void FileTraceLogWriter::write(const char* str, size_t len) {
if (traceFileFD < 0) {
return;
}
auto ptr = str;
int remaining = len;
bool needsResolve = false;
Expand Down Expand Up @@ -227,41 +230,45 @@ void FileTraceLogWriter::sync() {
}

void FileTraceLogWriter::cleanupTraceFiles() {
// Setting maxLogsSize=0 disables trace file cleanup based on dir size
if (!g_network->isSimulated() && maxLogsSize > 0) {
if (!g_network->isSimulated()) {
try {
// Rename/finalize any stray files ending in tracePartialFileSuffix for this process.
if (!tracePartialFileSuffix.empty()) {
for (const auto& f : platform::listFiles(directory, tracePartialFileSuffix)) {
if (f.substr(0, processName.length()) == processName) {
for (const auto& relpath : platform::listFiles(directory, tracePartialFileSuffix)) {
if (relpath.substr(0, processName.length()) == processName) {
std::string f = joinPath(directory, relpath);
renameFile(f, f.substr(0, f.size() - tracePartialFileSuffix.size()));
}
}
}

std::vector<std::string> existingFiles = platform::listFiles(directory, extension);
std::vector<std::string> existingTraceFiles;
// Setting maxLogsSize=0 disables trace file cleanup based on dir size
if (maxLogsSize > 0) {
std::vector<std::string> existingFiles = platform::listFiles(directory, extension);
std::vector<std::string> existingTraceFiles;

for (auto f = existingFiles.begin(); f != existingFiles.end(); ++f) {
if (f->substr(0, processName.length()) == processName) {
existingTraceFiles.push_back(*f);
for (auto f = existingFiles.begin(); f != existingFiles.end(); ++f) {
if (f->substr(0, processName.length()) == processName) {
existingTraceFiles.push_back(*f);
}
}
}

// reverse sort, so we preserve the most recent files and delete the oldest
std::sort(existingTraceFiles.begin(), existingTraceFiles.end(), std::greater<std::string>());
// reverse sort, so we preserve the most recent files and delete the oldest
std::sort(existingTraceFiles.begin(), existingTraceFiles.end(), std::greater<std::string>());

uint64_t runningTotal = 0;
std::vector<std::string>::iterator fileListIterator = existingTraceFiles.begin();
uint64_t runningTotal = 0;
std::vector<std::string>::iterator fileListIterator = existingTraceFiles.begin();

while (runningTotal < maxLogsSize && fileListIterator != existingTraceFiles.end()) {
runningTotal += (fileSize(joinPath(directory, *fileListIterator)) + FLOW_KNOBS->ZERO_LENGTH_FILE_PAD);
++fileListIterator;
}
while (runningTotal < maxLogsSize && fileListIterator != existingTraceFiles.end()) {
runningTotal +=
(fileSize(joinPath(directory, *fileListIterator)) + FLOW_KNOBS->ZERO_LENGTH_FILE_PAD);
++fileListIterator;
}

while (fileListIterator != existingTraceFiles.end()) {
deleteFile(joinPath(directory, *fileListIterator));
++fileListIterator;
while (fileListIterator != existingTraceFiles.end()) {
deleteFile(joinPath(directory, *fileListIterator));
++fileListIterator;
}
}
} catch (Error&) {
}
Expand Down

0 comments on commit 134f07a

Please sign in to comment.