diff --git a/fdbserver/AccumulativeChecksumUtil.cpp b/fdbserver/AccumulativeChecksumUtil.cpp index ffab93726a8..8c4fe89f36f 100644 --- a/fdbserver/AccumulativeChecksumUtil.cpp +++ b/fdbserver/AccumulativeChecksumUtil.cpp @@ -20,6 +20,7 @@ #include "fdbserver/AccumulativeChecksumUtil.h" #include "fdbserver/Knobs.h" +#include "fmt/format.h" void updateMutationWithAcsAndAddMutationToAcsBuilder(std::shared_ptr acsBuilder, MutationRef& mutation, @@ -316,7 +317,7 @@ uint64_t AccumulativeChecksumValidator::getAndClearTotalAddedMutations() { } TEST_CASE("noSim/AccumulativeChecksum/MutationRef") { - printf("testing MutationRef encoding/decoding\n"); + fmt::println("testing MutationRef encoding/decoding"); MutationRef m(MutationRef::SetValue, "TestKey"_sr, "TestValue"_sr); m.setAccumulativeChecksumIndex(512); BinaryWriter wr(AssumeVersion(ProtocolVersion::withMutationChecksum())); @@ -331,7 +332,7 @@ TEST_CASE("noSim/AccumulativeChecksum/MutationRef") { rd >> de; - printf("Deserialized mutation: %s\n", de.toString().c_str()); + fmt::println("Deserialized mutation: {}", de.toString()); if (de.type != m.type || de.param1 != m.param1 || de.param2 != m.param2) { TraceEvent(SevError, "MutationMismatch") diff --git a/fdbserver/BackupPartitionMap.actor.cpp b/fdbserver/BackupPartitionMap.actor.cpp index a0c98dbff57..e874990deed 100644 --- a/fdbserver/BackupPartitionMap.actor.cpp +++ b/fdbserver/BackupPartitionMap.actor.cpp @@ -20,6 +20,7 @@ #include "fdbserver/BackupPartitionMap.actor.h" #include "fdbserver/DDShardTracker.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. std::string serializePartitionListJSON(PartitionMap const& partitionMap) { @@ -244,8 +245,8 @@ TEST_CASE("/BackupPartitionMap/calculateBackupPartitionKeyRanges/MultipleSmallSh KeyRangeMap shards(defaultData); for (int i = 0; i < 1000; i++) { - Key start = Key(format("shard%04d", i)); - Key end = (i == 999) ? normalKeys.end : Key(format("shard%04d", i + 1)); + Key start = Key(fmt::format("shard{:04}", i)); + Key end = (i == 999) ? normalKeys.end : Key(fmt::format("shard{:04}", i + 1)); ShardTrackedData data; StorageMetrics metrics; diff --git a/fdbserver/BackupWorker.actor.cpp b/fdbserver/BackupWorker.actor.cpp index 5cfb6d36959..170853f079a 100644 --- a/fdbserver/BackupWorker.actor.cpp +++ b/fdbserver/BackupWorker.actor.cpp @@ -36,6 +36,7 @@ #include "flow/IRandom.h" #include "fdbclient/Tracing.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. #define SevDebugMemory SevVerbose @@ -461,7 +462,7 @@ ACTOR static Future shouldBackupWorkerExitEarly(BackupData* self) { TraceEvent e("BackupWorkerGotStartKey", self->myId); int i = 1; for (auto [uid, version] : uidVersions) { - e.detail(format("BackupID%d", i), uid).detail(format("Version%d", i), version); + e.detail(fmt::format("BackupID{}", i), uid).detail(fmt::format("Version{}", i), version); i++; if (shouldExit && version < self->endVersion.get()) { shouldExit = false; @@ -500,7 +501,7 @@ ACTOR static Future monitorBackupStartedKeyChanges(BackupData* self) { TraceEvent e("BackupWorkerGotStartKey", self->myId); int i = 1; for (auto [uid, version] : uidVersions) { - e.detail(format("BackupID%d", i), uid).detail(format("Version%d", i), version); + e.detail(fmt::format("BackupID{}", i), uid).detail(fmt::format("Version{}", i), version); i++; } } diff --git a/fdbserver/ClusterRecovery.actor.cpp b/fdbserver/ClusterRecovery.actor.cpp index 025958ce3b2..c0a8c2bbec1 100644 --- a/fdbserver/ClusterRecovery.actor.cpp +++ b/fdbserver/ClusterRecovery.actor.cpp @@ -33,6 +33,7 @@ #include "flow/ProtocolVersion.h" #include "flow/Trace.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. static std::set const& normalClusterRecoveryErrors() { @@ -637,7 +638,7 @@ ACTOR static Future> getMinBackupVersion(Referencedbgid); int i = 1; for (auto [uid, version] : uidVersions) { - e.detail(format("BackupID%d", i), uid).detail(format("Version%d", i), version); + e.detail(fmt::format("BackupID{}", i), uid).detail(fmt::format("Version{}", i), version); i++; minVersion = minVersion.present() ? std::min(version, minVersion.get()) : version; } diff --git a/fdbserver/ConsistencyScan.actor.cpp b/fdbserver/ConsistencyScan.actor.cpp index f2fa12981f1..e17900f3a8b 100644 --- a/fdbserver/ConsistencyScan.actor.cpp +++ b/fdbserver/ConsistencyScan.actor.cpp @@ -44,6 +44,7 @@ #include "flow/DeterministicRandom.h" #include "flow/Trace.h" #include "fdbserver/QuietDatabase.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. #define DEBUG_SCAN_PROGRESS false @@ -280,7 +281,7 @@ ACTOR Future consistencyCheckReadData(UID myId, state GetKeyValuesReply current = rangeResult.get(); DisabledTraceEvent("ConsistencyCheck_GetKeyValuesStream", myId) .detail("DataSize", current.data.size()) - .detail(format("StorageServer%d", j).c_str(), (*storageServerInterfaces)[j].id()); + .detail(fmt::format("StorageServer{}", j).c_str(), (*storageServerInterfaces)[j].id()); *totalReadAmount += current.data.expectedSize(); // If we haven't encountered a valid storage server yet, then mark this as the baseline // to compare against @@ -295,42 +296,40 @@ ACTOR Future consistencyCheckReadData(UID myId, // Be especially verbose if in simulation if (g_network->isSimulated()) { int invalidIndex = -1; - fmt::print("MISMATCH AT VERSION {0}\n", req.version); - printf("\n%sSERVER %d (%s); shard = %s - %s:\n", - "", - j, - (*storageServerInterfaces)[j].address().toString().c_str(), - printable(req.begin.getKey()).c_str(), - printable(req.end.getKey()).c_str()); + fmt::println("MISMATCH AT VERSION {0}", req.version); + fmt::print("\n{}SERVER {} ({}); shard = {} - {}:\n", + "", + j, + (*storageServerInterfaces)[j].address().toString(), + printable(req.begin.getKey()), + printable(req.end.getKey())); for (int k = 0; k < current.data.size(); k++) { - printf("%d. %s => %s\n", - k, - printable(current.data[k].key).c_str(), - printable(current.data[k].value).c_str()); + fmt::println( + "{}. {} => {}", k, printable(current.data[k].key), printable(current.data[k].value)); if (invalidIndex < 0 && (k >= reference.data.size() || current.data[k].key != reference.data[k].key || current.data[k].value != reference.data[k].value)) invalidIndex = k; } - printf("\n%sSERVER %d (%s); shard = %s - %s:\n", - "", - firstValidServer->get(), - (*storageServerInterfaces)[firstValidServer->get()].address().toString().c_str(), - printable(req.begin.getKey()).c_str(), - printable(req.end.getKey()).c_str()); + fmt::print("\n{}SERVER {} ({}); shard = {} - {}:\n", + "", + firstValidServer->get(), + (*storageServerInterfaces)[firstValidServer->get()].address().toString(), + printable(req.begin.getKey()), + printable(req.end.getKey())); for (int k = 0; k < reference.data.size(); k++) { - printf("%d. %s => %s\n", - k, - printable(reference.data[k].key).c_str(), - printable(reference.data[k].value).c_str()); + fmt::println("{}. {} => {}", + k, + printable(reference.data[k].key), + printable(reference.data[k].value)); if (invalidIndex < 0 && (k >= current.data.size() || reference.data[k].key != current.data[k].key || reference.data[k].value != current.data[k].value)) invalidIndex = k; } - printf("\nMISMATCH AT %d\n\n", invalidIndex); + fmt::print("\nMISMATCH AT {}\n\n", invalidIndex); } // Data for trace event @@ -461,21 +460,21 @@ ACTOR Future consistencyCheckReadData(UID myId, TraceEvent(isExpectedTSSMismatch || isFailed || expectInjected ? SevWarn : SevError, "ConsistencyCheck_DataInconsistent", myId) - .detail(format("StorageServer%d", j).c_str(), (*storageServerInterfaces)[j].id()) - .detail(format("StorageServer%d", firstValidServer->get()).c_str(), + .detail(fmt::format("StorageServer{}", j).c_str(), (*storageServerInterfaces)[j].id()) + .detail(fmt::format("StorageServer{}", firstValidServer->get()).c_str(), (*storageServerInterfaces)[firstValidServer->get()].id()) .detail("ShardBegin", req.begin.getKey()) .detail("ShardEnd", req.end.getKey()) .detail("VersionNumber", req.version) - .detail(format("Server%dUniques", j).c_str(), currentUniques) - .detail(format("Server%dUniqueKey", j).c_str(), currentUniqueKey) - .detail(format("Server%dUniques", firstValidServer->get()).c_str(), referenceUniques) - .detail(format("Server%dUniqueKey", firstValidServer->get()).c_str(), referenceUniqueKey) + .detail(fmt::format("Server{}Uniques", j).c_str(), currentUniques) + .detail(fmt::format("Server{}UniqueKey", j).c_str(), currentUniqueKey) + .detail(fmt::format("Server{}Uniques", firstValidServer->get()).c_str(), referenceUniques) + .detail(fmt::format("Server{}UniqueKey", firstValidServer->get()).c_str(), referenceUniqueKey) .detail("ValueMismatches", valueMismatches) .detail("ValueMismatchKey", valueMismatchKey) .detail("MatchingKVPairs", matchingKVPairs) - .detail(format("Server%dHasMore", j).c_str(), current.more) - .detail(format("Server%dHasMore", firstValidServer->get()).c_str(), reference.more) + .detail(fmt::format("Server{}HasMore", j).c_str(), current.more) + .detail(fmt::format("Server{}HasMore", firstValidServer->get()).c_str(), reference.more) .detail("IsTSS", isTss) .detail("IsInjected", expectInjected); @@ -2005,7 +2004,7 @@ ACTOR Future checkDataConsistency(Database cx, .detail("NumSampledKeys", sampledKeys) .detail("NumSampledKeysWithProb", sampledKeysWithProb); - testFailure(format("Shard size is more than %f std dev from estimate", failErrorNumStdDev), + testFailure(fmt::format("Shard size is more than {:f} std dev from estimate", failErrorNumStdDev), performQuiescentChecks, success, failureIsError); @@ -2048,8 +2047,8 @@ ACTOR Future checkDataConsistency(Database cx, .detail("ShardEnd", printable(range.end)) .detail("ShardCount", ranges.size()) .detail("SampledKeys", sampledKeys); - testFailure(format("Shard size in quiescent database is too %s", - (sampledBytes < shardBounds.min.bytes) ? "small" : "large"), + testFailure(fmt::format("Shard size in quiescent database is too {}", + (sampledBytes < shardBounds.min.bytes) ? "small" : "large"), performQuiescentChecks, success, failureIsError); diff --git a/fdbserver/Coordination.actor.cpp b/fdbserver/Coordination.actor.cpp index a442a8bcf44..f5a6ed4a88f 100644 --- a/fdbserver/Coordination.actor.cpp +++ b/fdbserver/Coordination.actor.cpp @@ -33,6 +33,7 @@ #include "fdbclient/MonitorLeader.h" #include "flow/network.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. // This module implements coordinationServer() and the interfaces in CoordinationInterface.h @@ -797,7 +798,7 @@ ACTOR Future coordinationServer(std::string dataFolder, Reference>> fs; fs.reserve(2); for (int i = 0; i < 2; ++i) { - std::string file = joinPath(dataFolder, format("%s%d.fdq", fileCoordinatorPrefix.c_str(), i)); + std::string file = joinPath(dataFolder, fmt::format("{}{}.fdq", fileCoordinatorPrefix, i)); fs.push_back( IAsyncFileSystem::filesystem()->open(file, IAsyncFile::OPEN_READWRITE | IAsyncFile::OPEN_UNCACHED | diff --git a/fdbserver/DDRelocationQueue.actor.cpp b/fdbserver/DDRelocationQueue.actor.cpp index 3db03189a1e..80853261f01 100644 --- a/fdbserver/DDRelocationQueue.actor.cpp +++ b/fdbserver/DDRelocationQueue.actor.cpp @@ -38,6 +38,7 @@ #include "fdbserver/DDTxnProcessor.h" #include "flow/DebugTrace.h" #include "fdbserver/DDRelocationQueue.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. #define WORK_FULL_UTILIZATION 10000 // This is not a knob; it is a fixed point scaling factor! @@ -392,7 +393,7 @@ class ParallelTCInfo final : public ReferenceCounted, public IDa std::string id; for (int i = 0; i < teams.size(); i++) { auto const& team = teams[i]; - id += (i == teams.size() - 1) ? team->getTeamID() : format("%s, ", team->getTeamID().c_str()); + id += (i == teams.size() - 1) ? team->getTeamID() : fmt::format("{}, ", team->getTeamID()); } return id; } @@ -421,8 +422,9 @@ std::string Busyness::toString() { j++; if (i != 1) result += ", "; - result += i + 1 == j ? format("%03d", i * 100) : format("%03d/%03d", i * 100, (j - 1) * 100); - result += format("=%1.02f (%d/%d)", (float)ledger[i] / WORK_FULL_UTILIZATION, ledger[i], WORK_FULL_UTILIZATION); + result += i + 1 == j ? fmt::format("{:03}", i * 100) : fmt::format("{:03}/{:03}", i * 100, (j - 1) * 100); + result += fmt::format( + "={:1.02f} ({}/{})", (float)ledger[i] / WORK_FULL_UTILIZATION, ledger[i], WORK_FULL_UTILIZATION); i = j; } return result; diff --git a/fdbserver/DDTeamCollection.actor.cpp b/fdbserver/DDTeamCollection.actor.cpp index 18d3538ca93..f77eba08b51 100644 --- a/fdbserver/DDTeamCollection.actor.cpp +++ b/fdbserver/DDTeamCollection.actor.cpp @@ -30,6 +30,7 @@ #include "flow/Trace.h" #include "flow/network.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. namespace { @@ -6271,11 +6272,11 @@ class DDTeamCollectionUnitTest { int zone_id = process_id / 10; int machine_id = process_id / 5; - printf("testMachineTeamCollection: process_id:%d zone_id:%d machine_id:%d ip_addr:%s\n", - process_id, - zone_id, - machine_id, - interface.address().toString().c_str()); + fmt::println("testMachineTeamCollection: process_id:{} zone_id:{} machine_id:{} ip_addr:{}", + process_id, + zone_id, + machine_id, + interface.address().toString()); interface.locality.set("processid"_sr, Standalone(std::to_string(process_id))); interface.locality.set("machineid"_sr, Standalone(std::to_string(machine_id))); interface.locality.set("zoneid"_sr, Standalone(std::to_string(zone_id))); @@ -6288,7 +6289,7 @@ class DDTeamCollectionUnitTest { } int totalServerIndex = collection->constructMachinesFromServers(); - printf("testMachineTeamCollection: construct machines for %d servers\n", totalServerIndex); + fmt::println("testMachineTeamCollection: construct machines for {} servers", totalServerIndex); return collection; } @@ -6325,7 +6326,7 @@ class DDTeamCollectionUnitTest { state std::unique_ptr collection = testMachineTeamCollection(teamSize, policy, processSize); if (collection == nullptr) { - fprintf(stderr, "collection is null\n"); + fmt::println(stderr, "collection is null"); return Void(); } @@ -6951,10 +6952,10 @@ class DDTeamCollectionUnitTest { wait(collection->getTeam(bestReq)); const auto [bestTeam, found1] = bestReq.reply.getFuture().get(); - fmt::print("{} {} {}\n", - SERVER_KNOBS->CPU_PIVOT_RATIO, - collection->teamPivots.pivotCPU, - collection->teamPivots.pivotAvailableSpaceRatio); + fmt::println("{} {} {}", + SERVER_KNOBS->CPU_PIVOT_RATIO, + collection->teamPivots.pivotCPU, + collection->teamPivots.pivotAvailableSpaceRatio); ASSERT(bestTeam.present()); ASSERT_EQ(bestTeam.get()->getServerIDs(), std::vector{ UID(2, 0) }); diff --git a/fdbserver/DDTxnProcessor.actor.cpp b/fdbserver/DDTxnProcessor.actor.cpp index 42c23518545..d1b2db17bfb 100644 --- a/fdbserver/DDTxnProcessor.actor.cpp +++ b/fdbserver/DDTxnProcessor.actor.cpp @@ -24,6 +24,7 @@ #include "fdbserver/DataDistribution.actor.h" #include "fdbclient/DatabaseContext.h" #include "flow/genericactors.actor.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. static void updateServersAndCompleteSources(std::set& servers, @@ -1071,10 +1072,8 @@ ACTOR Future rawStartMovement(std::shared_ptr mgs, } // 2. merge ops will coalesce the boundary in finishMovement; intersectRanges = mgs->shardMapping->intersectingRanges(keys); - fmt::print("Keys: {}; intersect: {} {}\n", - keys.toString(), - intersectRanges.begin().begin(), - intersectRanges.end().begin()); + fmt::println( + "Keys: {}; intersect: {} {}", keys.toString(), intersectRanges.begin().begin(), intersectRanges.end().begin()); // NOTE: What if there is a split follow up by a merge? // ASSERT(keys.begin == intersectRanges.begin().begin()); // ASSERT(keys.end == intersectRanges.end().begin()); diff --git a/fdbserver/DataDistribution.actor.cpp b/fdbserver/DataDistribution.actor.cpp index 31db3402438..df542fd718b 100644 --- a/fdbserver/DataDistribution.actor.cpp +++ b/fdbserver/DataDistribution.actor.cpp @@ -53,6 +53,7 @@ #include "flow/flow.h" #include "flow/genericactors.actor.h" #include "flow/serialize.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. static const std::string ddServerBulkDumpFolder = "ddBulkDumpFiles"; @@ -4876,12 +4877,11 @@ ACTOR Future doAuditLocationMetadata(Reference self, // 1. check mapFromKeyServers => mapFromServerKeys for (auto& [ssid, keyServerRanges] : mapFromKeyServers) { if (!mapFromServerKeys.contains(ssid)) { - std::string error = - format("KeyServers and serverKeys mismatch: Some key in range(%s, %s) exists " - "on Server(%s) in KeyServers but not ServerKeys", - claimRange.toString().c_str(), - claimRange.toString().c_str(), - ssid.toString().c_str()); + std::string error = fmt::format("KeyServers and serverKeys mismatch: Some key in range({}, {}) " + "exists on Server({}) in KeyServers but not ServerKeys", + claimRange.begin.toString(), + claimRange.end.toString(), + ssid.toString()); errors.push_back(error); TraceEvent(SevError, "DDDoAuditLocationMetadataError", self->ddId) .setMaxFieldLength(-1) @@ -4896,11 +4896,11 @@ ACTOR Future doAuditLocationMetadata(Reference self, if (anyMismatch.present()) { // mismatch detected KeyRange mismatchedRangeByKeyServer = anyMismatch.get().first; KeyRange mismatchedRangeByServerKey = anyMismatch.get().second; - std::string error = - format("KeyServers and serverKeys mismatch on Server(%s): KeyServer: %s; ServerKey: %s", - ssid.toString().c_str(), - mismatchedRangeByKeyServer.toString().c_str(), - mismatchedRangeByServerKey.toString().c_str()); + std::string error = fmt::format( + "KeyServers and serverKeys mismatch on Server({}): KeyServer: {}; ServerKey: {}", + ssid.toString(), + mismatchedRangeByKeyServer.toString(), + mismatchedRangeByServerKey.toString()); errors.push_back(error); TraceEvent(SevError, "DDDoAuditLocationMetadataError", self->ddId) .setMaxFieldLength(-1) @@ -4916,12 +4916,11 @@ ACTOR Future doAuditLocationMetadata(Reference self, // 2. check mapFromServerKeys => mapFromKeyServers for (auto& [ssid, serverKeyRanges] : mapFromServerKeys) { if (!mapFromKeyServers.contains(ssid)) { - std::string error = - format("KeyServers and serverKeys mismatch: Some key of range(%s, %s) exists " - "on Server(%s) in ServerKeys but not KeyServers", - claimRange.toString().c_str(), - claimRange.toString().c_str(), - ssid.toString().c_str()); + std::string error = fmt::format("KeyServers and serverKeys mismatch: Some key of range({}, {}) " + "exists on Server({}) in ServerKeys but not KeyServers", + claimRange.begin.toString(), + claimRange.end.toString(), + ssid.toString()); errors.push_back(error); TraceEvent(SevError, "DDDoAuditLocationMetadataError", self->ddId) .setMaxFieldLength(-1) diff --git a/fdbserver/DiskQueue.actor.cpp b/fdbserver/DiskQueue.actor.cpp index adc31f16997..5224be8126d 100644 --- a/fdbserver/DiskQueue.actor.cpp +++ b/fdbserver/DiskQueue.actor.cpp @@ -26,6 +26,7 @@ #include "flow/genericactors.actor.h" #include "flow/xxhash.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. typedef bool (*compare_pages)(void*, void*); @@ -83,7 +84,7 @@ struct StringBuffer { // SOMEDAY: Use a new arena and discard the old one after copying? reserved = std::max(size, reserved * 2); if (reserved > 1e9) { - printf("WOAH! Huge allocation\n"); + fmt::println("WOAH! Huge allocation"); TraceEvent(SevError, "StringBufferHugeAllocation", id) .detail("Alignment", alignment) .detail("Reserved", reserved) @@ -268,7 +269,7 @@ class RawDiskQueue_TwoFiles : public Tracked { std::string basename; std::string fileExtension; - std::string filename(int i) const { return basename + format("%d.%s", i, fileExtension.c_str()); } + std::string filename(int i) const { return basename + fmt::format("{}.{}", i, fileExtension); } UID dbgid; int64_t dbg_file0BeginSeq; @@ -969,7 +970,7 @@ class DiskQueue final : public IDiskQueue, public Tracked { .suppressFor(1.0) .detail("PushedPages", pushedPageCount()) .detail("NextPageSeq", nextPageSeq) - .detail("Details", format("%d pages", pushedPageCount())) + .detail("Details", fmt::format("{} pages", pushedPageCount())) .detail("File0Name", rawQueue->files[0].dbgFilename); if (g_network->isSimulated()) warnAlwaysForMemory = false; @@ -1686,7 +1687,7 @@ TEST_CASE("performance/fdbserver/DiskQueue") { } while (loopCount < 4000) { if (loopCount % 100 == 0) { - printf("loop count: %d\n", loopCount); + fmt::println("loop count: {}", loopCount); } if (++loopCount % 2 == 0) { state IDiskQueue::location frontLocation = locations.front(); diff --git a/fdbserver/KeyValueStoreRocksDB.actor.cpp b/fdbserver/KeyValueStoreRocksDB.actor.cpp index 24b2272834a..826dfadcd3f 100644 --- a/fdbserver/KeyValueStoreRocksDB.actor.cpp +++ b/fdbserver/KeyValueStoreRocksDB.actor.cpp @@ -70,6 +70,7 @@ #include "fdbserver/RocksDBCheckpointUtils.actor.h" #include "fdbserver/RocksDBCommon.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // has to be last include #ifdef WITH_ROCKSDB @@ -1153,8 +1154,8 @@ ACTOR Future rocksDBMetricLogger(UID id, for (auto& [name, histogram] : histogramStats) { rocksdb::HistogramData histogram_data; statistics->histogramData(histogram, &histogram_data); - e.detail(format("%s%s", name, "P95"), histogram_data.percentile95); - e.detail(format("%s%s", name, "P99"), histogram_data.percentile99); + e.detail(fmt::format("{}{}", name, "P95"), histogram_data.percentile95); + e.detail(fmt::format("{}{}", name, "P99"), histogram_data.percentile99); } } @@ -3000,8 +3001,8 @@ TEST_CASE("noSim/RocksDB/RangeClear") { state int i = 0; for (; i < 50000; ++i) { - state std::string key1 = format("\xffprefix/%d", i); - state std::string key2 = format("\xffprefix/%d", i + 1); + state std::string key1 = fmt::format("\xffprefix/{}", i); + state std::string key2 = fmt::format("\xffprefix/{}", i + 1); kvStore->set({ key2, std::to_string(i) }); RangeResult result = wait(kvStore->readRange(KeyRangeRef(shardPrefix, key1), 10000, 10000)); diff --git a/fdbserver/KeyValueStoreSQLite.actor.cpp b/fdbserver/KeyValueStoreSQLite.actor.cpp index 24d1c049ec5..0ba50361995 100644 --- a/fdbserver/KeyValueStoreSQLite.actor.cpp +++ b/fdbserver/KeyValueStoreSQLite.actor.cpp @@ -84,7 +84,7 @@ struct PageChecksumCodec { bool operator==(const SumType& rhs) const { return part1 == rhs.part1 && part2 == rhs.part2; } uint32_t part1; uint32_t part2; - std::string toString() { return format("0x%08x%08x", part1, part2); } + std::string toString() { return fmt::format("0x{:08x}{:08x}", part1, part2); } }; // Calculates and then either stores or verifies a checksum. @@ -458,23 +458,23 @@ void hexdump(FILE* fout, StringRef val) { const unsigned char* buf = val.begin(); int i, j; for (i = 0; i < buflen; i += 32) { - fprintf(fout, "%06x: ", i); + fmt::print(fout, "{:06x}: ", i); for (j = 0; j < 32; j++) { if (j == 16) - fprintf(fout, " "); + fmt::print(fout, " "); if (i + j < buflen) - fprintf(fout, "%02x ", buf[i + j]); + fmt::print(fout, "{:02x} ", buf[i + j]); else - fprintf(fout, " "); + fmt::print(fout, " "); } - fprintf(fout, " "); + fmt::print(fout, " "); for (j = 0; j < 32; j++) { if (j == 16) - fprintf(fout, " "); + fmt::print(fout, " "); if (i + j < buflen) - fprintf(fout, "%c", isprint(buf[i + j]) ? buf[i + j] : '.'); + fmt::print(fout, "{:c}", isprint(buf[i + j]) ? buf[i + j] : '.'); } - fprintf(fout, "\n"); + fmt::println(fout, ""); } } @@ -2220,7 +2220,7 @@ void KeyValueStoreSQLite::startReadThreads() { TaskPriority taskId = g_network->getCurrentTask(); g_network->setCurrentTask(TaskPriority::DiskRead); for (int i = 0; i < nReadThreads; i++) { - std::string threadName = format("fdb-sqlite-r-%d", i); + std::string threadName = fmt::format("fdb-sqlite-r-{}", i); if (threadName.size() > 15) { threadName = "fdb-sqlite-r"; } @@ -2305,7 +2305,7 @@ void GenerateIOLogChecksumFile(std::string filename) { uint8_t buf[4096]; unsigned int c = 0; while (fread(buf, 1, 4096, f) > 0) - fprintf(fout, "%u %u\n", c++, hashlittle(buf, 4096, 0xab12fd93)); + fmt::println(fout, "{} {}", c++, hashlittle(buf, 4096, 0xab12fd93)); fclose(f); fclose(fout); } @@ -2370,11 +2370,7 @@ ACTOR Future KVFileDump(std::string filename) { if (debugS != nullptr) debug = true; - fprintf(stderr, - "Dump start: %s, end: %s, debug: %s\n", - printable(k).c_str(), - printable(endk).c_str(), - debug ? "true" : "false"); + fmt::println(stderr, "Dump start: {}, end: {}, debug: {}", printable(k), printable(endk), debug ? "true" : "false"); while (true) { RangeResult kv = wait(store->readRange(KeyRangeRef(k, endk), 1000)); @@ -2393,8 +2389,8 @@ ACTOR Future KVFileDump(std::string filename) { fwrite(data, sizeof(uint8_t), size, stdout); if (debug) { - fprintf(stderr, "key: %s\n", printable(one.key).c_str()); - fprintf(stderr, "val: %s\n", printable(one.value).c_str()); + fmt::println(stderr, "key: {}", printable(one.key)); + fmt::println(stderr, "val: {}", printable(one.value)); } } @@ -2404,7 +2400,7 @@ ACTOR Future KVFileDump(std::string filename) { k = keyAfter(kv[kv.size() - 1].key); } fflush(stdout); - fmt::print(stderr, "Counted: {}\n", count); + fmt::println(stderr, "Counted: {}", count); if (store->getError().isError()) wait(store->getError()); diff --git a/fdbserver/KeyValueStoreShardedRocksDB.actor.cpp b/fdbserver/KeyValueStoreShardedRocksDB.actor.cpp index 2de4aaf8979..fd93a7befa6 100644 --- a/fdbserver/KeyValueStoreShardedRocksDB.actor.cpp +++ b/fdbserver/KeyValueStoreShardedRocksDB.actor.cpp @@ -48,6 +48,7 @@ #include "fdbserver/IKeyValueStore.h" #include "fdbserver/RocksDBCheckpointUtils.actor.h" #include "fdbserver/RocksDBCommon.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // has to be last include #ifdef WITH_ROCKSDB @@ -2199,7 +2200,7 @@ struct RocksDBMetrics { auto manifests = getManifestBytes(manifestDirectory); int idx = 0; for (const auto& [fileName, fileBytes] : manifests) { - e.detail(format("Manifest-%d", idx), format("%s-%lld", fileName.c_str(), fileBytes)); + e.detail(fmt::format("Manifest-{}", idx), fmt::format("{}-{}", fileName, fileBytes)); manifestBytesTotal += fileBytes; idx++; } @@ -4007,7 +4008,7 @@ TEST_CASE("noSim/ShardedRocksDB/RangeOps") { // write to shard 1 state RangeResult expectedRows; for (int i = 0; i < 30; ++i) { - std::string key = format("%02d", i); + std::string key = fmt::format("{:02}", i); std::string value = std::to_string(i); kvStore->set({ key, value }); expectedRows.push_back_deep(expectedRows.arena(), { key, value }); @@ -4015,7 +4016,7 @@ TEST_CASE("noSim/ShardedRocksDB/RangeOps") { // write to shard 2 for (int i = 40; i < 70; ++i) { - std::string key = format("%02d", i); + std::string key = fmt::format("{:02}", i); std::string value = std::to_string(i); kvStore->set({ key, value }); expectedRows.push_back_deep(expectedRows.arena(), { key, value }); @@ -4066,7 +4067,7 @@ TEST_CASE("noSim/ShardedRocksDB/RangeOps") { kvStore->persistRangeMapping(KeyRangeRef("7"_sr, "9"_sr), true); for (i = 70; i < 90; ++i) { - std::string key = format("%02d", i); + std::string key = fmt::format("{:02}", i); std::string value = std::to_string(i); kvStore->set({ key, value }); expectedRows.push_back_deep(expectedRows.arena(), { key, value }); @@ -4747,8 +4748,8 @@ TEST_CASE("perf/ShardedRocksDB/RangeClearSysKey") { state std::string key1; state std::string key2; for (; i < deleteCount; ++i) { - key1 = format("\xffprefix/%d", i); - key2 = format("\xffprefix/%d", i + 1); + key1 = fmt::format("\xffprefix/{}", i); + key2 = fmt::format("\xffprefix/{}", i + 1); kvStore->set({ key2, std::to_string(i) }); kvStore->clear({ KeyRangeRef(shardPrefix, key1) }); @@ -4773,8 +4774,8 @@ TEST_CASE("perf/ShardedRocksDB/RangeClearSysKey") { i = 0; for (; i < deleteCount; ++i) { - key1 = format("\xffprefix/%d", i); - key2 = format("\xffprefix/%d", i + 1); + key1 = fmt::format("\xffprefix/{}", i); + key2 = fmt::format("\xffprefix/{}", i + 1); kvStore->set({ key2, std::to_string(i) }); RangeResult result = wait(kvStore->readRange(KeyRangeRef(shardPrefix, key1), 10000, 10000)); @@ -4809,8 +4810,8 @@ TEST_CASE("perf/ShardedRocksDB/RangeClearUserKey") { state std::string key1; state std::string key2; for (; i < deleteCount; ++i) { - key1 = format("prefix/%d", i); - key2 = format("prefix/%d", i + 1); + key1 = fmt::format("prefix/{}", i); + key2 = fmt::format("prefix/{}", i + 1); kvStore->set({ key2, std::to_string(i) }); kvStore->clear({ KeyRangeRef(shardPrefix, key1) }); @@ -4834,8 +4835,8 @@ TEST_CASE("perf/ShardedRocksDB/RangeClearUserKey") { std::cout << "Restarted.\n"; i = 0; for (; i < deleteCount; ++i) { - key1 = format("prefix/%d", i); - key2 = format("prefix/%d", i + 1); + key1 = fmt::format("prefix/{}", i); + key2 = fmt::format("prefix/{}", i + 1); kvStore->set({ key2, std::to_string(i) }); RangeResult result = wait(kvStore->readRange(KeyRangeRef(shardPrefix, key1), 10000, 10000)); @@ -4857,20 +4858,20 @@ ACTOR Future testWrites(IKeyValueStore* kvStore, int writeCount) { while (i < writeCount) { state int endCount = deterministicRandom()->randomInt(i + 1, i + 1000); - state std::string beginKey = format("key-%6d", i); - state std::string endKey = format("key-%6d", endCount); + state std::string beginKey = fmt::format("key-{:6}", i); + state std::string endKey = fmt::format("key-{:6}", endCount); wait(kvStore->addRange(KeyRangeRef(beginKey, endKey), deterministicRandom()->randomUniqueID().toString())); kvStore->persistRangeMapping(KeyRangeRef(beginKey, endKey), true); wait(kvStore->commit(false)); for (; i < endCount; ++i) { - std::string key = format("key-%6d", i); - std::string value = format("value-%d", i); + std::string key = fmt::format("key-{:6}", i); + std::string value = fmt::format("value-{}", i); kvStore->set({ key, value }); // Add random clear ranges. if (deterministicRandom()->random01() < 0.1) { - std::string clearKey = format("key-%d", deterministicRandom()->randomInt(0, i + 1)); + std::string clearKey = fmt::format("key-{}", deterministicRandom()->randomInt(0, i + 1)); kvStore->clear({ key, key + "/" }); } @@ -4888,7 +4889,7 @@ ACTOR Future testReadValue(IKeyValueStore* kvStore, int readCount) { state std::string key; state std::string value; for (; i < readCount; ++i) { - key = format("key-%6d", deterministicRandom()->randomInt(0, readCount)); + key = fmt::format("key-{:6}", deterministicRandom()->randomInt(0, readCount)); Optional val = wait(kvStore->readValue(key)); } return Void(); @@ -4897,7 +4898,7 @@ ACTOR Future testReadValue(IKeyValueStore* kvStore, int readCount) { ACTOR Future testReadRange(IKeyValueStore* kvStore, int readCount) { state int i = 0; for (; i < readCount; ++i) { - std::string key = format("key-%6d", deterministicRandom()->randomInt(0, readCount)); + std::string key = fmt::format("key-{:6}", deterministicRandom()->randomInt(0, readCount)); // Enable forward read and backward read. int recordCount = deterministicRandom()->randomInt(-500, 500); RangeResult result = wait(kvStore->readRange(KeyRangeRef(key, "key0"_sr), recordCount, 10000)); diff --git a/fdbserver/LogSystemConfig.cpp b/fdbserver/LogSystemConfig.cpp index 575ab9db2f1..96fb1430d9f 100644 --- a/fdbserver/LogSystemConfig.cpp +++ b/fdbserver/LogSystemConfig.cpp @@ -19,16 +19,17 @@ */ #include "fdbserver/LogSystemConfig.h" +#include "fmt/format.h" std::string TLogSet::toString() const { - return format("anti: %d replication: %d local: %d routers: %d tLogs: %s backupWorkers: %s locality: %d", - tLogWriteAntiQuorum, - tLogReplicationFactor, - isLocal, - logRouters.size(), - describe(tLogs).c_str(), - describe(backupWorkers).c_str(), - locality); + return fmt::format("anti: {} replication: {} local: {} routers: {} tLogs: {} backupWorkers: {} locality: {}", + tLogWriteAntiQuorum, + tLogReplicationFactor, + isLocal, + logRouters.size(), + describe(tLogs), + describe(backupWorkers), + locality); } bool TLogSet::operator==(const TLogSet& rhs) const { @@ -104,11 +105,11 @@ bool OldTLogConf::isEqualIds(OldTLogConf const& r) const { } std::string LogSystemConfig::toString() const { - return format("type: %d oldGenerations: %d tags: %d %s", - logSystemType, - oldTLogs.size(), - logRouterTags, - describe(tLogs).c_str()); + return fmt::format("type: {} oldGenerations: {} tags: {} {}", + static_cast(logSystemType), + oldTLogs.size(), + logRouterTags, + describe(tLogs)); } Optional LogSystemConfig::getRemoteDcId() const { diff --git a/fdbserver/MetricLogger.actor.cpp b/fdbserver/MetricLogger.actor.cpp index 2e69993dbe7..b937cd86659 100644 --- a/fdbserver/MetricLogger.actor.cpp +++ b/fdbserver/MetricLogger.actor.cpp @@ -42,6 +42,7 @@ #include "flow/network.h" #include "flow/IUDPSocket.h" #include "flow/IConnection.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. struct MetricsRule { @@ -487,10 +488,10 @@ TEST_CASE("/fdbserver/metrics/TraceEvents") { std::string metricsConnFile = getenv2("METRICS_CONNFILE"); std::string metricsPrefix = getenv2("METRICS_PREFIX"); if (metricsConnFile == "") { - fprintf(stdout, "Metrics cluster file must be specified in environment variable METRICS_CONNFILE\n"); + fmt::println(stdout, "Metrics cluster file must be specified in environment variable METRICS_CONNFILE"); return Void(); } - fprintf(stdout, "Using environment variables METRICS_CONNFILE and METRICS_PREFIX.\n"); + fmt::println(stdout, "Using environment variables METRICS_CONNFILE and METRICS_PREFIX."); state Database metricsDb = Database::createDatabase(metricsConnFile, ApiVersion::LATEST_VERSION); TDMetricCollection::getTDMetrics()->address = "0.0.0.0:0"_sr; @@ -501,16 +502,16 @@ TEST_CASE("/fdbserver/metrics/TraceEvents") { state int chunk = 4000; state int total = 200000; - fprintf(stdout, "Writing trace event named Dummy with fields a, b, c, d, j, k, s, x, y, z.\n"); - fprintf(stdout, " There is a %f second pause every %d events\n", w, chunk); - fprintf(stdout, " %d events will be logged.\n", total); - fprintf(stdout, " a is always present. It starts with = 0 and increments by 1 with each event.\n"); - fprintf(stdout, " b, if present, is always a*2.\n"); - fprintf(stdout, " c, if present, is always a*3.\n"); - fprintf(stdout, " b and c are never present in the same event.\n"); - fprintf(stdout, " x, y, and z, if present, are doubles and equal to 1.5 * a, b, and c, respectively\n"); - fprintf(stdout, " d is always present, is a string, and rotates through the values 'one', 'two', and ''.\n"); - fprintf(stdout, " Plotting j on the x axis and k on the y axis should look like x=sin(2t), y=sin(3t)\n"); + fmt::println(stdout, "Writing trace event named Dummy with fields a, b, c, d, j, k, s, x, y, z."); + fmt::println(stdout, " There is a {:f} second pause every {} events", w, chunk); + fmt::println(stdout, " {} events will be logged.", total); + fmt::println(stdout, " a is always present. It starts with = 0 and increments by 1 with each event."); + fmt::println(stdout, " b, if present, is always a*2."); + fmt::println(stdout, " c, if present, is always a*3."); + fmt::println(stdout, " b and c are never present in the same event."); + fmt::println(stdout, " x, y, and z, if present, are doubles and equal to 1.5 * a, b, and c, respectively"); + fmt::println(stdout, " d is always present, is a string, and rotates through the values 'one', 'two', and ''."); + fmt::println(stdout, " Plotting j on the x axis and k on the y axis should look like x=sin(2t), y=sin(3t)"); state Int64MetricHandle intMetric = Int64MetricHandle("DummyInt"_sr); state BoolMetricHandle boolMetric = BoolMetricHandle("DummyBool"_sr); diff --git a/fdbserver/MockGlobalState.actor.cpp b/fdbserver/MockGlobalState.actor.cpp index f86e5caa719..64c9cda13dc 100644 --- a/fdbserver/MockGlobalState.actor.cpp +++ b/fdbserver/MockGlobalState.actor.cpp @@ -22,6 +22,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/DataDistribution.actor.h" #include "fdbclient/FDBTypes.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" class MockGlobalStateImpl { @@ -592,10 +593,10 @@ std::shared_ptr& MockGlobalState::g_mockState() { } void MockGlobalState::initializeClusterLayout(const BasicSimulationConfig& conf) { - fmt::print("MGS Cluster Layout: {} dc, {} machines, {} processes per machine.\n", - conf.datacenters, - conf.machine_count, - conf.processes_per_machine); + fmt::println("MGS Cluster Layout: {} dc, {} machines, {} processes per machine.", + conf.datacenters, + conf.machine_count, + conf.processes_per_machine); int mod = conf.machine_count % conf.datacenters; for (int i = 0; i < conf.datacenters; ++i) { @@ -619,7 +620,7 @@ void MockGlobalState::initializeClusterLayout(const BasicSimulationConfig& conf) seedProcesses.emplace_back(processes.back()); fmt::print("(seed) "); } - fmt::print("Mock Process: {}\n", processes.back()->locality.toString()); + fmt::println("Mock Process: {}", processes.back()->locality.toString()); } } } @@ -645,7 +646,7 @@ void MockGlobalState::initializeAsEmptyDatabaseMGS(const DatabaseConfiguration& allServers[id] = makeReference(ssi, defaultDiskSpace); allServers[id]->serverKeys.insert(allKeys, { MockShardStatus::COMPLETED, 0 }); } - fmt::print("\n"); + fmt::println(""); shardMapping->assignRangeToTeams(allKeys, { Team(serverIds, true) }); } diff --git a/fdbserver/MockS3Server.actor.cpp b/fdbserver/MockS3Server.actor.cpp index f141aceef34..b7354a4a099 100644 --- a/fdbserver/MockS3Server.actor.cpp +++ b/fdbserver/MockS3Server.actor.cpp @@ -42,6 +42,7 @@ #include "rapidjson/stringbuffer.h" #include "rapidjson/prettywriter.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. /* @@ -131,7 +132,7 @@ struct MockS3GlobalStorage { void clearStorage() { buckets.clear(); multipartUploads.clear(); - TraceEvent("MockS3GlobalStorageCleared").detail("Address", format("%p", this)); + TraceEvent("MockS3GlobalStorageCleared").detail("Address", fmt::format("{}", fmt::ptr(this))); } // Enable persistence to specified directory @@ -830,15 +831,12 @@ class MockS3ServerImpl { } // Generate XML response - std::string xml = format("\n" - "\n" - " %s\n" - " %s\n" - " %s\n" - "", - bucket.c_str(), - object.c_str(), - uploadId.c_str()); + std::string xml = fmt::format("\n\n " + "{}\n {}\n {}\n" + "", + bucket, + object, + uploadId); self->sendXMLResponse(response, 200, xml); @@ -950,15 +948,12 @@ class MockS3ServerImpl { } // Generate completion XML response - std::string xml = format("\n" - "\n" - " %s\n" - " %s\n" - " %s\n" - "", - bucket.c_str(), - object.c_str(), - getGlobalStorage().buckets[bucket][object].etag.c_str()); + std::string xml = fmt::format("\n\n " + "{}\n {}\n {}\n" + "", + bucket, + object, + getGlobalStorage().buckets[bucket][object].etag); self->sendXMLResponse(response, 200, xml); @@ -1171,7 +1166,7 @@ class MockS3ServerImpl { content.substr(static_cast(rangeStart), static_cast(rangeEnd - rangeStart + 1)); response->code = 206; // Partial Content response->data.headers["Content-Range"] = - format("bytes %lld-%lld/%zu", rangeStart, rangeEnd, content.size()); + fmt::format("bytes {}-{}/{}", rangeStart, rangeEnd, content.size()); // For range requests, calculate MD5 of the partial content, not full content contentMD5 = HTTP::computeMD5Sum(responseContent); } else { @@ -1455,13 +1450,10 @@ class MockS3ServerImpl { TraceEvent("MockS3Error").detail("Code", code).detail("ErrorCode", errorCode).detail("Message", message); - std::string xml = format("\n" - "\n" - " %s\n" - " %s\n" - "", - errorCode.c_str(), - message.c_str()); + std::string xml = fmt::format("\n\n " + "{}\n {}\n", + errorCode, + message); sendXMLResponse(response, code, xml); } @@ -2175,7 +2167,7 @@ ACTOR Future startMockS3ServerReal_impl(NetworkAddress listenAddress, std: TraceEvent("MockS3ServerRealStarted") .detail("ListenAddress", listenAddress.toString()) - .detail("ServerPtr", format("%p", server.getPtr())); + .detail("ServerPtr", fmt::format("{}", fmt::ptr(server.getPtr()))); // Keep the server running indefinitely wait(Never()); diff --git a/fdbserver/MockS3ServerChaos.actor.cpp b/fdbserver/MockS3ServerChaos.actor.cpp index 463d0a52374..57c26bd919e 100644 --- a/fdbserver/MockS3ServerChaos.actor.cpp +++ b/fdbserver/MockS3ServerChaos.actor.cpp @@ -26,6 +26,7 @@ #include "fdbrpc/simulator.h" #include "flow/Trace.h" #include "flow/IRandom.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // Clear the chaos server registry (for testing/debugging only) @@ -82,17 +83,12 @@ double getOperationMultiplier(S3Operation op) { // Generate S3-compatible error XML std::string generateS3ErrorXML(const std::string& code, const std::string& message, const std::string& resource) { - return format("\n" - "\n" - " %s\n" - " %s\n" - " %s\n" - " %s\n" - "", - code.c_str(), - message.c_str(), - resource.c_str(), - deterministicRandom()->randomUniqueID().toString().c_str()); + return fmt::format("\n\n {}\n " + "{}\n {}\n {}\n", + code, + message, + resource, + deterministicRandom()->randomUniqueID().toString()); } // Phase 1: Inject delay if configured @@ -362,4 +358,4 @@ ACTOR Future startMockS3ServerChaos(NetworkAddress listenAddress) { return Void(); } -#include "flow/unactorcompiler.h" \ No newline at end of file +#include "flow/unactorcompiler.h" diff --git a/fdbserver/QuietDatabase.actor.cpp b/fdbserver/QuietDatabase.actor.cpp index 6063f079165..95b448d34bb 100644 --- a/fdbserver/QuietDatabase.actor.cpp +++ b/fdbserver/QuietDatabase.actor.cpp @@ -38,6 +38,7 @@ #include "fdbserver/Knobs.h" #include "fdbserver/WorkerInterface.actor.h" #include "fdbclient/ManagementAPI.actor.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. ACTOR Future> getWorkers(Reference const> dbInfo, int flags = 0) { @@ -891,7 +892,7 @@ ACTOR Future disableConsistencyScanInSim(Database db, bool waitForCompleti if (waitForCompletion) { TraceEvent("ConsistencyScan_SimDisableWaiting").log(); - printf("Waiting for consistency scan to complete...\n"); + fmt::println("Waiting for consistency scan to complete..."); loop { bool waitForCorruption = g_simulator->doInjectConsistencyScanCorruption.present() && g_simulator->doInjectConsistencyScanCorruption.get(); @@ -931,7 +932,7 @@ ACTOR Future disableConsistencyScanInSim(Database db, bool waitForCompleti config.enabled = false; } else { TraceEvent("ConsistencyScan_SimDisableAlreadyDisabled").log(); - printf("Consistency scan already complete.\n"); + fmt::println("Consistency scan already complete."); return Void(); } @@ -952,7 +953,7 @@ ACTOR Future disableConsistencyScanInSim(Database db, bool waitForCompleti ISimulator::SimConsistencyScanState::DisabledEnd); CODE_PROBE(true, "Consistency Scan disabled in simulation"); TraceEvent("ConsistencyScan_SimDisabled").log(); - printf("Consistency scan complete.\n"); + fmt::println("Consistency scan complete."); return Void(); } @@ -997,13 +998,13 @@ ACTOR Future waitForQuietDatabase(Database cx, // The quiet database check (which runs at the end of every test) will always time out due to active data movement. // To get around this, quiet Database will disable the perpetual wiggle in the setup phase. - printf("Set perpetual_storage_wiggle=0 ...\n"); + fmt::println("Set perpetual_storage_wiggle=0 ..."); state Version version = wait(setPerpetualStorageWiggle(cx, false, LockAware::True)); - printf("Set perpetual_storage_wiggle=0 Done.\n"); + fmt::println("Set perpetual_storage_wiggle=0 Done."); - printf("Disabling backup worker ...\n"); + fmt::println("Disabling backup worker ..."); wait(disableBackupWorker(cx)); - printf("Disabled backup worker.\n"); + fmt::println("Disabled backup worker."); wait(disableConsistencyScanInSim(cx, false)); diff --git a/fdbserver/RemoteIKeyValueStore.actor.cpp b/fdbserver/RemoteIKeyValueStore.actor.cpp index 98c4bd584c8..52edfa2379a 100644 --- a/fdbserver/RemoteIKeyValueStore.actor.cpp +++ b/fdbserver/RemoteIKeyValueStore.actor.cpp @@ -31,6 +31,7 @@ #include "fdbserver/Knobs.h" #include "fdbserver/RemoteIKeyValueStore.actor.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. StringRef KeyValueStoreProcess::_name = "KeyValueStoreProcess"_sr; @@ -194,7 +195,7 @@ ACTOR static Future flowProcessRunner(RemoteIKeyValueStore* self, Promise RestoreConfigFR::getProgress_impl(ReferencegetReadVersion().get() - lastError.get().second) / CLIENT_KNOBS->CORE_VERSIONSPERSECOND); TraceEvent("FileRestoreProgress") @@ -250,18 +252,18 @@ ACTOR Future RestoreConfigFR::getProgress_impl(Reference RestoreConfigFR::getProgress(Reference tr) { Reference restore = Reference(this); @@ -286,14 +288,14 @@ ACTOR Future RestoreConfigFR::getFullStatus_impl(Reference RestoreConfigFR::getFullStatus(Reference tr) { diff --git a/fdbserver/RestoreLoader.actor.cpp b/fdbserver/RestoreLoader.actor.cpp index d3ed1d9ac19..235361b71e5 100644 --- a/fdbserver/RestoreLoader.actor.cpp +++ b/fdbserver/RestoreLoader.actor.cpp @@ -31,6 +31,7 @@ #include "fdbserver/MutationTracking.h" #include "fdbserver/StorageMetrics.actor.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. // SerializedMutationListMap: Buffered mutation lists from data blocks in log files @@ -908,8 +909,8 @@ ACTOR Future sendMutationsToApplier( if (e.isEnabled()) { int i = 0; for (auto& [key, uid] : *pRangeToApplier) { - e.detail(format("Range%d", i).c_str(), printable(key)) - .detail(format("UID%d", i).c_str(), uid.toString()); + e.detail(fmt::format("Range{}", i).c_str(), printable(key)) + .detail(fmt::format("UID{}", i).c_str(), uid.toString()); i++; } } diff --git a/fdbserver/RestoreUtil.cpp b/fdbserver/RestoreUtil.cpp index af00208d718..3ca12de9219 100644 --- a/fdbserver/RestoreUtil.cpp +++ b/fdbserver/RestoreUtil.cpp @@ -21,6 +21,7 @@ // This file implements the functions defined in RestoreUtil.h #include "fdbserver/RestoreUtil.h" +#include "fmt/format.h" const std::vector RestoreRoleStr = { "Invalid", "Controller", "Loader", "Applier" }; int numRoles = RestoreRoleStr.size(); @@ -60,7 +61,7 @@ bool debugFRMutation(const char* context, Version version, MutationRef const& mu std::string getRoleStr(RestoreRole role) { if ((int)role >= numRoles || (int)role < 0) { - printf("[ERROR] role:%d is out of scope\n", (int)role); + fmt::println("[ERROR] role:{} is out of scope", (int)role); return "[Unset]"; } return RestoreRoleStr[(int)role]; diff --git a/fdbserver/RocksDBCommon.cpp b/fdbserver/RocksDBCommon.cpp index 9b86ac07304..311d5b6b244 100644 --- a/fdbserver/RocksDBCommon.cpp +++ b/fdbserver/RocksDBCommon.cpp @@ -24,6 +24,7 @@ #include "fdbserver/Knobs.h" #include "flow/Trace.h" +#include "fmt/format.h" namespace RocksDBCommon { @@ -38,21 +39,21 @@ StringRef toStringRef(rocksdb::Slice s) { std::string getErrorReason(rocksdb::BackgroundErrorReason reason) { switch (reason) { case rocksdb::BackgroundErrorReason::kFlush: - return format("%d Flush", reason); + return fmt::format("{} Flush", static_cast(reason)); case rocksdb::BackgroundErrorReason::kCompaction: - return format("%d Compaction", reason); + return fmt::format("{} Compaction", static_cast(reason)); case rocksdb::BackgroundErrorReason::kWriteCallback: - return format("%d WriteCallback", reason); + return fmt::format("{} WriteCallback", static_cast(reason)); case rocksdb::BackgroundErrorReason::kMemTable: - return format("%d MemTable", reason); + return fmt::format("{} MemTable", static_cast(reason)); case rocksdb::BackgroundErrorReason::kManifestWrite: - return format("%d ManifestWrite", reason); + return fmt::format("{} ManifestWrite", static_cast(reason)); case rocksdb::BackgroundErrorReason::kFlushNoWAL: - return format("%d FlushNoWAL", reason); + return fmt::format("{} FlushNoWAL", static_cast(reason)); case rocksdb::BackgroundErrorReason::kManifestWriteNoWAL: - return format("%d ManifestWriteNoWAL", reason); + return fmt::format("{} ManifestWriteNoWAL", static_cast(reason)); default: - return format("%d Unknown", reason); + return fmt::format("{} Unknown", static_cast(reason)); } } diff --git a/fdbserver/ShardsAffectedByTeamFailure.cpp b/fdbserver/ShardsAffectedByTeamFailure.cpp index 013b0f2bf20..002159b5aa4 100644 --- a/fdbserver/ShardsAffectedByTeamFailure.cpp +++ b/fdbserver/ShardsAffectedByTeamFailure.cpp @@ -19,6 +19,7 @@ */ #include "fdbserver/ShardsAffectedByTeamFailure.h" +#include "fmt/format.h" std::vector ShardsAffectedByTeamFailure::getShardsFor(Team team) const { std::vector r; @@ -213,7 +214,7 @@ void ShardsAffectedByTeamFailure::check() const { if (!team_shards.contains(std::make_pair(*t, i->range()))) { std::string teamDesc, shards; for (int k = 0; k < t->servers.size(); k++) - teamDesc += format("%llx ", t->servers[k].first()); + teamDesc += fmt::format("{:x} ", t->servers[k].first()); for (auto x = team_shards.lower_bound(std::make_pair(*t, KeyRangeRef())); x != team_shards.end() && x->first == *t; ++x) diff --git a/fdbserver/SimulatedCluster.actor.cpp b/fdbserver/SimulatedCluster.actor.cpp index 8837d9849ef..50797b58a8a 100644 --- a/fdbserver/SimulatedCluster.actor.cpp +++ b/fdbserver/SimulatedCluster.actor.cpp @@ -61,6 +61,7 @@ #include "fdbserver/SimulatedCluster.h" #include "flow/IConnection.h" #include "fdbserver/MockGlobalState.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. #undef max @@ -110,7 +111,7 @@ std::string describe(bool const& val) { template <> std::string describe(int const& val) { - return format("%d", val); + return fmt::format("{}", val); } template <> @@ -784,7 +785,7 @@ ACTOR Future simulatedFDBDRebooter(Reference simulatedFDBDRebooter(ReferencegetCurrentProcess() == process); // simulatedFDBD catch called on different process TraceEvent(e.code() == error_code_actor_cancelled || e.code() == error_code_file_not_found || @@ -972,7 +973,7 @@ ACTOR Future simulatedMachine(ClusterConnectionString connStr, if (restarting) { myFolders.push_back( ini.GetValue(printable(localities.machineId()).c_str(), - format("%d", i * listenPerProcess).c_str(), + fmt::format("{}", i * listenPerProcess).c_str(), joinPath(baseFolder, deterministicRandom()->randomUniqueID().toString()).c_str())); if (i == 0) { @@ -981,13 +982,13 @@ ACTOR Future simulatedMachine(ClusterConnectionString connStr, if (!coordinationFolder.size()) coordinationFolder = ini.GetValue( printable(localities.machineId()).c_str(), - format("c%d", i * listenPerProcess).c_str(), + fmt::format("c{}", i * listenPerProcess).c_str(), joinPath(baseFolder, deterministicRandom()->randomUniqueID().toString()).c_str()); coordFolders.push_back(coordinationFolder); } else { coordFolders.push_back( ini.GetValue(printable(localities.machineId()).c_str(), - format("c%d", i * listenPerProcess).c_str(), + fmt::format("c{}", i * listenPerProcess).c_str(), joinPath(baseFolder, deterministicRandom()->randomUniqueID().toString()).c_str())); } } else { @@ -1329,7 +1330,7 @@ ACTOR Future restartSimulatedSystem(std::vector>* systemActor for (int i = 0; i < machineCount; i++) { Optional> dcUID; Optional> zoneId; - std::string machineIdString = ini.GetValue("META", format("%d", i).c_str()); + std::string machineIdString = ini.GetValue("META", fmt::format("{}", i).c_str()); Standalone machineId = StringRef(machineIdString); std::string dcUIDini = ini.GetValue(machineIdString.c_str(), "dcUID"); @@ -1380,7 +1381,7 @@ ACTOR Future restartSimulatedSystem(std::vector>* systemActor if (ip == nullptr) { for (int i = 0; i < processes; i++) { const char* val = - ini.GetValue(machineIdString.c_str(), format("ipAddr%d", i * listenersPerProcess).c_str()); + ini.GetValue(machineIdString.c_str(), fmt::format("ipAddr{}", i * listenersPerProcess).c_str()); ipAddrs.push_back(parseIp(val)); } } else { @@ -1767,11 +1768,11 @@ void SimulationConfig::setReplicationType(const TestConfig& testConfig) { 1)); // The anti quorum cannot be more than half of the replication factor, or the // log system will continue to accept commits when a recovery is impossible // Go through buildConfiguration, as it sets tLogPolicy/storagePolicy. - set_config(format("storage_replicas:=%d log_replicas:=%d log_anti_quorum:=%d " - "replica_datacenters:=1 min_replica_datacenters:=1", - storage_servers, - replication_factor, - anti_quorum)); + set_config(fmt::format("storage_replicas:={} log_replicas:={} log_anti_quorum:={} replica_datacenters:=1 " + "min_replica_datacenters:=1", + storage_servers, + replication_factor, + anti_quorum)); break; } case 1: { @@ -1801,15 +1802,17 @@ void SimulationConfig::setReplicationType(const TestConfig& testConfig) { } if (deterministicRandom()->random01() < 0.5) { int logSpill = deterministicRandom()->randomInt(TLogSpillType::VALUE, TLogSpillType::END); - set_config(format("log_spill:=%d", logSpill)); + set_config(fmt::format("log_spill:={}", logSpill)); int logVersion = deterministicRandom()->randomInt(TLogVersion::MIN_RECRUITABLE, testConfig.maxTLogVersion + 1); - set_config(format("log_version:=%d", logVersion)); + set_config(fmt::format("log_version:={}", logVersion)); } else { - if (deterministicRandom()->random01() < 0.7) - set_config(format("log_version:=%d", testConfig.maxTLogVersion)); - if (deterministicRandom()->random01() < 0.5) - set_config(format("log_spill:=%d", TLogSpillType::DEFAULT)); + if (deterministicRandom()->random01() < 0.7) { + set_config(fmt::format("log_version:={}", testConfig.maxTLogVersion)); + } + if (deterministicRandom()->random01() < 0.5) { + set_config(fmt::format("log_spill:={}", static_cast(TLogSpillType::DEFAULT))); + } } } } @@ -2115,7 +2118,8 @@ void SimulationConfig::setTss(const TestConfig& testConfig) { std::max(0, std::min(tssCount, db.usableRegions * ((machine_count / datacenters) - db.storageTeamSize) / 2)); if (!testConfig.config.present() && tssCount > 0) { - std::string confStr = format("tss_count:=%d tss_storage_engine:=%d", tssCount, db.storageServerStoreType); + std::string confStr = + fmt::format("tss_count:={} tss_storage_engine:={}", tssCount, static_cast(db.storageServerStoreType)); set_config(confStr); double tssRandom = deterministicRandom()->random01(); if (tssRandom > 0.5 || !faultInjectionActivated) { @@ -2129,7 +2133,7 @@ void SimulationConfig::setTss(const TestConfig& testConfig) { // delay injection g_simulator->tssMode = ISimulator::TSSMode::EnabledAddDelay; } - printf("enabling tss for simulation in mode %d: %s\n", g_simulator->tssMode, confStr.c_str()); + fmt::println("enabling tss for simulation in mode {}: {}", static_cast(g_simulator->tssMode), confStr); } } @@ -2219,7 +2223,8 @@ void setupSimulatedSystem(std::vector>* systemActors, // handle tss_storage_engine separately because the passthrough needs the enum ordinal, but it's serialized to json // as the string name if (simconfig.db.desiredTSSCount > 0) { - startingConfigString += format(" tss_storage_engine:=%d", simconfig.db.testingStorageServerStoreType); + startingConfigString += + fmt::format(" tss_storage_engine:={}", static_cast(simconfig.db.testingStorageServerStoreType)); } if (g_simulator->originalRegions != "") { @@ -2422,11 +2427,12 @@ void setupSimulatedSystem(std::vector>* systemActors, } else if (testConfig.extraDatabaseMode != ISimulator::ExtraDatabaseMode::Disabled) { for (int i = 0; i < extraDatabaseCount; ++i) { g_simulator->extraDatabases.push_back( - useHostname - ? ClusterConnectionString(extraCoordinatorHostnames[i], StringRef(format("ExtraCluster%04d:0", i))) - .toString() - : ClusterConnectionString(extraCoordinatorAddresses[i], StringRef(format("ExtraCluster%04d:0", i))) - .toString()); + useHostname ? ClusterConnectionString(extraCoordinatorHostnames[i], + StringRef(fmt::format("ExtraCluster{:04}:0", i))) + .toString() + : ClusterConnectionString(extraCoordinatorAddresses[i], + StringRef(fmt::format("ExtraCluster{:04}:0", i))) + .toString()); } } @@ -2443,7 +2449,7 @@ void setupSimulatedSystem(std::vector>* systemActors, ProcessClass::StatelessClass }; for (int dc = 0; dc < dataCenters; dc++) { // FIXME: test unset dcID - Optional> dcUID = StringRef(format("%d", dc)); + Optional> dcUID = StringRef(fmt::format("{}", dc)); std::vector machineIdentities; int machines = machineCount / dataCenters + (dc < machineCount % dataCenters); // add remainder of machines to first datacenter @@ -2453,19 +2459,19 @@ void setupSimulatedSystem(std::vector>* systemActors, int simHTTPMachines = 0; if (testConfig.simHTTPServerEnabled) { simHTTPMachines = deterministicRandom()->randomInt(1, 4); - fmt::print("sim http machines = {0}\n", simHTTPMachines); + fmt::println("sim http machines = {0}", simHTTPMachines); } int extraStorageMachineCount = testConfig.extraStorageMachineCountPerDC; int totalMachines = machines + simHTTPMachines + extraStorageMachineCount; - printf("Datacenter %d: %d/%d machines, %d/%d coordinators, %d other machines\n", - dc, - machines, - machineCount, - dcCoordinators, - coordinatorCount, - totalMachines - machines); + fmt::println("Datacenter {}: {}/{} machines, {}/{} coordinators, {} other machines", + dc, + machines, + machineCount, + dcCoordinators, + coordinatorCount, + totalMachines - machines); ASSERT_LE(dcCoordinators, machines); int useSeedForMachine = deterministicRandom()->randomInt(0, totalMachines); diff --git a/fdbserver/SkipList.cpp b/fdbserver/SkipList.cpp index 9b0d5709107..954b501f287 100644 --- a/fdbserver/SkipList.cpp +++ b/fdbserver/SkipList.cpp @@ -34,6 +34,7 @@ #include "fdbclient/SystemData.h" #include "fdbserver/ConflictSet.h" #include "flow/UnitTest.h" +#include "fmt/format.h" static std::vector skc; @@ -1114,7 +1115,7 @@ void miniConflictSetTest() { mini.any(a, b); // Tests correctness internally } } - printf("miniConflictSetTest complete\n"); + fmt::println("miniConflictSetTest complete"); } void operatorLessThanTest() { @@ -1153,7 +1154,7 @@ void operatorLessThanTest() { } // namespace void skipListTest() { - printf("Skip list test\n"); + fmt::println("Skip list test"); miniConflictSetTest(); @@ -1182,9 +1183,9 @@ void skipListTest() { testData[i][j] = KeyRangeRef(setK(testDataArena, key), setK(testDataArena, key2)); } } - printf("Test data generated: %d batches, %d/batch\n", batches, data_per_batch); + fmt::println("Test data generated: {} batches, {}/batch", batches, data_per_batch); - printf("Running\n"); + fmt::println("Running"); int readCount = 1, writeCount = 1; int cranges = 0, tcount = 0; @@ -1227,26 +1228,26 @@ void skipListTest() { version++; } double elapsed = timer() - start; - printf("New conflict set: %0.3f sec\n", elapsed); - printf(" %0.3f Mtransactions/sec\n", tcount / elapsed / 1e6); - printf(" %0.3f Mkeys/sec\n", cranges * 2 / elapsed / 1e6); + fmt::println("New conflict set: {:.3f} sec", elapsed); + fmt::println(" {:.3f} Mtransactions/sec", tcount / elapsed / 1e6); + fmt::println(" {:.3f} Mkeys/sec", cranges * 2 / elapsed / 1e6); elapsed = g_detectConflicts.getValue(); - printf("Detect only: %0.3f sec\n", elapsed); - printf(" %0.3f Mtransactions/sec\n", tcount / elapsed / 1e6); - printf(" %0.3f Mkeys/sec\n", cranges * 2 / elapsed / 1e6); + fmt::println("Detect only: {:.3f} sec", elapsed); + fmt::println(" {:.3f} Mtransactions/sec", tcount / elapsed / 1e6); + fmt::println(" {:.3f} Mkeys/sec", cranges * 2 / elapsed / 1e6); elapsed = g_checkRead.getValue() + g_merge.getValue(); - printf("Skiplist only: %0.3f sec\n", elapsed); - printf(" %0.3f Mtransactions/sec\n", tcount / elapsed / 1e6); - printf(" %0.3f Mkeys/sec\n", cranges * 2 / elapsed / 1e6); + fmt::println("Skiplist only: {:.3f} sec", elapsed); + fmt::println(" {:.3f} Mtransactions/sec", tcount / elapsed / 1e6); + fmt::println(" {:.3f} Mkeys/sec", cranges * 2 / elapsed / 1e6); - printf("Performance counters:\n"); + fmt::println("Performance counters:"); for (const auto& counter : skc) { - printf("%20s: %s\n", counter->getMetric().name().c_str(), counter->getMetric().formatted().c_str()); + fmt::println("{:>20}: {}", counter->getMetric().name(), counter->getMetric().formatted()); } - printf("%d entries in version history\n", cs->versionHistory.count()); + fmt::println("{} entries in version history", cs->versionHistory.count()); } TEST_CASE("/fdbserver/skiplist/miniConflictSetCompatibility") { diff --git a/fdbserver/Status.actor.cpp b/fdbserver/Status.actor.cpp index a8d0ce32865..07e0c43bcd6 100644 --- a/fdbserver/Status.actor.cpp +++ b/fdbserver/Status.actor.cpp @@ -791,8 +791,7 @@ ACTOR static Future processStatusFetcher( std::string fileName = event.getValue("Filename"); JsonBuilderObject msgObj = JsonString::makeMessage( "file_open_error", - format("Could not open file '%s' (%s).", fileName.c_str(), event.getValue("Error").c_str()) - .c_str()); + fmt::format("Could not open file '{}' ({}).", fileName, event.getValue("Error")).c_str()); msgObj["file_name"] = fileName; // Map the address of the worker to the error message object @@ -1071,7 +1070,7 @@ ACTOR static Future processStatusFetcher( if (ssLag[address] >= 60) { messages.push_back(JsonString::makeMessage( "storage_server_lagging", - format("Storage server lagging by %lld seconds.", (int64_t)ssLag[address]).c_str())); + fmt::format("Storage server lagging by {} seconds.", (int64_t)ssLag[address]).c_str())); } // Store the message array into the status object that represents the worker process @@ -1365,19 +1364,19 @@ ACTOR static Future doProbe(Future probe, if (isAvailable != nullptr) { *isAvailable = false; } - incomplete_reasons->insert(format( - "Unable to retrieve latency probe information (%s: %s).", description, result.getError().what())); + incomplete_reasons->insert(fmt::format( + "Unable to retrieve latency probe information ({}: {}).", description, result.getError().what())); } else { - (*probeObj)[format("%s_seconds", prefix).c_str()] = result.get(); + (*probeObj)[fmt::format("{}_seconds", prefix).c_str()] = result.get(); } } when(wait(delay(timeoutSeconds))) { if (isAvailable != nullptr) { *isAvailable = false; } - messages->push_back( - JsonString::makeMessage(format("%s_probe_timeout", prefix).c_str(), - format("Unable to %s after %d seconds.", description, timeoutSeconds).c_str())); + messages->push_back(JsonString::makeMessage( + fmt::format("{}_probe_timeout", prefix).c_str(), + fmt::format("Unable to {} after {} seconds.", description, timeoutSeconds).c_str())); } } @@ -1438,7 +1437,7 @@ ACTOR static Future latencyProbeFetcher(Database cx, if (e.code() == error_code_actor_cancelled) { throw; } - incomplete_reasons->insert(format("Unable to retrieve latency probe information (%s).", e.what())); + incomplete_reasons->insert(fmt::format("Unable to retrieve latency probe information ({}).", e.what())); } return statusObj; @@ -1470,7 +1469,7 @@ ACTOR static Future versionEpochStatusFetcher(Database cx, if (e.code() == error_code_actor_cancelled) { throw; } - incomplete_reasons->insert(format("Unable to retrieve version epoch information (%s).", e.what())); + incomplete_reasons->insert(fmt::format("Unable to retrieve version epoch information ({}).", e.what())); } return message; } @@ -1499,8 +1498,8 @@ ACTOR static Future consistencyCheckStatusFetcher(Database cx, if (e.code() == error_code_timed_out) { messages->push_back( JsonString::makeMessage("consistencycheck_suspendkey_fetch_timeout", - format("Timed out trying to fetch `%s` from the database.", - printable(fdbShouldConsistencyCheckBeSuspended).c_str()) + fmt::format("Timed out trying to fetch `{}` from the database.", + printable(fdbShouldConsistencyCheckBeSuspended)) .c_str())); break; } @@ -1511,7 +1510,7 @@ ACTOR static Future consistencyCheckStatusFetcher(Database cx, if (e.code() == error_code_actor_cancelled) { throw; } - incomplete_reasons->insert(format("Unable to retrieve consistency check settings (%s).", e.what())); + incomplete_reasons->insert(fmt::format("Unable to retrieve consistency check settings ({}).", e.what())); } return Void(); } @@ -1565,15 +1564,14 @@ ACTOR static Future logRangeWarningFetcher(Database cx, if (loggingRanges.contains(LogRangeAndUID(range, logUid))) { std::pair rangePair = std::make_pair(range.begin, range.end); if (existingRanges.contains(rangePair)) { - std::string rangeDescription = (range == getDefaultBackupSharedRange()) - ? "the default backup set" - : format("`%s` - `%s`", - printable(range.begin).c_str(), - printable(range.end).c_str()); + std::string rangeDescription = + (range == getDefaultBackupSharedRange()) + ? "the default backup set" + : fmt::format("`{}` - `{}`", printable(range.begin), printable(range.end)); messages->push_back(JsonString::makeMessage( "duplicate_mutation_streams", - format("Backup and DR are not sharing the same stream of mutations for %s", - rangeDescription.c_str()) + fmt::format("Backup and DR are not sharing the same stream of mutations for {}", + rangeDescription) .c_str())); break; } @@ -1584,11 +1582,10 @@ ACTOR static Future logRangeWarningFetcher(Database cx, break; } catch (Error& e) { if (e.code() == error_code_timed_out) { - messages->push_back( - JsonString::makeMessage("duplicate_mutation_fetch_timeout", - format("Timed out trying to fetch `%s` from the database.", - printable(destUidLookupPrefix).c_str()) - .c_str())); + messages->push_back(JsonString::makeMessage( + "duplicate_mutation_fetch_timeout", + fmt::format("Timed out trying to fetch `{}` from the database.", printable(destUidLookupPrefix)) + .c_str())); break; } wait(tr.onError(e)); @@ -1598,7 +1595,7 @@ ACTOR static Future logRangeWarningFetcher(Database cx, if (e.code() == error_code_actor_cancelled) { throw; } - incomplete_reasons->insert(format("Unable to retrieve log ranges (%s).", e.what())); + incomplete_reasons->insert(fmt::format("Unable to retrieve log ranges ({}).", e.what())); } return Void(); } @@ -2716,8 +2713,8 @@ ACTOR Future layerStatusFetcher(Database cx, if (e.code() == error_code_actor_cancelled) { throw; } - incomplete_reasons->insert(format("Unable to retrieve layer status (%s).", e.what())); - json.create("_error") = format("Unable to retrieve layer status (%s).", e.what()); + incomplete_reasons->insert(fmt::format("Unable to retrieve layer status ({}).", e.what())); + json.create("_error") = fmt::format("Unable to retrieve layer status ({}).", e.what()); json.create("_valid") = false; } @@ -2756,7 +2753,7 @@ ACTOR Future lockedStatusFetcher(Database cx, } when(wait(getTimeout)) { incomplete_reasons->insert( - format("Unable to determine if database is locked after %d seconds.", timeoutSeconds)); + fmt::format("Unable to determine if database is locked after {} seconds.", timeoutSeconds)); } } break; @@ -2767,7 +2764,7 @@ ACTOR Future lockedStatusFetcher(Database cx, if (e.code() == error_code_actor_cancelled) throw; - incomplete_reasons->insert(format("Unable to determine if database is locked (%s).", e.what())); + incomplete_reasons->insert(fmt::format("Unable to determine if database is locked ({}).", e.what())); break; } } @@ -3472,13 +3469,13 @@ bool checkAsciiNumber(const char* s) { JsonBuilderObject number; number.setKeyRawNumber("number", s); std::string js = number.getJson(); - printf("'%s' => %s\n", s, js.c_str()); + fmt::println("'{}' => {}", s, js); try { // Make sure it parses as JSON readJSONStrictly(js); } catch (Error& e) { - printf("error: %s\n", e.what()); + fmt::println("error: {}", e.what()); return false; } @@ -3487,14 +3484,14 @@ bool checkAsciiNumber(const char* s) { bool checkJson(const JsonBuilder& j, const char* expected) { std::string js = j.getJson(); - printf("json: '%s'\n", js.c_str()); - printf("expected: '%s'\n\n", expected); + fmt::println("json: '{}'", js); + fmt::print("expected: '{}'\n\n", expected); try { // Make sure it parses as JSON readJSONStrictly(js); } catch (Error& e) { - printf("error: %s\n", e.what()); + fmt::println("error: {}", e.what()); return false; } @@ -3660,7 +3657,7 @@ JsonBuilderObject randomDocument(const std::vector& strings, int& l TEST_CASE("Lstatus/json/builderPerf") { std::vector strings; int c = 1000000; - printf("Generating random strings\n"); + fmt::println("Generating random strings"); while (--c) strings.push_back(deterministicRandom()->randomAlphaNumeric(deterministicRandom()->randomInt(0, 50))); @@ -3668,7 +3665,7 @@ TEST_CASE("Lstatus/json/builderPerf") { int level = 6; int iterations = 200; - printf("Generating and serializing random document\n"); + fmt::println("Generating and serializing random document"); int64_t bytes = 0; double generated = 0; @@ -3693,17 +3690,17 @@ TEST_CASE("Lstatus/json/builderPerf") { std::string jsStr = json_spirit::write_string(mv); double jsSerialize = timer() - start; - printf("JsonBuilder: %8lu bytes %-7.5f gen + %-7.5f serialize = %-7.5f\n", - s.size(), - generate, - serialize, - generate + serialize); - printf("json_spirit: %8lu bytes %-7.5f parse + %-7.5f serialize = %-7.5f\n", - jsStr.size(), - jsParse, - jsSerialize, - jsParse + jsSerialize); - printf("\n"); + fmt::println("JsonBuilder: {:8} bytes {:<7.5f} gen + {:<7.5f} serialize = {:<7.5f}", + s.size(), + generate, + serialize, + generate + serialize); + fmt::println("json_spirit: {:8} bytes {:<7.5f} parse + {:<7.5f} serialize = {:<7.5f}", + jsStr.size(), + jsParse, + jsSerialize, + jsParse + jsSerialize); + fmt::println(""); generated += generate; serialized += serialize; @@ -3711,16 +3708,16 @@ TEST_CASE("Lstatus/json/builderPerf") { } double elapsed = generated + serialized; - fmt::print("RESULT: {0}" - " bytes {1} elements {2} levels {3} seconds ({4} gen, {5} serialize) {6} MB/s {7} items/s\n", - bytes, - iterations * elements, - level, - elapsed, - generated, - elapsed - generated, - bytes / elapsed / 1e6, - iterations * elements / elapsed); + fmt::println( + "RESULT: {0} bytes {1} elements {2} levels {3} seconds ({4} gen, {5} serialize) {6} MB/s {7} items/s", + bytes, + iterations * elements, + level, + elapsed, + generated, + elapsed - generated, + bytes / elapsed / 1e6, + iterations * elements / elapsed); return Void(); } @@ -3792,15 +3789,15 @@ TEST_CASE("/status/json/merging") { c.create("mixed_numeric_sum_6.$sum") = 4.5; c.create("mixed_numeric_min_0.$min") = (double)0.0; - printf("a = \n%s\n", json_spirit::write_string(json_spirit::mValue(objA), json_spirit::pretty_print).c_str()); - printf("b = \n%s\n", json_spirit::write_string(json_spirit::mValue(objB), json_spirit::pretty_print).c_str()); - printf("c = \n%s\n", json_spirit::write_string(json_spirit::mValue(objC), json_spirit::pretty_print).c_str()); + fmt::print("a = \n{}\n", json_spirit::write_string(json_spirit::mValue(objA), json_spirit::pretty_print)); + fmt::print("b = \n{}\n", json_spirit::write_string(json_spirit::mValue(objB), json_spirit::pretty_print)); + fmt::print("c = \n{}\n", json_spirit::write_string(json_spirit::mValue(objC), json_spirit::pretty_print)); JSONDoc::expires_reference_version = 2; a.absorb(b); a.absorb(c); a.cleanOps(); - printf("result = \n%s\n", json_spirit::write_string(json_spirit::mValue(objA), json_spirit::pretty_print).c_str()); + fmt::print("result = \n{}\n", json_spirit::write_string(json_spirit::mValue(objA), json_spirit::pretty_print)); std::string result = json_spirit::write_string(json_spirit::mValue(objA)); std::string expected = "{\"a\":\"justA\",\"b\":\"justB\",\"bool_true\":true,\"expired\":null,\"int_one\":1,\"int_" "total_30\":30,\"int_unmatched\":{\"ERROR\":\"Values do not " @@ -3811,9 +3808,7 @@ TEST_CASE("/status/json/merging") { "\"double_max_5\":5,\"double_min_2\":2,\"int_11\":11,\"obj_count_3\":3}}"; if (result != expected) { - printf("ERROR: Combined doc does not match expected.\nexpected:\n\n%s\nresult:\n%s\n", - expected.c_str(), - result.c_str()); + fmt::print("ERROR: Combined doc does not match expected.\nexpected:\n\n{}\nresult:\n{}\n", expected, result); ASSERT(false); } diff --git a/fdbserver/TagPartitionedLogSystem.actor.cpp b/fdbserver/TagPartitionedLogSystem.actor.cpp index 736ec7a6f92..61d319b4299 100644 --- a/fdbserver/TagPartitionedLogSystem.actor.cpp +++ b/fdbserver/TagPartitionedLogSystem.actor.cpp @@ -26,6 +26,7 @@ #include "fdbrpc/ReplicationUtils.h" #include "fdbserver/WaitFailure.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. ACTOR Future minVersionWhenReady(Future f, @@ -50,9 +51,9 @@ ACTOR Future minVersionWhenReady(Future f, std::string message; if (reply.isError()) { // FIXME Use C++20 format when it is available - message = format("TLogPushRespondError%04d", index++); + message = fmt::format("TLogPushRespondError{:04}", index++); } else { - message = format("TLogPushNoResponse%04d", index++); + message = fmt::format("TLogPushNoResponse{:04}", index++); } TraceEvent(g_network->isSimulated() ? SevInfo : SevWarnAlways, message.c_str()) .detail("TLogID", tlogID); @@ -197,7 +198,7 @@ void TagPartitionedLogSystem::delref() { std::string TagPartitionedLogSystem::describe() const { std::string result; for (int i = 0; i < tLogs.size(); i++) { - result += format("%d: ", i); + result += fmt::format("{}: ", i); for (int j = 0; j < tLogs[i]->logServers.size(); j++) { result += tLogs[i]->logServers[j]->get().id().toString() + ((j == tLogs[i]->logServers.size() - 1) ? " " : ", "); diff --git a/fdbserver/TestTLogServer.actor.cpp b/fdbserver/TestTLogServer.actor.cpp index a2bcd642b07..c5e9c1e8cb8 100644 --- a/fdbserver/TestTLogServer.actor.cpp +++ b/fdbserver/TestTLogServer.actor.cpp @@ -34,6 +34,7 @@ #include "flow/IRandom.h" #include "flow/DebugTrace.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // must be last include namespace { @@ -258,8 +259,8 @@ ACTOR Future TLogTestContext::sendPushMessages(TLogTestContext* pTLogTestC state Version next = pTLogTestContext->initVersion; for (; i < pTLogTestContext->numCommits; i++) { - Standalone key = StringRef(format("key %d", i)); - Standalone val = StringRef(format("value %d", i)); + Standalone key = StringRef(fmt::format("key {}", i)); + Standalone val = StringRef(fmt::format("value {}", i)); MutationRef m(MutationRef::Type::SetValue, key, val); // build commit request @@ -370,8 +371,8 @@ ACTOR Future TLogTestContext::peekCommitMessages(TLogTestContext* pTLogTes rd >> m; // validate data - Standalone expectedKey = StringRef(format("key %d", i)); - Standalone expectedVal = StringRef(format("value %d", i)); + Standalone expectedKey = StringRef(fmt::format("key {}", i)); + Standalone expectedVal = StringRef(fmt::format("value {}", i)); ASSERT_WE_THINK(m.param1 == expectedKey); ASSERT_WE_THINK(m.param2 == expectedVal); diff --git a/fdbserver/VersionedBTree.actor.cpp b/fdbserver/VersionedBTree.actor.cpp index c222439b857..9cea1553b52 100644 --- a/fdbserver/VersionedBTree.actor.cpp +++ b/fdbserver/VersionedBTree.actor.cpp @@ -94,7 +94,7 @@ std::string toString(LogicalPageID id) { if (id == invalidLogicalPageID) { return "LogicalPageID{invalid}"; } - return format("LogicalPageID{%u}", id); + return fmt::format("LogicalPageID{{{}}}", id); } std::string toString(Version v) { @@ -187,7 +187,7 @@ std::string toString(const Optional& o) { template std::string toString(const std::pair& o) { - return format("{%s, %s}", toString(o.first).c_str(), toString(o.second).c_str()); + return fmt::format("{{{}, {}}}", toString(o.first), toString(o.second)); } constexpr static int ioMinPriority = 0; @@ -441,25 +441,25 @@ class FIFOQueue { std::string toString() const { if (mode == WRITE) { - return format("{WriteCursor %s:%p pos=%s:%d rawEndOffset=%d}", - queue->name.c_str(), - this, - ::toString(pageID).c_str(), - offset, - page ? header()->endOffset : -1); + return fmt::format("{{WriteCursor {}:{} pos={}:{} rawEndOffset={}}}", + queue->name, + fmt::ptr(this), + ::toString(pageID), + offset, + page ? header()->endOffset : -1); } if (mode == POP || mode == READONLY) { - return format("{ReadCursor %s:%p pos=%s:%d rawEndOffset=%d endPage=%s nextPage=%s}", - queue->name.c_str(), - this, - ::toString(pageID).c_str(), - offset, - (page && header()) ? header()->endOffset : -1, - ::toString(endPageID).c_str(), - ::toString(nextPageID).c_str()); + return fmt::format("{{ReadCursor {}:{} pos={}:{} rawEndOffset={} endPage={} nextPage={}}}", + queue->name, + fmt::ptr(this), + ::toString(pageID), + offset, + (page && header()) ? header()->endOffset : -1, + ::toString(endPageID), + ::toString(nextPageID)); } ASSERT(mode == NONE); - return format("{NullCursor=%p}", this); + return fmt::format("{{NullCursor={}}}", fmt::ptr(this)); } // Returns true if the mutex cannot be immediately taken. @@ -1341,9 +1341,9 @@ class FIFOQueue { std::string name; void toTraceEvent(TraceEvent& e, const char* prefix) const { - e.detail(format("%sRecords", prefix), numEntries); - e.detail(format("%sPages", prefix), numPages); - e.detail(format("%sRecordsPerPage", prefix), numPages > 0 ? (double)numEntries / numPages : 0); + e.detail(fmt::format("{}Records", prefix), numEntries); + e.detail(fmt::format("{}Pages", prefix), numPages); + e.detail(fmt::format("{}RecordsPerPage", prefix), numPages > 0 ? (double)numEntries / numPages : 0); } }; @@ -1383,9 +1383,9 @@ struct RedwoodMetrics { } std::string name = - format("%s%s", PagerEventsStrings[(int)p.first], PagerEventReasonsStrings[(int)p.second]); + fmt::format("{}{}", PagerEventsStrings[(int)p.first], PagerEventReasonsStrings[(int)p.second]); int count = getEventReason(p.first, p.second); - result += format("%-15s %8u %8u/s ", name.c_str(), count, int(count / elapsed)); + result += fmt::format("{:<15} {:8} {:8}/s ", name, count, int(count / elapsed)); prevEvent = p.first; } @@ -1398,7 +1398,7 @@ struct RedwoodMetrics { for (const auto& p : pairs) { std::string name = format(level == 0 ? "" : "L%d", level) + - format("%s%s", PagerEventsStrings[(int)p.first], PagerEventReasonsStrings[(int)p.second]); + fmt::format("{}{}", PagerEventsStrings[(int)p.first], PagerEventReasonsStrings[(int)p.second]); int count = getEventReason(p.first, p.second); t->detail(std::move(name), count); } @@ -1761,10 +1761,10 @@ class ObjectCache : NonCopyable { reservedSize, movedOutCount); for (auto& entry : evictionOrder) { - s += format("\n\tindex %s size %d evictable %d\n", - ::toString(entry.index).c_str(), - entry.size, - entry.item.evictable()); + s += fmt::format("\n\tindex {} size {} evictable {}\n", + ::toString(entry.index), + entry.size, + entry.item.evictable()); } s += "}\n"; return s; @@ -1981,11 +1981,11 @@ class DWALPager final : public IPager2 { bool operator<(const RemappedPage& rhs) const { return version < rhs.version; } std::string toString() const { - return format("RemappedPage(%c: %s -> %s %s}", - getType(), - ::toString(originalPageID).c_str(), - ::toString(newPageID).c_str(), - ::toString(version).c_str()); + return fmt::format("RemappedPage({:c}: {} -> {} {}}}", + static_cast(getType()), + ::toString(originalPageID), + ::toString(newPageID), + ::toString(version)); } }; @@ -1996,7 +1996,7 @@ class DWALPager final : public IPager2 { bool operator<(const ExtentUsedListEntry& rhs) const { return queueID < rhs.queueID; } std::string toString() const { - return format("ExtentUsedListEntry{%s @%s}", ::toString(extentID).c_str(), ::toString(queueID).c_str()); + return fmt::format("ExtentUsedListEntry{{{} @{}}}", ::toString(extentID), ::toString(queueID)); } }; @@ -3999,9 +3999,9 @@ struct SplitStringRef { int expectedSize() const { return size(); } - std::string toString() const { return format("%s%s", a.toString().c_str(), b.toString().c_str()); } + std::string toString() const { return fmt::format("{}{}", a.toString(), b.toString()); } - std::string toHexString() const { return format("%s%s", a.toHexString().c_str(), b.toHexString().c_str()); } + std::string toHexString() const { return fmt::format("{}{}", a.toHexString(), b.toHexString()); } struct const_iterator { const uint8_t* ptr; @@ -4389,15 +4389,15 @@ struct RedwoodRecordRef { int keySuffixLen = getKeySuffixLength(); int valueLen = getValueLength(); - return format("lengthFormat: %d totalDeltaSize: %d flags: %s prefixLen: %d keySuffixLen: %d " - "valueLen %d raw: %s", - lengthFormat, - size(), - flagString.c_str(), - prefixLen, - keySuffixLen, - valueLen, - StringRef((const uint8_t*)this, size()).toHexString().c_str()); + return fmt::format("lengthFormat: {} totalDeltaSize: {} flags: {} prefixLen: {} keySuffixLen: {} " + "valueLen {} raw: {}", + lengthFormat, + size(), + flagString, + prefixLen, + keySuffixLen, + valueLen, + StringRef((const uint8_t*)this, size()).toHexString()); } }; @@ -4514,12 +4514,12 @@ struct RedwoodRecordRef { std::string toString(bool leaf = true) const { std::string r; - r += format("'%s' => ", key.printable().c_str()); + r += fmt::format("'{}' => ", key.printable()); if (value.present()) { if (leaf) { - r += format("'%s'", kvformat(value.get()).c_str()); + r += fmt::format("'{}'", kvformat(value.get())); } else { - r += format("[%s]", ::toString(getChildPage()).c_str()); + r += fmt::format("[{}]", ::toString(getChildPage())); } } else { r += "(absent)"; @@ -4624,7 +4624,7 @@ struct BoundaryRefAndPage { std::vector> extPages; std::string toString() const { - return format("[%s, %d pages]", lowerBound.toString().c_str(), extPages.size() + (firstPage ? 1 : 0)); + return fmt::format("[{}, {} pages]", lowerBound.toString(), extPages.size() + (firstPage ? 1 : 0)); } }; @@ -4700,15 +4700,15 @@ class DecodeBoundaryVerifier { auto b = i->second.upper_bound(v); --b; if (b->second.lower != lowerBound || b->second.upper != upperBound) { - fprintf(stderr, - "Boundary mismatch on %s %s\nUsing:\n\t'%s'\n\t'%s'\nWritten %s:\n\t'%s'\n\t'%s'\n", - ::toString(id).c_str(), - ::toString(v).c_str(), - lowerBound.printable().c_str(), - upperBound.printable().c_str(), - ::toString(b->first).c_str(), - b->second.lower.printable().c_str(), - b->second.upper.printable().c_str()); + fmt::print(stderr, + "Boundary mismatch on {} {}\nUsing:\n\t'{}'\n\t'{}'\nWritten {}:\n\t'{}'\n\t'{}'\n", + ::toString(id), + ::toString(v), + lowerBound.printable(), + upperBound.printable(), + ::toString(b->first), + b->second.lower.printable(), + b->second.upper.printable()); return false; } @@ -4842,11 +4842,11 @@ class VersionedBTree { EncryptionAtRestModeDeprecated encryptionModeDeprecated = EncryptionAtRestModeDeprecated::DISABLED; std::string toString() { - return format("{formatVersion=%d height=%d root=%s lazyDeleteQueue=%s}", - (int)formatVersion, - (int)height, - ::toString(root).c_str(), - lazyDeleteQueue.toString().c_str()); + return fmt::format("{{formatVersion={} height={} root={} lazyDeleteQueue={}}}", + (int)formatVersion, + (int)height, + ::toString(root), + lazyDeleteQueue.toString()); } template @@ -5208,7 +5208,7 @@ class VersionedBTree { return RedwoodRecordRef(userKey, value); } - std::string toString() const { return format("op=%d val='%s'", op, printable(value).c_str()); } + std::string toString() const { return fmt::format("op={} val='{}'", static_cast(op), printable(value)); } }; struct RangeMutation { @@ -5240,10 +5240,10 @@ class VersionedBTree { } std::string toString() const { - return format("boundaryChanged=%d clearAfterBoundary=%d boundaryValue=%s", - boundaryChanged, - clearAfterBoundary, - ::toString(boundaryValue).c_str()); + return fmt::format("boundaryChanged={} clearAfterBoundary={} boundaryValue={}", + boundaryChanged, + clearAfterBoundary, + ::toString(boundaryValue)); } }; @@ -5475,17 +5475,17 @@ class VersionedBTree { int endIndex() const { return startIndex + count; } std::string toString() const { - return format("{start=%d count=%d used %d/%d bytes (%.2f%% slack) kvBytes=%d blocks=%d blockSize=%d " - "large=%d}", - startIndex, - count, - usedBytes(), - pageSize, - slackFraction() * 100, - kvBytes, - blockCount, - blockSize, - largeDeltaTree); + return fmt::format( + "{{start={} count={} used {}/{} bytes ({:.2f}% slack) kvBytes={} blocks={} blockSize={} large={}}}", + startIndex, + count, + usedBytes(), + pageSize, + slackFraction() * 100, + kvBytes, + blockCount, + blockSize, + largeDeltaTree); } // Move an item from a to b if a has 2 or more items and the item fits in b @@ -6165,21 +6165,22 @@ class VersionedBTree { std::string toString() const { std::string s; - s += format("SubtreeSlice: addr=%p skipLen=%d subtreeCleared=%d childrenChanged=%d inPlaceUpdate=%d\n", - this, - skipLen, - childrenChanged && newLinks.empty(), - childrenChanged, - inPlaceUpdate); - s += format("SubtreeLower: %s\n", subtreeLowerBound.toString(false).c_str()); - s += format(" DecodeLower: %s\n", decodeLowerBound.toString(false).c_str()); - s += format(" DecodeUpper: %s\n", decodeUpperBound.toString(false).c_str()); - s += format("SubtreeUpper: %s\n", subtreeUpperBound.toString(false).c_str()); - s += format("expectedUpperBound: %s\n", - expectedUpperBound.present() ? expectedUpperBound.get().toString(false).c_str() : "(null)"); - s += format("newLinks:\n"); + s += fmt::format("SubtreeSlice: addr={} skipLen={} subtreeCleared={} childrenChanged={} inPlaceUpdate={}\n", + fmt::ptr(this), + skipLen, + childrenChanged && newLinks.empty(), + childrenChanged, + inPlaceUpdate); + s += fmt::format("SubtreeLower: {}\n", subtreeLowerBound.toString(false)); + s += fmt::format(" DecodeLower: {}\n", decodeLowerBound.toString(false)); + s += fmt::format(" DecodeUpper: {}\n", decodeUpperBound.toString(false)); + s += fmt::format("SubtreeUpper: {}\n", subtreeUpperBound.toString(false)); + s += + fmt::format("expectedUpperBound: {}\n", + expectedUpperBound.present() ? expectedUpperBound.get().toString(false).c_str() : "(null)"); + s += fmt::format("newLinks:\n"); for (int i = 0; i < newLinks.size(); ++i) { - s += format(" %i: %s\n", i, newLinks[i].toString(false).c_str()); + s += fmt::format(" {}: {}\n", i, newLinks[i].toString(false)); } s.resize(s.size() - 1); return s; @@ -6369,10 +6370,10 @@ class VersionedBTree { state std::string context; if (REDWOOD_DEBUG) { - context = format("CommitSubtree(root=%s+%d %s): ", - toString(rootID.front()).c_str(), - rootID.size() - 1, - ::toString(batch->writeVersion).c_str()); + context = fmt::format("CommitSubtree(root={}+{} {}): ", + toString(rootID.front()), + rootID.size() - 1, + ::toString(batch->writeVersion)); } debug_printf("%s rootID=%s\n", context.c_str(), toString(rootID).c_str()); debug_print(addPrefix(context, update->toString())); @@ -6405,7 +6406,7 @@ class VersionedBTree { state BTreePage* btPage = (BTreePage*)page->mutateData(); if (height != btPage->height) { - fprintf(stderr, "height [%d] != btPage->height [%d]\n", height, btPage->height); + fmt::println(stderr, "height [{}] != btPage->height [{}]", height, btPage->height); ASSERT(false); } ASSERT(height == btPage->height); @@ -7249,28 +7250,29 @@ class VersionedBTree { // path entries at dumpHeight or below will have their entire pages printed std::string toString(int dumpHeight = 0) const { - std::string r = format("{ptr=%p reason=%s %s ", - this, - PagerEventReasonsStrings[(int)reason], - ::toString(pager->getVersion()).c_str()); + std::string r = fmt::format("{{ptr={} reason={} {} ", + fmt::ptr(this), + PagerEventReasonsStrings[(int)reason], + ::toString(pager->getVersion())); for (int i = 0; i < path.size(); ++i) { std::string id = ""; #if REDWOOD_DEBUG id = ::toString(path[i].id); #endif int height = path[i].btPage()->height; - r += format("\n\t[Level=%d ID=%s ptr=%p Cursor=%s] ", - height, - id.c_str(), - path[i].page->data(), - path[i].cursor.valid() ? path[i].cursor.get().toString(path[i].btPage()->isLeaf()).c_str() - : ""); + r += fmt::format("\n\t[Level={} ID={} ptr={} Cursor={}] ", + height, + id, + fmt::ptr(path[i].page->data()), + path[i].cursor.valid() + ? path[i].cursor.get().toString(path[i].btPage()->isLeaf()).c_str() + : ""); if (height <= dumpHeight) { BTreePage::BinaryTree::Cursor c = path[i].cursor; c.moveFirst(); int i = 0; while (c.valid()) { - r += format("\n\t\%7d: %s", ++i, c.get().toString(height == 1).c_str()); + r += fmt::format("\n\t\{:7}: {}", ++i, c.get().toString(height == 1)); c.moveNext(); } } @@ -8299,8 +8301,13 @@ struct IntIntPair { int size() const { return sizeof(Delta); } std::string toString() const { - return format( - "DELTA{prefixSource=%d deleted=%d dk=%d(0x%x) dv=%d(0x%x)}", prefixSource, deleted, dk, dk, dv, dv); + return fmt::format("DELTA{{prefixSource={} deleted={} dk={}(0x{:x}) dv={}(0x{:x})}}", + prefixSource, + deleted, + dk, + dk, + dv, + dv); } }; @@ -8348,7 +8355,7 @@ struct IntIntPair { int k; int v; - std::string toString() const { return format("{k=%d(0x%x) v=%d(0x%x)}", k, k, v, v); } + std::string toString() const { return fmt::format("{{k={0}(0x{0:x}) v={1}(0x{1:x})}}", k, v); } }; int deltaTest(RedwoodRecordRef rec, RedwoodRecordRef base) { @@ -8361,15 +8368,15 @@ int deltaTest(RedwoodRecordRef rec, RedwoodRecordRef base) { RedwoodRecordRef decoded = d.apply(base, mem); if (decoded != rec || expectedSize != deltaSize || d.size() != deltaSize) { - printf("\n"); - printf("Base: %s\n", base.toString().c_str()); - printf("Record: %s\n", rec.toString().c_str()); - printf("Decoded: %s\n", decoded.toString().c_str()); - printf("deltaSize(): %d\n", expectedSize); - printf("writeDelta(): %d\n", deltaSize); - printf("d.size(): %d\n", d.size()); - printf("DeltaToString: %s\n", d.toString().c_str()); - printf("RedwoodRecordRef::Delta test failure!\n"); + fmt::println(""); + fmt::println("Base: {}", base.toString()); + fmt::println("Record: {}", rec.toString()); + fmt::println("Decoded: {}", decoded.toString()); + fmt::println("deltaSize(): {}", expectedSize); + fmt::println("writeDelta(): {}", deltaSize); + fmt::println("d.size(): {}", d.size()); + fmt::println("DeltaToString: {}", d.toString()); + fmt::println("RedwoodRecordRef::Delta test failure!"); ASSERT(false); } @@ -8488,14 +8495,14 @@ void RedwoodMetrics::getFields(TraceEvent* e, std::string* s, bool skipZeroes) { for (auto& m : metrics) { char c = m.first[0]; if (c != 0 && (!skipZeroes || m.second != 0)) { - e->detail(format("L%d%s", i, m.first + (c == '-' ? 1 : 0)), m.second); + e->detail(fmt::format("L{}{}", i, m.first + (c == '-' ? 1 : 0)), m.second); } } metric.events.toTraceEvent(e, i); } if (s != nullptr) { - *s += format("\nLevel %d\n\t", i); + *s += fmt::format("\nLevel {}\n\t", i); for (auto& m : metrics) { const char* name = m.first; @@ -8508,7 +8515,7 @@ void RedwoodMetrics::getFields(TraceEvent* e, std::string* s, bool skipZeroes) { if (*name == '\0') { *s += "\n\t"; } else if (!skipZeroes || m.second != 0) { - *s += format("%-15s %8u %8u/s ", name, m.second, rate ? int(m.second / elapsed) : 0); + *s += fmt::format("{:<15} {:8} {:8}/s ", name, m.second, rate ? int(m.second / elapsed) : 0); } } *s += metric.events.toString(i, elapsed); @@ -8527,21 +8534,21 @@ void RedwoodMetrics::getIOLockFields(TraceEvent* e, std::string* s) { e->detail("IOWaitingTotal", ioLock->getWaitersCount()); for (int priority = 0; priority <= maxPriority; ++priority) { - e->detail(format("IOActiveP%d", priority), ioLock->getRunnersCount(priority)); - e->detail(format("IOWaitingP%d", priority), ioLock->getWaitersCount(priority)); + e->detail(fmt::format("IOActiveP{}", priority), ioLock->getRunnersCount(priority)); + e->detail(fmt::format("IOWaitingP{}", priority), ioLock->getWaitersCount(priority)); } } if (s != nullptr) { *s += "\n"; - *s += format("%-15s %-8u ", "IOActiveTotal", ioLock->getRunnersCount()); + *s += fmt::format("{:<15} {:<8} ", "IOActiveTotal", ioLock->getRunnersCount()); for (int priority = 0; priority <= maxPriority; ++priority) { - *s += format("IOActiveP%-6d %-8u ", priority, ioLock->getRunnersCount(priority)); + *s += fmt::format("IOActiveP{:<6} {:<8} ", priority, ioLock->getRunnersCount(priority)); } *s += "\n"; - *s += format("%-15s %-8u ", "IOWaitingTotal", ioLock->getWaitersCount()); + *s += fmt::format("{:<15} {:<8} ", "IOWaitingTotal", ioLock->getWaitersCount()); for (int priority = 0; priority <= maxPriority; ++priority) { - *s += format("IOWaitingP%-5d %-8u ", priority, ioLock->getWaitersCount(priority)); + *s += fmt::format("IOWaitingP{:<5} {:<8} ", priority, ioLock->getWaitersCount(priority)); } } } @@ -8552,7 +8559,7 @@ TEST_CASE("/redwood/correctness/unit/RedwoodRecordRef") { ASSERT(RedwoodRecordRef::Delta::LengthFormatSizes[2] == 6); ASSERT(RedwoodRecordRef::Delta::LengthFormatSizes[3] == 8); - fmt::print("sizeof(RedwoodRecordRef) = {}\n", sizeof(RedwoodRecordRef)); + fmt::println("sizeof(RedwoodRecordRef) = {}", sizeof(RedwoodRecordRef)); // Test pageID stuff. { @@ -8607,7 +8614,8 @@ TEST_CASE("/redwood/correctness/unit/RedwoodRecordRef") { bytes += deltaTest(a, b); } double elapsed = timer() - start; - printf("DeltaTest() on random large records %f M/s %f MB/s\n", count / elapsed / 1e6, bytes / elapsed / 1e6); + fmt::println( + "DeltaTest() on random large records {:f} M/s {:f} MB/s", count / elapsed / 1e6, bytes / elapsed / 1e6); keyBuffer.resize(30); valueBuffer.resize(100); @@ -8619,7 +8627,8 @@ TEST_CASE("/redwood/correctness/unit/RedwoodRecordRef") { RedwoodRecordRef b = randomRedwoodRecordRef(keyBuffer, valueBuffer); bytes += deltaTest(a, b); } - printf("DeltaTest() on random small records %f M/s %f MB/s\n", count / elapsed / 1e6, bytes / elapsed / 1e6); + fmt::println( + "DeltaTest() on random small records {:f} M/s {:f} MB/s", count / elapsed / 1e6, bytes / elapsed / 1e6); RedwoodRecordRef rec1; RedwoodRecordRef rec2; @@ -8717,17 +8726,17 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/RedwoodRecordRef") { tree->build(bufferSize, &items[0], &items[items.size()], &prev, &next); - printf("Count=%d Size=%d InitialHeight=%d largeTree=%d\n", - (int)items.size(), - (int)tree->size(), - (int)tree->initialHeight, - largeTree); + fmt::println("Count={} Size={} InitialHeight={} largeTree={}", + (int)items.size(), + (int)tree->size(), + (int)tree->initialHeight, + largeTree); debug_printf("Data(%p): %s\n", tree, StringRef((uint8_t*)tree, tree->size()).toHexString().c_str()); DeltaTree::Mirror r(tree, &prev, &next); // Test delete/insert behavior for each item, making no net changes - printf("Testing seek/delete/insert for existing keys with random values\n"); + fmt::println("Testing seek/delete/insert for existing keys with random values"); ASSERT(tree->numItems == items.size()); for (auto rec : items) { // Insert existing should fail @@ -8757,7 +8766,7 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/RedwoodRecordRef") { DeltaTree::Mirror rValuesOnly(tree, &prev, &next); DeltaTree::Cursor fwdValueOnly = rValuesOnly.getCursor(); - printf("Verifying tree contents using forward, reverse, and value-only iterators\n"); + fmt::println("Verifying tree contents using forward, reverse, and value-only iterators"); ASSERT(fwd.moveFirst()); ASSERT(fwdValueOnly.moveFirst()); ASSERT(rev.moveLast()); @@ -8765,27 +8774,25 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/RedwoodRecordRef") { int i = 0; while (1) { if (fwd.get() != items[i]) { - printf("forward iterator i=%d\n %s found\n %s expected\n", - i, - fwd.get().toString().c_str(), - items[i].toString().c_str()); - printf("Delta: %s\n", fwd.node->raw->delta(largeTree).toString().c_str()); + fmt::print( + "forward iterator i={}\n {} found\n {} expected\n", i, fwd.get().toString(), items[i].toString()); + fmt::println("Delta: {}", fwd.node->raw->delta(largeTree).toString()); ASSERT(false); } if (rev.get() != items[items.size() - 1 - i]) { - printf("reverse iterator i=%d\n %s found\n %s expected\n", - i, - rev.get().toString().c_str(), - items[items.size() - 1 - i].toString().c_str()); - printf("Delta: %s\n", rev.node->raw->delta(largeTree).toString().c_str()); + fmt::print("reverse iterator i={}\n {} found\n {} expected\n", + i, + rev.get().toString(), + items[items.size() - 1 - i].toString()); + fmt::println("Delta: {}", rev.node->raw->delta(largeTree).toString()); ASSERT(false); } if (fwdValueOnly.get().value != items[i].value) { - printf("forward values-only iterator i=%d\n %s found\n %s expected\n", - i, - fwdValueOnly.get().toString().c_str(), - items[i].toString().c_str()); - printf("Delta: %s\n", fwdValueOnly.node->raw->delta(largeTree).toString().c_str()); + fmt::print("forward values-only iterator i={}\n {} found\n {} expected\n", + i, + fwdValueOnly.get().toString(), + items[i].toString()); + fmt::println("Delta: {}", fwdValueOnly.node->raw->delta(largeTree).toString()); ASSERT(false); } ++i; @@ -8808,28 +8815,26 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/RedwoodRecordRef") { DeltaTree::Mirror mirror(tree, &prev, &next); DeltaTree::Cursor c = mirror.getCursor(); - printf("Doing 20M random seeks using the same cursor from the same mirror.\n"); + fmt::println("Doing 20M random seeks using the same cursor from the same mirror."); double start = timer(); for (int i = 0; i < 20000000; ++i) { const RedwoodRecordRef& query = items[deterministicRandom()->randomInt(0, items.size())]; if (!c.seekLessThanOrEqual(query)) { - printf("Not found! query=%s\n", query.toString().c_str()); + fmt::println("Not found! query={}", query.toString()); ASSERT(false); } if (c.get() != query) { - printf("Found incorrect node! query=%s found=%s\n", - query.toString().c_str(), - c.get().toString().c_str()); + fmt::println("Found incorrect node! query={} found={}", query.toString(), c.get().toString()); ASSERT(false); } } double elapsed = timer() - start; - printf("Elapsed %f\n", elapsed); + fmt::println("Elapsed {:f}", elapsed); } { - printf("Doing 5M random seeks using 10k random cursors, each from a different mirror.\n"); + fmt::println("Doing 5M random seeks using 10k random cursors, each from a different mirror."); double start = timer(); std::vector::Mirror*> mirrors; std::vector::Cursor> cursors; @@ -8842,18 +8847,16 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/RedwoodRecordRef") { const RedwoodRecordRef& query = items[deterministicRandom()->randomInt(0, items.size())]; DeltaTree::Cursor& c = cursors[deterministicRandom()->randomInt(0, cursors.size())]; if (!c.seekLessThanOrEqual(query)) { - printf("Not found! query=%s\n", query.toString().c_str()); + fmt::println("Not found! query={}", query.toString()); ASSERT(false); } if (c.get() != query) { - printf("Found incorrect node! query=%s found=%s\n", - query.toString().c_str(), - c.get().toString().c_str()); + fmt::println("Found incorrect node! query={} found={}", query.toString(), c.get().toString()); ASSERT(false); } } double elapsed = timer() - start; - printf("Elapsed %f\n", elapsed); + fmt::println("Elapsed {:f}", elapsed); } return Void(); @@ -8894,17 +8897,17 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/RedwoodRecordRef2") { tree->build(bufferSize, &items[0], &items[items.size()], &prev, &next); - printf("Count=%d Size=%d InitialHeight=%d largeTree=%d\n", - (int)items.size(), - (int)tree->size(), - (int)tree->initialHeight, - largeTree); + fmt::println("Count={} Size={} InitialHeight={} largeTree={}", + (int)items.size(), + (int)tree->size(), + (int)tree->initialHeight, + largeTree); debug_printf("Data(%p): %s\n", tree, StringRef((uint8_t*)tree, tree->size()).toHexString().c_str()); DeltaTree2::Cursor c(makeReference::DecodeCache>(prev, next), tree); // Test delete/insert behavior for each item, making no net changes - printf("Testing seek/delete/insert for existing keys with random values\n"); + fmt::println("Testing seek/delete/insert for existing keys with random values"); ASSERT(tree->numItems == items.size()); for (auto rec : items) { // Insert existing should fail @@ -8935,7 +8938,7 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/RedwoodRecordRef2") { makeReference::DecodeCache>(prev, next), (DeltaTree2*)tree); - printf("Verifying tree contents using forward, reverse, and value-only iterators\n"); + fmt::println("Verifying tree contents using forward, reverse, and value-only iterators"); ASSERT(fwd.moveFirst()); ASSERT(fwdValueOnly.moveFirst()); ASSERT(rev.moveLast()); @@ -8943,27 +8946,25 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/RedwoodRecordRef2") { int i = 0; while (1) { if (fwd.get() != items[i]) { - printf("forward iterator i=%d\n %s found\n %s expected\n", - i, - fwd.get().toString().c_str(), - items[i].toString().c_str()); - printf("Cursor: %s\n", fwd.toString().c_str()); + fmt::print( + "forward iterator i={}\n {} found\n {} expected\n", i, fwd.get().toString(), items[i].toString()); + fmt::println("Cursor: {}", fwd.toString()); ASSERT(false); } if (rev.get() != items[items.size() - 1 - i]) { - printf("reverse iterator i=%d\n %s found\n %s expected\n", - i, - rev.get().toString().c_str(), - items[items.size() - 1 - i].toString().c_str()); - printf("Cursor: %s\n", rev.toString().c_str()); + fmt::print("reverse iterator i={}\n {} found\n {} expected\n", + i, + rev.get().toString(), + items[items.size() - 1 - i].toString()); + fmt::println("Cursor: {}", rev.toString()); ASSERT(false); } if (fwdValueOnly.get().value != items[i].value) { - printf("forward values-only iterator i=%d\n %s found\n %s expected\n", - i, - fwdValueOnly.get().toString().c_str(), - items[i].toString().c_str()); - printf("Cursor: %s\n", fwdValueOnly.toString().c_str()); + fmt::print("forward values-only iterator i={}\n {} found\n {} expected\n", + i, + fwdValueOnly.get().toString(), + items[i].toString()); + fmt::println("Cursor: {}", fwdValueOnly.toString()); ASSERT(false); } ++i; @@ -8986,24 +8987,22 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/RedwoodRecordRef2") { DeltaTree2::Cursor c(makeReference::DecodeCache>(prev, next), tree); - printf("Doing 20M random seeks using the same cursor from the same mirror.\n"); + fmt::println("Doing 20M random seeks using the same cursor from the same mirror."); double start = timer(); for (int i = 0; i < 20000000; ++i) { const RedwoodRecordRef& query = items[deterministicRandom()->randomInt(0, items.size())]; if (!c.seekLessThanOrEqual(query)) { - printf("Not found! query=%s\n", query.toString().c_str()); + fmt::println("Not found! query={}", query.toString()); ASSERT(false); } if (c.get() != query) { - printf("Found incorrect node! query=%s found=%s\n", - query.toString().c_str(), - c.get().toString().c_str()); + fmt::println("Found incorrect node! query={} found={}", query.toString(), c.get().toString()); ASSERT(false); } } double elapsed = timer() - start; - printf("Elapsed %f\n", elapsed); + fmt::println("Elapsed {:f}", elapsed); } // { @@ -9090,24 +9089,24 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { }; auto printTrees = [&] { - printf("DeltaTree: Count=%d Size=%d InitialHeight=%d MaxHeight=%d\n", - (int)tree->numItems, - (int)tree->size(), - (int)tree->initialHeight, - (int)tree->maxHeight); + fmt::println("DeltaTree: Count={} Size={} InitialHeight={} MaxHeight={}", + (int)tree->numItems, + (int)tree->size(), + (int)tree->initialHeight, + (int)tree->maxHeight); debug_printf("Data(%p): %s\n", tree, StringRef((uint8_t*)tree, tree->size()).toHexString().c_str()); - printf("DeltaTree2: Count=%d Size=%d InitialHeight=%d MaxHeight=%d\n", - (int)tree2->numItems, - (int)tree2->size(), - (int)tree2->initialHeight, - (int)tree2->maxHeight); + fmt::println("DeltaTree2: Count={} Size={} InitialHeight={} MaxHeight={}", + (int)tree2->numItems, + (int)tree2->size(), + (int)tree2->initialHeight, + (int)tree2->maxHeight); debug_printf("Data(%p): %s\n", tree2, StringRef((uint8_t*)tree2, tree2->size()).toHexString().c_str()); }; // Iterate through items and tree forward and backward, verifying tree contents. auto scanAndVerify = [&]() { - printf("Verify DeltaTree contents.\n"); + fmt::println("Verify DeltaTree contents."); DeltaTree::Cursor fwd = r.getCursor(); DeltaTree::Cursor rev = r.getCursor(); @@ -9117,18 +9116,16 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { for (int i = 0; i < items.size(); ++i) { if (fwd.get() != items[i]) { printItems(); - printf("forward iterator i=%d\n %s found\n %s expected\n", - i, - fwd.get().toString().c_str(), - items[i].toString().c_str()); + fmt::print( + "forward iterator i={}\n {} found\n {} expected\n", i, fwd.get().toString(), items[i].toString()); ASSERT(false); } if (rev.get() != items[items.size() - 1 - i]) { printItems(); - printf("reverse iterator i=%d\n %s found\n %s expected\n", - i, - rev.get().toString().c_str(), - items[items.size() - 1 - i].toString().c_str()); + fmt::print("reverse iterator i={}\n {} found\n {} expected\n", + i, + rev.get().toString(), + items[items.size() - 1 - i].toString()); ASSERT(false); } @@ -9149,7 +9146,7 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { // Iterate through items and tree forward and backward, verifying tree contents. auto scanAndVerify2 = [&]() { - printf("Verify DeltaTree2 contents.\n"); + fmt::println("Verify DeltaTree2 contents."); DeltaTree2::Cursor fwd(cache, tree2); DeltaTree2::Cursor rev(cache, tree2); @@ -9160,18 +9157,16 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { for (int i = 0; i < items.size(); ++i) { if (fwd.get() != items[i]) { printItems(); - printf("forward iterator i=%d\n %s found\n %s expected\n", - i, - fwd.get().toString().c_str(), - items[i].toString().c_str()); + fmt::print( + "forward iterator i={}\n {} found\n {} expected\n", i, fwd.get().toString(), items[i].toString()); ASSERT(false); } if (rev.get() != items[items.size() - 1 - i]) { printItems(); - printf("reverse iterator i=%d\n %s found\n %s expected\n", - i, - rev.get().toString().c_str(), - items[items.size() - 1 - i].toString().c_str()); + fmt::print("reverse iterator i={}\n {} found\n {} expected\n", + i, + rev.get().toString(), + items[items.size() - 1 - i].toString()); ASSERT(false); } @@ -9242,7 +9237,7 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { scanAndVerify2(); // For each randomly selected new item to be deleted, delete it from the DeltaTree2 and from uniqueItems - printf("Deleting some items\n"); + fmt::println("Deleting some items"); for (auto p : toDelete) { uniqueItems.erase(p); @@ -9263,7 +9258,7 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { scanAndVerify(); scanAndVerify2(); - printf("Verifying insert/erase behavior for existing items\n"); + fmt::println("Verifying insert/erase behavior for existing items"); // Test delete/insert behavior for each item, making no net changes for (auto p : items) { // Insert existing should fail @@ -9294,7 +9289,7 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { scanAndVerify(); scanAndVerify2(); - printf("Verifying seek behaviors\n"); + fmt::println("Verifying seek behaviors"); DeltaTree::Cursor s = r.getCursor(); DeltaTree2::Cursor s2(cache, tree2); @@ -9306,20 +9301,16 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { ASSERT(s.seekLessThanOrEqual(q)); if (s.get() != p) { printItems(); - printf("seekLessThanOrEqual(%s) found %s expected %s\n", - q.toString().c_str(), - s.get().toString().c_str(), - p.toString().c_str()); + fmt::println( + "seekLessThanOrEqual({}) found {} expected {}", q.toString(), s.get().toString(), p.toString()); ASSERT(false); } ASSERT(s2.seekLessThanOrEqual(q)); if (s2.get() != p) { printItems(); - printf("seekLessThanOrEqual(%s) found %s expected %s\n", - q.toString().c_str(), - s2.get().toString().c_str(), - p.toString().c_str()); + fmt::println( + "seekLessThanOrEqual({}) found {} expected {}", q.toString(), s2.get().toString(), p.toString()); ASSERT(false); } } @@ -9332,20 +9323,16 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { ASSERT(s.seekGreaterThanOrEqual(q)); if (s.get() != p) { printItems(); - printf("seekGreaterThanOrEqual(%s) found %s expected %s\n", - q.toString().c_str(), - s.get().toString().c_str(), - p.toString().c_str()); + fmt::println( + "seekGreaterThanOrEqual({}) found {} expected {}", q.toString(), s.get().toString(), p.toString()); ASSERT(false); } ASSERT(s2.seekGreaterThanOrEqual(q)); if (s2.get() != p) { printItems(); - printf("seekGreaterThanOrEqual(%s) found %s expected %s\n", - q.toString().c_str(), - s2.get().toString().c_str(), - p.toString().c_str()); + fmt::println( + "seekGreaterThanOrEqual({}) found {} expected {}", q.toString(), s2.get().toString(), p.toString()); ASSERT(false); } } @@ -9360,20 +9347,16 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { ASSERT(s.seekLessThanOrEqual(q)); if (s.get() != p) { printItems(); - printf("seekLessThanOrEqual(%s) found %s expected %s\n", - q.toString().c_str(), - s.get().toString().c_str(), - p.toString().c_str()); + fmt::println( + "seekLessThanOrEqual({}) found {} expected {}", q.toString(), s.get().toString(), p.toString()); ASSERT(false); } ASSERT(s2.seekLessThanOrEqual(q)); if (s2.get() != p) { printItems(); - printf("seekLessThanOrEqual(%s) found %s expected %s\n", - q.toString().c_str(), - s2.get().toString().c_str(), - p.toString().c_str()); + fmt::println( + "seekLessThanOrEqual({}) found {} expected {}", q.toString(), s2.get().toString(), p.toString()); ASSERT(false); } } @@ -9388,20 +9371,16 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { ASSERT(s.seekGreaterThanOrEqual(q)); if (s.get() != p) { printItems(); - printf("seekGreaterThanOrEqual(%s) found %s expected %s\n", - q.toString().c_str(), - s.get().toString().c_str(), - p.toString().c_str()); + fmt::println( + "seekGreaterThanOrEqual({}) found {} expected {}", q.toString(), s.get().toString(), p.toString()); ASSERT(false); } ASSERT(s2.seekGreaterThanOrEqual(q)); if (s2.get() != p) { printItems(); - printf("seekGreaterThanOrEqual(%s) found %s expected %s\n", - q.toString().c_str(), - s2.get().toString().c_str(), - p.toString().c_str()); + fmt::println( + "seekGreaterThanOrEqual({}) found {} expected {}", q.toString(), s2.get().toString(), p.toString()); ASSERT(false); } } @@ -9415,11 +9394,9 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { ASSERT(s.seekLessThanOrEqual(q, 0, &s)); if (s.get() != p) { printItems(); - printf("i=%d j=%d\n", i, j); - printf("seekLessThanOrEqual(%s) found %s expected %s\n", - q.toString().c_str(), - s.get().toString().c_str(), - p.toString().c_str()); + fmt::println("i={} j={}", i, j); + fmt::println( + "seekLessThanOrEqual({}) found {} expected {}", q.toString(), s.get().toString(), p.toString()); ASSERT(false); } } @@ -9436,7 +9413,7 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { ASSERT(s.seekLessThanOrEqual(q, 0, &s)); if (s.get() != p) { printItems(); - printf("i=%d j=%d\n", i, j); + fmt::println("i={} j={}", i, j); ASSERT(false); } } @@ -9475,15 +9452,15 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { pos = newPos; } double elapsed = timer() - start; - fmt::print("Seek/skip test, count={0} jumpMax={1}, items={2}, oldSeek={3} useHint={4}: Elapsed {5} seconds " - "{6:.2f} M/s\n", - count, - jumpMax, - items.size(), - old, - useHint, - elapsed, - double(count) / elapsed / 1e6); + fmt::println("Seek/skip test, count={0} jumpMax={1}, items={2}, oldSeek={3} useHint={4}: Elapsed {5} seconds " + "{6:.2f} M/s", + count, + jumpMax, + items.size(), + old, + useHint, + elapsed, + double(count) / elapsed / 1e6); }; auto skipSeekPerformance2 = [&](int jumpMax, bool old, bool useHint, int count) { @@ -9519,16 +9496,15 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { pos = newPos; } double elapsed = timer() - start; - fmt::print("DeltaTree2 Seek/skip test, count={0} jumpMax={1}, items={2}, oldSeek={3} useHint={4}: Elapsed {5} " - "seconds " - "{6:.2f} M/s\n", - count, - jumpMax, - items.size(), - old, - useHint, - elapsed, - double(count) / elapsed / 1e6); + fmt::println("DeltaTree2 Seek/skip test, count={0} jumpMax={1}, items={2}, oldSeek={3} useHint={4}: Elapsed " + "{5} seconds {6:.2f} M/s", + count, + jumpMax, + items.size(), + old, + useHint, + elapsed, + double(count) / elapsed / 1e6); }; // Compare seeking to nearby elements with and without hints, using the old and new SeekLessThanOrEqual methods. @@ -9553,16 +9529,16 @@ TEST_CASE("Lredwood/correctness/unit/deltaTree/IntIntPair") { // Verify the result is less than or equal, and if seek fails then p must be lower than lowest (first) item if (!s.seekLessThanOrEqual(p)) { if (p >= items.front()) { - printf("Seek failed! query=%s front=%s\n", p.toString().c_str(), items.front().toString().c_str()); + fmt::println("Seek failed! query={} front={}", p.toString(), items.front().toString()); ASSERT(false); } } else if (s.get() > p) { - printf("Found incorrect node! query=%s found=%s\n", p.toString().c_str(), s.get().toString().c_str()); + fmt::println("Found incorrect node! query={} found={}", p.toString(), s.get().toString()); ASSERT(false); } } double elapsed = timer() - start; - printf("Random seek test: Elapsed %f\n", elapsed); + fmt::println("Random seek test: Elapsed {:f}", elapsed); return Void(); } @@ -9591,14 +9567,14 @@ TEST_CASE(":/redwood/performance/mutationBuffer") { // This test uses pregenerated short random keys int count = 10e6; - printf("Generating %d strings...\n", count); + fmt::println("Generating {} strings...", count); Arena arena; std::vector strings; while (strings.size() < count) { strings.push_back(randomString(arena, 5)); } - fmt::print("Inserting {} elements and then finding each string...\n", count); + fmt::println("Inserting {} elements and then finding each string...", count); double start = timer(); VersionedBTree::MutationBuffer m; for (int i = 0; i < count; ++i) { @@ -9610,7 +9586,7 @@ TEST_CASE(":/redwood/performance/mutationBuffer") { } double elapsed = timer() - start; - printf("count=%d elapsed=%f\n", count, elapsed); + fmt::println("count={} elapsed={:f}", count, elapsed); return Void(); } @@ -9618,21 +9594,21 @@ TEST_CASE(":/redwood/performance/mutationBuffer") { // This test is only useful with Arena debug statements which show when aligned buffers are allocated and freed. TEST_CASE(":/redwood/pager/ArenaPage") { Arena x; - printf("Making p\n"); + fmt::println("Making p"); auto p = makeReference(4096, 4096); - printf("Made p=%p\n", p->data()); - printf("Clearing p\n"); + fmt::println("Made p={}", fmt::ptr(p->data())); + fmt::println("Clearing p"); p.clear(); - printf("Making p\n"); + fmt::println("Making p"); p = makeReference(4096, 4096); - printf("Made p=%p\n", p->data()); - printf("Making x depend on p\n"); + fmt::println("Made p={}", fmt::ptr(p->data())); + fmt::println("Making x depend on p"); x.dependsOn(p->getArena()); - printf("Clearing p\n"); + fmt::println("Clearing p"); p.clear(); - printf("Clearing x\n"); + fmt::println("Clearing x"); x = Arena(); - printf("Pointer should be freed\n"); + fmt::println("Pointer should be freed"); return Void(); } @@ -9757,38 +9733,38 @@ TEST_CASE("Lredwood/correctness/btree") { state EncodingType encodingType = EncodingType::XXHash64; - printf("\n"); - printf("file: %s\n", file.c_str()); + fmt::println(""); + fmt::println("file: {}", file); printf("maxPageOps: %" PRId64 "\n", maxPageOps); - printf("maxVerificationMapEntries: %d\n", maxVerificationMapEntries); + fmt::println("maxVerificationMapEntries: {}", maxVerificationMapEntries); printf("maxRecordsRead: %" PRId64 "\n", maxRecordsRead); - printf("pagerMemoryOnly: %d\n", pagerMemoryOnly); - printf("serialTest: %d\n", serialTest); - printf("shortTest: %d\n", shortTest); - printf("encodingType: %d\n", encodingType); - printf("pageSize: %d\n", pageSize); - printf("extentSize: %d\n", extentSize); - printf("keyGenerator: %s\n", keyGen.toString().c_str()); - printf("valueGenerator: %s\n", valGen.toString().c_str()); - printf("maxCommitSize: %d\n", maxCommitSize); - printf("setExistingKeyProbability: %f\n", setExistingKeyProbability); - printf("clearProbability: %f\n", clearProbability); - printf("clearExistingBoundaryProbability: %f\n", clearExistingBoundaryProbability); - printf("clearKnownNodeBoundaryProbability: %f\n", clearKnownNodeBoundaryProbability); - printf("clearSingleKeyProbability: %f\n", clearSingleKeyProbability); - printf("clearPostSetProbability: %f\n", clearPostSetProbability); - printf("coldStartProbability: %f\n", coldStartProbability); - printf("maxColdStarts: %d\n", maxColdStarts); - printf("advanceOldVersionProbability: %f\n", advanceOldVersionProbability); - printf("pageCacheBytes: %s\n", pageCacheBytes == 0 ? "default" : format("%" PRId64, pageCacheBytes).c_str()); + fmt::println("pagerMemoryOnly: {}", pagerMemoryOnly); + fmt::println("serialTest: {}", serialTest); + fmt::println("shortTest: {}", shortTest); + fmt::println("encodingType: {}", static_cast(encodingType)); + fmt::println("pageSize: {}", pageSize); + fmt::println("extentSize: {}", extentSize); + fmt::println("keyGenerator: {}", keyGen.toString()); + fmt::println("valueGenerator: {}", valGen.toString()); + fmt::println("maxCommitSize: {}", maxCommitSize); + fmt::println("setExistingKeyProbability: {:f}", setExistingKeyProbability); + fmt::println("clearProbability: {:f}", clearProbability); + fmt::println("clearExistingBoundaryProbability: {:f}", clearExistingBoundaryProbability); + fmt::println("clearKnownNodeBoundaryProbability: {:f}", clearKnownNodeBoundaryProbability); + fmt::println("clearSingleKeyProbability: {:f}", clearSingleKeyProbability); + fmt::println("clearPostSetProbability: {:f}", clearPostSetProbability); + fmt::println("coldStartProbability: {:f}", coldStartProbability); + fmt::println("maxColdStarts: {}", maxColdStarts); + fmt::println("advanceOldVersionProbability: {:f}", advanceOldVersionProbability); + fmt::println("pageCacheBytes: {}", pageCacheBytes == 0 ? "default" : format("%" PRId64, pageCacheBytes)); printf("versionIncrement: %" PRId64 "\n", versionIncrement); printf("remapCleanupWindowBytes: %" PRId64 "\n", remapCleanupWindowBytes); - printf("\n"); + fmt::println(""); - printf("Deleting existing test data...\n"); + fmt::println("Deleting existing test data..."); deleteFile(file); - printf("Initializing...\n"); + fmt::println("Initializing..."); pager = new DWALPager( pageSize, extentSize, file, pageCacheBytes, remapCleanupWindowBytes, concurrentExtentReads, pagerMemoryOnly); @@ -9969,10 +9945,10 @@ TEST_CASE("Lredwood/correctness/btree") { printf("Commit complete. Next commit %d bytes, %" PRId64 " bytes committed so far.", mutationBytesThisCommit, mutationBytes.get() - mutationBytesThisCommit); - printf(" Stats: Insert %.2f MB/s ClearedKeys %.2f MB/s Total %.2f\n", - (keyBytesInserted.rate() + valueBytesInserted.rate()) / 1e6, - keyBytesCleared.rate() / 1e6, - mutationBytes.rate() / 1e6); + fmt::println(" Stats: Insert {:.2f} MB/s ClearedKeys {:.2f} MB/s Total {:.2f}", + (keyBytesInserted.rate() + valueBytesInserted.rate()) / 1e6, + keyBytesCleared.rate() / 1e6, + mutationBytes.rate() / 1e6); // Sometimes advance the oldest version to close the gap between the oldest and latest versions by a // random amount. @@ -9986,19 +9962,19 @@ TEST_CASE("Lredwood/correctness/btree") { commit = map(btree->commit(version), [&, v = version](Void) { // Update pager ops before clearing metrics totalPageOps += g_redwoodMetrics.pageOps(); - fmt::print("Committed {0} PageOps {1}/{2} ({3:.2f}%) VerificationMapEntries {4}/{5} ({6:.2f}%) " - "RecordsRead {7}/{8} ({9:.2f}%)\n", - toString(v).c_str(), - totalPageOps, - maxPageOps, - totalPageOps * 100.0 / maxPageOps, - written.size(), - maxVerificationMapEntries, - written.size() * 100.0 / maxVerificationMapEntries, - totalRecordsRead, - maxRecordsRead, - totalRecordsRead * 100.0 / maxRecordsRead); - printf("Committed:\n%s\n", g_redwoodMetrics.toString(true).c_str()); + fmt::println("Committed {0} PageOps {1}/{2} ({3:.2f}%) VerificationMapEntries {4}/{5} ({6:.2f}%) " + "RecordsRead {7}/{8} ({9:.2f}%)", + toString(v), + totalPageOps, + maxPageOps, + totalPageOps * 100.0 / maxPageOps, + written.size(), + maxVerificationMapEntries, + written.size() * 100.0 / maxVerificationMapEntries, + totalRecordsRead, + maxRecordsRead, + totalRecordsRead * 100.0 / maxRecordsRead); + fmt::print("Committed:\n{}\n", g_redwoodMetrics.toString(true)); // Notify the background verifier that version is committed and therefore readable committedVersions.send(v); @@ -10022,7 +9998,7 @@ TEST_CASE("Lredwood/correctness/btree") { // Recover from disk at random if (!pagerMemoryOnly && deterministicRandom()->random01() < coldStartProbability) { ++coldStarts; - printf("Recovering from disk after next commit.\n"); + fmt::println("Recovering from disk after next commit."); // Wait for outstanding commit debug_printf("Waiting for outstanding commit\n"); @@ -10038,7 +10014,7 @@ TEST_CASE("Lredwood/correctness/btree") { btree->close(); wait(closedFuture); - printf("Reopening btree from disk.\n"); + fmt::println("Reopening btree from disk."); IPager2* pager = new DWALPager( pageSize, extentSize, file, pageCacheBytes, remapCleanupWindowBytes, concurrentExtentReads, false); @@ -10136,7 +10112,7 @@ ACTOR Future randomSeeks(VersionedBTree* btree, ++c; } double elapsed = timer() - readStart; - printf("Random seek speed %d/s\n", int(count / elapsed)); + fmt::println("Random seek speed {}/s", int(count / elapsed)); return Void(); } @@ -10173,8 +10149,8 @@ ACTOR Future randomScans(VersionedBTree* btree, } } double elapsed = timer() - readStart; - fmt::print( - "Completed {0} scans: width={1} totalbytesRead={2} prefetchBytes={3} scansRate={4} scans/s {5:.2f} MB/s\n", + fmt::println( + "Completed {0} scans: width={1} totalbytesRead={2} prefetchBytes={3} scansRate={4} scans/s {5:.2f} MB/s", count, width, totalScanBytes, @@ -10190,9 +10166,7 @@ struct ExtentQueueEntry { bool operator<(const ExtentQueueEntry& rhs) const { return entry < rhs.entry; } - std::string toString() const { - return format("{%s}", StringRef((const uint8_t*)entry, size).toHexString().c_str()); - } + std::string toString() const { return fmt::format("{{{}}}", StringRef((const uint8_t*)entry, size).toHexString()); } }; typedef FIFOQueue> ExtentQueueT; @@ -10206,11 +10180,11 @@ TEST_CASE(":/redwood/performance/extentQueue") { state std::string fileName = reload ? "unittest.redwood-v1" : getenv("TESTFILE"); if (reload) { - printf("Deleting old test data\n"); + fmt::println("Deleting old test data"); deleteFile(fileName); } - printf("Filename: %s\n", fileName.c_str()); + fmt::println("Filename: {}", fileName); state int pageSize = params.getInt("pageSize").orDefault(SERVER_KNOBS->REDWOOD_DEFAULT_PAGE_SIZE); state int extentSize = params.getInt("extentSize").orDefault(SERVER_KNOBS->REDWOOD_DEFAULT_EXTENT_SIZE); state int64_t cacheSizeBytes = params.getInt("cacheSizeBytes").orDefault(FLOW_KNOBS->PAGE_CACHE_4K); @@ -10223,8 +10197,8 @@ TEST_CASE(":/redwood/performance/extentQueue") { state int currentCommitSize = 0; state int64_t cumulativeCommitSize = 0; - printf("pageSize: %d\n", pageSize); - printf("extentSize: %d\n", extentSize); + fmt::println("pageSize: {}", pageSize); + fmt::println("extentSize: {}", extentSize); printf("cacheSizeBytes: %" PRId64 "\n", cacheSizeBytes); printf("remapCleanupWindowBytes: %" PRId64 "\n", remapCleanupWindowBytes); @@ -10245,10 +10219,10 @@ TEST_CASE(":/redwood/performance/extentQueue") { for (v = 1; v <= numEntries; ++v) { // Sometimes do a commit if (currentCommitSize >= targetCommitSize) { - fmt::print("currentCommitSize: {0}, cumulativeCommitSize: {1}, pageCacheCount: {2}\n", - currentCommitSize, - cumulativeCommitSize, - pager->getPageCacheCount()); + fmt::println("currentCommitSize: {0}, cumulativeCommitSize: {1}, pageCacheCount: {2}", + currentCommitSize, + cumulativeCommitSize, + pager->getPageCacheCount()); wait(m_extentQueue.flush()); wait(pager->commit(pager->getLastCommittedVersion() + 1, ObjectWriter::toValue(m_extentQueue.getState(), Unversioned()))); @@ -10268,10 +10242,10 @@ TEST_CASE(":/redwood/performance/extentQueue") { } } cumulativeCommitSize += currentCommitSize; - fmt::print( - "Final cumulativeCommitSize: {0}, pageCacheCount: {1}\n", cumulativeCommitSize, pager->getPageCacheCount()); + fmt::println( + "Final cumulativeCommitSize: {0}, pageCacheCount: {1}", cumulativeCommitSize, pager->getPageCacheCount()); wait(m_extentQueue.flush()); - printf("Commit ExtentQueue getState(): %s\n", m_extentQueue.getState().toString().c_str()); + fmt::println("Commit ExtentQueue getState(): {}", m_extentQueue.getState().toString()); wait(pager->commit(pager->getLastCommittedVersion() + 1, ObjectWriter::toValue(m_extentQueue.getState(), Unversioned()))); @@ -10280,16 +10254,16 @@ TEST_CASE(":/redwood/performance/extentQueue") { wait(onClosed); } - printf("Reopening pager file from disk.\n"); + fmt::println("Reopening pager file from disk."); pager = new DWALPager( pageSize, extentSize, fileName, cacheSizeBytes, remapCleanupWindowBytes, concurrentExtentReads, false); wait(success(pager->init())); - printf("Starting ExtentQueue FastPath Recovery from Disk.\n"); + fmt::println("Starting ExtentQueue FastPath Recovery from Disk."); // reopen the pager from disk extentQueueState = ObjectReader::fromStringRef(pager->getCommitRecord(), Unversioned()); - printf("Recovered ExtentQueue getState(): %s\n", extentQueueState.toString().c_str()); + fmt::println("Recovered ExtentQueue getState(): {}", extentQueueState.toString()); m_extentQueue.recover(pager, extentQueueState, "ExtentQueueRecovered"); state double intervalStart = timer(); @@ -10325,27 +10299,27 @@ TEST_CASE(":/redwood/performance/extentQueue") { } state double elapsed = timer() - start; - printf("Completed fastpath extent queue recovery: elapsed=%f entriesRead=%d recoveryRate=%f MB/s\n", - elapsed, - entriesRead, - cumulativeCommitSize / elapsed / 1e6); + fmt::println("Completed fastpath extent queue recovery: elapsed={:f} entriesRead={} recoveryRate={:f} MB/s", + elapsed, + entriesRead, + cumulativeCommitSize / elapsed / 1e6); - fmt::print("pageCacheCount: {0} extentCacheCount: {1}\n", pager->getPageCacheCount(), pager->getExtentCacheCount()); + fmt::println("pageCacheCount: {0} extentCacheCount: {1}", pager->getPageCacheCount(), pager->getExtentCacheCount()); pager->extentCacheClear(); m_extentQueue.resetHeadReader(); - printf("Starting ExtentQueue SlowPath Recovery from Disk.\n"); + fmt::println("Starting ExtentQueue SlowPath Recovery from Disk."); intervalStart = timer(); start = intervalStart; // peekAll the queue using regular slow path Standalone>> entries = wait(m_extentQueue.peekAll()); elapsed = timer() - start; - printf("Completed slowpath extent queue recovery: elapsed=%f entriesRead=%d recoveryRate=%f MB/s\n", - elapsed, - entries.size(), - cumulativeCommitSize / elapsed / 1e6); + fmt::println("Completed slowpath extent queue recovery: elapsed={:f} entriesRead={} recoveryRate={:f} MB/s", + elapsed, + entries.size(), + cumulativeCommitSize / elapsed / 1e6); return Void(); } @@ -10384,32 +10358,32 @@ TEST_CASE(":/redwood/performance/set") { state bool traceMetrics = params.getInt("traceMetrics").orDefault(0); state bool destructiveSanityCheck = params.getInt("destructiveSanityCheck").orDefault(0); - printf("file: %s\n", file.c_str()); - printf("openExisting: %d\n", openExisting); - printf("insertRecords: %d\n", insertRecords); - printf("destructiveSanityCheck: %d\n", destructiveSanityCheck); - printf("pagerMemoryOnly: %d\n", pagerMemoryOnly); - printf("pageSize: %d\n", pageSize); - printf("extentSize: %d\n", extentSize); + fmt::println("file: {}", file); + fmt::println("openExisting: {}", openExisting); + fmt::println("insertRecords: {}", insertRecords); + fmt::println("destructiveSanityCheck: {}", destructiveSanityCheck); + fmt::println("pagerMemoryOnly: {}", pagerMemoryOnly); + fmt::println("pageSize: {}", pageSize); + fmt::println("extentSize: {}", extentSize); printf("pageCacheBytes: %" PRId64 "\n", pageCacheBytes); - printf("trailingIntegerIndexRange: %d\n", nodeCount); - printf("maxChangesPerCommit: %d\n", maxRecordsPerCommit); - printf("minKeyPrefixBytes: %d\n", minKeyPrefixBytes); - printf("maxKeyPrefixBytes: %d\n", maxKeyPrefixBytes); - printf("minConsecutiveRun: %d\n", minConsecutiveRun); - printf("maxConsecutiveRun: %d\n", maxConsecutiveRun); - printf("minValueSize: %d\n", minValueSize); - printf("maxValueSize: %d\n", maxValueSize); - printf("maxCommitSize: %d\n", maxKVBytesPerCommit); + fmt::println("trailingIntegerIndexRange: {}", nodeCount); + fmt::println("maxChangesPerCommit: {}", maxRecordsPerCommit); + fmt::println("minKeyPrefixBytes: {}", minKeyPrefixBytes); + fmt::println("maxKeyPrefixBytes: {}", maxKeyPrefixBytes); + fmt::println("minConsecutiveRun: {}", minConsecutiveRun); + fmt::println("maxConsecutiveRun: {}", maxConsecutiveRun); + fmt::println("minValueSize: {}", minValueSize); + fmt::println("maxValueSize: {}", maxValueSize); + fmt::println("maxCommitSize: {}", maxKVBytesPerCommit); printf("kvBytesTarget: %" PRId64 "\n", kvBytesTarget); - printf("KeyLexicon '%c' to '%c'\n", firstKeyChar, lastKeyChar); + fmt::println("KeyLexicon '{:c}' to '{:c}'", firstKeyChar, lastKeyChar); printf("remapCleanupWindowBytes: %" PRId64 "\n", remapCleanupWindowBytes); - printf("concurrentScans: %d\n", concurrentScans); - printf("concurrentSeeks: %d\n", concurrentSeeks); - printf("seeks: %d\n", seeks); - printf("scans: %d\n", scans); - printf("scanWidth: %d\n", scanWidth); - printf("scanPrefetchBytes: %d\n", scanPrefetchBytes); + fmt::println("concurrentScans: {}", concurrentScans); + fmt::println("concurrentSeeks: {}", concurrentSeeks); + fmt::println("seeks: {}", seeks); + fmt::println("scans: {}", scans); + fmt::println("scanWidth: {}", scanWidth); + fmt::println("scanPrefetchBytes: {}", scanPrefetchBytes); // If using stdout for metrics, prevent trace event metrics logger from starting if (!traceMetrics) { @@ -10418,7 +10392,7 @@ TEST_CASE(":/redwood/performance/set") { } if (!openExisting) { - printf("Deleting old test data\n"); + fmt::println("Deleting old test data"); deleteFile(file); } @@ -10426,7 +10400,7 @@ TEST_CASE(":/redwood/performance/set") { pageSize, extentSize, file, pageCacheBytes, remapCleanupWindowBytes, concurrentExtentReads, pagerMemoryOnly); state VersionedBTree* btree = new VersionedBTree(pager, file, UID(), {}); wait(btree->init()); - printf("Initialized. StorageBytes=%s\n", btree->getStorageBytes().toString().c_str()); + fmt::println("Initialized. StorageBytes={}", btree->getStorageBytes().toString()); state int64_t kvBytesThisCommit = 0; state int64_t kvBytesTotal = 0; @@ -10434,7 +10408,7 @@ TEST_CASE(":/redwood/performance/set") { state Future commit = Void(); state std::string value(maxValueSize, 'v'); - printf("Starting.\n"); + fmt::println("Starting."); state double intervalStart = timer(); state double start = intervalStart; state int sinceYield = 0; @@ -10481,9 +10455,9 @@ TEST_CASE(":/redwood/performance/set") { btree->toTraceEvent(e); e.log(); - printf("Cumulative %.2f MB keyValue bytes written at %.2f MB/s\n", - kvBytesTotal / 1e6, - kvBytesTotal / (timer() - start) / 1e6); + fmt::println("Cumulative {:.2f} MB keyValue bytes written at {:.2f} MB/s", + kvBytesTotal / 1e6, + kvBytesTotal / (timer() - start) / 1e6); // Avoid capturing via this to freeze counter values int recs = recordsThisCommit; @@ -10495,14 +10469,14 @@ TEST_CASE(":/redwood/performance/set") { commit = map(btree->commit(++version), [=](Void result) { if (!traceMetrics) { - printf("%s\n", g_redwoodMetrics.toString(true).c_str()); + fmt::println("{}", g_redwoodMetrics.toString(true)); } double elapsed = timer() - *pIntervalStart; - printf("Committed %d keyValueBytes in %d records in %f seconds, %.2f MB/s\n", - kvb, - recs, - elapsed, - kvb / elapsed / 1e6); + fmt::println("Committed {} keyValueBytes in {} records in {:f} seconds, {:.2f} MB/s", + kvb, + recs, + elapsed, + kvb / elapsed / 1e6); *pIntervalStart = timer(); return Void(); }); @@ -10514,22 +10488,21 @@ TEST_CASE(":/redwood/performance/set") { } wait(commit); - printf("Cumulative %.2f MB keyValue bytes written at %.2f MB/s\n", - kvBytesTotal / 1e6, - kvBytesTotal / (timer() - start) / 1e6); - printf("StorageBytes=%s\n", btree->getStorageBytes().toString().c_str()); + fmt::println("Cumulative {:.2f} MB keyValue bytes written at {:.2f} MB/s", + kvBytesTotal / 1e6, + kvBytesTotal / (timer() - start) / 1e6); + fmt::println("StorageBytes={}", btree->getStorageBytes().toString()); } state Future stats = - traceMetrics ? Void() - : recurring([&]() { printf("Stats:\n%s\n", g_redwoodMetrics.toString(true).c_str()); }, 1.0); + traceMetrics ? Void() : recurring([&]() { fmt::print("Stats:\n{}\n", g_redwoodMetrics.toString(true)); }, 1.0); if (scans > 0) { - printf("Parallel scans, concurrency=%d, scans=%d, scanWidth=%d, scanPreftchBytes=%d ...\n", - concurrentScans, - scans, - scanWidth, - scanPrefetchBytes); + fmt::println("Parallel scans, concurrency={}, scans={}, scanWidth={}, scanPreftchBytes={} ...", + concurrentScans, + scans, + scanWidth, + scanPrefetchBytes); for (int x = 0; x < concurrentScans; ++x) { actors.add( randomScans(btree, scans / concurrentScans, scanWidth, scanPrefetchBytes, firstKeyChar, lastKeyChar)); @@ -10538,7 +10511,7 @@ TEST_CASE(":/redwood/performance/set") { } if (seeks > 0) { - printf("Parallel seeks, concurrency=%d, seeks=%d ...\n", concurrentSeeks, seeks); + fmt::println("Parallel seeks, concurrency={}, seeks={} ...", concurrentSeeks, seeks); for (int x = 0; x < concurrentSeeks; ++x) { actors.add( randomSeeks(btree, Optional(), true, seeks / concurrentSeeks, firstKeyChar, lastKeyChar, 4)); @@ -10566,7 +10539,7 @@ struct PrefixSegment { int length; int cardinality; - std::string toString() const { return format("{%d bytes, %d choices}", length, cardinality); } + std::string toString() const { return fmt::format("{{{} bytes, {} choices}}", length, cardinality); } }; // Utility class for generating kv pairs under a prefix pattern @@ -10686,7 +10659,7 @@ struct KVSource { int numPrefixes() const { return prefixes.size(); }; std::string toString() const { - return format("{prefixLen=%d prefixes=%d format=%s}", prefixLen, numPrefixes(), ::toString(desc).c_str()); + return fmt::format("{{prefixLen={} prefixes={} format={}}}", prefixLen, numPrefixes(), ::toString(desc)); } }; @@ -10721,15 +10694,15 @@ ACTOR Future prefixClusteredInsert(IKeyValueStore* kvs, state int recordsPerPrefix = recordCountTarget / source.numPrefixes(); fmt::print("\nstoreType: {}\n", static_cast(kvs->getType())); - fmt::print("commitTarget: {}\n", commitTarget); - fmt::print("prefixSource: {}\n", source.toString()); - fmt::print("usePrefixesInOrder: {}\n", usePrefixesInOrder); - fmt::print("suffixSize: {}\n", suffixSize); - fmt::print("valueSize: {}\n", valueSize); - fmt::print("recordSize: {}\n", recordSize); - fmt::print("recordsPerPrefix: {}\n", recordsPerPrefix); - fmt::print("recordCountTarget: {}\n", recordCountTarget); - fmt::print("kvBytesTarget: {}\n", kvBytesTarget); + fmt::println("commitTarget: {}", commitTarget); + fmt::println("prefixSource: {}", source.toString()); + fmt::println("usePrefixesInOrder: {}", usePrefixesInOrder); + fmt::println("suffixSize: {}", suffixSize); + fmt::println("valueSize: {}", valueSize); + fmt::println("recordSize: {}", recordSize); + fmt::println("recordsPerPrefix: {}", recordsPerPrefix); + fmt::println("recordCountTarget: {}", recordCountTarget); + fmt::println("kvBytesTarget: {}", kvBytesTarget); state int64_t kvBytes = 0; state int64_t kvBytesTotal = 0; @@ -10744,12 +10717,13 @@ ACTOR Future prefixClusteredInsert(IKeyValueStore* kvs, state std::function stats = [&]() { double elapsed = timer() - start; - printf("Cumulative stats: %.2f seconds %.2f MB keyValue bytes %d records %.2f MB/s %.2f rec/s\r", - elapsed, - kvBytesTotal / 1e6, - records, - kvBytesTotal / elapsed / 1e6, - records / elapsed); + fmt::print( + "Cumulative stats: {:.2f} seconds {:.2f} MB keyValue bytes {} records {:.2f} MB/s {:.2f} rec/s\r", + elapsed, + kvBytesTotal / 1e6, + records, + kvBytesTotal / elapsed / 1e6, + records / elapsed); fflush(stdout); }; @@ -10784,20 +10758,19 @@ ACTOR Future prefixClusteredInsert(IKeyValueStore* kvs, // since the last commit are persisted. For the purposes of how this is used currently, I don't think it matters // though stats(); - printf("\n"); + fmt::println(""); intervalStart = timer(); StorageBytes sb = wait(getStableStorageBytes(kvs)); - printf("storageBytes: %s (stable after %.2f seconds)\n", toString(sb).c_str(), timer() - intervalStart); + fmt::println("storageBytes: {} (stable after {:.2f} seconds)", toString(sb), timer() - intervalStart); if (clearAfter) { - printf("Clearing all keys\n"); + fmt::println("Clearing all keys"); intervalStart = timer(); kvs->clear(KeyRangeRef(""_sr, "\xff"_sr)); state StorageBytes sbClear = wait(getStableStorageBytes(kvs)); - printf("Cleared all keys in %.2f seconds, final storageByte: %s\n", - timer() - intervalStart, - toString(sbClear).c_str()); + fmt::println( + "Cleared all keys in {:.2f} seconds, final storageByte: {}", timer() - intervalStart, toString(sbClear)); } return Void(); @@ -10811,11 +10784,11 @@ ACTOR Future sequentialInsert(IKeyValueStore* kvs, int prefixLen, int valu state int64_t kvBytesTarget = (int64_t)recordCountTarget * recordSize; fmt::print("\nstoreType: {}\n", static_cast(kvs->getType())); - fmt::print("commitTarget: {}\n", commitTarget); - fmt::print("valueSize: {}\n", valueSize); - fmt::print("recordSize: {}\n", recordSize); - fmt::print("recordCountTarget: {}\n", recordCountTarget); - fmt::print("kvBytesTarget: {}\n", kvBytesTarget); + fmt::println("commitTarget: {}", commitTarget); + fmt::println("valueSize: {}", valueSize); + fmt::println("recordSize: {}", recordSize); + fmt::println("recordCountTarget: {}", recordCountTarget); + fmt::println("kvBytesTarget: {}", kvBytesTarget); state int64_t kvBytes = 0; state int64_t kvBytesTotal = 0; @@ -10830,12 +10803,13 @@ ACTOR Future sequentialInsert(IKeyValueStore* kvs, int prefixLen, int valu state std::function stats = [&]() { double elapsed = timer() - start; - printf("Cumulative stats: %.2f seconds %.2f MB keyValue bytes %d records %.2f MB/s %.2f rec/s\r", - elapsed, - kvBytesTotal / 1e6, - records, - kvBytesTotal / elapsed / 1e6, - records / elapsed); + fmt::print( + "Cumulative stats: {:.2f} seconds {:.2f} MB keyValue bytes {} records {:.2f} MB/s {:.2f} rec/s\r", + elapsed, + kvBytesTotal / 1e6, + records, + kvBytesTotal / elapsed / 1e6, + records / elapsed); fflush(stdout); }; @@ -10865,7 +10839,7 @@ ACTOR Future sequentialInsert(IKeyValueStore* kvs, int prefixLen, int valu wait(commit); stats(); - printf("\n"); + fmt::println(""); return Void(); } @@ -10891,7 +10865,7 @@ ACTOR Future doPrefixInsertComparison(int suffixSize, state IKeyValueStore* redwood = openKVStore(KeyValueStoreType::SSD_REDWOOD_V1, "test.redwood-v1", UID(), 0); wait(prefixClusteredInsert(redwood, suffixSize, valueSize, source, recordCountTarget, usePrefixesInOrder, true)); wait(closeKVS(redwood)); - printf("\n"); + fmt::println(""); deleteFile("test.sqlite"); deleteFile("test.sqlite-wal"); @@ -10899,7 +10873,7 @@ ACTOR Future doPrefixInsertComparison(int suffixSize, state IKeyValueStore* sqlite = openKVStore(KeyValueStoreType::SSD_BTREE_V2, "test.sqlite", UID(), 0); wait(prefixClusteredInsert(sqlite, suffixSize, valueSize, source, recordCountTarget, usePrefixesInOrder, true)); wait(closeKVS(sqlite)); - printf("\n"); + fmt::println(""); return Void(); } @@ -10935,7 +10909,7 @@ TEST_CASE(":/redwood/performance/sequentialInsert") { state IKeyValueStore* redwood = openKVStore(KeyValueStoreType::SSD_REDWOOD_V1, "test.redwood-v1", UID(), 0); wait(sequentialInsert(redwood, prefixLen, valueSize, recordCountTarget)); wait(closeKVS(redwood)); - printf("\n"); + fmt::println(""); return Void(); } @@ -10951,11 +10925,11 @@ ACTOR Future randomRangeScans(IKeyValueStore* kvs, int byteLimit, Optional options = Optional()) { fmt::print("\nstoreType: {}\n", static_cast(kvs->getType())); - fmt::print("prefixSource: {}\n", source.toString()); - fmt::print("suffixSize: {}\n", suffixSize); - fmt::print("recordCountTarget: {}\n", recordCountTarget); - fmt::print("singlePrefix: {}\n", singlePrefix); - fmt::print("rowLimit: {}\n", rowLimit); + fmt::println("prefixSource: {}", source.toString()); + fmt::println("suffixSize: {}", suffixSize); + fmt::println("recordCountTarget: {}", recordCountTarget); + fmt::println("singlePrefix: {}", singlePrefix); + fmt::println("rowLimit: {}", rowLimit); state int64_t recordSize = source.prefixLen + suffixSize + valueSize; state int64_t bytesRead = 0; @@ -10966,15 +10940,15 @@ ACTOR Future randomRangeScans(IKeyValueStore* kvs, state double start = timer(); state std::function stats = [&]() { double elapsed = timer() - start; - fmt::print("Cumulative stats: {0:.2f} seconds {1} queries {2:.2f} MB {3} records {4:.2f} qps {5:.2f} MB/s " - "{6:.2f} rec/s\r\n", - elapsed, - queries, - bytesRead / 1e6, - recordsRead, - queries / elapsed, - bytesRead / elapsed / 1e6, - recordsRead / elapsed); + fmt::println("Cumulative stats: {0:.2f} seconds {1} queries {2:.2f} MB {3} records {4:.2f} qps {5:.2f} MB/s " + "{6:.2f} rec/s\r", + elapsed, + queries, + bytesRead / 1e6, + recordsRead, + queries / elapsed, + bytesRead / elapsed / 1e6, + recordsRead / elapsed); fflush(stdout); }; @@ -10996,7 +10970,7 @@ ACTOR Future randomRangeScans(IKeyValueStore* kvs, } stats(); - printf("\n"); + fmt::println(""); return Void(); } @@ -11027,7 +11001,7 @@ TEST_CASE(":/redwood/performance/randomRangeScans") { wait(randomRangeScans(redwood, suffixSize, source, valueSize, queryRecordTarget, false, 10000, maxByteLimit)); wait(randomRangeScans(redwood, suffixSize, source, valueSize, queryRecordTarget, false, 1000000, maxByteLimit)); wait(closeKVS(redwood)); - printf("\n"); + fmt::println(""); return Void(); } diff --git a/fdbserver/fdbserver.actor.cpp b/fdbserver/fdbserver.actor.cpp index 02185dccfc0..cfe228e2472 100644 --- a/fdbserver/fdbserver.actor.cpp +++ b/fdbserver/fdbserver.actor.cpp @@ -370,7 +370,7 @@ UID getSharedMemoryMachineId() { if (++numTries == 10) criticalError(FDB_EXIT_ERROR, "SharedMemoryError", - format("Could not open shared memory - %s", ex.what()).c_str()); + fmt::format("Could not open shared memory - {}", ex.what()).c_str()); } } } @@ -380,7 +380,7 @@ UID getSharedMemoryMachineId() { ACTOR void failAfter(Future trigger, ISimulator::ProcessInfo* m = g_simulator->getCurrentProcess()) { wait(trigger); if (enableFailures) { - printf("Killing machine: %s at %f\n", m->address.toString().c_str(), now()); + fmt::println("Killing machine: {} at {:f}", m->address.toString(), now()); g_simulator->killProcess(m, ISimulator::KillType::KillInstantly); } } @@ -468,14 +468,14 @@ void testSerializationSpeed() { deallocate += timer() - tstart; } double elapsed = (timer() - testBegin); - printf("Test speed: %0.1f MB/sec (%0.0f/sec)\n", bytes / 1e6 / elapsed, 1000000 / elapsed); - printf(" Build: %0.1f MB/sec\n", bytes / 1e6 / build); - printf(" Serialize: %0.1f MB/sec\n", bytes / 1e6 / serialize); - printf(" Copy: %0.1f MB/sec\n", bytes / 1e6 / copy); - printf(" Deserialize: %0.1f MB/sec\n", bytes / 1e6 / deserialize); - printf(" Deallocate: %0.1f MB/sec\n", bytes / 1e6 / deallocate); - printf(" Bytes: %0.1f MB\n", bytes / 1e6); - printf("\n"); + fmt::println("Test speed: {:.1f} MB/sec ({:.0f}/sec)", bytes / 1e6 / elapsed, 1000000 / elapsed); + fmt::println(" Build: {:.1f} MB/sec", bytes / 1e6 / build); + fmt::println(" Serialize: {:.1f} MB/sec", bytes / 1e6 / serialize); + fmt::println(" Copy: {:.1f} MB/sec", bytes / 1e6 / copy); + fmt::println(" Deserialize: {:.1f} MB/sec", bytes / 1e6 / deserialize); + fmt::println(" Deallocate: {:.1f} MB/sec", bytes / 1e6 / deallocate); + fmt::println(" Bytes: {:.1f} MB", bytes / 1e6); + fmt::println(""); } std::string toHTML(const StringRef& binaryString) { @@ -496,7 +496,7 @@ std::string toHTML(const StringRef& binaryString) { else if (c > 32 && c < 127) s += c; else - s += format("[%02x]", c); + s += fmt::format("[{:02x}]", c); } return s; @@ -510,7 +510,7 @@ ACTOR Future dumpDatabase(Database cx, std::string outputFilename, KeyRang try { state KeySelectorRef iter = firstGreaterOrEqual(range.begin); state Arena arena; - fprintf(output, "\n"); + fmt::println(output, ""); Version ver = wait(tr.getReadVersion()); fprintf(output, "

Database version: %" PRId64 "

", ver); @@ -518,13 +518,13 @@ ACTOR Future dumpDatabase(Database cx, std::string outputFilename, KeyRang RangeResult results = wait(tr.getRange(iter, firstGreaterOrEqual(range.end), 1000)); for (int r = 0; r < results.size(); r++) { std::string key = toHTML(results[r].key), value = toHTML(results[r].value); - fprintf(output, "

%s := %s

\n", key.c_str(), value.c_str()); + fmt::println(output, "

{} := {}

", key, value); } if (results.size() < 1000) break; iter = firstGreaterThan(KeyRef(arena, results[results.size() - 1].key)); } - fprintf(output, ""); + fmt::print(output, ""); fclose(output); TraceEvent("DatabaseDumped").detail("Filename", outputFilename); return Void(); @@ -577,28 +577,28 @@ void* parentWatcher(void* arg) { #endif static void printBuildInformation() { - printf("%s", jsonBuildInformation().c_str()); + fmt::print("{}", jsonBuildInformation()); } static void printVersion() { printf("FoundationDB " FDB_VT_PACKAGE_NAME " (v" FDB_VT_VERSION ")\n"); - printf("source version %s\n", getSourceVersion()); + fmt::println("source version {}", getSourceVersion()); printf("protocol %" PRIx64 "\n", currentProtocolVersion().version()); #ifdef WITH_ROCKSDB if (FDB_ROCKSDB_GIT_HASH[0] != '\0') { - printf("rocksdb %d.%d.%d (commit %s)\n", - FDB_ROCKSDB_MAJOR, - FDB_ROCKSDB_MINOR, - FDB_ROCKSDB_PATCH, - FDB_ROCKSDB_GIT_HASH); + fmt::println("rocksdb {}.{}.{} (commit {})", + FDB_ROCKSDB_MAJOR, + FDB_ROCKSDB_MINOR, + FDB_ROCKSDB_PATCH, + FDB_ROCKSDB_GIT_HASH); } else { - printf("rocksdb %d.%d.%d\n", FDB_ROCKSDB_MAJOR, FDB_ROCKSDB_MINOR, FDB_ROCKSDB_PATCH); + fmt::println("rocksdb {}.{}.{}", FDB_ROCKSDB_MAJOR, FDB_ROCKSDB_MINOR, FDB_ROCKSDB_PATCH); } #endif } static void printHelpTeaser(const char* name) { - fprintf(stderr, "Try `%s --help' for more information.\n", name); + fmt::println(stderr, "Try `{} --help' for more information.", name); } static void printOptionUsage(std::string option, std::string description) { @@ -613,7 +613,7 @@ static void printOptionUsage(std::string option, std::string description) { std::stringstream sstream(description); if (sstream.eof()) { - printf("%s", result.c_str()); + fmt::print("{}", result); return; } @@ -636,12 +636,12 @@ static void printOptionUsage(std::string option, std::string description) { } result += currLine + '\n'; - printf("%s", result.c_str()); + fmt::print("{}", result); } static void printUsage(const char* name, bool devhelp) { printf("FoundationDB " FDB_VT_PACKAGE_NAME " (v" FDB_VT_VERSION ")\n"); - printf("Usage: %s -p ADDRESS [OPTIONS]\n\n", name); + fmt::print("Usage: {} -p ADDRESS [OPTIONS]\n\n", name); printOptionUsage("-p ADDRESS, --public-address ADDRESS", " Public address, specified as `IP_ADDRESS:PORT' or `auto:PORT'."); printOptionUsage("-l ADDRESS, --listen-address ADDRESS", @@ -725,11 +725,11 @@ static void printUsage(const char* name, bool devhelp) { " collector -- None or FluentD (FluentD requires collector_endpoint to be set)\n" " collector_endpoint -- IP:PORT of the fluentd server\n" " collector_protocol -- UDP or TCP (default is UDP)"); - printf("%s", TLS_HELP); + fmt::print("{}", TLS_HELP); printOptionUsage("-v, --version", "Print version information and exit."); printOptionUsage("-h, -?, --help", "Display this help and exit."); if (devhelp) { - printf(" --build-flags Print build information and exit.\n"); + fmt::println(" --build-flags Print build information and exit."); printOptionUsage("-r ROLE, --role ROLE", " Server role (valid options are fdbd, test, multitest," " simulation, networktestclient, networktestserver, restore" @@ -798,32 +798,26 @@ static void printUsage(const char* name, bool devhelp) { printOptionUsage("--use-future-protocol-version [true,false]", " Run the process with a simulated future protocol version." " This option can be used testing purposes only!"); - printf("\n" - "The 'kvfiledump' role dump all key-values from kvfile to stdout in binary format:\n" - "{key length}{key binary}{value length}{value binary}, length is 4 bytes int\n" - "(little endianness). This role takes 3 environment variables as parameters:\n" - " - FDB_DUMP_STARTKEY: start key for the dump, default is empty\n" - " - FDB_DUMP_ENDKEY: end key for the dump, default is \"\\xff\\xff\"\n" - " - FDB_DUMP_DEBUG: print key-values to stderr in escaped format\n"); - - printf( - "\n" - "The 'changedescription' role replaces the old cluster key in all coordinators' data file to the specified " - "new cluster key,\n" - "which is passed in by '--new-cluster-key'. In particular, cluster key means '[description]:[id]'.\n" - "'--datadir' is supposed to point to the top level directory of FDB's data, where subdirectories are for " - "each process's data.\n" - "The given cluster file passed in by '-C, --cluster-file' is considered to contain the old cluster key.\n" - "It is used before restoring a snapshotted cluster to let the cluster have a different cluster key.\n" - "Please make sure run it on every host in the cluster with the same '--new-cluster-key'.\n"); + fmt::print("\nThe 'kvfiledump' role dump all key-values from kvfile to stdout in binary format:\n{{key " + "length}}{{key binary}}{{value length}}{{value binary}}, length is 4 bytes int\n(little " + "endianness). This role takes 3 environment variables as parameters:\n - FDB_DUMP_STARTKEY: start " + "key for the dump, default is empty\n - FDB_DUMP_ENDKEY: end key for the dump, default is " + "\"\\xff\\xff\"\n - FDB_DUMP_DEBUG: print key-values to stderr in escaped format\n"); + + fmt::print("\nThe 'changedescription' role replaces the old cluster key in all coordinators' data file to the " + "specified new cluster key,\nwhich is passed in by '--new-cluster-key'. In particular, cluster key " + "means '[description]:[id]'.\n'--datadir' is supposed to point to the top level directory of FDB's " + "data, where subdirectories are for each process's data.\nThe given cluster file passed in by '-C, " + "--cluster-file' is considered to contain the old cluster key.\nIt is used before restoring a " + "snapshotted cluster to let the cluster have a different cluster key.\nPlease make sure run it on " + "every host in the cluster with the same '--new-cluster-key'.\n"); } else { printOptionUsage("--dev-help", "Display developer-specific help and exit."); } - printf("\n" - "SIZE parameters may use one of the multiplicative suffixes B=1, KB=10^3,\n" - "KiB=2^10, MB=10^6, MiB=2^20, GB=10^9, GiB=2^30, TB=10^12, or TiB=2^40.\n"); + fmt::print("\nSIZE parameters may use one of the multiplicative suffixes B=1, KB=10^3,\nKiB=2^10, MB=10^6, " + "MiB=2^20, GB=10^9, GiB=2^30, TB=10^12, or TiB=2^40.\n"); } extern bool g_crashOnError; @@ -908,7 +902,7 @@ Optional checkBuggifyOverride(const char* testFile) { ifs.close(); return false; } else { - fprintf(stderr, "ERROR: Unknown buggify override state `%s'\n", value.c_str()); + fmt::println(stderr, "ERROR: Unknown buggify override state `{}'", value); flushAndExit(FDB_EXIT_ERROR); } } @@ -949,7 +943,7 @@ Optional checkFaultInjectionOverride(const char* testFile) { ifs.close(); return false; } else { - fprintf(stderr, "ERROR: Unknown fault injection override state `%s'\n", value.c_str()); + fmt::println(stderr, "ERROR: Unknown fault injection override state `{}'", value); flushAndExit(FDB_EXIT_ERROR); } } @@ -966,14 +960,15 @@ std::pair buildNetworkAddresses( const std::vector& publicAddressStrs, std::vector& listenAddressStrs) { if (listenAddressStrs.size() > 0 && publicAddressStrs.size() != listenAddressStrs.size()) { - fprintf(stderr, - "ERROR: Listen addresses (if provided) should be equal to the number of public addresses in order.\n"); + fmt::println( + stderr, + "ERROR: Listen addresses (if provided) should be equal to the number of public addresses in order."); flushAndExit(FDB_EXIT_ERROR); } listenAddressStrs.resize(publicAddressStrs.size(), "public"); if (publicAddressStrs.size() > 2) { - fprintf(stderr, "ERROR: maximum 2 public/listen addresses are allowed\n"); + fmt::println(stderr, "ERROR: maximum 2 public/listen addresses are allowed"); flushAndExit(FDB_EXIT_ERROR); } @@ -994,19 +989,19 @@ std::pair buildNetworkAddresses( const IPAddress publicIP = connectionRecord.getConnectionString().determineLocalSourceIP(); currentPublicAddress = NetworkAddress(publicIP, parsedAddress.port, true, parsedAddress.isTLS()); } catch (Error& e) { - fprintf(stderr, - "ERROR: could not determine public address automatically from `%s': %s\n", - publicAddressStr.c_str(), - e.what()); + fmt::println(stderr, + "ERROR: could not determine public address automatically from `{}': {}", + publicAddressStr, + e.what()); throw; } } else { try { currentPublicAddress = NetworkAddress::parse(publicAddressStr); } catch (Error&) { - fprintf(stderr, - "ERROR: Could not parse network address `%s' (specify as IP_ADDRESS:PORT)\n", - publicAddressStr.c_str()); + fmt::println(stderr, + "ERROR: Could not parse network address `{}' (specify as IP_ADDRESS:PORT)", + publicAddressStr); throw; } } @@ -1018,7 +1013,7 @@ std::pair buildNetworkAddresses( } if (!currentPublicAddress.isValid()) { - fprintf(stderr, "ERROR: %s is not a valid IP address\n", currentPublicAddress.toString().c_str()); + fmt::println(stderr, "ERROR: {} is not a valid IP address", currentPublicAddress.toString()); flushAndExit(FDB_EXIT_ERROR); } @@ -1030,17 +1025,18 @@ std::pair buildNetworkAddresses( try { currentListenAddress = NetworkAddress::parse(listenAddressStr); } catch (Error&) { - fprintf(stderr, - "ERROR: Could not parse network address `%s' (specify as IP_ADDRESS:PORT)\n", - listenAddressStr.c_str()); + fmt::println(stderr, + "ERROR: Could not parse network address `{}' (specify as IP_ADDRESS:PORT)", + listenAddressStr); throw; } if (currentListenAddress.isTLS() != currentPublicAddress.isTLS()) { - fprintf(stderr, - "ERROR: TLS state of listen address: %s is not equal to the TLS state of public address: %s.\n", - listenAddressStr.c_str(), - publicAddressStr.c_str()); + fmt::println( + stderr, + "ERROR: TLS state of listen address: {} is not equal to the TLS state of public address: {}.", + listenAddressStr, + publicAddressStr); flushAndExit(FDB_EXIT_ERROR); } } @@ -1071,16 +1067,15 @@ std::pair buildNetworkAddresses( }); } if (!matchCoordinatorsTls) { - fprintf(stderr, - "ERROR: TLS state of public address %s does not match in coordinator list.\n", - publicAddressStr.c_str()); + fmt::println( + stderr, "ERROR: TLS state of public address {} does not match in coordinator list.", publicAddressStr); flushAndExit(FDB_EXIT_ERROR); } } if (publicNetworkAddresses.secondaryAddress.present() && publicNetworkAddresses.address.isTLS() == publicNetworkAddresses.secondaryAddress.get().isTLS()) { - fprintf(stderr, "ERROR: only one public address of each TLS state is allowed.\n"); + fmt::println(stderr, "ERROR: only one public address of each TLS state is allowed."); flushAndExit(FDB_EXIT_ERROR); } @@ -1227,7 +1222,7 @@ struct CLIOptions { if (role == ServerRole::ConsistencyCheck || role == ServerRole::ConsistencyCheckUrgent) { if (!publicAddressStrs.empty()) { - fprintf(stderr, "ERROR: Public address cannot be specified for consistency check processes\n"); + fmt::println(stderr, "ERROR: Public address cannot be specified for consistency check processes"); printHelpTeaser(name); flushAndExit(FDB_EXIT_ERROR); } @@ -1243,10 +1238,8 @@ struct CLIOptions { for (const std::string& knob : getEnvironmentKnobOptions()) { auto pos = knob.find_first_of("="); if (pos == std::string::npos) { - fprintf(stderr, - "Error: malformed environment knob option: %s%s\n", - ENVIRONMENT_KNOB_OPTION_PREFIX, - knob.c_str()); + fmt::println( + stderr, "Error: malformed environment knob option: {}{}", ENVIRONMENT_KNOB_OPTION_PREFIX, knob); TraceEvent(SevWarnAlways, "MalformedEnvironmentVariableKnob") .detail("Key", ENVIRONMENT_KNOB_OPTION_PREFIX + knob); } else { @@ -1259,7 +1252,7 @@ struct CLIOptions { void parseArgsInternal(int argc, char* argv[]) { auto warnDeprecatedOption = [](const char* optionText) { - fprintf(stderr, "WARNING: option `%s' is deprecated and ignored\n", optionText); + fmt::println(stderr, "WARNING: option `{}' is deprecated and ignored", optionText); TraceEvent(SevWarnAlways, "DeprecatedCommandLineOption").detail("Option", optionText); }; @@ -1278,27 +1271,27 @@ struct CLIOptions { while (args.Next()) { if (args.LastError() == SO_ARG_INVALID_DATA) { - fprintf(stderr, "ERROR: invalid argument to option `%s'\n", args.OptionText()); + fmt::println(stderr, "ERROR: invalid argument to option `{}'", args.OptionText()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } if (args.LastError() == SO_ARG_INVALID) { - fprintf(stderr, "ERROR: argument given for option `%s'\n", args.OptionText()); + fmt::println(stderr, "ERROR: argument given for option `{}'", args.OptionText()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } if (args.LastError() == SO_ARG_MISSING) { - fprintf(stderr, "ERROR: missing argument for option `%s'\n", args.OptionText()); + fmt::println(stderr, "ERROR: missing argument for option `{}'", args.OptionText()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } if (args.LastError() == SO_OPT_INVALID) { - fprintf(stderr, "ERROR: unknown option: `%s'\n", args.OptionText()); + fmt::println(stderr, "ERROR: unknown option: `{}'", args.OptionText()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } if (args.LastError() != SO_SUCCESS) { - fprintf(stderr, "ERROR: error parsing options\n"); + fmt::println(stderr, "ERROR: error parsing options"); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1323,7 +1316,7 @@ struct CLIOptions { case OPT_KNOB: { Optional knobName = extractPrefixedArgument("--knob", args.OptionSyntax()); if (!knobName.present()) { - fprintf(stderr, "ERROR: unable to parse knob option '%s'\n", args.OptionSyntax()); + fmt::println(stderr, "ERROR: unable to parse knob option '{}'", args.OptionSyntax()); flushAndExit(FDB_EXIT_ERROR); } knobs.emplace_back(knobName.get(), args.OptionArg()); @@ -1332,7 +1325,7 @@ struct CLIOptions { case OPT_PROFILER: { Optional profilerArg = extractPrefixedArgument("--profiler", args.OptionSyntax()); if (!profilerArg.present()) { - fprintf(stderr, "ERROR: unable to parse profiler option '%s'\n", args.OptionSyntax()); + fmt::println(stderr, "ERROR: unable to parse profiler option '{}'", args.OptionSyntax()); flushAndExit(FDB_EXIT_ERROR); } profilerConfig.emplace(profilerArg.get(), args.OptionArg()); @@ -1341,7 +1334,7 @@ struct CLIOptions { case OPT_UNITTESTPARAM: { Optional testArg = extractPrefixedArgument("--test", args.OptionSyntax()); if (!testArg.present()) { - fprintf(stderr, "ERROR: unable to parse unit test option '%s'\n", args.OptionSyntax()); + fmt::println(stderr, "ERROR: unable to parse unit test option '{}'", args.OptionSyntax()); flushAndExit(FDB_EXIT_ERROR); } testParams.set(testArg.get(), args.OptionArg()); @@ -1350,7 +1343,7 @@ struct CLIOptions { case OPT_LOCALITY: { Optional localityKey = extractPrefixedArgument("--locality", args.OptionSyntax()); if (!localityKey.present()) { - fprintf(stderr, "ERROR: unable to parse locality key '%s'\n", args.OptionSyntax()); + fmt::println(stderr, "ERROR: unable to parse locality key '{}'", args.OptionSyntax()); flushAndExit(FDB_EXIT_ERROR); } Standalone key = StringRef(localityKey.get()); @@ -1361,7 +1354,7 @@ struct CLIOptions { case OPT_IP_TRUSTED_MASK: { Optional subnetKey = extractPrefixedArgument("--trusted-subnet", args.OptionSyntax()); if (!subnetKey.present()) { - fprintf(stderr, "ERROR: unable to parse locality key '%s'\n", args.OptionSyntax()); + fmt::println(stderr, "ERROR: unable to parse locality key '{}'", args.OptionSyntax()); flushAndExit(FDB_EXIT_ERROR); } allowList.addTrustedSubnet(args.OptionArg()); @@ -1427,7 +1420,7 @@ struct CLIOptions { else if (!strcmp(sRole, "mocks3server")) role = ServerRole::MockS3Server; else { - fprintf(stderr, "ERROR: Unknown role `%s'\n", sRole); + fmt::println(stderr, "ERROR: Unknown role `{}'", sRole); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1470,7 +1463,7 @@ struct CLIOptions { char* end; rsssize = strtoull(a, &end, 10); if (*end) { - fprintf(stderr, "ERROR: Unrecognized memory size `%s'\n", a); + fmt::println(stderr, "ERROR: Unrecognized memory size `{}'", a); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1491,7 +1484,7 @@ struct CLIOptions { useNet2 = true; useThreadPool = true; } else { - fprintf(stderr, "ERROR: Unknown network implementation `%s'\n", a); + fmt::println(stderr, "ERROR: Unknown network implementation `{}'", a); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1504,7 +1497,7 @@ struct CLIOptions { else if (!strcmp(a, "now")) g_trace_clock.store(TRACE_CLOCK_NOW); else { - fprintf(stderr, "ERROR: Unknown clock source `%s'\n", a); + fmt::println(stderr, "ERROR: Unknown clock source `{}'", a); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1513,7 +1506,7 @@ struct CLIOptions { case OPT_NUMTESTERS: { const char* a = args.OptionArg(); if (!sscanf(a, "%d", &minTesterCount)) { - fprintf(stderr, "ERROR: Could not parse numtesters `%s'\n", a); + fmt::println(stderr, "ERROR: Could not parse numtesters `{}'", a); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1523,7 +1516,7 @@ struct CLIOptions { const char* a = args.OptionArg(); ti = parse_with_suffix(a); if (!ti.present()) { - fprintf(stderr, "ERROR: Could not parse logsize `%s'\n", a); + fmt::println(stderr, "ERROR: Could not parse logsize `{}'", a); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1535,7 +1528,7 @@ struct CLIOptions { const char* a = args.OptionArg(); ti = parse_with_suffix(a); if (!ti.present()) { - fprintf(stderr, "ERROR: Could not parse maxlogssize `%s'\n", a); + fmt::println(stderr, "ERROR: Could not parse maxlogssize `{}'", a); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1548,7 +1541,7 @@ struct CLIOptions { char* end; maxLogs = strtoull(a, &end, 10); if (*end) { - fprintf(stderr, "ERROR: Unrecognized maximum number of logs `%s'\n", a); + fmt::println(stderr, "ERROR: Unrecognized maximum number of logs `{}'", a); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1562,7 +1555,8 @@ struct CLIOptions { auto pHandle = OpenProcess(SYNCHRONIZE, FALSE, parent_pid); if (!pHandle) { TraceEvent("ParentProcessOpenError").GetLastError(); - fprintf(stderr, "Could not open parent process at pid %d (error %d)", parent_pid, GetLastError()); + fmt::print( + stderr, "Could not open parent process at pid {} (error {})", parent_pid, GetLastError()); throw platform_error(); } startThread(&parentWatcher, pHandle, 0, "fdb-parentwatch"); @@ -1598,7 +1592,7 @@ struct CLIOptions { } else if (tracer == "network_lossy") { openTracer(TracerType::NETWORK_LOSSY); } else { - fprintf(stderr, "ERROR: Unknown or unsupported tracer: `%s'", args.OptionArg()); + fmt::print(stderr, "ERROR: Unknown or unsupported tracer: `{}'", args.OptionArg()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1617,7 +1611,7 @@ struct CLIOptions { char* end; randomSeed = (uint32_t)strtoul(args.OptionArg(), &end, 0); if (*end) { - fprintf(stderr, "ERROR: Could not parse random seed `%s'\n", args.OptionArg()); + fmt::println(stderr, "ERROR: Could not parse random seed `{}'", args.OptionArg()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1627,7 +1621,7 @@ struct CLIOptions { char* end; reseedTime = strtod(args.OptionArg(), &end); if (*end || reseedTime < 0) { - fprintf(stderr, "ERROR: Could not parse reseed time `%s' (must be >= 0)\n", args.OptionArg()); + fmt::println(stderr, "ERROR: Could not parse reseed time `{}' (must be >= 0)", args.OptionArg()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1645,7 +1639,7 @@ struct CLIOptions { sRole = args.OptionArg(); processClass = ProcessClass(sRole, ProcessClass::CommandLineSource); if (processClass == ProcessClass::InvalidClass) { - fprintf(stderr, "ERROR: Unknown machine class `%s'\n", sRole); + fmt::println(stderr, "ERROR: Unknown machine class `{}'", sRole); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1656,7 +1650,7 @@ struct CLIOptions { case OPT_MEMLIMIT: ti = parse_with_suffix(args.OptionArg(), "MiB"); if (!ti.present()) { - fprintf(stderr, "ERROR: Could not parse memory limit from `%s'\n", args.OptionArg()); + fmt::println(stderr, "ERROR: Could not parse memory limit from `{}'", args.OptionArg()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1665,7 +1659,7 @@ struct CLIOptions { case OPT_VMEMLIMIT: ti = parse_with_suffix(args.OptionArg(), "MiB"); if (!ti.present()) { - fprintf(stderr, "ERROR: Could not parse virtual memory limit from `%s'\n", args.OptionArg()); + fmt::println(stderr, "ERROR: Could not parse virtual memory limit from `{}'", args.OptionArg()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1674,7 +1668,7 @@ struct CLIOptions { case OPT_STORAGEMEMLIMIT: ti = parse_with_suffix(args.OptionArg(), "MB"); if (!ti.present()) { - fprintf(stderr, "ERROR: Could not parse storage memory limit from `%s'\n", args.OptionArg()); + fmt::println(stderr, "ERROR: Could not parse storage memory limit from `{}'", args.OptionArg()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1683,7 +1677,7 @@ struct CLIOptions { case OPT_CACHEMEMLIMIT: ti = parse_with_suffix(args.OptionArg(), "MiB"); if (!ti.present()) { - fprintf(stderr, "ERROR: Could not parse cache memory limit from `%s'\n", args.OptionArg()); + fmt::println(stderr, "ERROR: Could not parse cache memory limit from `{}'", args.OptionArg()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1691,8 +1685,8 @@ struct CLIOptions { // parameter knobs.emplace_back( "page_cache_4k", - format("%lld", ti.get() / 4096 * 4096)); // The cache holds 4K pages, so we can truncate this to the - // next smaller multiple of 4K. + fmt::format("{}", ti.get() / 4096 * 4096)); // The cache holds 4K pages, so we can truncate this to + // the next smaller multiple of 4K. break; case OPT_BUGGIFY: if (!strcmp(args.OptionArg(), "on")) @@ -1700,7 +1694,7 @@ struct CLIOptions { else if (!strcmp(args.OptionArg(), "off")) buggifyEnabled = false; else { - fprintf(stderr, "ERROR: Unknown buggify state `%s'\n", args.OptionArg()); + fmt::println(stderr, "ERROR: Unknown buggify state `{}'", args.OptionArg()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1711,7 +1705,7 @@ struct CLIOptions { else if (!strcmp(args.OptionArg(), "off")) faultInjectionEnabled = false; else { - fprintf(stderr, "ERROR: Unknown fault injection state `%s'\n", args.OptionArg()); + fmt::println(stderr, "ERROR: Unknown fault injection state `{}'", args.OptionArg()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1737,7 +1731,7 @@ struct CLIOptions { case OPT_IO_TRUST_SECONDS: { const char* a = args.OptionArg(); if (!sscanf(a, "%lf", &fileIoTimeout)) { - fprintf(stderr, "ERROR: Could not parse io_trust_seconds `%s'\n", a); + fmt::println(stderr, "ERROR: Could not parse io_trust_seconds `{}'", a); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1748,7 +1742,7 @@ struct CLIOptions { break; case OPT_TRACE_FORMAT: if (!selectTraceFormatter(args.OptionArg())) { - fprintf(stderr, "WARNING: Unrecognized trace format `%s'\n", args.OptionArg()); + fmt::println(stderr, "WARNING: Unrecognized trace format `{}'", args.OptionArg()); } break; case OPT_WHITELIST_BINPATH: @@ -1764,7 +1758,7 @@ struct CLIOptions { case OPT_PROXY: proxy = args.OptionArg(); if (!Hostname::isHostname(proxy.get()) && !NetworkAddress::parseOptional(proxy.get()).present()) { - fprintf(stderr, "ERROR: proxy format should be either IP:port or host:port\n"); + fmt::println(stderr, "ERROR: proxy format should be either IP:port or host:port"); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1887,7 +1881,7 @@ struct CLIOptions { if (proxyENV != nullptr && !proxy.present()) { proxy = proxyENV; if (!Hostname::isHostname(proxy.get()) && !NetworkAddress::parseOptional(proxy.get()).present()) { - fprintf(stderr, "ERROR: proxy format should be either IP:port or host:port\n"); + fmt::println(stderr, "ERROR: proxy format should be either IP:port or host:port"); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1899,22 +1893,23 @@ struct CLIOptions { try { ProfilerConfig::instance().reset(profilerConfig); } catch (ConfigError& e) { - printf("Error setting up profiler: %s", e.description.c_str()); + fmt::print("Error setting up profiler: {}", e.description); flushAndExit(FDB_EXIT_ERROR); } if (seedConnString.length() && seedConnFile.length()) { - fprintf( - stderr, "%s\n", "--seed-cluster-file and --seed-connection-string may not both be specified at once."); + fmt::println( + stderr, "{}", "--seed-cluster-file and --seed-connection-string may not both be specified at once."); flushAndExit(FDB_EXIT_ERROR); } bool seedSpecified = seedConnFile.length() || seedConnString.length(); if (seedSpecified && !connFile.length()) { - fprintf(stderr, - "%s\n", - "If -seed-cluster-file or --seed-connection-string is specified, -C must be specified as well."); + fmt::println( + stderr, + "{}", + "If -seed-cluster-file or --seed-connection-string is specified, -C must be specified as well."); flushAndExit(FDB_EXIT_ERROR); } @@ -1922,7 +1917,7 @@ struct CLIOptions { metricsConnFile = ""; if (metricsConnFile != "" && metricsPrefix == "") { - fprintf(stderr, "If a metrics cluster file is specified, a metrics prefix is required.\n"); + fmt::println(stderr, "If a metrics cluster file is specified, a metrics prefix is required."); flushAndExit(FDB_EXIT_ERROR); } @@ -1942,9 +1937,9 @@ struct CLIOptions { try { connectionString = readFileBytes(seedConnFile, MAX_CLUSTER_FILE_BYTES); } catch (Error& e) { - fprintf(stderr, - "%s\n", - ClusterConnectionFile::getErrorString(std::make_pair(seedConnFile, false), e).c_str()); + fmt::println(stderr, + "{}", + ClusterConnectionFile::getErrorString(std::make_pair(seedConnFile, false), e)); throw; } } @@ -1952,7 +1947,7 @@ struct CLIOptions { try { ccs = ClusterConnectionString(connectionString); } catch (Error& e) { - fprintf(stderr, "%s\n", ClusterConnectionString::getErrorString(connectionString, e).c_str()); + fmt::println(stderr, "{}", ClusterConnectionString::getErrorString(connectionString, e)); throw; } connectionFile = makeReference(connFile, ccs); @@ -1962,7 +1957,7 @@ struct CLIOptions { resolvedClusterFile = ClusterConnectionFile::lookupClusterFileName(connFile); connectionFile = makeReference(resolvedClusterFile.first); } catch (Error& e) { - fprintf(stderr, "%s\n", ClusterConnectionFile::getErrorString(resolvedClusterFile, e).c_str()); + fmt::println(stderr, "{}", ClusterConnectionFile::getErrorString(resolvedClusterFile, e)); throw; } } @@ -1981,13 +1976,13 @@ struct CLIOptions { } if (role == ServerRole::SearchMutations && !targetKey) { - fprintf(stderr, "ERROR: please specify a target key\n"); + fmt::println(stderr, "ERROR: please specify a target key"); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } if (role == ServerRole::NetworkTestClient && !testServersStr.size()) { - fprintf(stderr, "ERROR: please specify --testservers\n"); + fmt::println(stderr, "ERROR: please specify --testservers"); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -1995,10 +1990,10 @@ struct CLIOptions { if (role == ServerRole::ChangeClusterKey) { bool error = false; if (!newClusterKey.size()) { - fprintf(stderr, "ERROR: please specify --new-cluster-key\n"); + fmt::println(stderr, "ERROR: please specify --new-cluster-key"); error = true; } else if (connectionFile->getConnectionString().clusterKey() == newClusterKey) { - fprintf(stderr, "ERROR: the new cluster key is the same as the old one\n"); + fmt::println(stderr, "ERROR: the new cluster key is the same as the old one"); error = true; } if (error) { @@ -2047,16 +2042,15 @@ bool validateSimulationDataFiles(std::string const& dataFolder, bool isRestartin for (const auto& file : files) { if (file != "restartInfo.ini" && file != getTestEncryptionFileName()) { TraceEvent(SevError, "IncompatibleFileFound").detail("DataFolder", dataFolder).detail("FileName", file); - fprintf(stderr, - "ERROR: Data folder `%s' is non-empty; please use clean, fdb-only folder\n", - dataFolder.c_str()); + fmt::println( + stderr, "ERROR: Data folder `{}' is non-empty; please use clean, fdb-only folder", dataFolder); return false; } } } else if (isRestarting && files.empty()) { TraceEvent(SevWarnAlways, "FileNotFound").detail("DataFolder", dataFolder); - printf("ERROR: Data folder `%s' is empty, but restarting option selected. Run Phase 1 test first\n", - dataFolder.c_str()); + fmt::println("ERROR: Data folder `{}' is empty, but restarting option selected. Run Phase 1 test first", + dataFolder); return false; } @@ -2087,12 +2081,12 @@ int main(int argc, char* argv[]) { const auto role = opts.role; if (role == ServerRole::Simulation) { - printf("Random seed is %u...\n", opts.randomSeed); + fmt::println("Random seed is {}...", opts.randomSeed); bindDeterministicRandomToOpenssl(); } if (opts.zoneId.present()) - printf("ZoneId set to %s, dcId to %s\n", printable(opts.zoneId).c_str(), printable(opts.dcId).c_str()); + fmt::println("ZoneId set to {}, dcId to {}", printable(opts.zoneId), printable(opts.dcId)); if (opts.buggifyEnabled) { enableGeneralBuggify(); @@ -2120,9 +2114,9 @@ int main(int argc, char* argv[]) { if (!SERVER_KNOBS->ALLOW_DANGEROUS_KNOBS) { if (SERVER_KNOBS->REMOTE_KV_STORE) { - fprintf(stderr, - "ERROR : explicitly setting REMOTE_KV_STORE is dangerous! set ALLOW_DANGEROUS_KNOBS to " - "proceed anyways\n"); + fmt::println(stderr, + "ERROR : explicitly setting REMOTE_KV_STORE is dangerous! set ALLOW_DANGEROUS_KNOBS to " + "proceed anyways"); flushAndExit(FDB_EXIT_ERROR); } } @@ -2131,12 +2125,12 @@ int main(int argc, char* argv[]) { EvictablePageCache::evictionPolicyStringToEnum(FLOW_KNOBS->CACHE_EVICTION_POLICY); if (opts.memLimit > 0 && opts.virtualMemLimit > 0 && opts.memLimit > opts.virtualMemLimit) { - fprintf(stderr, "ERROR : --memory-vsize has to be no less than --memory"); + fmt::print(stderr, "ERROR : --memory-vsize has to be no less than --memory"); flushAndExit(FDB_EXIT_ERROR); } if (opts.memLimit > 0 && opts.memLimit <= FLOW_KNOBS->PAGE_CACHE_4K) { - fprintf(stderr, "ERROR: --memory has to be larger than --cache-memory\n"); + fmt::println(stderr, "ERROR: --memory has to be larger than --cache-memory"); flushAndExit(FDB_EXIT_ERROR); } @@ -2208,7 +2202,7 @@ int main(int argc, char* argv[]) { role == ServerRole::FlowProcess || role == ServerRole::MockS3Server); if (opts.publicAddressStrs.empty()) { if (expectsPublicAddress) { - fprintf(stderr, "ERROR: The -p or --public-address option is required\n"); + fmt::println(stderr, "ERROR: The -p or --public-address option is required"); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -2252,11 +2246,11 @@ int main(int argc, char* argv[]) { errorF.get(); } catch (Error& e) { TraceEvent("BindError").error(e); - fprintf(stderr, - "Error initializing networking with public address %s and listen address %s (%s)\n", - publicAddress.toString().c_str(), - listenAddress.toString().c_str(), - e.what()); + fmt::println(stderr, + "Error initializing networking with public address {} and listen address {} ({})", + publicAddress.toString(), + listenAddress.toString(), + e.what()); printHelpTeaser(argv[0]); flushAndExit(FDB_EXIT_ERROR); } @@ -2355,10 +2349,10 @@ int main(int argc, char* argv[]) { .detail("DataFolder", dataFolder) .detail("SuspiciousFile", dir); - fprintf(stderr, - "ERROR: Data folder `%s' had non fdb file `%s'; please use clean, fdb-only folder\n", - dataFolder.c_str(), - dir.c_str()); + fmt::println(stderr, + "ERROR: Data folder `{}' had non fdb file `{}'; please use clean, fdb-only folder", + dataFolder, + dir); flushAndExit(FDB_EXIT_ERROR); } @@ -2491,18 +2485,18 @@ int main(int argc, char* argv[]) { // Call fast restore for the class FastRestoreClass. This is a short-cut to run fast restore in circus if (opts.processClass == ProcessClass::FastRestoreClass) { - printf("Run as fast restore worker\n"); + fmt::println("Run as fast restore worker"); ASSERT(opts.connectionFile); auto dataFolder = opts.dataFolder; if (!dataFolder.size()) - dataFolder = format("fdb/%d/", opts.publicAddresses.address.port); // SOMEDAY: Better default + dataFolder = fmt::format("fdb/{}/", opts.publicAddresses.address.port); // SOMEDAY: Better default std::vector> actors(listenErrors.begin(), listenErrors.end()); actors.push_back(restoreWorker(opts.connectionFile, opts.localities, dataFolder)); f = stopAfter(waitForAll(actors)); - printf("Fast restore worker started\n"); + fmt::println("Fast restore worker started"); g_network->run(); - printf("g_network->run() done\n"); + fmt::println("g_network->run() done"); } else { // Call fdbd roles in conventional way ASSERT(opts.connectionFile); @@ -2510,7 +2504,7 @@ int main(int argc, char* argv[]) { auto dataFolder = opts.dataFolder; if (!dataFolder.size()) - dataFolder = format("fdb/%d/", opts.publicAddresses.address.port); // SOMEDAY: Better default + dataFolder = fmt::format("fdb/{}/", opts.publicAddresses.address.port); // SOMEDAY: Better default std::vector> actors(listenErrors.begin(), listenErrors.end()); @@ -2614,7 +2608,7 @@ int main(int argc, char* argv[]) { GenerateIOLogChecksumFile(opts.kvFile); result = Void(); } catch (Error& e) { - fprintf(stderr, "Fatal Error: %s\n", e.what()); + fmt::println(stderr, "Fatal Error: {}", e.what()); } f = result; @@ -2657,7 +2651,7 @@ int main(int argc, char* argv[]) { f = stopAfter(coordChangeClusterKey(opts.dataFolder, newClusterKey, oldClusterKey)); g_network->run(); } else if (role == ServerRole::MockS3Server) { - printf("Starting MockS3Server on %s\n", opts.publicAddresses.address.toString().c_str()); + fmt::println("Starting MockS3Server on {}", opts.publicAddresses.address.toString()); f = stopAfter(startMockS3ServerReal(opts.publicAddresses.address, opts.mocks3PersistenceDir)); g_network->run(); } @@ -2674,8 +2668,8 @@ int main(int argc, char* argv[]) { .detail("RandomUnseed", unseed); if (role == ServerRole::Simulation) { - printf("Unseed: %d\n", unseed); - printf("Elapsed: %f simsec, %f real seconds\n", now() - startNow, timer() - start); + fmt::println("Unseed: {}", unseed); + fmt::println("Elapsed: {:f} simsec, {:f} real seconds", now() - startNow, timer() - start); } // IFailureMonitor::failureMonitor().address_info.clear(); @@ -2713,7 +2707,7 @@ int main(int argc, char* argv[]) { if (role == ServerRole::Simulation) { unsigned long sevErrorEventsLogged = TraceEvent::CountEventsLoggedAt(SevError); if (sevErrorEventsLogged > 0) { - printf("%lu SevError events logged\n", sevErrorEventsLogged); + fmt::println("{} SevError events logged", sevErrorEventsLogged); rc = FDB_EXIT_ERROR; } } @@ -2758,12 +2752,12 @@ int main(int argc, char* argv[]) { for (int i = 0; i < typeNames.size(); i++) { const char* n = typeNames[i].second; auto& f = allocInstr[n]; - printf("%+d\t%+d\t%d\t%d\t%s\n", - f.allocCount, - -f.deallocCount, - f.allocCount - f.deallocCount, - f.maxAllocated, - typeNames[i].first.c_str()); + fmt::println("{:+}\t{:+}\t{}\t{}\t{}", + f.allocCount, + -f.deallocCount, + f.allocCount - f.deallocCount, + f.maxAllocated, + typeNames[i].first); } // We're about to exit and clean up data structures, this will wreak havoc on allocation recording @@ -2773,18 +2767,18 @@ int main(int argc, char* argv[]) { // printf("\n%d tests passed; %d tests failed\n", passCount, failCount); flushAndExit(rc); } catch (Error& e) { - fprintf(stderr, "Error: %s\n", e.what()); + fmt::println(stderr, "Error: {}", e.what()); TraceEvent(SevError, "MainError").error(e); // printf("\n%d tests passed; %d tests failed\n", passCount, failCount); flushAndExit(FDB_EXIT_MAIN_ERROR); } catch (boost::system::system_error& e) { ASSERT_WE_THINK(false); // boost errors shouldn't leak - fprintf(stderr, "boost::system::system_error: %s (%d)", e.what(), e.code().value()); + fmt::print(stderr, "boost::system::system_error: {} ({})", e.what(), e.code().value()); TraceEvent(SevError, "MainError").error(unknown_error()).detail("RootException", e.what()); // printf("\n%d tests passed; %d tests failed\n", passCount, failCount); flushAndExit(FDB_EXIT_MAIN_EXCEPTION); } catch (std::exception& e) { - fprintf(stderr, "std::exception: %s\n", e.what()); + fmt::println(stderr, "std::exception: {}", e.what()); TraceEvent(SevError, "MainError").error(unknown_error()).detail("RootException", e.what()); // printf("\n%d tests passed; %d tests failed\n", passCount, failCount); flushAndExit(FDB_EXIT_MAIN_EXCEPTION); diff --git a/fdbserver/include/fdbserver/ClusterController.actor.h b/fdbserver/include/fdbserver/ClusterController.actor.h index 2e17876184b..71522635e0b 100644 --- a/fdbserver/include/fdbserver/ClusterController.actor.h +++ b/fdbserver/include/fdbserver/ClusterController.actor.h @@ -39,6 +39,7 @@ #include "flow/NetworkAddress.h" #include "flow/SystemMonitor.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. struct WorkerInfo : NonCopyable { @@ -1614,7 +1615,10 @@ class ClusterControllerData { degraded == r.degraded; } - std::string toString() const { return format("%d %d %d %d %d", worstFit, worstUsed, count, degraded, bestFit); } + std::string toString() const { + return fmt::format( + "{} {} {} {} {}", static_cast(worstFit), worstUsed, count, degraded, static_cast(bestFit)); + } }; std::set>> getDatacenters(DatabaseConfiguration const& conf, diff --git a/fdbserver/include/fdbserver/DDRelocationQueue.h b/fdbserver/include/fdbserver/DDRelocationQueue.h index 12b207e0985..e8700781122 100644 --- a/fdbserver/include/fdbserver/DDRelocationQueue.h +++ b/fdbserver/include/fdbserver/DDRelocationQueue.h @@ -24,6 +24,7 @@ #include "fdbserver/DataDistribution.actor.h" #include "fdbserver/MovingWindow.h" +#include "fmt/format.h" // send request/signal to DDRelocationQueue through interface // call synchronous method from components outside DDRelocationQueue @@ -152,7 +153,7 @@ class DDQueue : public IDDRelocationQueue, public ReferenceCounted { std::unordered_map counter; std::string toString(const Item& item) const { - return format("%d %d %d %d", item[0], item[1], item[2], item[3]); + return fmt::format("{} {} {} {}", item[0], item[1], item[2], item[3]); } void traceReasonItem(TraceEvent* event, const ReasonItem& item) const { diff --git a/fdbserver/include/fdbserver/DataDistributionTeam.h b/fdbserver/include/fdbserver/DataDistributionTeam.h index a35f8216185..5e328b07bde 100644 --- a/fdbserver/include/fdbserver/DataDistributionTeam.h +++ b/fdbserver/include/fdbserver/DataDistributionTeam.h @@ -21,6 +21,7 @@ #pragma once #include "fdbclient/StorageServerInterface.h" +#include "fmt/format.h" struct GetTeamRequest; namespace data_distribution { @@ -86,8 +87,8 @@ struct IDataDistributionTeam { std::string getDesc() const { const auto& servers = getLastKnownServerInterfaces(); - std::string s = format("TeamID %s; ", getTeamID().c_str()); - s += format("Size %d; ", servers.size()); + std::string s = fmt::format("TeamID {}; ", getTeamID()); + s += fmt::format("Size {}; ", servers.size()); for (int i = 0; i < servers.size(); i++) { if (i) s += ", "; diff --git a/fdbserver/include/fdbserver/DeltaTree.h b/fdbserver/include/fdbserver/DeltaTree.h index 82f58b22b95..888f30e3338 100644 --- a/fdbserver/include/fdbserver/DeltaTree.h +++ b/fdbserver/include/fdbserver/DeltaTree.h @@ -25,6 +25,7 @@ #include "fdbclient/FDBTypes.h" #include "fdbserver/Knobs.h" #include +#include "fmt/format.h" #define DELTATREE_DEBUG 0 @@ -982,11 +983,11 @@ struct DeltaTree2 { }; std::string toString(DeltaTree2* tree) const { - return format("Node{offset=%d leftChild=%d rightChild=%d delta=%s}", - tree->nodeOffset(this), - getLeftChildOffset(tree->largeNodes), - getRightChildOffset(tree->largeNodes), - delta(tree->largeNodes).toString().c_str()); + return fmt::format("Node{{offset={} leftChild={} rightChild={} delta={}}}", + tree->nodeOffset(this), + getLeftChildOffset(tree->largeNodes), + getRightChildOffset(tree->largeNodes), + delta(tree->largeNodes).toString()); } #define getMember(m) (large ? largeOffsets.m : smallOffsets.m) @@ -1044,13 +1045,13 @@ struct DeltaTree2 { Node* node(DeltaTree2* tree) const { return tree->nodeAt(nodeOffset); } std::string toString() const { - return format("DecodedNode{nodeOffset=%d leftChildIndex=%d rightChildIndex=%d leftParentIndex=%d " - "rightParentIndex=%d}", - (int)nodeOffset, - (int)leftChildIndex, - (int)rightChildIndex, - (int)leftParentIndex, - (int)rightParentIndex); + return fmt::format("DecodedNode{{nodeOffset={} leftChildIndex={} rightChildIndex={} leftParentIndex={} " + "rightParentIndex={}}}", + (int)nodeOffset, + (int)leftChildIndex, + (int)rightChildIndex, + (int)leftParentIndex, + (int)rightParentIndex); } }; #pragma pack(pop) @@ -1123,15 +1124,15 @@ struct DeltaTree2 { } std::string toString() const { - std::string s = format("DecodeCache{%p\n", this); - s += format("upperBound %s\n", upperBound.toString().c_str()); - s += format("lowerBound %s\n", lowerBound.toString().c_str()); - s += format("arenaSize %d\n", arena.getSize()); - s += format("decodedNodes %d {\n", decodedNodes.size()); + std::string s = fmt::format("DecodeCache{{{}\n", fmt::ptr(this)); + s += fmt::format("upperBound {}\n", upperBound.toString()); + s += fmt::format("lowerBound {}\n", lowerBound.toString()); + s += fmt::format("arenaSize {}\n", arena.getSize()); + s += fmt::format("decodedNodes {} {{\n", decodedNodes.size()); for (auto const& n : decodedNodes) { - s += format(" %s\n", n.toString().c_str()); + s += fmt::format(" {}\n", n.toString()); } - s += format("}}\n"); + s += fmt::format("}}}}\n"); return s; } }; @@ -1187,14 +1188,14 @@ struct DeltaTree2 { std::string toString() const { if (nodeIndex == -1) { - return format("Cursor{nodeIndex=-1}"); - } - return format("Cursor{item=%s indexItem=%s nodeIndex=%d decodedNode=%s node=%s ", - item.present() ? item.get().toString().c_str() : "", - get(cache->get(nodeIndex)).toString().c_str(), - nodeIndex, - cache->get(nodeIndex).toString().c_str(), - node()->toString(tree).c_str()); + return fmt::format("Cursor{{nodeIndex=-1}}"); + } + return fmt::format("Cursor{{item={} indexItem={} nodeIndex={} decodedNode={} node={} ", + item.present() ? item.get().toString().c_str() : "", + get(cache->get(nodeIndex)).toString(), + nodeIndex, + cache->get(nodeIndex).toString(), + node()->toString(tree)); } bool valid() const { return nodeIndex != -1; } diff --git a/fdbserver/include/fdbserver/IDiskQueue.h b/fdbserver/include/fdbserver/IDiskQueue.h index 3a123d7f84c..b8d250be37b 100644 --- a/fdbserver/include/fdbserver/IDiskQueue.h +++ b/fdbserver/include/fdbserver/IDiskQueue.h @@ -25,6 +25,7 @@ #include "fdbclient/FDBTypes.h" #include "fdbserver/IKeyValueStore.h" #include "flow/BooleanParam.h" +#include "fmt/format.h" FDB_BOOLEAN_PARAM(CheckHashes); @@ -37,7 +38,7 @@ class IDiskQueue : public IClosable { location(int64_t lo) : hi(0), lo(lo) {} location(int64_t hi, int64_t lo) : hi(hi), lo(lo) {} operator std::string() const { - return format("%lld.%lld", hi, lo); + return fmt::format("{}.{}", hi, lo); } // FIXME: Return a 'HumanReadableDescription' instead of std::string, make TraceEvent::detail accept that (for // safety) diff --git a/fdbserver/include/fdbserver/LogProtocolMessage.h b/fdbserver/include/fdbserver/LogProtocolMessage.h index c235a870b6a..2f2575674ac 100644 --- a/fdbserver/include/fdbserver/LogProtocolMessage.h +++ b/fdbserver/include/fdbserver/LogProtocolMessage.h @@ -24,6 +24,7 @@ #include "fdbclient/FDBTypes.h" #include "fdbclient/CommitTransaction.h" +#include "fmt/format.h" template typename Ar::READER& applyVersionStartingHere(Ar& ar, VersionOptions vo) { @@ -53,7 +54,9 @@ struct LogProtocolMessage { LogProtocolMessage() {} - std::string toString() const { return format("code: %d", MutationRef::Reserved_For_LogProtocolMessage); } + std::string toString() const { + return fmt::format("code: {}", static_cast(MutationRef::Reserved_For_LogProtocolMessage)); + } template void serialize(Ar& ar) { diff --git a/fdbserver/include/fdbserver/LogSystemConfig.h b/fdbserver/include/fdbserver/LogSystemConfig.h index 7c2ceb3493b..51891a3dd77 100644 --- a/fdbserver/include/fdbserver/LogSystemConfig.h +++ b/fdbserver/include/fdbserver/LogSystemConfig.h @@ -26,6 +26,7 @@ #include "fdbserver/TLogInterface.h" #include "fdbrpc/ReplicationPolicy.h" #include "fdbclient/DatabaseConfiguration.h" +#include "fmt/format.h" template struct OptionalInterface { @@ -149,7 +150,7 @@ struct OldTLogConf { explicit OldTLogConf(const OldLogData&); std::string toString() const { - return format("end: %d tags: %d %s", epochEnd, logRouterTags, describe(tLogs).c_str()); + return fmt::format("end: {} tags: {} {}", epochEnd, logRouterTags, describe(tLogs)); } bool operator==(const OldTLogConf& rhs) const; diff --git a/fdbserver/include/fdbserver/MasterInterface.h b/fdbserver/include/fdbserver/MasterInterface.h index d932e7faf6d..87bbdf86336 100644 --- a/fdbserver/include/fdbserver/MasterInterface.h +++ b/fdbserver/include/fdbserver/MasterInterface.h @@ -36,6 +36,7 @@ #ifdef WITH_SWIFT #include "flow/swift_future_support.h" +#include "fmt/format.h" #endif /* WITH_SWIFT */ using DBRecoveryCount = uint64_t; @@ -249,7 +250,7 @@ struct LifetimeToken { bool isEqual(LifetimeToken const& toCompare) { return ccID.compare(toCompare.ccID) == 0 && count == toCompare.count; } - std::string toString() const { return ccID.shortString() + format("#%lld", count); } + std::string toString() const { return ccID.shortString() + fmt::format("#{}", count); } void operator++() { ++count; } template diff --git a/fdbserver/include/fdbserver/OTELSpanContextMessage.h b/fdbserver/include/fdbserver/OTELSpanContextMessage.h index bb3283281c5..127a2cf82a6 100644 --- a/fdbserver/include/fdbserver/OTELSpanContextMessage.h +++ b/fdbserver/include/fdbserver/OTELSpanContextMessage.h @@ -25,6 +25,7 @@ #include "fdbclient/Tracing.h" #include "fdbclient/FDBTypes.h" #include "fdbclient/CommitTransaction.h" +#include "fmt/format.h" struct OTELSpanContextMessage { // This message is pushed into the the transaction logs' memory to inform @@ -43,9 +44,9 @@ struct OTELSpanContextMessage { OTELSpanContextMessage(SpanContext const& spanContext) : spanContext(spanContext) {} std::string toString() const { - return format("code: %d, span context: %s", - MutationRef::Reserved_For_OTELSpanContextMessage, - spanContext.toString().c_str()); + return fmt::format("code: {}, span context: {}", + static_cast(MutationRef::Reserved_For_OTELSpanContextMessage), + spanContext.toString()); } template diff --git a/fdbserver/include/fdbserver/RestoreApplier.actor.h b/fdbserver/include/fdbserver/RestoreApplier.actor.h index 419c734aa94..dbfb83708ca 100644 --- a/fdbserver/include/fdbserver/RestoreApplier.actor.h +++ b/fdbserver/include/fdbserver/RestoreApplier.actor.h @@ -40,6 +40,7 @@ #include "fdbserver/RestoreRoleCommon.actor.h" #include "fdbserver/RestoreWorkerInterface.actor.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // has to be last include Value applyAtomicOp(Optional existingValue, Value value, MutationRef::Type type); @@ -285,7 +286,7 @@ struct ApplierBatchData : public ReferenceCounted { targetWriteRateMB(SERVER_KNOBS->FASTRESTORE_WRITE_BW_MB / SERVER_KNOBS->FASTRESTORE_NUM_APPLIERS), totalBytesToWrite(-1), applyingDataBytes(0), counters(this, nodeID, batchIndex) { pollMetrics = - counters.cc.traceCounters(format("FastRestoreApplierMetrics%d", batchIndex), + counters.cc.traceCounters(fmt::format("FastRestoreApplierMetrics{}", batchIndex), nodeID, SERVER_KNOBS->FASTRESTORE_ROLE_LOGGING_DELAY, nodeID.toString() + "/RestoreApplierMetrics/" + std::to_string(batchIndex)); diff --git a/fdbserver/include/fdbserver/RestoreLoader.actor.h b/fdbserver/include/fdbserver/RestoreLoader.actor.h index c876b40fa86..da3a2d1e695 100644 --- a/fdbserver/include/fdbserver/RestoreLoader.actor.h +++ b/fdbserver/include/fdbserver/RestoreLoader.actor.h @@ -40,6 +40,7 @@ #include "fdbserver/RestoreWorkerInterface.actor.h" #include "fdbclient/BackupContainer.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // has to be last include class LoaderVersionBatchState : RoleVersionBatchState { @@ -94,7 +95,7 @@ struct LoaderBatchData : public ReferenceCounted { explicit LoaderBatchData(UID nodeID, int batchIndex) : vbState(LoaderVersionBatchState::NOT_INIT), loadFileReqs(0), counters(this, nodeID, batchIndex) { pollMetrics = - counters.cc.traceCounters(format("FastRestoreLoaderMetrics%d", batchIndex), + counters.cc.traceCounters(fmt::format("FastRestoreLoaderMetrics{}", batchIndex), nodeID, SERVER_KNOBS->FASTRESTORE_ROLE_LOGGING_DELAY, nodeID.toString() + "/RestoreLoaderMetrics/" + std::to_string(batchIndex)); diff --git a/fdbserver/include/fdbserver/RestoreWorker.actor.h b/fdbserver/include/fdbserver/RestoreWorker.actor.h index fb3196015cd..b58753d4484 100644 --- a/fdbserver/include/fdbserver/RestoreWorker.actor.h +++ b/fdbserver/include/fdbserver/RestoreWorker.actor.h @@ -40,6 +40,7 @@ #include "fdbserver/RestoreApplier.actor.h" #include "fdbserver/RestoreWorkerInterface.actor.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // must be last include // Each restore worker (a process) is assigned for a role. @@ -60,7 +61,7 @@ struct RestoreWorkerData : NonCopyable, public ReferenceCounted(MutationRef::Reserved_For_SpanContextMessage), + spanContext.toString()); } template diff --git a/fdbserver/include/fdbserver/StorageServerUtils.h b/fdbserver/include/fdbserver/StorageServerUtils.h index c879dd984c6..32545ab9808 100644 --- a/fdbserver/include/fdbserver/StorageServerUtils.h +++ b/fdbserver/include/fdbserver/StorageServerUtils.h @@ -25,6 +25,7 @@ #include "fdbclient/FDBTypes.h" #include "flow/flow.h" #include "fdbclient/StorageCheckpoint.h" +#include "fmt/format.h" enum class MoveInPhase : std::int8_t { Pending = 0, @@ -90,7 +91,7 @@ struct MoveInShardMetaData { bool doBulkLoading() const { return this->conductBulkLoad; } uint64_t destShardId() const { return this->dataMoveId.first(); } - std::string destShardIdString() const { return format("%016llx", this->dataMoveId.first()); } + std::string destShardIdString() const { return fmt::format("{:016x}", this->dataMoveId.first()); } std::string toString() const { return "MoveInShardMetaData: [Range]: " + describe(this->ranges) + diff --git a/fdbserver/include/fdbserver/art_impl.h b/fdbserver/include/fdbserver/art_impl.h index 009b513897a..dbe9b5231f9 100644 --- a/fdbserver/include/fdbserver/art_impl.h +++ b/fdbserver/include/fdbserver/art_impl.h @@ -1,3 +1,4 @@ +#include "fmt/format.h" /* * art_impl.h * @@ -124,7 +125,7 @@ art_leaf* art_tree::minimum(art_node* n) { case ART_NODE4_KV: return ART_FAT_NODE_LEAF(n); default: - printf("%d\n", n->type); + fmt::println("{}", static_cast(n->type)); UNSTOPPABLE_ASSERT(false); } } diff --git a/fdbserver/include/fdbserver/workloads/ApiWorkload.h b/fdbserver/include/fdbserver/workloads/ApiWorkload.h index 8c9cd1ed948..3daea54b429 100644 --- a/fdbserver/include/fdbserver/workloads/ApiWorkload.h +++ b/fdbserver/include/fdbserver/workloads/ApiWorkload.h @@ -27,6 +27,7 @@ #include "fdbclient/ReadYourWrites.h" #include "fdbclient/ThreadSafeTransaction.h" #include "fdbserver/workloads/MemoryKeyValueStore.h" +#include "fmt/format.h" // an enumeration of apis being tested enum TransactionType { NATIVE, READ_YOUR_WRITES, THREAD_SAFE, MULTI_VERSION }; @@ -270,7 +271,7 @@ struct ApiWorkload : TestWorkload { ApiWorkload(WorkloadContext const& wcx, int maxClients = -1) : TestWorkload(wcx), maxClients(maxClients), success(true), transactionFactory(nullptr) { clientPrefixInt = getOption(options, "clientId"_sr, clientId); - clientPrefix = format("%010d", clientPrefixInt); + clientPrefix = fmt::format("{:010}", clientPrefixInt); numKeys = getOption(options, "numKeys"_sr, 5000); onlyLowerCase = getOption(options, "onlyLowerCase"_sr, false); diff --git a/fdbserver/include/fdbserver/workloads/AsyncFile.actor.h b/fdbserver/include/fdbserver/workloads/AsyncFile.actor.h index 71184bae0a0..07ac89c1d1a 100644 --- a/fdbserver/include/fdbserver/workloads/AsyncFile.actor.h +++ b/fdbserver/include/fdbserver/workloads/AsyncFile.actor.h @@ -30,6 +30,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include "flow/IAsyncFile.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. class RandomByteGenerator { @@ -132,7 +133,7 @@ struct AsyncFileWorkload : TestWorkload { state Future lastWrite = Void(); for (i = oldSize & ~(chunkSize - 1); i < newSize; i += chunkSize) { if (i >> 30 != (i + (chunkSize)) >> 30) // each GB - printf("Building test file: %d GB\n", int((i + (chunkSize)) >> 30)); + fmt::println("Building test file: {} GB", int((i + (chunkSize)) >> 30)); if (self->fillRandom) rbg.writeRandomBytesToBuffer(data->buffer, chunkSize); auto w = lastWrite; diff --git a/fdbserver/include/fdbserver/workloads/BulkSetup.h b/fdbserver/include/fdbserver/workloads/BulkSetup.h index 1b377947117..a5543bd701a 100644 --- a/fdbserver/include/fdbserver/workloads/BulkSetup.h +++ b/fdbserver/include/fdbserver/workloads/BulkSetup.h @@ -33,6 +33,7 @@ #include "fdbserver/ServerDBInfo.h" #include "fdbserver/QuietDatabase.h" #include "fdbrpc/simulator.h" +#include "fmt/format.h" template struct sfinae_true : std::true_type {}; @@ -160,8 +161,8 @@ Future setupRangeWorker(Database cx, Error err; setAuthToken(*workload, tr); try { - std::string countKey = format("keycount|%d|%d", workload->clientId, actorId); - std::string bytesKey = format("bytesstored|%d|%d", workload->clientId, actorId); + std::string countKey = fmt::format("keycount|{}|{}", workload->clientId, actorId); + std::string bytesKey = fmt::format("bytesstored|{}|{}", workload->clientId, actorId); tr.set(StringRef(countKey), StringRef((uint8_t*)&keysLoaded, sizeof(uint64_t))); tr.set(StringRef(bytesKey), StringRef((uint8_t*)&bytesStored, sizeof(uint64_t))); diff --git a/fdbserver/networktest.actor.cpp b/fdbserver/networktest.actor.cpp index 93d0991268f..00a1d675bdb 100644 --- a/fdbserver/networktest.actor.cpp +++ b/fdbserver/networktest.actor.cpp @@ -82,9 +82,9 @@ ACTOR Future networkTestServer() { when(wait(logging)) { auto spd = sent / (now() - lastTime); if (FLOW_KNOBS->NETWORK_TEST_SCRIPT_MODE) { - fprintf(stderr, "%f\t%.3f\t%.3f\n", spd, latency.mean() * 1e6, latency.stddev() * 1e6); + fmt::println(stderr, "{:f}\t{:.3f}\t{:.3f}", spd, latency.mean() * 1e6, latency.stddev() * 1e6); } else { - fprintf(stderr, "responses per second: %f (%f us)\n", spd, latency.mean() * 1e6); + fmt::println(stderr, "responses per second: {:f} ({:f} us)", spd, latency.mean() * 1e6); } latency.reset(); lastTime = now(); @@ -119,9 +119,9 @@ ACTOR Future networkTestStreamingServer() { when(wait(logging)) { auto spd = sent / (now() - lastTime); if (FLOW_KNOBS->NETWORK_TEST_SCRIPT_MODE) { - fprintf(stderr, "%f\t%.3f\t%.3f\n", spd, latency.mean() * 1e6, latency.stddev() * 1e6); + fmt::println(stderr, "{:f}\t{:.3f}\t{:.3f}", spd, latency.mean() * 1e6, latency.stddev() * 1e6); } else { - fprintf(stderr, "responses per second: %f (%f us)\n", spd, latency.mean() * 1e6); + fmt::println(stderr, "responses per second: {:f} ({:f} us)", spd, latency.mean() * 1e6); } latency.reset(); lastTime = now(); @@ -212,10 +212,10 @@ ACTOR Future logger(int* sent, int* completed, LatencyStats* latency) { if (FLOW_KNOBS->NETWORK_TEST_SCRIPT_MODE) { if (iteration == 2) { // We don't report the first iteration because of warm-up effects. - printf("%f\t%.3f\t%.3f\n", spd, latency->mean() * 1e6, latency->stddev() * 1e6); + fmt::println("{:f}\t{:.3f}\t{:.3f}", spd, latency->mean() * 1e6, latency->stddev() * 1e6); } } else { - fprintf(stderr, "messages per second: %f (%6.3f us)\n", spd, latency->mean() * 1e6); + fmt::println(stderr, "messages per second: {:f} ({:6.3f} us)", spd, latency->mean() * 1e6); } latency->reset(); lastTime = now(); @@ -227,10 +227,10 @@ ACTOR Future logger(int* sent, int* completed, LatencyStats* latency) { } static void networkTestnanosleep() { - printf("nanosleep speed test\n"); + fmt::println("nanosleep speed test"); #ifdef __linux__ - printf("\nnanosleep(10) latencies:"); + fmt::print("\nnanosleep(10) latencies:"); for (int i = 0; i < 10; i++) { double before = timer_monotonic(); @@ -240,10 +240,10 @@ static void networkTestnanosleep() { nanosleep(&tv, nullptr); double after = timer_monotonic(); - printf(" %0.3lf", (after - before) * 1e6); + fmt::print(" {:.3f}", (after - before) * 1e6); } - printf("\nnanosleep(10) latency after 5ms spin:"); + fmt::print("\nnanosleep(10) latency after 5ms spin:"); for (int i = 0; i < 10; i++) { double a = timer_monotonic() + 5e-3; while (timer_monotonic() < a) { @@ -255,10 +255,10 @@ static void networkTestnanosleep() { tv.tv_nsec = 10; nanosleep(&tv, nullptr); double after = timer_monotonic(); - printf(" %0.3lf", (after - before) * 1e6); + fmt::print(" {:.3f}", (after - before) * 1e6); } - printf("\nnanosleep(20000) latency:"); + fmt::print("\nnanosleep(20000) latency:"); for (int i = 0; i < 10; i++) { double before = timer_monotonic(); timespec tv; @@ -267,11 +267,11 @@ static void networkTestnanosleep() { nanosleep(&tv, nullptr); double after = timer_monotonic(); - printf(" %0.3lf", (after - before) * 1e6); + fmt::print(" {:.3f}", (after - before) * 1e6); } - printf("\n"); + fmt::println(""); - printf("nanosleep(20000) loop\n"); + fmt::println("nanosleep(20000) loop"); while (true) { timespec tv; tv.tv_sec = 0; @@ -334,7 +334,7 @@ struct RandomIntRange { int get() const { return (max == 0) ? 0 : nondeterministicRandom()->randomInt(min, max + 1); } - std::string toString() const { return format("%d:%d", min, max); } + std::string toString() const { return fmt::format("{}:{}", min, max); } }; struct P2PNetworkTest { @@ -372,19 +372,19 @@ struct P2PNetworkTest { std::string statsString() { double elapsed = now() - startTime; - std::string s = format( - "%.2f MB/s bytes in %.2f MB/s bytes out %.2f/s completed sessions in %.2f/s completed sessions out ", - bytesReceived / elapsed / 1e6, - bytesSent / elapsed / 1e6, - sessionsIn / elapsed, - sessionsOut / elapsed); - s += format("Total Errors %d connect error=%d accept error=%d session error=%d ", - connectErrors + acceptErrors + sessionErrors, - connectErrors, - acceptErrors, - sessionErrors); - s += format("Remaining time %.0f seconds", - targetDuration > 0 ? std::max(0.0, targetDuration - (now() - globalStartTime)) : 0.0); + std::string s = fmt::format("{:.2f} MB/s bytes in {:.2f} MB/s bytes out {:.2f}/s completed sessions in " + "{:.2f}/s completed sessions out ", + bytesReceived / elapsed / 1e6, + bytesSent / elapsed / 1e6, + sessionsIn / elapsed, + sessionsOut / elapsed); + s += fmt::format("Total Errors {} connect error={} accept error={} session error={} ", + connectErrors + acceptErrors + sessionErrors, + connectErrors, + acceptErrors, + sessionErrors); + s += fmt::format("Remaining time {:.0f} seconds", + targetDuration > 0 ? std::max(0.0, targetDuration - (now() - globalStartTime)) : 0.0); bytesSent = 0; bytesReceived = 0; sessionsIn = 0; @@ -593,27 +593,27 @@ struct P2PNetworkTest { self->startTime = now(); - fmt::print("{0} listeners, {1} remotes, {2} outgoing connections\n", - self->listeners.size(), - self->remotes.size(), - self->connectionsOut); + fmt::println("{0} listeners, {1} remotes, {2} outgoing connections", + self->listeners.size(), + self->remotes.size(), + self->connectionsOut); for (auto n : self->remotes) { - printf("Remote: %s\n", n.toString().c_str()); + fmt::println("Remote: {}", n.toString()); } for (auto el : self->listeners) { - printf("Listener: %s\n", el->getListenAddress().toString().c_str()); + fmt::println("Listener: {}", el->getListenAddress().toString()); } if (!self->listeners.empty()) { state Reference conn1 = wait(self->listeners[0]->accept()); - printf("Server: connected from %s\n", conn1->getPeerAddress().toString().c_str()); + fmt::println("Server: connected from {}", conn1->getPeerAddress().toString()); try { wait(conn1->acceptHandshake()); - printf("Server: connected from %s, handshake done\n", conn1->getPeerAddress().toString().c_str()); + fmt::println("Server: connected from {}, handshake done", conn1->getPeerAddress().toString()); } catch (Error& e) { - printf("Server: handshake error %s\n", e.what()); + fmt::println("Server: handshake error {}", e.what()); } threadSleep(11.0); return Void(); @@ -621,9 +621,9 @@ struct P2PNetworkTest { if (!self->remotes.empty()) { state Reference conn2 = wait(INetworkConnections::net()->connect(self->remotes[0])); - printf("Client: connected to %s\n", self->remotes[0].toString().c_str()); + fmt::println("Client: connected to {}", self->remotes[0].toString()); wait(conn2->connectHandshake()); - printf("Client: connected to %s, handshake done\n", self->remotes[0].toString().c_str()); + fmt::println("Client: connected to {}, handshake done", self->remotes[0].toString()); } return Void(); @@ -635,30 +635,30 @@ struct P2PNetworkTest { self->startTime = now(); self->globalStartTime = self->startTime; - fmt::print("{0} listeners, {1} remotes, {2} outgoing connections\n", - self->listeners.size(), - self->remotes.size(), - self->connectionsOut); + fmt::println("{0} listeners, {1} remotes, {2} outgoing connections", + self->listeners.size(), + self->remotes.size(), + self->connectionsOut); for (auto n : self->remotes) { - printf("Remote: %s\n", n.toString().c_str()); + fmt::println("Remote: {}", n.toString()); } for (auto el : self->listeners) { - printf("Listener: %s\n", el->getListenAddress().toString().c_str()); + fmt::println("Listener: {}", el->getListenAddress().toString()); actors.add(incoming(self, el)); } - printf("Request size: %s\n", self->requestBytes.toString().c_str()); - printf("Response size: %s\n", self->replyBytes.toString().c_str()); - printf("Requests per outgoing session: %s\n", self->requests.toString().c_str()); - printf("Delay before socket read: %s\n", self->waitReadMilliseconds.toString().c_str()); - printf("Delay before socket write: %s\n", self->waitWriteMilliseconds.toString().c_str()); - printf("Delay before session close: %s\n", self->idleMilliseconds.toString().c_str()); - printf("Send/Recv size %d bytes\n", FLOW_KNOBS->MAX_PACKET_SEND_BYTES); + fmt::println("Request size: {}", self->requestBytes.toString()); + fmt::println("Response size: {}", self->replyBytes.toString()); + fmt::println("Requests per outgoing session: {}", self->requests.toString()); + fmt::println("Delay before socket read: {}", self->waitReadMilliseconds.toString()); + fmt::println("Delay before socket write: {}", self->waitWriteMilliseconds.toString()); + fmt::println("Delay before session close: {}", self->idleMilliseconds.toString()); + fmt::println("Send/Recv size {} bytes", FLOW_KNOBS->MAX_PACKET_SEND_BYTES); if ((self->remotes.empty() || self->connectionsOut == 0) && self->listeners.empty()) { - printf("No listeners and no remotes or connectionsOut, so there is nothing to do!\n"); + fmt::println("No listeners and no remotes or connectionsOut, so there is nothing to do!"); ASSERT((!self->remotes.empty() && (self->connectionsOut > 0)) || !self->listeners.empty()); } @@ -670,7 +670,7 @@ struct P2PNetworkTest { loop { wait(delay(1.0, TaskPriority::Max)); - printf("%s\n", self->statsString().c_str()); + fmt::println("{}", self->statsString()); if (self->targetDuration > 0 && now() - self->globalStartTime > self->targetDuration) { break; } diff --git a/fdbserver/pubsub.actor.cpp b/fdbserver/pubsub.actor.cpp index 1a17c9014a3..49ad2c8e03b 100644 --- a/fdbserver/pubsub.actor.cpp +++ b/fdbserver/pubsub.actor.cpp @@ -21,10 +21,11 @@ #include #include "fdbclient/NativeAPI.actor.h" #include "fdbserver/pubsub.h" +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. Value uInt64ToValue(uint64_t v) { - return StringRef(format("%016llx", v)); + return StringRef(fmt::format("{:016x}", v)); } uint64_t valueToUInt64(const StringRef& v) { uint64_t x = 0; @@ -33,70 +34,70 @@ uint64_t valueToUInt64(const StringRef& v) { } Key keyForInbox(uint64_t inbox) { - return StringRef(format("i/%016llx", inbox)); + return StringRef(fmt::format("i/{:016x}", inbox)); } Key keyForInboxSubscription(uint64_t inbox, uint64_t feed) { - return StringRef(format("i/%016llx/subs/%016llx", inbox, feed)); + return StringRef(fmt::format("i/{:016x}/subs/{:016x}", inbox, feed)); } Key keyForInboxSubscriptionCount(uint64_t inbox) { - return StringRef(format("i/%016llx/subsCnt", inbox)); + return StringRef(fmt::format("i/{:016x}/subsCnt", inbox)); } Key keyForInboxStalePrefix(uint64_t inbox) { - return StringRef(format("i/%016llx/stale/", inbox)); + return StringRef(fmt::format("i/{:016x}/stale/", inbox)); } Key keyForInboxStaleFeed(uint64_t inbox, uint64_t feed) { - return StringRef(format("i/%016llx/stale/%016llx", inbox, feed)); + return StringRef(fmt::format("i/{:016x}/stale/{:016x}", inbox, feed)); } Key keyForInboxCacheByIDPrefix(uint64_t inbox) { - return StringRef(format("i/%016llx/cid/", inbox)); + return StringRef(fmt::format("i/{:016x}/cid/", inbox)); } Key keyForInboxCacheByID(uint64_t inbox, uint64_t messageId) { - return StringRef(format("i/%016llx/cid/%016llx", inbox, messageId)); + return StringRef(fmt::format("i/{:016x}/cid/{:016x}", inbox, messageId)); } Key keyForInboxCacheByFeedPrefix(uint64_t inbox) { - return StringRef(format("i/%016llx/cf/", inbox)); + return StringRef(fmt::format("i/{:016x}/cf/", inbox)); } Key keyForInboxCacheByFeed(uint64_t inbox, uint64_t feed) { - return StringRef(format("i/%016llx/cf/%016llx", inbox, feed)); + return StringRef(fmt::format("i/{:016x}/cf/{:016x}", inbox, feed)); } Key keyForFeed(uint64_t feed) { - return StringRef(format("f/%016llx", feed)); + return StringRef(fmt::format("f/{:016x}", feed)); } Key keyForFeedSubscriber(uint64_t feed, uint64_t inbox) { - return StringRef(format("f/%016llx/subs/%016llx", feed, inbox)); + return StringRef(fmt::format("f/{:016x}/subs/{:016x}", feed, inbox)); } Key keyForFeedSubscriberCount(uint64_t feed) { - return StringRef(format("f/%016llx/subscCnt", feed)); + return StringRef(fmt::format("f/{:016x}/subscCnt", feed)); } Key keyForFeedMessage(uint64_t feed, uint64_t message) { - return StringRef(format("f/%016llx/m/%016llx", feed, message)); + return StringRef(fmt::format("f/{:016x}/m/{:016x}", feed, message)); } Key keyForFeedMessagePrefix(uint64_t feed) { - return StringRef(format("f/%016llx/m/", feed)); + return StringRef(fmt::format("f/{:016x}/m/", feed)); } Key keyForFeedMessageCount(uint64_t feed) { - return StringRef(format("f/%016llx/messCount", feed)); + return StringRef(fmt::format("f/{:016x}/messCount", feed)); } // the following should go at some point: change over to range query of count 1 from feed message list Key keyForFeedLatestMessage(uint64_t feed) { - return StringRef(format("f/%016llx/latestMessID", feed)); + return StringRef(fmt::format("f/{:016x}/latestMessID", feed)); } Key keyForFeedWatcherPrefix(uint64_t feed) { - return StringRef(format("f/%016llx/watchers/", feed)); + return StringRef(fmt::format("f/{:016x}/watchers/", feed)); } Key keyForFeedWatcher(uint64_t feed, uint64_t inbox) { - return StringRef(format("f/%016llx/watchers/%016llx", feed, inbox)); + return StringRef(fmt::format("f/{:016x}/watchers/{:016x}", feed, inbox)); } Standalone messagePrefix("m/"_sr); Key keyForMessage(uint64_t message) { - return StringRef(format("m/%016llx", message)); + return StringRef(fmt::format("m/{:016x}", message)); } Key keyForDisptchEntry(uint64_t message) { - return StringRef(format("d/%016llx", message)); + return StringRef(fmt::format("d/{:016x}", message)); } PubSub::PubSub(Database _cx) : cx(_cx) {} diff --git a/fdbserver/storageserver.actor.cpp b/fdbserver/storageserver.actor.cpp index b60e9bc81e6..7e15f7c7620 100644 --- a/fdbserver/storageserver.actor.cpp +++ b/fdbserver/storageserver.actor.cpp @@ -890,7 +890,7 @@ struct StorageServer : public IStorageMetricsService { public: struct PendingNewShard { - PendingNewShard(uint64_t shardId, KeyRangeRef range) : shardId(format("%016llx", shardId)), range(range) {} + PendingNewShard(uint64_t shardId, KeyRangeRef range) : shardId(fmt::format("{:016x}", shardId)), range(range) {} std::string toString() const { return fmt::format("PendingNewShard: [ShardID]: {} [Range]: {}", @@ -1548,9 +1548,9 @@ struct StorageServer : public IStorageMetricsService { TraceEvent(SevVerbose, "StorageServerAddShardClear") .detail("NewShardRange", newShard->range()) .detail("Range", it->value()->range()) - .detail("ShardID", format("%016llx", it->value()->getShardId())) - .detail("NewShardID", format("%016llx", newShard->getDesiredShardId())) - .detail("NewShardActualID", format("%016llx", newShard->getShardId())); + .detail("ShardID", fmt::format("{:016x}", it->value()->getShardId())) + .detail("NewShardID", fmt::format("{:016x}", newShard->getDesiredShardId())) + .detail("NewShardActualID", fmt::format("{:016x}", newShard->getShardId())); } } } @@ -1875,8 +1875,8 @@ void validate(StorageServer* data, bool force = false) { for (auto s = data->shards.ranges().begin(); s != data->shards.ranges().end(); ++s) { TraceEvent(SevVerbose, "ValidateShard", data->thisServerID) .detail("Range", s->range()) - .detail("ShardID", format("%016llx", s->value()->getShardId())) - .detail("DesiredShardID", format("%016llx", s->value()->getDesiredShardId())) + .detail("ShardID", fmt::format("{:016x}", s->value()->getShardId())) + .detail("DesiredShardID", fmt::format("{:016x}", s->value()->getDesiredShardId())) .detail("ShardRange", s->value()->range()) .detail("ShardState", s->value()->debugDescribeState()) .log(); @@ -4083,11 +4083,11 @@ ACTOR Future auditStorageServerShardQ(StorageServer* data, AuditStorageReq if (anyMismatch.present()) { // mismatch detected KeyRange mismatchedRangeByServerKey = anyMismatch.get().first; KeyRange mismatchedRangeByKeyServer = anyMismatch.get().second; - std::string error = - format("KeyServers and serverKeys mismatch on Server(%s): ServerKey: %s; KeyServer: %s", - data->thisServerID.toString().c_str(), - mismatchedRangeByServerKey.toString().c_str(), - mismatchedRangeByKeyServer.toString().c_str()); + std::string error = fmt::format( + "KeyServers and serverKeys mismatch on Server({}): ServerKey: {}; KeyServer: {}", + data->thisServerID.toString(), + mismatchedRangeByServerKey.toString(), + mismatchedRangeByKeyServer.toString()); TraceEvent(SevError, "SSAuditStorageSsShardError", data->thisServerID) .setMaxFieldLength(-1) .setMaxEventLength(-1) @@ -4108,11 +4108,11 @@ ACTOR Future auditStorageServerShardQ(StorageServer* data, AuditStorageReq if (anyMismatch.present()) { // mismatch detected KeyRange mismatchedRangeByServerKey = anyMismatch.get().first; KeyRange mismatchedRangeByLocalView = anyMismatch.get().second; - std::string error = - format("Storage server shard info mismatch on Server(%s): ServerKey: %s; ServerShardInfo: %s", - data->thisServerID.toString().c_str(), - mismatchedRangeByServerKey.toString().c_str(), - mismatchedRangeByLocalView.toString().c_str()); + std::string error = fmt::format( + "Storage server shard info mismatch on Server({}): ServerKey: {}; ServerShardInfo: {}", + data->thisServerID.toString(), + mismatchedRangeByServerKey.toString(), + mismatchedRangeByLocalView.toString()); TraceEvent(SevError, "SSAuditStorageSsShardError", data->thisServerID) .setMaxFieldLength(-1) .setMaxEventLength(-1) @@ -4419,10 +4419,10 @@ std::vector compareSourceAndRestoredData(UID thisServerID, if (sourceKV.key == restoredKeyWithoutPrefix) { // Keys match, compare values if (sourceKV.value != restoredKV.value) { - std::string error = format("Value Mismatch for Key %s: source value: %s, restored value: %s", - Traceable::toString(sourceKV.key).c_str(), - Traceable::toString(sourceKV.value).c_str(), - Traceable::toString(restoredKV.value).c_str()); + std::string error = fmt::format("Value Mismatch for Key {}: source value: {}, restored value: {}", + Traceable::toString(sourceKV.key), + Traceable::toString(sourceKV.value), + Traceable::toString(restoredKV.value)); TraceEvent(SevError, "SSAuditRestoreError", thisServerID) .setMaxFieldLength(-1) .setMaxEventLength(-1) @@ -4441,7 +4441,7 @@ std::vector compareSourceAndRestoredData(UID thisServerID, } else if (sourceKV.key < restoredKeyWithoutPrefix) { // Source key missing from restored data std::string error = - format("Missing key in restored data: %s", Traceable::toString(sourceKV.key).c_str()); + fmt::format("Missing key in restored data: {}", Traceable::toString(sourceKV.key)); TraceEvent(SevError, "SSAuditRestoreError", thisServerID) .setMaxFieldLength(-1) .setMaxEventLength(-1) @@ -4455,7 +4455,7 @@ std::vector compareSourceAndRestoredData(UID thisServerID, } else { // Extra key in restored data (treat as validation error) std::string error = - format("Extra key in restored data: %s", Traceable::toString(restoredKV.key).c_str()); + fmt::format("Extra key in restored data: {}", Traceable::toString(restoredKV.key)); TraceEvent(SevError, "SSAuditRestoreError", thisServerID) .setMaxFieldLength(-1) .setMaxEventLength(-1) @@ -4476,8 +4476,8 @@ std::vector compareSourceAndRestoredData(UID thisServerID, // We require !sourceReply.more because if there's more source data to fetch, // we can't definitively say keys are missing until we've seen all source data. if (errors.empty() && sourceIdx < sourceReply.data.size() && !sourceReply.more && !restoredReply.more) { - std::string error = format("Missing key(s) in restored data, next source key: %s", - Traceable::toString(sourceReply.data[sourceIdx].key).c_str()); + std::string error = fmt::format("Missing key(s) in restored data, next source key: {}", + Traceable::toString(sourceReply.data[sourceIdx].key)); TraceEvent(SevError, "SSAuditRestoreError", thisServerID) .setMaxFieldLength(-1) .setMaxEventLength(-1) @@ -4492,8 +4492,8 @@ std::vector compareSourceAndRestoredData(UID thisServerID, // Check for any remaining restored keys that don't have matching source keys if (errors.empty() && restoredIdx < restoredReply.data.size() && !restoredReply.more) { // Extra keys found in restored data - treat as validation error - std::string error = format("Extra key(s) in restored data, first extra key: %s", - Traceable::toString(restoredReply.data[restoredIdx].key).c_str()); + std::string error = fmt::format("Extra key(s) in restored data, first extra key: {}", + Traceable::toString(restoredReply.data[restoredIdx].key)); TraceEvent(SevError, "SSAuditRestoreError", thisServerID) .setMaxFieldLength(-1) .setMaxEventLength(-1) @@ -4877,11 +4877,11 @@ ACTOR Future auditStorageShardReplicaQ(StorageServer* data, AuditStorageRe } // Check if mismatch if (remoteKV.key != localKV.key) { - error = format("Key Mismatch: local server (%016llx): %s, remote server(%016llx) %s", - data->thisServerID.first(), - Traceable::toString(localKV.key).c_str(), - remoteServer.uniqueID.first(), - Traceable::toString(remoteKV.key).c_str()); + error = fmt::format("Key Mismatch: local server ({:016x}): {}, remote server({:016x}) {}", + data->thisServerID.first(), + Traceable::toString(localKV.key), + remoteServer.uniqueID.first(), + Traceable::toString(remoteKV.key)); TraceEvent(SevError, "SSAuditStorageShardReplicaError", data->thisServerID) .setMaxFieldLength(-1) .setMaxEventLength(-1) @@ -4893,13 +4893,13 @@ ACTOR Future auditStorageShardReplicaQ(StorageServer* data, AuditStorageRe errors.push_back(error); break; } else if (remoteKV.value != localKV.value) { - error = format( - "Value Mismatch for Key %s: local server (%016llx): %s, remote server(%016llx) %s", - Traceable::toString(localKV.key).c_str(), + error = fmt::format( + "Value Mismatch for Key {}: local server ({:016x}): {}, remote server({:016x}) {}", + Traceable::toString(localKV.key), data->thisServerID.first(), - Traceable::toString(localKV.value).c_str(), + Traceable::toString(localKV.value), remoteServer.uniqueID.first(), - Traceable::toString(remoteKV.value).c_str()); + Traceable::toString(remoteKV.value)); TraceEvent(SevError, "SSAuditStorageShardReplicaError", data->thisServerID) .setMaxFieldLength(-1) .setMaxEventLength(-1) @@ -4939,10 +4939,10 @@ ACTOR Future auditStorageShardReplicaQ(StorageServer* data, AuditStorageRe data->thisServerID); } std::string error = - format("Missing key(s) form local server (%lld), next key: %s, remote server(%016llx) ", - data->thisServerID.first(), - Traceable::toString(remote.data[i].key).c_str(), - remoteServer.uniqueID.first()); + fmt::format("Missing key(s) form local server ({}), next key: {}, remote server({:016x}) ", + data->thisServerID.first(), + Traceable::toString(remote.data[i].key), + remoteServer.uniqueID.first()); TraceEvent(SevError, "SSAuditStorageShardReplicaError", data->thisServerID) .setMaxFieldLength(-1) .setMaxEventLength(-1) @@ -4960,10 +4960,10 @@ ACTOR Future auditStorageShardReplicaQ(StorageServer* data, AuditStorageRe data->thisServerID); } std::string error = - format("Missing key(s) form remote server (%lld), next local server(%016llx) key: %s", - remoteServer.uniqueID.first(), - data->thisServerID.first(), - Traceable::toString(local.data[i].key).c_str()); + fmt::format("Missing key(s) form remote server ({}), next local server({:016x}) key: {}", + remoteServer.uniqueID.first(), + data->thisServerID.first(), + Traceable::toString(local.data[i].key)); TraceEvent(SevError, "SSAuditStorageShardReplicaError", data->thisServerID) .setMaxFieldLength(-1) .setMaxEventLength(-1) @@ -10250,8 +10250,7 @@ ACTOR Future updateStorage(StorageServer* data) { unlimitedCommitBytes = UnlimitedCommitBytes::False; ASSERT(data->durableVersion.get() == data->storageVersion()); if (g_network->isSimulated()) { - double endTime = - g_simulator->checkDisabled(format("%s/updateStorage", data->thisServerID.toString().c_str())); + double endTime = g_simulator->checkDisabled(fmt::format("{}/updateStorage", data->thisServerID.toString())); if (endTime > now()) { wait(delay(endTime - now(), TaskPriority::UpdateStorage)); } @@ -11613,7 +11612,8 @@ ACTOR Future metricsCore(StorageServer* self, StorageServerInterface ssi) self->thisServerID.toString() + "/StorageMetrics", [self = self](TraceEvent& te) { te.detail("StorageEngine", self->storage.getKeyValueStoreType().toString()); - te.detail("RocksDBVersion", format("%d.%d.%d", FDB_ROCKSDB_MAJOR, FDB_ROCKSDB_MINOR, FDB_ROCKSDB_PATCH)); + te.detail("RocksDBVersion", + fmt::format("{}.{}.{}", FDB_ROCKSDB_MAJOR, FDB_ROCKSDB_MINOR, FDB_ROCKSDB_PATCH)); te.detail("Tag", self->tag.toString()); std::vector rpr = self->readPriorityRanks; te.detail("ReadsTotalActive", self->ssLock->getRunnersCount()); @@ -11952,7 +11952,7 @@ ACTOR Future storageEngineConsistencyCheck(StorageServer* self) { continue; } if (it.value()->assigned()) { - currentShards.insert(it.range(), format("%016llx", it.value()->getShardId())); + currentShards.insert(it.range(), fmt::format("{:016x}", it.value()->getShardId())); teamShardCount[it.value()->getTeamId()]++; } } @@ -12809,7 +12809,7 @@ To reach 64, need to save: 11 bytes + all padding void versionedMapTest() { VersionedMap vm; - printf("SS Ptree node is %zu bytes\n", sizeof(StorageServer::VersionedData::PTreeT)); + fmt::println("SS Ptree node is {} bytes", sizeof(StorageServer::VersionedData::PTreeT)); const int NSIZE = sizeof(VersionedMap::PTreeT); const int ASIZE = NSIZE <= 64 ? 64 : nextFastAllocatedSize(NSIZE); @@ -12834,7 +12834,7 @@ void versionedMapTest() { for (auto i = vm.atLatest().begin(); i != vm.atLatest().end(); ++i) ++count; - printf("PTree node is %d bytes, allocated as %d bytes\n", NSIZE, ASIZE); - printf("%d distinct after %d insertions\n", count, 1000 * 1000); - printf("Memory used: %f MB\n", (after - before) / 1e6); + fmt::println("PTree node is {} bytes, allocated as {} bytes", NSIZE, ASIZE); + fmt::println("{} distinct after {} insertions", count, 1000 * 1000); + fmt::println("Memory used: {:f} MB", (after - before) / 1e6); } diff --git a/fdbserver/test.cpp b/fdbserver/test.cpp index d3ba2bfe936..4ce72a9724c 100644 --- a/fdbserver/test.cpp +++ b/fdbserver/test.cpp @@ -58,6 +58,7 @@ #include "flow/Trace.h" #include "flow/CoroUtils.h" +#include "fmt/format.h" WorkloadContext::WorkloadContext() {} @@ -77,7 +78,7 @@ void emplaceIndex(uint8_t* data, int offset, int64_t index) { } Key doubleToTestKey(double p) { - return StringRef(format("%016llx", *(uint64_t*)&p)); + return StringRef(fmt::format("{:016x}", *(uint64_t*)&p)); } double testKeyToDouble(const KeyRef& p) { @@ -523,17 +524,15 @@ Future> getWorkloadIface(WorkloadRequest work, evt.detail("TestName", testName); if (!workload) { evt.detail("Reason", "Null workload"); - fprintf(stderr, - "ERROR: Workload could not be created, perhaps testName (%s) is not a valid workload\n", - printable(testName).c_str()); + fmt::println(stderr, + "ERROR: Workload could not be created, perhaps testName ({}) is not a valid workload", + printable(testName)); } else { evt.detail("Reason", "Not all options consumed"); - fprintf(stderr, "ERROR: Workload had invalid options. The following were unrecognized:\n"); + fmt::println(stderr, "ERROR: Workload had invalid options. The following were unrecognized:"); for (int i = 0; i < unconsumedOptions.size(); i++) - fprintf(stderr, - " '%s' = '%s'\n", - unconsumedOptions[i].key.toString().c_str(), - unconsumedOptions[i].value.toString().c_str()); + fmt::println( + stderr, " '{}' = '{}'", unconsumedOptions[i].key.toString(), unconsumedOptions[i].value.toString()); } throw test_specification_invalid(); } @@ -547,7 +546,7 @@ Future> getWorkloadIface(WorkloadRequest work, std::vector>> ifaces; if (work.options.size() < 1) { TraceEvent(SevError, "TestCreationError").detail("Reason", "No options provided"); - fprintf(stderr, "ERROR: No options were provided for workload.\n"); + fmt::println(stderr, "ERROR: No options were provided for workload."); throw test_specification_invalid(); } @@ -597,35 +596,35 @@ void printSimulatedTopology() { } return lhs->address < rhs->address; }); - printf("Simulated Cluster Topology:\n"); - printf("===========================\n"); + fmt::println("Simulated Cluster Topology:"); + fmt::println("==========================="); Optional> dcId, dataHallId, zoneId, machineId; for (auto p : processes) { std::string indent = ""; if (dcId != p->locality.dcId()) { dcId = p->locality.dcId(); - printf("%sdcId: %s\n", indent.c_str(), p->locality.describeDcId().c_str()); + fmt::println("{}dcId: {}", indent, p->locality.describeDcId()); } indent += " "; if (dataHallId != p->locality.dataHallId()) { dataHallId = p->locality.dataHallId(); - printf("%sdataHallId: %s\n", indent.c_str(), p->locality.describeDataHall().c_str()); + fmt::println("{}dataHallId: {}", indent, p->locality.describeDataHall()); } indent += " "; if (zoneId != p->locality.zoneId()) { zoneId = p->locality.zoneId(); - printf("%szoneId: %s\n", indent.c_str(), p->locality.describeZone().c_str()); + fmt::println("{}zoneId: {}", indent, p->locality.describeZone()); } indent += " "; if (machineId != p->locality.machineId()) { machineId = p->locality.machineId(); - printf("%smachineId: %s\n", indent.c_str(), p->locality.describeMachineId().c_str()); + fmt::println("{}machineId: {}", indent, p->locality.describeMachineId()); } indent += " "; - printf("%sAddress: %s\n", indent.c_str(), p->address.toString().c_str()); + fmt::println("{}Address: {}", indent, p->address.toString()); indent += " "; - printf("%sClass: %s\n", indent.c_str(), p->startingClass.toString().c_str()); - printf("%sName: %s\n", indent.c_str(), p->name.c_str()); + fmt::println("{}Class: {}", indent, p->startingClass.toString()); + fmt::println("{}Name: {}", indent, p->name); } } @@ -823,7 +822,7 @@ Future runWorkloadAsync(Database cx, if (action == 1) { // setup - printf("Test received trigger for setup...\n"); + fmt::println("Test received trigger for setup..."); TraceEvent("TestSetupBeginning", workIface.id()).detail("Workload", workload->description()); if (!setupResult.present()) { try { @@ -859,7 +858,7 @@ Future runWorkloadAsync(Database cx, TraceEvent("TestComplete", workIface.id()) .detail("Workload", workload->description()) .detail("OK", !startResult.get().isError()); - printf("%s complete\n", workload->description().c_str()); + fmt::println("{} complete", workload->description()); } sendResult(startReq, startResult); } else if (action == 3) { @@ -909,9 +908,9 @@ Future testerServerWorkload(WorkloadRequest work, try { std::map details; details["WorkloadTitle"] = printable(work.title); - details["ClientId"] = format("%d", work.clientId); - details["ClientCount"] = format("%d", work.clientCount); - details["WorkloadTimeout"] = format("%d", work.timeout); + details["ClientId"] = fmt::format("{}", work.clientId); + details["ClientCount"] = fmt::format("{}", work.clientCount); + details["WorkloadTimeout"] = fmt::format("{}", work.timeout); startRole(Role::TESTER, workIface.id(), UID(), details); if (work.useDatabase) { @@ -924,7 +923,7 @@ Future testerServerWorkload(WorkloadRequest work, Reference workload = co_await getWorkloadIface(work, ccr, dbInfo); if (!workload) { TraceEvent("TestCreationError").detail("Reason", "Workload could not be created"); - fprintf(stderr, "ERROR: The workload could not be created.\n"); + fmt::println(stderr, "ERROR: The workload could not be created."); throw test_specification_invalid(); } Future test = runWorkloadAsync(cx, workIface, workload, work.databasePingDelay) || @@ -1166,19 +1165,19 @@ std::vector aggregateMetrics(std::vector> me std::vector workloadMetrics = metrics[i]; TraceEvent("MetricsReturned").detail("Count", workloadMetrics.size()); for (int m = 0; m < workloadMetrics.size(); m++) { - printf("Metric (%d, %d): %s, %f, %s\n", - i, - m, - workloadMetrics[m].name().c_str(), - workloadMetrics[m].value(), - workloadMetrics[m].formatted().c_str()); + fmt::println("Metric ({}, {}): {}, {:f}, {}", + i, + m, + workloadMetrics[m].name(), + workloadMetrics[m].value(), + workloadMetrics[m].formatted()); metricMap[workloadMetrics[m].name()].push_back(workloadMetrics[m]); } } TraceEvent("Metric") .detail("Name", "Reporting Clients") .detail("Value", (double)metrics.size()) - .detail("Formatted", format("%d", metrics.size()).c_str()); + .detail("Formatted", fmt::format("{}", metrics.size()).c_str()); std::vector result; std::map>::iterator it; @@ -1229,10 +1228,10 @@ Future checkConsistencyScanAfterTest(Database cx, TesterConsistencyScanSta csState->enabled = false; if (csState->enableAfter || csState->waitForComplete) { - printf("Enabling consistency scan after test ...\n"); + fmt::println("Enabling consistency scan after test ..."); TraceEvent("TestProgress").log("checkConsistencyScanAfterTest: calling enableConsistencyScanInSim()"); co_await enableConsistencyScanInSim(cx); - printf("Enabled consistency scan after test.\n"); + fmt::println("Enabled consistency scan after test."); TraceEvent("TestProgress").log("checkConsistencyScanAfterTest: enableConsistencyScanInSim() returned."); } @@ -1287,7 +1286,7 @@ Future runWorkload(Database const& cx, if (specCopy.phases & TestWorkload::SETUP) { std::vector>> setups; - printf("setting up test (%s)...\n", printable(specCopy.title).c_str()); + fmt::println("setting up test ({})...", printable(specCopy.title)); TraceEvent("TestSetupStart").detail("WorkloadTitle", specCopy.title); setups.reserve(workloads.size()); for (int i = 0; i < workloads.size(); i++) @@ -1300,14 +1299,14 @@ Future runWorkload(Database const& cx, if (specCopy.phases & TestWorkload::EXECUTION) { TraceEvent("TestStarting").detail("WorkloadTitle", specCopy.title); - printf("running test (%s)...\n", printable(specCopy.title).c_str()); + fmt::println("running test ({})...", printable(specCopy.title)); std::vector>> starts; starts.reserve(workloads.size()); for (int i = 0; i < workloads.size(); i++) starts.push_back(workloads[i].start.template getReplyUnlessFailedFor(waitForFailureTime, 0)); co_await waitForAll(starts); throwIfError(starts, "StartFailedForWorkload" + printable(specCopy.title)); - printf("%s complete\n", printable(specCopy.title).c_str()); + fmt::println("{} complete", printable(specCopy.title)); TraceEvent("TestComplete").detail("WorkloadTitle", specCopy.title); TraceEvent("TestProgress").log("runWorkload: workload [%s] start finished", name.c_str()); } @@ -1320,7 +1319,7 @@ Future runWorkload(Database const& cx, std::vector>> checks; TraceEvent("TestCheckingResults").detail("WorkloadTitle", specCopy.title); - printf("checking test (%s)...\n", name.c_str()); + fmt::println("checking test ({})...", name); TraceEvent("TestProgress").log("runWorkload: calling check interface for test [%s]", name.c_str()); checks.reserve(workloads.size()); @@ -1343,7 +1342,7 @@ Future runWorkload(Database const& cx, if (specCopy.phases & TestWorkload::METRICS) { std::vector>>> metricTasks; - printf("fetching metrics (%s)...\n", printable(specCopy.title).c_str()); + fmt::println("fetching metrics ({})...", printable(specCopy.title)); TraceEvent("TestFetchingMetrics").detail("WorkloadTitle", specCopy.title); TraceEvent("TestProgress").log("runWorkload: calling metrics interface for test [%s]", name.c_str()); metricTasks.reserve(workloads.size()); @@ -1510,8 +1509,8 @@ Future checkConsistency(Database cx, options.push_back_deep(options.arena(), KeyValueRef("testName"_sr, "ConsistencyCheck"_sr)); options.push_back_deep(options.arena(), KeyValueRef("performQuiescentChecks"_sr, performQuiescent)); options.push_back_deep(options.arena(), KeyValueRef("performTSSCheck"_sr, performTSSCheck)); - options.push_back_deep(options.arena(), - KeyValueRef("maxDDRunTime"_sr, ValueRef(options.arena(), format("%f", maxDDRunTime)))); + options.push_back_deep( + options.arena(), KeyValueRef("maxDDRunTime"_sr, ValueRef(options.arena(), fmt::format("{:f}", maxDDRunTime)))); options.push_back_deep(options.arena(), KeyValueRef("distributed"_sr, "false"_sr)); spec.options.push_back_deep(spec.options.arena(), options); @@ -2116,7 +2115,7 @@ Future runTest(Database cx, fTestResults = timeoutError(fTestResults, spec.timeout); } DistributedTestResults _testResults = co_await fTestResults; - printf("Test complete\n"); + fmt::println("Test complete"); TraceEvent("TestProgress").log("runTest: test [%s] complete", name.c_str()); testResults = _testResults; logMetrics(testResults.metrics); @@ -2131,7 +2130,7 @@ Future runTest(Database cx, .error(e) .detail("Reason", "Test timed out") .detail("Timeout", spec.timeout); - fprintf(stderr, "ERROR: Test [%s] timed out after %d seconds.\n", name.c_str(), spec.timeout); + fmt::println(stderr, "ERROR: Test [{}] timed out after {} seconds.", name, spec.timeout); testResults.failures = testers.size(); testResults.successes = 0; } else { @@ -2147,7 +2146,7 @@ Future runTest(Database cx, bool ok = testResults.ok(); if (spec.useDB) { - printf("%d test clients passed; %d test clients failed\n", testResults.successes, testResults.failures); + fmt::println("{} test clients passed; {} test clients failed", testResults.successes, testResults.failures); TraceEvent("TestProgress") .log("runTest: [%d] test clients passed; [%d] test clients failed", testResults.successes, @@ -2168,17 +2167,17 @@ Future runTest(Database cx, // Disable consistency scan before checkConsistency because otherwise it will prevent quiet database from // quiescing co_await checkConsistencyScanAfterTest(cx, consistencyScanState); - printf("Consistency scan done\n"); + fmt::println("Consistency scan done"); TraceEvent("TestProgress").log("runTest: checkConsistencyScanAfterTest returned"); // Run the consistency check workload if (spec.runConsistencyCheck) { bool quiescent = g_network->isSimulated() ? !BUGGIFY : spec.waitForQuiescenceEnd; try { - printf("Running urgent consistency check...\n"); + fmt::println("Running urgent consistency check..."); TraceEvent("TestProgress").log("Running urgent consistency check"); co_await timeoutError(checkConsistencyUrgentSim(cx, testers), 20000.0); - printf("Urgent consistency check done\nRunning consistency check...\n"); + fmt::print("Urgent consistency check done\nRunning consistency check...\n"); TraceEvent("TestProgress").log("Urgent consistency check done; now invoking checkConsistency()"); co_await timeoutError(checkConsistency(cx, testers, @@ -2189,7 +2188,7 @@ Future runTest(Database cx, spec.databasePingDelay, dbInfo), 20000.0); - printf("Consistency check done\n"); + fmt::println("Consistency check done"); TraceEvent("TestProgress").log("checkConsistency() returned"); } catch (Error& e) { TraceEvent("TestProgress").log("Exception in checkConsistencyUrgentSim or checkConsistency"); @@ -2240,7 +2239,7 @@ Future runTest(Database cx, failCount++; } - printf("%d test clients passed; %d test clients failed\n", testResults.successes, testResults.failures); + fmt::println("{} test clients passed; {} test clients failed", testResults.successes, testResults.failures); TraceEvent("TestProgress") .log( "runTest: [%d] test clients passed; [%d] test clients failed", testResults.successes, testResults.failures); @@ -2863,8 +2862,8 @@ Future runTests7(Reference runTests7(Reference runTests7(Reference knobProtectiveGroup; for (; idx < tests.size(); idx++) { - printf("Run test:%s start\n", tests[idx].title.toString().c_str()); + fmt::println("Run test:{} start", tests[idx].title.toString()); TraceEvent("TestProgress").log("runTests7: starting test [%s]", tests[idx].title.toString().c_str()); knobProtectiveGroup = std::make_unique(tests[idx].overrideKnobs); co_await success(runTest(cx, testers, tests[idx], dbInfo, &consistencyScanState)); knobProtectiveGroup.reset(nullptr); - printf("Run test:%s Done.\n", tests[idx].title.toString().c_str()); + fmt::println("Run test:{} Done.", tests[idx].title.toString()); TraceEvent("TestProgress").log("runTests7: done running test [%s]", tests[idx].title.toString().c_str()); } - printf("\n%d tests passed; %d tests failed.\n", passCount, failCount); + fmt::print("\n{} tests passed; {} tests failed.\n", passCount, failCount); TraceEvent("TestProgress").log("runTests7: [%d] tests passed; [%d] tests failed.", passCount, failCount); bool ranConsistencyScan = false; @@ -3051,7 +3050,7 @@ Future runTests7(Reference invoking checkConsistencyScanAfterTest()"); - printf("Waiting for DD to end...\n"); + fmt::println("Waiting for DD to end..."); TraceEvent("QuietDatabaseEndStart"); try { TraceEvent("QuietDatabaseEndWait"); @@ -3075,7 +3074,7 @@ Future runTests7(Reference runTests(Reference const& connRecordUnsaf spec.timeout = 0; spec.waitForQuiescenceBegin = false; spec.waitForQuiescenceEnd = false; - std::string rateLimitMax = format("%d", CLIENT_KNOBS->CONSISTENCY_CHECK_RATE_LIMIT_MAX); + std::string rateLimitMax = fmt::format("{}", CLIENT_KNOBS->CONSISTENCY_CHECK_RATE_LIMIT_MAX); options.push_back_deep(options.arena(), KeyValueRef("testName"_sr, "ConsistencyCheck"_sr)); options.push_back_deep(options.arena(), KeyValueRef("performQuiescentChecks"_sr, "false"_sr)); options.push_back_deep(options.arena(), KeyValueRef("distributed"_sr, "false"_sr)); @@ -3257,7 +3256,7 @@ Future runTests(Reference const& connRecordUnsaf TraceEvent(SevError, "TestHarnessFail") .detail("Reason", "file open failed") .detail("File", fileName.c_str()); - fprintf(stderr, "ERROR: Could not open file `%s'\n", fileName.c_str()); + fmt::println(stderr, "ERROR: Could not open file `{}'", fileName); co_return; } enableClientInfoLogging(); // Enable Client Info logging by default for tester diff --git a/fdbserver/worker.actor.cpp b/fdbserver/worker.actor.cpp index cc7115c26e0..46c7aa64a64 100644 --- a/fdbserver/worker.actor.cpp +++ b/fdbserver/worker.actor.cpp @@ -90,6 +90,7 @@ #include #include #endif +#include "fmt/format.h" #include "flow/actorcompiler.h" // This must be the last #include. #if CENABLED(0, NOT_IN_CLEAN) @@ -2011,9 +2012,9 @@ ACTOR Future createClusterIdFile(std::string folder, UID clusterId) { throw; } if (!e.isInjectedFault()) { - fprintf(stderr, - "ERROR: error creating or opening cluster id file `%s'.\n", - joinPath(folder, clusterIdFilename).c_str()); + fmt::println(stderr, + "ERROR: error creating or opening cluster id file `{}'.", + joinPath(folder, clusterIdFilename)); } TraceEvent(SevError, "OpenClusterIdError").error(e); throw; @@ -2442,7 +2443,7 @@ ACTOR Future workerServer(Reference connRecord, std::map details; details["Locality"] = locality.toString(); details["DataFolder"] = folder; - details["StoresPresent"] = format("%d", stores.size()); + details["StoresPresent"] = fmt::format("{}", stores.size()); startRole(Role::WORKER, interf.id(), interf.id(), details); errorForwarders.add(traceRole(Role::WORKER, interf.id())); @@ -3206,8 +3207,8 @@ static std::set const& normalWorkerErrors() { ACTOR Future printTimeout() { wait(delay(5)); if (!g_network->isSimulated()) { - fprintf(stderr, "Warning: FDBD has not joined the cluster after 5 seconds.\n"); - fprintf(stderr, " Check configuration and availability using the 'status' command with the fdbcli\n"); + fmt::println(stderr, "Warning: FDBD has not joined the cluster after 5 seconds."); + fmt::println(stderr, " Check configuration and availability using the 'status' command with the fdbcli"); } return Void(); } @@ -3219,7 +3220,7 @@ ACTOR Future printOnFirstConnected(Referenceget().present() ? IFailureMonitor::failureMonitor().onStateEqual( ci->get().get().openDatabase.getEndpoint(), FailureStatus(false)) : Never())) { - printf("FDBD joined cluster.\n"); + fmt::println("FDBD joined cluster."); TraceEvent("FDBDConnected").log(); return Void(); } @@ -3602,7 +3603,7 @@ TEST_CASE("/fdbserver/storageengine/clearInflightCommits") { KeyValueStoreType storeType = randomStoreType(); ASSERT(storeType.isValid()); - fmt::print("Testing engine with store type {}\n", storeType.toString()); + fmt::println("Testing engine with store type {}", storeType.toString()); UID uid = deterministicRandom()->randomUniqueID(); std::string filename = filenameFromId(storeType, testDir, "", uid); @@ -3652,7 +3653,7 @@ TEST_CASE("/fdbserver/storageengine/clearInflightCommits") { Future closed = kvStore->onClosed(); kvStore->dispose(); - fmt::print("Waiting for engine to close\n"); + fmt::println("Waiting for engine to close"); wait(closed); platform::eraseDirectoryRecursive(testDir); @@ -3706,9 +3707,8 @@ ACTOR Future createAndLockProcessIdFile(std::string folder) { throw; } if (!e.isInjectedFault()) { - fprintf(stderr, - "ERROR: error creating or opening process id file `%s'.\n", - joinPath(folder, "processId").c_str()); + fmt::println( + stderr, "ERROR: error creating or opening process id file `{}'.", joinPath(folder, "processId")); } TraceEvent(SevError, "OpenProcessIdError").error(e); throw; diff --git a/fdbserver/workloads/ApiCorrectness.cpp b/fdbserver/workloads/ApiCorrectness.cpp index 07da9720168..f0e15c0d236 100644 --- a/fdbserver/workloads/ApiCorrectness.cpp +++ b/fdbserver/workloads/ApiCorrectness.cpp @@ -29,6 +29,7 @@ #include "fdbserver/workloads/MemoryKeyValueStore.h" #include "flow/IRandom.h" #include "flow/genericactors.actor.h" +#include "fmt/format.h" // An enum of API operation types used in the random test enum OperationType { SET, GET, GET_RANGE, GET_RANGE_SELECTOR, GET_KEY, CLEAR, CLEAR_RANGE, UNINITIALIZED }; @@ -635,10 +636,10 @@ struct ApiCorrectnessWorkload : ApiWorkload { // If there was a failure, print some debugging info about the failed key if (!result) { - printf("Bad result for key selector %s: db=%s, mem=%s\n", - selectors[i].toString().c_str(), - printable(keys[i]).c_str(), - printable(key).c_str()); + fmt::println("Bad result for key selector {}: db={}, mem={}", + selectors[i].toString(), + printable(keys[i]), + printable(key)); int dir = selectors[i].offset > 0 ? 1 : -1; for (int j = 0; j <= abs(selectors[i].offset); j++) { KeySelector sel = KeySelectorRef(selectors[i].getKey(), selectors[i].orEqual, j * dir); @@ -661,10 +662,7 @@ struct ApiCorrectnessWorkload : ApiWorkload { if (!(storeKey == self->store.startKey() && dbKey < StringRef(self->clientPrefix)) && !(storeKey == self->store.endKey() && dbKey > StringRef(self->clientPrefix + "\xff"))) - printf("Offset %d: db=%s, mem=%s\n", - j * dir, - printable(dbKey).c_str(), - printable(storeKey).c_str()); + fmt::println("Offset {}: db={}, mem={}", j * dir, printable(dbKey), printable(storeKey)); } break; diff --git a/fdbserver/workloads/ApiWorkload.cpp b/fdbserver/workloads/ApiWorkload.cpp index 13cb61d45e7..5c534830c6f 100644 --- a/fdbserver/workloads/ApiWorkload.cpp +++ b/fdbserver/workloads/ApiWorkload.cpp @@ -38,8 +38,8 @@ Future clearKeyspace(ApiWorkload* self) { Reference transaction = self->createTransaction(); Error err; try { - KeyRange range(KeyRangeRef(StringRef(format("%010d", self->clientPrefixInt)), - StringRef(format("%010d", self->clientPrefixInt + 1)))); + KeyRange range(KeyRangeRef(StringRef(fmt::format("{:010}", self->clientPrefixInt)), + StringRef(fmt::format("{:010}", self->clientPrefixInt + 1)))); transaction->clear(range); co_await transaction->commit(); @@ -92,7 +92,7 @@ Future start(Database cx, ApiWorkload* self) { co_await self->performTest(cx, data); } catch (Error& e) { if (e.code() != error_code_actor_cancelled) - self->testFailure(format("Unhandled error %d: %s", e.code(), e.name())); + self->testFailure(fmt::format("Unhandled error {}: {}", e.code(), e.name())); } } @@ -105,7 +105,7 @@ Future ApiWorkload::start(Database const& cx) { // Convenience function for reporting a test failure to trace log and stdout void ApiWorkload::testFailure(std::string reason) { - printf("test failure on client %d: %s\n", clientPrefixInt, reason.c_str()); + fmt::println("test failure on client {}: {}", clientPrefixInt, reason); TraceEvent(SevError, "TestFailure") .detail("Reason", description() + " " + reason) .detail("Workload", "ApiCorrectness"); @@ -121,18 +121,18 @@ bool ApiWorkload::compareResults(VectorRef dbResults, VectorRef storeResults, Version readVersion) { if (dbResults.size() != storeResults.size()) { - printf("%d. Size mismatch: %d - %d\n", clientPrefixInt, dbResults.size(), storeResults.size()); - printf("DB Range:\n"); + fmt::println("{}. Size mismatch: {} - {}", clientPrefixInt, dbResults.size(), storeResults.size()); + fmt::println("DB Range:"); for (int j = 0; j < dbResults.size(); j++) - printf("%d: %s %d\n", j, dbResults[j].key.toString().c_str(), dbResults[j].value.size()); + fmt::println("{}: {} {}", j, dbResults[j].key.toString(), dbResults[j].value.size()); - printf("Memory Range:\n"); + fmt::println("Memory Range:"); for (int j = 0; j < storeResults.size(); j++) - printf("%d: %s %d\n", j, storeResults[j].key.toString().c_str(), storeResults[j].value.size()); + fmt::println("{}: {} {}", j, storeResults[j].key.toString(), storeResults[j].value.size()); - fmt::print("Read Version: {}\n", readVersion); + fmt::println("Read Version: {}", readVersion); - TraceEvent(SevError, format("%s_CompareSizeMismatch", description().c_str()).c_str()) + TraceEvent(SevError, fmt::format("{}_CompareSizeMismatch", description()).c_str()) .detail("ReadVer", readVersion) .detail("ResultSize", dbResults.size()) .detail("StoreResultSize", storeResults.size()); @@ -142,18 +142,18 @@ bool ApiWorkload::compareResults(VectorRef dbResults, for (int i = 0; i < dbResults.size(); i++) { if (dbResults[i].key != storeResults[i].key || dbResults[i].value != storeResults[i].value) { - printf("%s mismatch at %d\n", dbResults[i].key != storeResults[i].key ? "Key" : "Value", i); - printf("DB Range:\n"); + fmt::println("{} mismatch at {}", dbResults[i].key != storeResults[i].key ? "Key" : "Value", i); + fmt::println("DB Range:"); for (int j = 0; j < dbResults.size(); j++) - printf("%d: %s %d\n", j, dbResults[j].key.toString().c_str(), dbResults[j].value.size()); + fmt::println("{}: {} {}", j, dbResults[j].key.toString(), dbResults[j].value.size()); - printf("Memory Range:\n"); + fmt::println("Memory Range:"); for (int j = 0; j < storeResults.size(); j++) - printf("%d: %s %d\n", j, storeResults[j].key.toString().c_str(), storeResults[j].value.size()); + fmt::println("{}: {} {}", j, storeResults[j].key.toString(), storeResults[j].value.size()); - fmt::print("Read Version: {}\n", readVersion); + fmt::println("Read Version: {}", readVersion); - TraceEvent(SevError, format("%s_CompareValueMismatch", description().c_str()).c_str()) + TraceEvent(SevError, fmt::format("{}_CompareValueMismatch", description()).c_str()) .detail("ReadVer", readVersion) .detail("ResultSize", dbResults.size()) .detail("DifferAt", i); @@ -321,23 +321,23 @@ Future chooseTransactionFactory(Database cx, std::vector self->transactionType = transactionType; if (transactionType == NATIVE) { - printf("client %d: Running NativeAPI Transactions\n", self->clientPrefixInt); + fmt::println("client {}: Running NativeAPI Transactions", self->clientPrefixInt); self->transactionFactory = Reference( new TransactionFactory, const Database>( cx, self->extraDB, self->useExtraDB)); } else if (transactionType == READ_YOUR_WRITES) { - printf("client %d: Running ReadYourWrites Transactions\n", self->clientPrefixInt); + fmt::println("client {}: Running ReadYourWrites Transactions", self->clientPrefixInt); self->transactionFactory = Reference( new TransactionFactory, const Database>( cx, self->extraDB, self->useExtraDB)); } else if (transactionType == THREAD_SAFE) { - printf("client %d: Running ThreadSafe Transactions\n", self->clientPrefixInt); + fmt::println("client {}: Running ThreadSafe Transactions", self->clientPrefixInt); Reference dbHandle = co_await unsafeThreadFutureToFuture(ThreadSafeDatabase::createFromExistingDatabase(cx)); self->transactionFactory = Reference( new TransactionFactory>(dbHandle, dbHandle, false)); } else if (transactionType == MULTI_VERSION) { - printf("client %d: Running Multi-Version Transactions\n", self->clientPrefixInt); + fmt::println("client {}: Running Multi-Version Transactions", self->clientPrefixInt); MultiVersionApi::api->selectApiVersion(cx->apiVersion.version()); Reference threadSafeHandle = co_await unsafeThreadFutureToFuture(ThreadSafeDatabase::createFromExistingDatabase(cx)); diff --git a/fdbserver/workloads/AsyncFileCorrectness.cpp b/fdbserver/workloads/AsyncFileCorrectness.cpp index e590fb877e3..f44f769142f 100644 --- a/fdbserver/workloads/AsyncFileCorrectness.cpp +++ b/fdbserver/workloads/AsyncFileCorrectness.cpp @@ -84,9 +84,8 @@ struct AsyncFileCorrectnessWorkload : public AsyncFileWorkload { if (maxOperationSize * numSimultaneousOperations > targetFileSize * 0.25) { targetFileSize *= (int)ceil((maxOperationSize * numSimultaneousOperations * 4.0) / targetFileSize); - fmt::print( - "Target file size is insufficient to support {0} simultaneous operations of size {1}; changing to " - "{2}\n", + fmt::println( + "Target file size is insufficient to support {0} simultaneous operations of size {1}; changing to {2}", numSimultaneousOperations, maxOperationSize, targetFileSize); @@ -392,12 +391,12 @@ struct AsyncFileCorrectnessWorkload : public AsyncFileWorkload { int64_t fileSize = co_await self->fileHandle->file->size(); int64_t fileSizeChange = fileSize - self->fileSize; if (fileSizeChange >= _PAGE_SIZE) { - fmt::print("Reopened file increased in size by {0} bytes (at most {1} allowed)\n", - fileSizeChange, - _PAGE_SIZE - 1); + fmt::println("Reopened file increased in size by {0} bytes (at most {1} allowed)", + fileSizeChange, + _PAGE_SIZE - 1); self->success = false; } else if (fileSizeChange < 0) { - fmt::print("Reopened file decreased in size by {} bytes\n", -fileSizeChange); + fmt::println("Reopened file decreased in size by {} bytes", -fileSizeChange); self->success = false; } @@ -409,7 +408,7 @@ struct AsyncFileCorrectnessWorkload : public AsyncFileWorkload { int64_t fileSize = co_await self->fileHandle->file->size(); if (fileSize != info.offset) { - printf("Incorrect file size reported after truncate\n"); + fmt::println("Incorrect file size reported after truncate"); self->success = false; } diff --git a/fdbserver/workloads/AtomicOps.cpp b/fdbserver/workloads/AtomicOps.cpp index d104c99c293..0b7b5446e3c 100644 --- a/fdbserver/workloads/AtomicOps.cpp +++ b/fdbserver/workloads/AtomicOps.cpp @@ -23,6 +23,7 @@ #include "fdbserver/workloads/BulkSetup.h" #include "fdbclient/ReadYourWrites.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" // #define SevAtomicOpDebug SevInfo #define SevAtomicOpDebug SevVerbose @@ -133,8 +134,8 @@ struct AtomicOpsWorkload : TestWorkload { void getMetrics(std::vector& m) override {} std::pair logDebugKey(int group) { - Key logKey(format("log%08x%08x%08x", group, clientId, opNum)); - Key debugKey(format("debug%08x%08x%08x", group, clientId, opNum)); + Key logKey(fmt::format("log{:08x}{:08x}{:08x}", group, clientId, opNum)); + Key debugKey(fmt::format("debug{:08x}{:08x}{:08x}", group, clientId, opNum)); opNum++; return std::make_pair(logKey, debugKey); } @@ -171,7 +172,7 @@ struct AtomicOpsWorkload : TestWorkload { try { for (int i = 0; i < self->nodeCount / 100; i++) { uint64_t intValue = 0; - tr.set(StringRef(format("ops%08x%08x", g, i)), + tr.set(StringRef(fmt::format("ops{:08x}{:08x}", g, i)), StringRef((const uint8_t*)&intValue, sizeof(intValue))); } co_await tr.commit(); @@ -195,7 +196,7 @@ struct AtomicOpsWorkload : TestWorkload { Key val = StringRef((const uint8_t*)&intValue, sizeof(intValue)); std::pair logDebugKey = self->logDebugKey(group); int nodeIndex = deterministicRandom()->randomInt(0, self->nodeCount / 100); - Key opsKey(format("ops%08x%08x", group, nodeIndex)); + Key opsKey(fmt::format("ops{:08x}{:08x}", group, nodeIndex)); Error err; try { tr.set(logDebugKey.first, val); // set log key @@ -230,7 +231,7 @@ struct AtomicOpsWorkload : TestWorkload { ReadYourWritesTransaction tr(cx); Error err; try { - Key begin(format("log%08x", g)); + Key begin(fmt::format("log{:08x}", g)); RangeResult log = co_await tr.getRange(KeyRangeRef(begin, strinc(begin)), CLIENT_KNOBS->TOO_MANY); if (log.more) { TraceEvent(SevError, "LogHitTxnLimits").detail("Result", log.toString()); @@ -257,7 +258,7 @@ struct AtomicOpsWorkload : TestWorkload { ReadYourWritesTransaction tr(cx); Error err; try { - Key begin(format("debug%08x", g)); + Key begin(fmt::format("debug{:08x}", g)); RangeResult debuglog = co_await tr.getRange(KeyRangeRef(begin, strinc(begin)), CLIENT_KNOBS->TOO_MANY); if (debuglog.more) { TraceEvent(SevError, "DebugLogHitTxnLimits").detail("Result", debuglog.toString()); @@ -276,7 +277,7 @@ struct AtomicOpsWorkload : TestWorkload { ReadYourWritesTransaction tr(cx); Error err; try { - Key begin(format("ops%08x", g)); + Key begin(fmt::format("ops{:08x}", g)); RangeResult ops = co_await tr.getRange(KeyRangeRef(begin, strinc(begin)), CLIENT_KNOBS->TOO_MANY); if (ops.more) { TraceEvent(SevError, "OpsHitTxnLimits").detail("Result", ops.toString()); @@ -303,7 +304,8 @@ struct AtomicOpsWorkload : TestWorkload { // Get mapping between opsKeys and debugKeys ReadYourWritesTransaction tr1(cx); std::map records; // - RangeResult debuglog = co_await tr1.getRange(prefixRange(format("debug%08x", g)), CLIENT_KNOBS->TOO_MANY); + RangeResult debuglog = + co_await tr1.getRange(prefixRange(fmt::format("debug{:08x}", g)), CLIENT_KNOBS->TOO_MANY); if (debuglog.more) { TraceEvent(SevError, "DebugLogHitTxnLimits").detail("Result", debuglog.toString()); co_return; @@ -315,7 +317,7 @@ struct AtomicOpsWorkload : TestWorkload { // Get log key's value and assign it to the associated debugKey ReadYourWritesTransaction tr2(cx); std::map logVal; // debugKey, log's value - RangeResult log = co_await tr2.getRange(prefixRange(format("log%08x", g)), CLIENT_KNOBS->TOO_MANY); + RangeResult log = co_await tr2.getRange(prefixRange(fmt::format("log{:08x}", g)), CLIENT_KNOBS->TOO_MANY); if (log.more) { TraceEvent(SevError, "LogHitTxnLimits").detail("Result", log.toString()); co_return; @@ -329,7 +331,7 @@ struct AtomicOpsWorkload : TestWorkload { // Get opsKeys and validate if it has correct value ReadYourWritesTransaction tr3(cx); std::map opsVal; // ops key, ops value - RangeResult ops = co_await tr3.getRange(prefixRange(format("ops%08x", g)), CLIENT_KNOBS->TOO_MANY); + RangeResult ops = co_await tr3.getRange(prefixRange(fmt::format("ops{:08x}", g)), CLIENT_KNOBS->TOO_MANY); if (ops.more) { TraceEvent(SevError, "OpsHitTxnLimits").detail("Result", ops.toString()); co_return; @@ -372,7 +374,7 @@ struct AtomicOpsWorkload : TestWorkload { try { { // Calculate the accumulated value in the log keyspace for the group g - Key begin(format("log%08x", g)); + Key begin(fmt::format("log{:08x}", g)); RangeResult log_ = co_await tr.getRange(KeyRangeRef(begin, strinc(begin)), CLIENT_KNOBS->TOO_MANY); log = log_; @@ -387,7 +389,7 @@ struct AtomicOpsWorkload : TestWorkload { { // Calculate the accumulated value in the ops keyspace for the group g - Key begin(format("ops%08x", g)); + Key begin(fmt::format("ops{:08x}", g)); RangeResult ops = co_await tr.getRange(KeyRangeRef(begin, strinc(begin)), CLIENT_KNOBS->TOO_MANY); uint64_t zeroValue = 0; @@ -404,7 +406,7 @@ struct AtomicOpsWorkload : TestWorkload { ASSERT(logResult.present()); ASSERT(opsResult.present()); TraceEvent(SevError, "LogMismatch") - .detail("Index", format("log%08x", g)) + .detail("Index", fmt::format("log{:08x}", g)) .detail("LogResult", printable(logResult)) .detail("OpsResult", printable(opsResult)); } diff --git a/fdbserver/workloads/Backup.cpp b/fdbserver/workloads/Backup.cpp index af8d9b0307a..e522af82d48 100644 --- a/fdbserver/workloads/Backup.cpp +++ b/fdbserver/workloads/Backup.cpp @@ -26,6 +26,7 @@ #include "fdbserver/Knobs.h" #include "fdbserver/workloads/workloads.actor.h" #include "flow/IRandom.h" +#include "fmt/format.h" // A workload which only performs backup operations. A separate workload is used to perform restore operations. struct BackupWorkload : TestWorkload { @@ -217,7 +218,7 @@ struct BackupWorkload : TestWorkload { if (!fdesc.isError()) { BackupDescription desc = fdesc.get(); co_await desc.resolveVersionTimes(cx); - printf("BackupDescription:\n%s\n", desc.toString().c_str()); + fmt::print("BackupDescription:\n{}\n", desc.toString()); restorable = desc.maxRestorableVersion.present(); } } @@ -238,9 +239,9 @@ struct BackupWorkload : TestWorkload { .detail("LastBackupUID", lastBackupUID) .detail("BackupTag", printable(tag)) .detail("WaitStatus", BackupAgentBase::getStateText(resultWait)); - printf("BackupCorrectnessMissingBackupContainer tag: %s status: %s\n", - printable(tag).c_str(), - BackupAgentBase::getStateText(resultWait)); + fmt::println("BackupCorrectnessMissingBackupContainer tag: {} status: {}", + printable(tag), + BackupAgentBase::getStateText(resultWait)); } // Check that backup is restorable else if (!restorable) { @@ -249,7 +250,7 @@ struct BackupWorkload : TestWorkload { .detail("BackupTag", printable(tag)) .detail("BackupFolder", lastBackupContainer->getURL()) .detail("WaitStatus", BackupAgentBase::getStateText(resultWait)); - printf("BackupCorrectnessNotRestorable: tag: %s\n", printable(tag).c_str()); + fmt::println("BackupCorrectnessNotRestorable: tag: {}", printable(tag)); } // Abort the backup, if not the first backup because the second backup may have aborted the backup diff --git a/fdbserver/workloads/BackupAndParallelRestoreCorrectness.cpp b/fdbserver/workloads/BackupAndParallelRestoreCorrectness.cpp index f9edb561f69..0b6d6ca5c87 100644 --- a/fdbserver/workloads/BackupAndParallelRestoreCorrectness.cpp +++ b/fdbserver/workloads/BackupAndParallelRestoreCorrectness.cpp @@ -28,6 +28,7 @@ #include "fdbserver/RestoreCommon.actor.h" #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/workloads/BulkSetup.h" +#include "fmt/format.h" #define TEST_ABORT_FASTRESTORE 0 @@ -276,7 +277,7 @@ struct BackupAndParallelRestoreCorrectnessWorkload : TestWorkload { if (!fdesc.isError()) { BackupDescription desc = fdesc.get(); co_await desc.resolveVersionTimes(cx); - printf("BackupDescription:\n%s\n", desc.toString().c_str()); + fmt::print("BackupDescription:\n{}\n", desc.toString()); restorable = desc.maxRestorableVersion.present(); } } @@ -297,9 +298,9 @@ struct BackupAndParallelRestoreCorrectnessWorkload : TestWorkload { .detail("LastBackupUID", lastBackupUID) .detail("BackupTag", printable(tag)) .detail("WaitStatus", resultWait); - printf("BackupCorrectnessMissingBackupContainer tag: %s status: %s\n", - printable(tag).c_str(), - BackupAgentBase::getStateText(resultWait)); + fmt::println("BackupCorrectnessMissingBackupContainer tag: {} status: {}", + printable(tag), + BackupAgentBase::getStateText(resultWait)); } // Check that backup is restorable else if (!restorable) { @@ -308,7 +309,7 @@ struct BackupAndParallelRestoreCorrectnessWorkload : TestWorkload { .detail("BackupTag", printable(tag)) .detail("BackupFolder", lastBackupContainer->getURL()) .detail("WaitStatus", BackupAgentBase::getStateText(resultWait)); - printf("BackupCorrectnessNotRestorable: tag: %s\n", printable(tag).c_str()); + fmt::println("BackupCorrectnessNotRestorable: tag: {}", printable(tag)); } // Abort the backup, if not the first backup because the second backup may have aborted the backup @@ -517,7 +518,7 @@ struct BackupAndParallelRestoreCorrectnessWorkload : TestWorkload { if (lastBackupContainer && performRestore) { if (deterministicRandom()->random01() < 0.5) { - printf("TODO: Check if restore can succeed if dirty restore is performed first\n"); + fmt::println("TODO: Check if restore can succeed if dirty restore is performed first"); // TODO: To support restore even after we attempt dirty restore. Not implemented in the 1st version // fast restore // wait(attemptDirtyRestore(this, cx, &backupAgent, StringRef(lastBackupContainer->getURL()), @@ -688,11 +689,11 @@ struct BackupAndParallelRestoreCorrectnessWorkload : TestWorkload { .detail("BackupTag", printable(backupTag)) .detail("TaskCount", taskCount) .detail("WaitCycles", waitCycles); - printf("%.6f %-10s Wait #%4d for %lld tasks to end\n", - now(), - randomID.toString().c_str(), - waitCycles, - (long long)taskCount); + fmt::println("{:.6f} {:<10} Wait #{:4} for {} tasks to end", + now(), + randomID.toString(), + waitCycles, + (long long)taskCount); co_await delay(5.0); co_await tr->commit(); @@ -711,7 +712,7 @@ struct BackupAndParallelRestoreCorrectnessWorkload : TestWorkload { .detail("BackupTag", printable(backupTag)) .detail("TaskCount", taskCount) .detail("WaitCycles", waitCycles); - printf("BackupCorrectnessLeftOverLogTasks: %ld\n", (long)taskCount); + fmt::println("BackupCorrectnessLeftOverLogTasks: {}", (long)taskCount); } RangeResult agentValues = @@ -720,9 +721,9 @@ struct BackupAndParallelRestoreCorrectnessWorkload : TestWorkload { // Error if the system keyspace for the backup tag is not empty if (agentValues.size() > 0) { displaySystemKeys++; - printf("BackupCorrectnessLeftOverMutationKeys: (%d) %s\n", - agentValues.size(), - printable(backupAgentKey).c_str()); + fmt::println("BackupCorrectnessLeftOverMutationKeys: ({}) {}", + agentValues.size(), + printable(backupAgentKey)); TraceEvent(SevError, "BackupCorrectnessLeftOverMutationKeys", randomID) .detail("BackupTag", printable(backupTag)) .detail("LeftOverKeys", agentValues.size()) @@ -731,12 +732,12 @@ struct BackupAndParallelRestoreCorrectnessWorkload : TestWorkload { TraceEvent("BARW_LeftOverKey", randomID) .detail("Key", printable(StringRef(s.key.toString()))) .detail("Value", printable(StringRef(s.value.toString()))); - printf(" Key: %-50s Value: %s\n", - printable(StringRef(s.key.toString())).c_str(), - printable(StringRef(s.value.toString())).c_str()); + fmt::println(" Key: {:<50} Value: {}", + printable(StringRef(s.key.toString())), + printable(StringRef(s.value.toString()))); } } else { - printf("No left over backup agent configuration keys\n"); + fmt::println("No left over backup agent configuration keys"); } Optional latestVersion = co_await tr->get(backupLatestVersionsKey); @@ -746,7 +747,7 @@ struct BackupAndParallelRestoreCorrectnessWorkload : TestWorkload { .detail("BackupLatestVersionsKey", backupLatestVersionsKey.printable()) .detail("DestUidValue", destUidValue.printable()); } else { - printf("No left over backup version key\n"); + fmt::println("No left over backup version key"); } RangeResult versions = co_await tr->getRange( @@ -758,15 +759,15 @@ struct BackupAndParallelRestoreCorrectnessWorkload : TestWorkload { // Error if the log/mutation keyspace for the backup tag is not empty if (logValues.size() > 0) { displaySystemKeys++; - printf("BackupCorrectnessLeftOverLogKeys: (%d) %s\n", - logValues.size(), - printable(backupLogValuesKey).c_str()); + fmt::println("BackupCorrectnessLeftOverLogKeys: ({}) {}", + logValues.size(), + printable(backupLogValuesKey)); TraceEvent(SevError, "BackupCorrectnessLeftOverLogKeys", randomID) .detail("BackupTag", printable(backupTag)) .detail("LeftOverKeys", logValues.size()) .detail("KeySpace", printable(backupLogValuesKey)); } else { - printf("No left over backup log keys\n"); + fmt::println("No left over backup log keys"); } } diff --git a/fdbserver/workloads/BackupCorrectness.cpp b/fdbserver/workloads/BackupCorrectness.cpp index 8d9e907b0ed..78871e7b24e 100644 --- a/fdbserver/workloads/BackupCorrectness.cpp +++ b/fdbserver/workloads/BackupCorrectness.cpp @@ -29,6 +29,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/workloads/BulkSetup.h" #include "flow/IRandom.h" +#include "fmt/format.h" // TODO: explain the purpose of this workload and how it different from the // 20+ (literally) other backup/restore workloads. @@ -358,7 +359,7 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload { if (!fdesc.isError()) { BackupDescription desc = fdesc.get(); co_await desc.resolveVersionTimes(cx); - printf("BackupDescription:\n%s\n", desc.toString().c_str()); + fmt::print("BackupDescription:\n{}\n", desc.toString()); restorable = desc.maxRestorableVersion.present(); } } @@ -379,9 +380,9 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload { .detail("LastBackupUID", lastBackupUID) .detail("BackupTag", printable(tag)) .detail("WaitStatus", BackupAgentBase::getStateText(resultWait)); - printf("BackupCorrectnessMissingBackupContainer tag: %s status: %s\n", - printable(tag).c_str(), - BackupAgentBase::getStateText(resultWait)); + fmt::println("BackupCorrectnessMissingBackupContainer tag: {} status: {}", + printable(tag), + BackupAgentBase::getStateText(resultWait)); } // Check that backup is restorable else if (!restorable) { @@ -390,7 +391,7 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload { .detail("BackupTag", printable(tag)) .detail("BackupFolder", lastBackupContainer->getURL()) .detail("WaitStatus", BackupAgentBase::getStateText(resultWait)); - printf("BackupCorrectnessNotRestorable: tag: %s\n", printable(tag).c_str()); + fmt::println("BackupCorrectnessNotRestorable: tag: {}", printable(tag)); } // Abort the backup, if not the first backup because the second backup may have aborted the backup @@ -505,7 +506,7 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload { return Void(); }); Standalone restoreTag(self->backupTag.toString() + "_system"); - printf("BackupCorrectness, backupAgent.restore is called for tag:%s\n", restoreTag.toString().c_str()); + fmt::println("BackupCorrectness, backupAgent.restore is called for tag:{}", restoreTag.toString()); co_await backupAgent->restore(cx, cx, restoreTag, @@ -523,7 +524,7 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload { InconsistentSnapshotOnly::False, ::invalidVersion, lastBackupContainer->getEncryptionKeyFileName()); - printf("BackupCorrectness, backupAgent.restore finished for tag:%s\n", restoreTag.toString().c_str()); + fmt::println("BackupCorrectness, backupAgent.restore finished for tag:{}", restoreTag.toString()); } Future _start(Database cx) { @@ -703,11 +704,11 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload { auto range = restoreRanges[restoreIndex]; Standalone restoreTag(backupTag.toString() + "_" + std::to_string(restoreIndex)); restoreTags.push_back(restoreTag); - printf("BackupCorrectness, restore for each range: backupAgent.restore is called for " - "restoreIndex:%d tag:%s ranges:%s\n", - restoreIndex, - range.toString().c_str(), - restoreTag.toString().c_str()); + fmt::println("BackupCorrectness, restore for each range: backupAgent.restore is called for " + "restoreIndex:{} tag:{} ranges:{}", + restoreIndex, + range.toString(), + restoreTag.toString()); restores.push_back(backupAgent.restore(cx, cx, restoreTag, @@ -729,9 +730,9 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload { multipleRangesInOneTag = true; Standalone restoreTag(backupTag.toString() + "_" + std::to_string(restoreIndex)); restoreTags.push_back(restoreTag); - printf("BackupCorrectness, backupAgent.restore is called for restoreIndex:%d tag:%s\n", - restoreIndex, - restoreTag.toString().c_str()); + fmt::println("BackupCorrectness, backupAgent.restore is called for restoreIndex:{} tag:{}", + restoreIndex, + restoreTag.toString()); restores.push_back(backupAgent.restore(cx, cx, restoreTag, @@ -876,7 +877,7 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload { .detail("BackupTag", printable(backupTag)) .detail("TaskCount", taskCount) .detail("WaitCycles", waitCycles); - printf("EndingNonZeroTasks: %ld\n", (long)taskCount); + fmt::println("EndingNonZeroTasks: {}", (long)taskCount); co_await TaskBucket::debugPrintRange(cx, normalKeys.end, StringRef()); } @@ -887,11 +888,11 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload { .detail("BackupTag", printable(backupTag)) .detail("TaskCount", taskCount) .detail("WaitCycles", waitCycles); - printf("%.6f %-10s Wait #%4d for %lld tasks to end\n", - now(), - randomID.toString().c_str(), - waitCycles, - (long long)taskCount); + fmt::println("{:.6f} {:<10} Wait #{:4} for {} tasks to end", + now(), + randomID.toString(), + waitCycles, + (long long)taskCount); co_await delay(5.0); @@ -905,9 +906,9 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload { // Error if the system keyspace for the backup tag is not empty if (agentValues.size() > 0) { displaySystemKeys++; - printf("BackupCorrectnessLeftOverMutationKeys: (%d) %s\n", - agentValues.size(), - printable(backupAgentKey).c_str()); + fmt::println("BackupCorrectnessLeftOverMutationKeys: ({}) {}", + agentValues.size(), + printable(backupAgentKey)); TraceEvent(SevError, "BackupCorrectnessLeftOverMutationKeys", randomID) .detail("BackupTag", printable(backupTag)) .detail("LeftOverKeys", agentValues.size()) @@ -916,12 +917,12 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload { TraceEvent("BARW_LeftOverKey", randomID) .detail("Key", printable(StringRef(s.key.toString()))) .detail("Value", printable(StringRef(s.value.toString()))); - printf(" Key: %-50s Value: %s\n", - printable(StringRef(s.key.toString())).c_str(), - printable(StringRef(s.value.toString())).c_str()); + fmt::println(" Key: {:<50} Value: {}", + printable(StringRef(s.key.toString())), + printable(StringRef(s.value.toString()))); } } else { - printf("No left over backup agent configuration keys\n"); + fmt::println("No left over backup agent configuration keys"); } Optional latestVersion = co_await tr->get(backupLatestVersionsKey); @@ -931,7 +932,7 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload { .detail("BackupLatestVersionsKey", backupLatestVersionsKey.printable()) .detail("DestUidValue", destUidValue.printable()); } else { - printf("No left over backup version key\n"); + fmt::println("No left over backup version key"); } RangeResult versions = co_await tr->getRange( @@ -943,15 +944,15 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload { // Error if the log/mutation keyspace for the backup tag is not empty if (logValues.size() > 0) { displaySystemKeys++; - printf("BackupCorrectnessLeftOverLogKeys: (%d) %s\n", - logValues.size(), - printable(backupLogValuesKey).c_str()); + fmt::println("BackupCorrectnessLeftOverLogKeys: ({}) {}", + logValues.size(), + printable(backupLogValuesKey)); TraceEvent(SevError, "BackupCorrectnessLeftOverLogKeys", randomID) .detail("BackupTag", printable(backupTag)) .detail("LeftOverKeys", logValues.size()) .detail("KeySpace", printable(backupLogValuesKey)); } else { - printf("No left over backup log keys\n"); + fmt::println("No left over backup log keys"); } } diff --git a/fdbserver/workloads/BackupCorrectnessPartitioned.cpp b/fdbserver/workloads/BackupCorrectnessPartitioned.cpp index 8e585713d12..8adda73b618 100644 --- a/fdbserver/workloads/BackupCorrectnessPartitioned.cpp +++ b/fdbserver/workloads/BackupCorrectnessPartitioned.cpp @@ -29,6 +29,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/workloads/BulkSetup.h" #include "flow/IRandom.h" +#include "fmt/format.h" // A workload for // https://github.com/apple/foundationdb/blob/main/design/backup_v2_partitioned_logs.md @@ -355,7 +356,7 @@ struct BackupAndRestorePartitionedCorrectnessWorkload : TestWorkload { if (!fdesc.isError()) { BackupDescription desc = fdesc.get(); co_await desc.resolveVersionTimes(cx); - printf("BackupDescription:\n%s\n", desc.toString().c_str()); + fmt::print("BackupDescription:\n{}\n", desc.toString()); restorable = desc.maxRestorableVersion.present(); } } @@ -376,9 +377,9 @@ struct BackupAndRestorePartitionedCorrectnessWorkload : TestWorkload { .detail("LastBackupUID", lastBackupUID) .detail("BackupTag", printable(tag)) .detail("WaitStatus", BackupAgentBase::getStateText(resultWait)); - printf("BackupCorrectnessMissingBackupContainer tag: %s status: %s\n", - printable(tag).c_str(), - BackupAgentBase::getStateText(resultWait)); + fmt::println("BackupCorrectnessMissingBackupContainer tag: {} status: {}", + printable(tag), + BackupAgentBase::getStateText(resultWait)); } // Check that backup is restorable else if (!restorable) { @@ -387,7 +388,7 @@ struct BackupAndRestorePartitionedCorrectnessWorkload : TestWorkload { .detail("BackupTag", printable(tag)) .detail("BackupFolder", lastBackupContainer->getURL()) .detail("WaitStatus", BackupAgentBase::getStateText(resultWait)); - printf("BackupCorrectnessNotRestorable: tag: %s\n", printable(tag).c_str()); + fmt::println("BackupCorrectnessNotRestorable: tag: {}", printable(tag)); } // Abort the backup, if not the first backup because the second backup may have aborted the backup @@ -451,7 +452,7 @@ struct BackupAndRestorePartitionedCorrectnessWorkload : TestWorkload { return Void(); }); Standalone restoreTag(self->backupTag.toString() + "_system"); - printf("BackupCorrectness, backupAgent.restore is called for tag:%s\n", restoreTag.toString().c_str()); + fmt::println("BackupCorrectness, backupAgent.restore is called for tag:{}", restoreTag.toString()); co_await backupAgent->restore(cx, cx, restoreTag, @@ -469,7 +470,7 @@ struct BackupAndRestorePartitionedCorrectnessWorkload : TestWorkload { InconsistentSnapshotOnly::False, ::invalidVersion, self->encryptionKeyFileName); - printf("BackupCorrectness, backupAgent.restore finished for tag:%s\n", restoreTag.toString().c_str()); + fmt::println("BackupCorrectness, backupAgent.restore finished for tag:{}", restoreTag.toString()); } Future _start(Database cx) { @@ -651,11 +652,11 @@ struct BackupAndRestorePartitionedCorrectnessWorkload : TestWorkload { .detail("BackupTag", printable(backupTag)) .detail("TaskCount", taskCount) .detail("WaitCycles", waitCycles); - printf("%.6f %-10s Wait #%4d for %lld tasks to end\n", - now(), - randomID.toString().c_str(), - waitCycles, - (long long)taskCount); + fmt::println("{:.6f} {:<10} Wait #{:4} for {} tasks to end", + now(), + randomID.toString(), + waitCycles, + (long long)taskCount); co_await delay(5.0); @@ -669,9 +670,9 @@ struct BackupAndRestorePartitionedCorrectnessWorkload : TestWorkload { // Error if the system keyspace for the backup tag is not empty if (agentValues.size() > 0) { displaySystemKeys++; - printf("BackupCorrectnessLeftOverMutationKeys: (%d) %s\n", - agentValues.size(), - printable(backupAgentKey).c_str()); + fmt::println("BackupCorrectnessLeftOverMutationKeys: ({}) {}", + agentValues.size(), + printable(backupAgentKey)); TraceEvent(SevError, "BackupCorrectnessLeftOverMutationKeys", randomID) .detail("BackupTag", printable(backupTag)) .detail("LeftOverKeys", agentValues.size()) @@ -680,12 +681,12 @@ struct BackupAndRestorePartitionedCorrectnessWorkload : TestWorkload { TraceEvent("BARW_LeftOverKey", randomID) .detail("Key", printable(StringRef(s.key.toString()))) .detail("Value", printable(StringRef(s.value.toString()))); - printf(" Key: %-50s Value: %s\n", - printable(StringRef(s.key.toString())).c_str(), - printable(StringRef(s.value.toString())).c_str()); + fmt::println(" Key: {:<50} Value: {}", + printable(StringRef(s.key.toString())), + printable(StringRef(s.value.toString()))); } } else { - printf("No left over backup agent configuration keys\n"); + fmt::println("No left over backup agent configuration keys"); } Optional latestVersion = co_await tr->get(backupLatestVersionsKey); @@ -695,7 +696,7 @@ struct BackupAndRestorePartitionedCorrectnessWorkload : TestWorkload { .detail("BackupLatestVersionsKey", backupLatestVersionsKey.printable()) .detail("DestUidValue", destUidValue.printable()); } else { - printf("No left over backup version key\n"); + fmt::println("No left over backup version key"); } RangeResult versions = co_await tr->getRange( @@ -707,15 +708,15 @@ struct BackupAndRestorePartitionedCorrectnessWorkload : TestWorkload { // Error if the log/mutation keyspace for the backup tag is not empty if (logValues.size() > 0) { displaySystemKeys++; - printf("BackupCorrectnessLeftOverLogKeys: (%d) %s\n", - logValues.size(), - printable(backupLogValuesKey).c_str()); + fmt::println("BackupCorrectnessLeftOverLogKeys: ({}) {}", + logValues.size(), + printable(backupLogValuesKey)); TraceEvent(SevError, "BackupCorrectnessLeftOverLogKeys", randomID) .detail("BackupTag", printable(backupTag)) .detail("LeftOverKeys", logValues.size()) .detail("KeySpace", printable(backupLogValuesKey)); } else { - printf("No left over backup log keys\n"); + fmt::println("No left over backup log keys"); } } diff --git a/fdbserver/workloads/BackupToDBCorrectness.cpp b/fdbserver/workloads/BackupToDBCorrectness.cpp index a7341eda569..6ff27d3d4ba 100644 --- a/fdbserver/workloads/BackupToDBCorrectness.cpp +++ b/fdbserver/workloads/BackupToDBCorrectness.cpp @@ -27,6 +27,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/workloads/BulkSetup.h" #include "flow/ApiVersion.h" +#include "fmt/format.h" // This workload tests backing up one cluster to another. @@ -466,7 +467,7 @@ struct BackupToDBCorrectnessWorkload : TestWorkload { .detail("BackupTag", printable(tag)) .detail("TaskCount", taskCount) .detail("WaitCycles", waitCycles); - printf("EndingNonZeroTasks: %ld\n", (long)taskCount); + fmt::println("EndingNonZeroTasks: {}", (long)taskCount); co_await TaskBucket::debugPrintRange(cx, "\xff"_sr, StringRef()); } @@ -477,11 +478,11 @@ struct BackupToDBCorrectnessWorkload : TestWorkload { .detail("BackupTag", printable(tag)) .detail("TaskCount", taskCount) .detail("WaitCycles", waitCycles); - printf("%.6f %-10s Wait #%4d for %lld tasks to end\n", - now(), - randomID.toString().c_str(), - waitCycles, - (long long)taskCount); + fmt::println("{:.6f} {:<10} Wait #{:4} for {} tasks to end", + now(), + randomID.toString(), + waitCycles, + (long long)taskCount); co_await delay(5.0); tr = makeReference(cx); @@ -494,9 +495,9 @@ struct BackupToDBCorrectnessWorkload : TestWorkload { // Error if the system keyspace for the backup tag is not empty if (agentValues.size() > 0) { displaySystemKeys++; - printf("BackupCorrectnessLeftoverMutationKeys: (%d) %s\n", - agentValues.size(), - printable(backupAgentKey).c_str()); + fmt::println("BackupCorrectnessLeftoverMutationKeys: ({}) {}", + agentValues.size(), + printable(backupAgentKey)); TraceEvent(SevError, "BackupCorrectnessLeftoverMutationKeys", randomID) .detail("BackupTag", printable(tag)) .detail("LeftoverKeys", agentValues.size()) @@ -505,12 +506,12 @@ struct BackupToDBCorrectnessWorkload : TestWorkload { TraceEvent("BARW_LeftoverKey", randomID) .detail("Key", printable(StringRef(s.key.toString()))) .detail("Value", printable(StringRef(s.value.toString()))); - printf(" Key: %-50s Value: %s\n", - printable(StringRef(s.key.toString())).c_str(), - printable(StringRef(s.value.toString())).c_str()); + fmt::println(" Key: {:<50} Value: {}", + printable(StringRef(s.key.toString())), + printable(StringRef(s.value.toString()))); } } else { - printf("No left over backup agent configuration keys\n"); + fmt::println("No left over backup agent configuration keys"); } Optional latestVersion = co_await tr->get(backupLatestVersionsKey); @@ -520,7 +521,7 @@ struct BackupToDBCorrectnessWorkload : TestWorkload { .detail("Key", backupLatestVersionsKey.printable()) .detail("Value", BinaryReader::fromStringRef(latestVersion.get(), Unversioned())); } else { - printf("No left over backup version key\n"); + fmt::println("No left over backup version key"); } RangeResult versions = co_await tr->getRange( @@ -532,9 +533,9 @@ struct BackupToDBCorrectnessWorkload : TestWorkload { // Error if the log/mutation keyspace for the backup tag is not empty if (logValues.size() > 0) { displaySystemKeys++; - printf("BackupCorrectnessLeftoverLogKeys: (%d) %s\n", - logValues.size(), - printable(backupLogValuesKey).c_str()); + fmt::println("BackupCorrectnessLeftoverLogKeys: ({}) {}", + logValues.size(), + printable(backupLogValuesKey)); TraceEvent(SevError, "BackupCorrectnessLeftoverLogKeys", randomID) .detail("BackupTag", printable(tag)) .detail("LeftoverKeys", logValues.size()) @@ -544,12 +545,12 @@ struct BackupToDBCorrectnessWorkload : TestWorkload { TraceEvent("BARW_LeftoverKey", randomID) .detail("Key", printable(StringRef(s.key.toString()))) .detail("Value", printable(StringRef(s.value.toString()))); - printf(" Key: %-50s Value: %s\n", - printable(StringRef(s.key.toString())).c_str(), - printable(StringRef(s.value.toString())).c_str()); + fmt::println(" Key: {:<50} Value: {}", + printable(StringRef(s.key.toString())), + printable(StringRef(s.value.toString()))); } } else { - printf("No left over backup log keys\n"); + fmt::println("No left over backup log keys"); } } diff --git a/fdbserver/workloads/BackupToDBUpgrade.cpp b/fdbserver/workloads/BackupToDBUpgrade.cpp index b3e463667dc..052b90deb57 100644 --- a/fdbserver/workloads/BackupToDBUpgrade.cpp +++ b/fdbserver/workloads/BackupToDBUpgrade.cpp @@ -26,6 +26,7 @@ #include "fdbserver/workloads/BulkSetup.h" #include "fdbclient/ManagementAPI.actor.h" #include "flow/ApiVersion.h" +#include "fmt/format.h" // TODO: explain the purpose of this workload and how it different from the // 20+ (literally) other backup/restore workloads. @@ -120,7 +121,7 @@ struct BackupToDBUpgradeWorkload : TestWorkload { for (auto r : self->backupRanges) { if (!r.empty()) { auto targetRange = r.withPrefix(self->backupPrefix); - printf("Clearing %s in destination\n", printable(targetRange).c_str()); + fmt::println("Clearing {} in destination", printable(targetRange)); tr->addReadConflictRange(targetRange); tr->clear(targetRange); } @@ -175,7 +176,7 @@ struct BackupToDBUpgradeWorkload : TestWorkload { .detail("BackupTag", printable(tag)) .detail("TaskCount", taskCount) .detail("WaitCycles", waitCycles); - printf("EndingNonZeroTasks: %ld\n", (long)taskCount); + fmt::println("EndingNonZeroTasks: {}", (long)taskCount); co_await TaskBucket::debugPrintRange(cx, "\xff"_sr, StringRef()); } @@ -186,7 +187,7 @@ struct BackupToDBUpgradeWorkload : TestWorkload { .detail("BackupTag", printable(tag)) .detail("TaskCount", taskCount) .detail("WaitCycles", waitCycles); - printf("%.6f Wait #%4d for %lld tasks to end\n", now(), waitCycles, (long long)taskCount); + fmt::println("{:.6f} Wait #{:4} for {} tasks to end", now(), waitCycles, (long long)taskCount); co_await delay(20.0); tr = makeReference(cx); @@ -199,9 +200,9 @@ struct BackupToDBUpgradeWorkload : TestWorkload { // Error if the system keyspace for the backup tag is not empty if (!agentValues.empty()) { displaySystemKeys++; - printf("BackupCorrectnessLeftoverMutationKeys: (%d) %s\n", - agentValues.size(), - printable(backupAgentKey).c_str()); + fmt::println("BackupCorrectnessLeftoverMutationKeys: ({}) {}", + agentValues.size(), + printable(backupAgentKey)); TraceEvent(SevError, "BackupCorrectnessLeftoverMutationKeys") .detail("BackupTag", printable(tag)) .detail("LeftoverKeys", agentValues.size()) @@ -210,12 +211,12 @@ struct BackupToDBUpgradeWorkload : TestWorkload { TraceEvent("DRU_LeftoverKey") .detail("Key", printable(StringRef(s.key.toString()))) .detail("Value", printable(StringRef(s.value.toString()))); - printf(" Key: %-50s Value: %s\n", - printable(StringRef(s.key.toString())).c_str(), - printable(StringRef(s.value.toString())).c_str()); + fmt::println(" Key: {:<50} Value: {}", + printable(StringRef(s.key.toString())), + printable(StringRef(s.value.toString()))); } } else { - printf("No left over backup agent configuration keys\n"); + fmt::println("No left over backup agent configuration keys"); } Optional latestVersion = co_await tr->get(backupLatestVersionsKey); @@ -225,7 +226,7 @@ struct BackupToDBUpgradeWorkload : TestWorkload { .detail("Key", backupLatestVersionsKey.printable()) .detail("Value", BinaryReader::fromStringRef(latestVersion.get(), Unversioned())); } else { - printf("No left over backup version key\n"); + fmt::println("No left over backup version key"); } RangeResult versions = co_await tr->getRange( @@ -237,9 +238,9 @@ struct BackupToDBUpgradeWorkload : TestWorkload { // Error if the log/mutation keyspace for the backup tag is not empty if (!logValues.empty()) { displaySystemKeys++; - printf("BackupCorrectnessLeftoverLogKeys: (%d) %s\n", - logValues.size(), - printable(backupLogValuesKey).c_str()); + fmt::println("BackupCorrectnessLeftoverLogKeys: ({}) {}", + logValues.size(), + printable(backupLogValuesKey)); TraceEvent(SevError, "BackupCorrectnessLeftoverLogKeys") .detail("BackupTag", printable(tag)) .detail("LeftoverKeys", logValues.size()) @@ -249,12 +250,12 @@ struct BackupToDBUpgradeWorkload : TestWorkload { TraceEvent("DRU_LeftoverKey") .detail("Key", printable(StringRef(s.key.toString()))) .detail("Value", printable(StringRef(s.value.toString()))); - printf(" Key: %-50s Value: %s\n", - printable(StringRef(s.key.toString())).c_str(), - printable(StringRef(s.value.toString())).c_str()); + fmt::println(" Key: {:<50} Value: {}", + printable(StringRef(s.key.toString())), + printable(StringRef(s.value.toString()))); } } else { - printf("No left over backup log keys\n"); + fmt::println("No left over backup log keys"); } } diff --git a/fdbserver/workloads/BulkLoad.cpp b/fdbserver/workloads/BulkLoad.cpp index 81fda548bec..380b21cf3f5 100644 --- a/fdbserver/workloads/BulkLoad.cpp +++ b/fdbserver/workloads/BulkLoad.cpp @@ -22,6 +22,7 @@ #include "fdbclient/NativeAPI.actor.h" #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct BulkLoadWorkload : TestWorkload { static constexpr auto NAME = "BulkLoad"; @@ -86,11 +87,11 @@ struct BulkLoadWorkload : TestWorkload { Error err; try { for (int i = 0; i < self->writesPerTransaction; i++) { - std::string key = format("%s/bulkload/%04x/%04x/%08x", - self->keyPrefix.toString().c_str(), - self->clientId, - actorId, - idx + i); + std::string key = fmt::format("{}/bulkload/{:04x}/{:04x}/{:08x}", + self->keyPrefix.toString(), + self->clientId, + actorId, + idx + i); tr.set(key, self->value); txnBytes += key.size() + self->value.size(); } diff --git a/fdbserver/workloads/CommitBugCheck.cpp b/fdbserver/workloads/CommitBugCheck.cpp index 55c99a4493d..835713e0713 100644 --- a/fdbserver/workloads/CommitBugCheck.cpp +++ b/fdbserver/workloads/CommitBugCheck.cpp @@ -20,6 +20,7 @@ #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" // Regression tests for 2 commit related bugs struct CommitBugWorkload : TestWorkload { @@ -33,7 +34,7 @@ struct CommitBugWorkload : TestWorkload { Future start(Database const& cx) override { return timeout(bug1(cx, this) && bug2(cx, this), 60, Void()); } Future bug1(Database cx, CommitBugWorkload* self) { - Key key = StringRef(format("B1Key%d", self->clientId)); + Key key = StringRef(fmt::format("B1Key{}", self->clientId)); Value val1 = "Value1"_sr; Value val2 = "Value2"_sr; @@ -104,7 +105,7 @@ struct CommitBugWorkload : TestWorkload { } Future bug2(Database cx, CommitBugWorkload* self) { - Key key = StringRef(format("B2Key%d", self->clientId)); + Key key = StringRef(fmt::format("B2Key{}", self->clientId)); for (int i = 0; i < 1000; ++i) { Transaction tr(cx); @@ -124,7 +125,7 @@ struct CommitBugWorkload : TestWorkload { } TraceEvent("CommitBug2SetKey").detail("Num", i + 1); - tr.set(key, StringRef(format("%d", i + 1))); + tr.set(key, StringRef(fmt::format("{}", i + 1))); co_await tr.commit(); TraceEvent("CommitBug2SetCompleted").detail("Num", i + 1); break; @@ -139,7 +140,7 @@ struct CommitBugWorkload : TestWorkload { Error caughtErr; try { TraceEvent("CommitBug2SetKey").detail("Num", i + 1); - tr.set(key, StringRef(format("%d", i + 1))); + tr.set(key, StringRef(fmt::format("{}", i + 1))); TraceEvent("CommitBug2SetCompleted").detail("Num", i + 1); co_await tr.commit(); break; diff --git a/fdbserver/workloads/ConfigureDatabase.cpp b/fdbserver/workloads/ConfigureDatabase.cpp index 056cd5f442a..2c46da59cc2 100644 --- a/fdbserver/workloads/ConfigureDatabase.cpp +++ b/fdbserver/workloads/ConfigureDatabase.cpp @@ -32,6 +32,7 @@ #include "fdbserver/QuietDatabase.h" #include "fdbserver/SimulatedCluster.h" #include "flow/IRandom.h" +#include "fmt/format.h" static const char* storageMigrationTypes[] = { "perpetual_storage_wiggle=0 storage_migration_type=aggressive", "perpetual_storage_wiggle=1", @@ -60,7 +61,7 @@ std::string generateRegions() { } if (deterministicRandom()->random01() < 0.25) { - return format(" usable_regions=%d", deterministicRandom()->randomInt(1, 3)); + return fmt::format(" usable_regions={}", deterministicRandom()->randomInt(1, 3)); } int primaryPriority = 1; @@ -204,8 +205,8 @@ std::string generateRegions() { ASSERT(false); // Programmer forgot to adjust cases. } - result += format(" log_routers=%d", deterministicRandom()->randomInt(1, 7)); - result += format(" remote_logs=%d", deterministicRandom()->randomInt(1, 7)); + result += fmt::format(" log_routers={}", deterministicRandom()->randomInt(1, 7)); + result += fmt::format(" remote_logs={}", deterministicRandom()->randomInt(1, 7)); } primaryObj["datacenters"] = primaryDcArr; @@ -217,7 +218,7 @@ std::string generateRegions() { if (deterministicRandom()->random01() < 0.8) { regionArr.push_back(remoteObj); if (deterministicRandom()->random01() < 0.25) { - result += format(" usable_regions=%d", deterministicRandom()->randomInt(1, 3)); + result += fmt::format(" usable_regions={}", deterministicRandom()->randomInt(1, 3)); } } @@ -262,10 +263,10 @@ struct ConfigureDatabaseWorkload : TestWorkload { return x; } - inline Standalone getDatabaseName(int dbIndex) { return StringRef(format("DestroyDB%d", dbIndex)); } + inline Standalone getDatabaseName(int dbIndex) { return StringRef(fmt::format("DestroyDB{}", dbIndex)); } static Future IssueConfigurationChange(Database cx, const std::string& config, bool force) { - printf("Issuing configuration change: %s\n", config.c_str()); + fmt::println("Issuing configuration change: {}", config); return ManagementAPI::changeConfig(cx.getReference(), config, force); } @@ -417,18 +418,18 @@ struct ConfigureDatabaseWorkload : TestWorkload { config += generateRegions(); if (deterministicRandom()->random01() < 0.5) - config += " logs=" + format("%d", randomRoleNumber()); + config += " logs=" + fmt::format("{}", randomRoleNumber()); if (deterministicRandom()->random01() < 0.2) { - config += " proxies=" + format("%d", deterministicRandom()->randomInt(2, 5)); + config += " proxies=" + fmt::format("{}", deterministicRandom()->randomInt(2, 5)); } else { if (deterministicRandom()->random01() < 0.5) - config += " commit_proxies=" + format("%d", randomRoleNumber()); + config += " commit_proxies=" + fmt::format("{}", randomRoleNumber()); if (deterministicRandom()->random01() < 0.5) - config += " grv_proxies=" + format("%d", randomRoleNumber()); + config += " grv_proxies=" + fmt::format("{}", randomRoleNumber()); } if (deterministicRandom()->random01() < 0.5) - config += " resolvers=" + format("%d", randomRoleNumber()); + config += " resolvers=" + fmt::format("{}", randomRoleNumber()); co_await IssueConfigurationChange(cx, config, false); diff --git a/fdbserver/workloads/ConflictRange.cpp b/fdbserver/workloads/ConflictRange.cpp index 4eb260fb4fb..9ba05f054ac 100644 --- a/fdbserver/workloads/ConflictRange.cpp +++ b/fdbserver/workloads/ConflictRange.cpp @@ -23,6 +23,7 @@ #include "fdbclient/ReadYourWrites.h" #include "fdbserver/workloads/workloads.actor.h" #include "fdbclient/ManagementAPI.actor.h" +#include "fmt/format.h" // For this test to report properly buggify must be disabled (flow.h) , and failConnection must be disabled in // (sim2.actor.cpp) @@ -96,7 +97,7 @@ struct ConflictRangeWorkload : TestWorkload { // Set one key after the end of the tested range. If this key is included in the result, then // we may have drifted into the system key-space and cannot evaluate the result. - Key sentinelKey = StringRef(format("%010d", self->maxKeySpace)); + Key sentinelKey = StringRef(fmt::format("{:010}", self->maxKeySpace)); while (true) { randomSets = !randomSets; @@ -118,8 +119,8 @@ struct ConflictRangeWorkload : TestWorkload { TraceEvent("ConflictRangeClear").detail("Begin", clearedBegin).detail("End", clearedEnd); } - tr0.clear( - KeyRangeRef(StringRef(format("%010d", 0)), StringRef(format("%010d", self->maxKeySpace)))); + tr0.clear(KeyRangeRef(StringRef(fmt::format("{:010}", 0)), + StringRef(fmt::format("{:010}", self->maxKeySpace)))); for (int i = 0; i < self->maxKeySpace; i++) { if (deterministicRandom()->random01() > 0.5) { TraceEvent("ConflictRangeInit").detail("Key", i); @@ -127,7 +128,7 @@ struct ConflictRangeWorkload : TestWorkload { clearedSet.insert(i); else { insertedSet.insert(i); - tr0.set(StringRef(format("%010d", i)), + tr0.set(StringRef(fmt::format("{:010}", i)), deterministicRandom()->randomUniqueID().toString()); } } @@ -143,7 +144,7 @@ struct ConflictRangeWorkload : TestWorkload { co_await tr0.onError(err); } - firstElement = Key(StringRef(format("%010d", *(insertedSet.begin())))); + firstElement = Key(StringRef(fmt::format("{:010}", *(insertedSet.begin())))); Transaction tr1(cx); Transaction tr2(cx); @@ -156,8 +157,8 @@ struct ConflictRangeWorkload : TestWorkload { // Generate a random getRange operation and execute it, if it produces results, save them, otherwise // retry. while (true) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace)); - myKeyB = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace)); + myKeyB = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace)); onEqualA = deterministicRandom()->randomInt(0, 2) != 0; onEqualB = deterministicRandom()->randomInt(0, 2) != 0; offsetA = deterministicRandom()->randomInt(-1 * self->maxOffset, self->maxOffset); @@ -179,7 +180,7 @@ struct ConflictRangeWorkload : TestWorkload { if (self->testReadYourWrites) { for (auto iter = clearedSet.begin(); iter != clearedSet.end(); ++iter) - tr1.set(StringRef(format("%010d", (*iter))), + tr1.set(StringRef(fmt::format("{:010}", (*iter))), deterministicRandom()->randomUniqueID().toString()); co_await tr1.commit(); tr1 = Transaction(cx); @@ -204,7 +205,7 @@ struct ConflictRangeWorkload : TestWorkload { if (!insertedSet.contains(proposedKey)) { TraceEvent("ConflictRangeSet").detail("Key", proposedKey); insertedSet.insert(proposedKey); - tr2.set(StringRef(format("%010d", proposedKey)), + tr2.set(StringRef(fmt::format("{:010}", proposedKey)), deterministicRandom()->randomUniqueID().toString()); break; } @@ -215,7 +216,7 @@ struct ConflictRangeWorkload : TestWorkload { if (insertedSet.contains(proposedKey)) { TraceEvent("ConflictRangeClear").detail("Key", proposedKey); insertedSet.erase(proposedKey); - tr2.clear(StringRef(format("%010d", proposedKey))); + tr2.clear(StringRef(fmt::format("{:010}", proposedKey))); break; } } @@ -228,8 +229,8 @@ struct ConflictRangeWorkload : TestWorkload { try { // Do the generated getRange in the other transaction and commit. if (self->testReadYourWrites) { - trRYOW.clear(KeyRangeRef(StringRef(format("%010d", clearedBegin)), - StringRef(format("%010d", clearedEnd)))); + trRYOW.clear(KeyRangeRef(StringRef(fmt::format("{:010}", clearedBegin)), + StringRef(fmt::format("{:010}", clearedEnd)))); RangeResult res = co_await trRYOW.getRange(KeySelectorRef(StringRef(myKeyA), onEqualA, offsetA), KeySelectorRef(StringRef(myKeyB), onEqualB, offsetB), randomLimit, @@ -237,7 +238,7 @@ struct ConflictRangeWorkload : TestWorkload { reverse); co_await trRYOW.commit(); } else { - tr3.clear(StringRef(format("%010d", self->maxKeySpace + 1))); + tr3.clear(StringRef(fmt::format("{:010}", self->maxKeySpace + 1))); RangeResult res = co_await tr3.getRange(KeySelectorRef(StringRef(myKeyA), onEqualA, offsetA), KeySelectorRef(StringRef(myKeyB), onEqualB, offsetB), randomLimit, @@ -255,8 +256,8 @@ struct ConflictRangeWorkload : TestWorkload { // If the commit fails, do the getRange again and check that the results are different from the // first execution. if (self->testReadYourWrites) { - tr1.clear(KeyRangeRef(StringRef(format("%010d", clearedBegin)), - StringRef(format("%010d", clearedEnd)))); + tr1.clear(KeyRangeRef(StringRef(fmt::format("{:010}", clearedBegin)), + StringRef(fmt::format("{:010}", clearedEnd)))); co_await tr1.commit(); tr1 = Transaction(cx); } @@ -294,7 +295,7 @@ struct ConflictRangeWorkload : TestWorkload { } if ((smallestResult == firstElement || - smallestResult == StringRef(format("%010d", *(insertedSet.begin())))) && + smallestResult == StringRef(fmt::format("{:010}", *(insertedSet.begin())))) && offsetA < 0) { // Results return the first element, and the begin offset is negative, so if a key // selector does not fully resolve the offset, a change won't effect results @@ -334,9 +335,10 @@ struct ConflictRangeWorkload : TestWorkload { .detail("Original", keyStr2); tr4 = Transaction(cx); - RangeResult res = co_await tr4.getRange( - KeyRangeRef(StringRef(format("%010d", 0)), StringRef(format("%010d", self->maxKeySpace))), - 200); + RangeResult res = + co_await tr4.getRange(KeyRangeRef(StringRef(fmt::format("{:010}", 0)), + StringRef(fmt::format("{:010}", self->maxKeySpace))), + 200); std::string allKeyEntries = ""; for (int i = 0; i < res.size(); i++) { allKeyEntries += printable(res[i].key) + " "; diff --git a/fdbserver/workloads/ConsistencyCheck.cpp b/fdbserver/workloads/ConsistencyCheck.cpp index 96b2c643266..59acc3503d8 100644 --- a/fdbserver/workloads/ConsistencyCheck.cpp +++ b/fdbserver/workloads/ConsistencyCheck.cpp @@ -41,6 +41,7 @@ #include "fdbrpc/SimulatorProcessInfo.h" #include "flow/CoroUtils.h" +#include "fmt/format.h" // #define SevCCheckInfo SevVerbose #define SevCCheckInfo SevInfo @@ -399,7 +400,7 @@ struct ConsistencyCheckWorkload : TestWorkload { TraceEvent("ConsistencyCheck_Retry") .error(e); // FIXME: consistency check does not retry in this case } else { - self->testFailure(format("Error %d - %s", e.code(), e.name())); + self->testFailure(fmt::format("Error {} - {}", e.code(), e.name())); } } } @@ -1102,10 +1103,10 @@ struct ConsistencyCheckWorkload : TestWorkload { } ev.detail(role + "Count", count).detail(role + "ExpectedCount", expectedCount); if (count != expectedCount) { - fmt::print("ConsistencyCheck failure: incorrect number {0} of singleton {1} running (expected {2})\n", - count, - role, - expectedCount); + fmt::println("ConsistencyCheck failure: incorrect number {0} of singleton {1} running (expected {2})", + count, + role, + expectedCount); } return count == expectedCount; } @@ -1129,10 +1130,10 @@ struct ConsistencyCheckWorkload : TestWorkload { if (!success) { // TODO REMOVE - fmt::print("ConsistencyCheck singletons: roles map:\n"); + fmt::println("ConsistencyCheck singletons: roles map:"); for (int i = 0; i < allProcesses.size(); i++) { - fmt::print( - "{0}: {1}\n", allProcesses[i]->address.toString(), g_simulator->getRoles(allProcesses[i]->address)); + fmt::println( + "{0}: {1}", allProcesses[i]->address.toString(), g_simulator->getRoles(allProcesses[i]->address)); } } diff --git a/fdbserver/workloads/ConsistencyCheckUrgent.cpp b/fdbserver/workloads/ConsistencyCheckUrgent.cpp index e4c22825040..21958ada189 100644 --- a/fdbserver/workloads/ConsistencyCheckUrgent.cpp +++ b/fdbserver/workloads/ConsistencyCheckUrgent.cpp @@ -35,6 +35,7 @@ #include "fdbclient/StorageServerInterface.h" #include "flow/network.h" #include "fdbrpc/SimulatorProcessInfo.h" +#include "fmt/format.h" // The ConsistencyCheckUrgent workload is designed to support the consistency check // urgent feature, a distributed version of the consistency check which emphasizes @@ -466,16 +467,17 @@ struct ConsistencyCheckUrgentWorkload : TestWorkload { TraceEvent(SevError, "ConsistencyCheck_DataInconsistent") .setMaxEventLength(-1) .setMaxFieldLength(-1) - .detail(format("StorageServer%d", j).c_str(), storageServers[j].toString()) - .detail(format("StorageServer%d", firstValidServer).c_str(), + .detail(fmt::format("StorageServer{}", j).c_str(), storageServers[j].toString()) + .detail(fmt::format("StorageServer{}", firstValidServer).c_str(), storageServers[firstValidServer].toString()) .detail("RangeBegin", req.begin.getKey()) .detail("RangeEnd", req.end.getKey()) .detail("VersionNumber", req.version) - .detail(format("Server%dUniques", j).c_str(), currentUniques) - .detail(format("Server%dUniqueKey", j).c_str(), currentUniqueKey) - .detail(format("Server%dUniques", firstValidServer).c_str(), referenceUniques) - .detail(format("Server%dUniqueKey", firstValidServer).c_str(), referenceUniqueKey) + .detail(fmt::format("Server{}Uniques", j).c_str(), currentUniques) + .detail(fmt::format("Server{}UniqueKey", j).c_str(), currentUniqueKey) + .detail(fmt::format("Server{}Uniques", firstValidServer).c_str(), referenceUniques) + .detail(fmt::format("Server{}UniqueKey", firstValidServer).c_str(), + referenceUniqueKey) .detail("ValueMismatches", valueMismatches) .detail("ValueMismatchKey", valueMismatchKey) .detail("MatchingKVPairs", matchingKVPairs) diff --git a/fdbserver/workloads/CpuProfiler.cpp b/fdbserver/workloads/CpuProfiler.cpp index 0ce5a853ee3..e063459af64 100644 --- a/fdbserver/workloads/CpuProfiler.cpp +++ b/fdbserver/workloads/CpuProfiler.cpp @@ -22,6 +22,7 @@ #include "fdbserver/QuietDatabase.h" #include "fdbserver/ServerDBInfo.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" // A workload which starts the CPU profiler at a given time and duration on all workers in a cluster struct CpuProfilerWorkload : TestWorkload { @@ -77,8 +78,9 @@ struct CpuProfilerWorkload : TestWorkload { req.duration = 0; // unused // The profiler output name will be the ip.port.prof - req.outputFile = StringRef(self->profilingWorkers[i].address().ip.toString() + "." + - format("%d", self->profilingWorkers[i].address().port) + ".profile.bin"); + req.outputFile = + StringRef(self->profilingWorkers[i].address().ip.toString() + "." + + fmt::format("{}", self->profilingWorkers[i].address().port) + ".profile.bin"); replies.push_back(self->profilingWorkers[i].clientInterface.profiler.tryGetReply(req)); } diff --git a/fdbserver/workloads/Cycle.cpp b/fdbserver/workloads/Cycle.cpp index ca958b0c7ab..f0ad7dba715 100644 --- a/fdbserver/workloads/Cycle.cpp +++ b/fdbserver/workloads/Cycle.cpp @@ -30,6 +30,7 @@ #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/workloads/BulkSetup.h" +#include "fmt/format.h" struct CycleWorkload : TestWorkload, Arena { static constexpr auto NAME = "Cycle"; @@ -268,10 +269,10 @@ struct CycleWorkload : TestWorkload, Arena { TraceEvent(SevWarnAlways, "TestFailure") .detail("Reason", "Rate below desired rate") .detail("File", __FILE__) - .detail( - "Details", - format("%.2f", - self->transactions.getMetric().value() / (self->transactionsPerSecond * self->testDuration))) + .detail("Details", + fmt::format("{:.2f}", + self->transactions.getMetric().value() / + (self->transactionsPerSecond * self->testDuration))) .detail("TransactionsAchieved", self->transactions.getMetric().value()) .detail("MinTransactionsExpected", self->testDuration * self->minExpectedTransactionsPerSecond) .detail("TransactionGoal", self->transactionsPerSecond * self->testDuration); diff --git a/fdbserver/workloads/DDBalance.cpp b/fdbserver/workloads/DDBalance.cpp index f91cdb67f27..3fbdcd5454a 100644 --- a/fdbserver/workloads/DDBalance.cpp +++ b/fdbserver/workloads/DDBalance.cpp @@ -22,6 +22,7 @@ #include "fdbclient/NativeAPI.actor.h" #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct DDBalanceWorkload : TestWorkload { static constexpr auto NAME = "DDBalance"; @@ -83,7 +84,7 @@ struct DDBalanceWorkload : TestWorkload { } Key key(int bin, int n, int actorid, int clientid) { - return StringRef(format("%08x%08x%08x%08x", bin, n, actorid, clientid)); + return StringRef(fmt::format("{:08x}{:08x}{:08x}{:08x}", bin, n, actorid, clientid)); } Value value(int n) { return doubleToTestKey(n); } diff --git a/fdbserver/workloads/DDMetricsExclude.cpp b/fdbserver/workloads/DDMetricsExclude.cpp index 2232331b942..07ca271d55f 100644 --- a/fdbserver/workloads/DDMetricsExclude.cpp +++ b/fdbserver/workloads/DDMetricsExclude.cpp @@ -24,6 +24,7 @@ #include "fdbserver/ServerDBInfo.h" #include "fdbclient/StatusClient.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct DDMetricsExcludeWorkload : TestWorkload { static constexpr auto NAME = "DDMetricsExclude"; @@ -43,7 +44,7 @@ struct DDMetricsExcludeWorkload : TestWorkload { } static Value getRandomValue() { - return Standalone(format("Value/%080d", deterministicRandom()->randomInt(0, 10e6))); + return Standalone(fmt::format("Value/{:080}", deterministicRandom()->randomInt(0, 10e6))); } Future getMovingDataAmount(Database cx) { diff --git a/fdbserver/workloads/DataDistributionMetrics.cpp b/fdbserver/workloads/DataDistributionMetrics.cpp index 8ada2c49230..ab797af6f56 100644 --- a/fdbserver/workloads/DataDistributionMetrics.cpp +++ b/fdbserver/workloads/DataDistributionMetrics.cpp @@ -24,6 +24,7 @@ #include "fdbclient/ReadYourWrites.h" #include "fdbclient/Schemas.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct DataDistributionMetricsWorkload : KVWorkload { static constexpr auto NAME = "DataDistributionMetrics"; @@ -48,7 +49,7 @@ struct DataDistributionMetricsWorkload : KVWorkload { } static Value getRandomValue() { - return Standalone(format("Value/%08d", deterministicRandom()->randomInt(0, 10e6))); + return Standalone(fmt::format("Value/{:08}", deterministicRandom()->randomInt(0, 10e6))); } Key keyForIndex(int n) { return doubleToTestKey((double)n / nodeCount, keyPrefix); } diff --git a/fdbserver/workloads/DiskDurabilityTest.cpp b/fdbserver/workloads/DiskDurabilityTest.cpp index 0cb6f8d8456..528154c0c22 100644 --- a/fdbserver/workloads/DiskDurabilityTest.cpp +++ b/fdbserver/workloads/DiskDurabilityTest.cpp @@ -95,7 +95,7 @@ struct DiskDurabilityTest : TestWorkload { for (int i = 0; i < r.size(); i++) { int bytesRead = co_await file->read(page, 4096, decodeKey(r[i].key) * 4096); if (bytesRead != 4096 || decodePage(page) != decodeValue(r[i].value)) { - printf("ValidationError\n"); + fmt::println("ValidationError"); TraceEvent(SevError, "ValidationError") .detail("At", decodeKey(r[i].key)) .detail("Expected", decodeValue(r[i].value)) @@ -114,7 +114,7 @@ struct DiskDurabilityTest : TestWorkload { if (failed) throw operation_failed(); - fmt::print("Verified {0}/{1} pages\n", verifyPages, size / 4096); + fmt::println("Verified {0}/{1} pages", verifyPages, size / 4096); TraceEvent(SevInfo, "Verified").detail("Pages", verifyPages).detail("Of", size / 4096); // Run diff --git a/fdbserver/workloads/ExpectStableThroughput.cpp b/fdbserver/workloads/ExpectStableThroughput.cpp index 639b577283e..3d2dbbce7ee 100644 --- a/fdbserver/workloads/ExpectStableThroughput.cpp +++ b/fdbserver/workloads/ExpectStableThroughput.cpp @@ -4,6 +4,7 @@ #include "fdbserver/Knobs.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" // This workload is meant to be run with the ThroughputQuotaWorklaod. // The ThroughputQuotaWorkload sets a total quota, and then this workload runs @@ -41,7 +42,7 @@ class ExpectStableThroughputWorkload : public TestWorkload { } } - Key getKey(int index) { return Key(format("%06d", index)).withPrefix(keyPrefix); } + Key getKey(int index) { return Key(fmt::format("{:06}", index)).withPrefix(keyPrefix); } Future runTransaction(Database cx) { Transaction tr(cx); diff --git a/fdbserver/workloads/ExternalWorkload.cpp b/fdbserver/workloads/ExternalWorkload.cpp index 4034724eace..f4ad7a91dfb 100644 --- a/fdbserver/workloads/ExternalWorkload.cpp +++ b/fdbserver/workloads/ExternalWorkload.cpp @@ -100,7 +100,8 @@ struct FDBLoggerImpl : FDBLogger { namespace capi { #include "foundationdb/CWorkload.h" -} +#include "fmt/format.h" +} // namespace capi namespace translator { template struct Wrapper { @@ -298,11 +299,11 @@ struct ExternalWorkload : TestWorkload, FDBWorkloadContext { static std::string toLibName(const std::string& name) { #if defined(__unixish__) && !defined(__APPLE__) - return format("lib%s.so", name.c_str()); + return fmt::format("lib{}.so", name); #elif defined(__APPLE__) - return format("lib%s.dylib", name.c_str()); + return fmt::format("lib{}.dylib", name); #elif defined(_WIN32) - return format("lib%s.dll", name.c_str()); + return fmt::format("lib{}.dll", name); #else #error Port me! #endif diff --git a/fdbserver/workloads/FastTriggeredWatches.cpp b/fdbserver/workloads/FastTriggeredWatches.cpp index bb86cacc28c..94d6dda9a62 100644 --- a/fdbserver/workloads/FastTriggeredWatches.cpp +++ b/fdbserver/workloads/FastTriggeredWatches.cpp @@ -23,6 +23,7 @@ #include "fdbclient/ReadYourWrites.h" #include "fdbserver/Knobs.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct FastTriggeredWatchesWorkload : TestWorkload { static constexpr auto NAME = "FastTriggeredWatches"; @@ -37,7 +38,7 @@ struct FastTriggeredWatchesWorkload : TestWorkload { : TestWorkload(wcx), operations("Operations"), retries("Retries") { testDuration = getOption(options, "testDuration"_sr, 600.0); nodes = getOption(options, "nodes"_sr, 100); - defaultValue = StringRef(format("%010d", deterministicRandom()->randomInt(0, 1000))); + defaultValue = StringRef(fmt::format("{:010}", deterministicRandom()->randomInt(0, 1000))); keyBytes = std::max(getOption(options, "keyBytes"_sr, 16), 16); } @@ -111,7 +112,7 @@ struct FastTriggeredWatchesWorkload : TestWorkload { Key setKey = keyForIndex(deterministicRandom()->randomInt(0, nodes)); Optional setValue; if (deterministicRandom()->random01() > 0.5) - setValue = StringRef(format("%010d", deterministicRandom()->randomInt(0, 1000))); + setValue = StringRef(fmt::format("{:010}", deterministicRandom()->randomInt(0, 1000))); // Set the value at setKey to something random Future setFuture = setter(cx, setKey, setValue); co_await delay(deterministicRandom()->random01()); diff --git a/fdbserver/workloads/FileSystem.cpp b/fdbserver/workloads/FileSystem.cpp index b119f82fb9e..852dfad7ac1 100644 --- a/fdbserver/workloads/FileSystem.cpp +++ b/fdbserver/workloads/FileSystem.cpp @@ -22,6 +22,7 @@ #include "fdbclient/NativeAPI.actor.h" #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct FileSystemWorkload : TestWorkload { static constexpr auto NAME = "FileSystem"; @@ -80,7 +81,7 @@ struct FileSystemWorkload : TestWorkload { m.emplace_back("Median Write Latency (ms, averaged)", 1000 * writeLatencies.median(), Averaged::True); } - Key keyForFileID(uint64_t id) { return StringRef(format("/files/id/%016llx", id)); } + Key keyForFileID(uint64_t id) { return StringRef(fmt::format("/files/id/{:016x}", id)); } void initializeFile(Transaction* tr, FileSystemWorkload* self, uint64_t id) { Key key = self->keyForFileID(id); @@ -88,8 +89,8 @@ struct FileSystemWorkload : TestWorkload { int pathLen = self->pathMinChars + deterministicRandom()->randomInt(0, self->pathCharRange); std::string path = ""; for (int i = 0; i < pathLen; i += 4) - path += - format(format("%%0%dx", std::min(pathLen - i, 4)).c_str(), deterministicRandom()->randomInt(0, 0xFFFF)); + path += format(fmt::format("%0{}x", std::min(pathLen - i, 4)).c_str(), + deterministicRandom()->randomInt(0, 0xFFFF)); uint64_t userID = deterministicRandom()->randomInt(0, self->userIDCount); int serverID = deterministicRandom()->randomInt(0, self->serverCount); bool deleted = deterministicRandom()->random01() < self->deletedFilesRatio; @@ -97,20 +98,21 @@ struct FileSystemWorkload : TestWorkload { tr->set(key, path); std::string keyStr(key.toString()); - tr->set(keyStr + "/size", format("%d", deterministicRandom()->randomInt(0, std::numeric_limits::max()))); - tr->set(keyStr + "/server", format("%d", deterministicRandom()->randomInt(0, self->serverCount))); + tr->set(keyStr + "/size", + fmt::format("{}", deterministicRandom()->randomInt(0, std::numeric_limits::max()))); + tr->set(keyStr + "/server", fmt::format("{}", deterministicRandom()->randomInt(0, self->serverCount))); tr->set(keyStr + "/deleted", deleted ? "1"_sr : "0"_sr); - tr->set(keyStr + "/server", format("%d", serverID)); + tr->set(keyStr + "/server", fmt::format("{}", serverID)); tr->set(keyStr + "/created", doubleToTestKey(time)); tr->set(keyStr + "/lastupdated", doubleToTestKey(time)); - tr->set(keyStr + "/userid", format("%016llx", userID)); + tr->set(keyStr + "/userid", fmt::format("{:016x}", userID)); if (deleted) - tr->set(format("/files/server/%08x/deleted/%016llx", serverID, id), doubleToTestKey(time)); - tr->set(format("/files/user/%016llx/updated/%016llx/%016llx", userID, *(uint64_t*)&time, id), path); - tr->set(format("/files/user/%016llx/path/", userID) + path, format("%016llx", id)); + tr->set(fmt::format("/files/server/{:08x}/deleted/{:016x}", serverID, id), doubleToTestKey(time)); + tr->set(fmt::format("/files/user/{:016x}/updated/{:016x}/{:016x}", userID, *(uint64_t*)&time, id), path); + tr->set(fmt::format("/files/user/{:016x}/path/", userID) + path, fmt::format("{:016x}", id)); // This index was not specified in the original test: it removes duplicated paths - tr->set("/files/path/" + path, format("%016llx", id)); + tr->set("/files/path/" + path, fmt::format("{:016x}", id)); } Future setupRange(Database cx, FileSystemWorkload* self, int begin, int end) { @@ -245,14 +247,14 @@ struct FileSystemWorkload : TestWorkload { int serverID = testKeyToInt(serverStr.get()); if (deleted.get().toString() == "1") { tr.set(keyStr + "/deleted", "0"_sr); - tr.clear(format("/files/server/%08x/deleted/%016llx", serverID, fileID)); + tr.clear(fmt::format("/files/server/{:08x}/deleted/{:016x}", serverID, fileID)); } else { tr.set(keyStr + "/deleted", "1"_sr); - tr.set(format("/files/server/%08x/deleted/%016llx", serverID, fileID), + tr.set(fmt::format("/files/server/{:08x}/deleted/{:016x}", serverID, fileID), doubleToTestKey(time)); } } else { - tr.set(keyStr + "/size", format("%d", size)); + tr.set(keyStr + "/size", fmt::format("{}", size)); } tr.set(keyStr + "/lastupdated", doubleToTestKey(time)); co_await tr.commit(); @@ -271,7 +273,7 @@ struct FileSystemWorkload : TestWorkload { Future> modificationQuery(FileSystemWorkload* self, Transaction* tr) { uint64_t userID = deterministicRandom()->randomInt(0, self->userIDCount); - std::string base = format("/files/user/%016llx", userID); + std::string base = fmt::format("/files/user/{:016x}", userID); if (self->loggingQueries) TraceEvent("UserQuery").detail("UserID", userID).detail("PathBase", base); Key keyEnd(base + "/updated0"); @@ -291,7 +293,7 @@ struct FileSystemWorkload : TestWorkload { Future> deletionQuery(FileSystemWorkload* self, Transaction* tr) { uint64_t serverID = deterministicRandom()->randomInt(0, self->serverCount); - std::string base = format("/files/server/%08x/deleted", serverID); + std::string base = fmt::format("/files/server/{:08x}/deleted", serverID); if (self->loggingQueries) TraceEvent("DeletionQuery").detail("ServerID", serverID).detail("PathBase", base); Key keyBegin(base + "/"); diff --git a/fdbserver/workloads/FuzzApiCorrectness.cpp b/fdbserver/workloads/FuzzApiCorrectness.cpp index e8897097e64..878cab3511f 100644 --- a/fdbserver/workloads/FuzzApiCorrectness.cpp +++ b/fdbserver/workloads/FuzzApiCorrectness.cpp @@ -34,6 +34,7 @@ #include "flow/ActorCollection.h" #include "fdbserver/workloads/workloads.actor.h" #include "flow/Arena.h" +#include "fmt/format.h" namespace ph = std::placeholders; @@ -222,13 +223,13 @@ struct FuzzApiCorrectnessWorkload : TestWorkload { .detail("NewSeverity", SevInfo); } - static TenantName getTenant(int num) { return TenantNameRef(format("tenant_%d", num)); } + static TenantName getTenant(int num) { return TenantNameRef(fmt::format("tenant_{}", num)); } Optional getTenantGroup(int num) { int groupNum = num % (numTenantGroups + 1); if (groupNum == numTenantGroups - 1) { return Optional(); } else { - return TenantGroupNameRef(format("tenantgroup_%d", groupNum)); + return TenantGroupNameRef(fmt::format("tenantgroup_{}", groupNum)); } } bool canUseTenant(Optional tenant) { @@ -266,7 +267,7 @@ struct FuzzApiCorrectnessWorkload : TestWorkload { if (adjacentKeys) { return Key(keyPrefixes[tenantNum] + std::string(idx, '\x00')); } else { - return Key(keyPrefixes[tenantNum] + format("%010d", idx)); + return Key(keyPrefixes[tenantNum] + fmt::format("{:010}", idx)); } } @@ -439,7 +440,7 @@ struct FuzzApiCorrectnessWorkload : TestWorkload { int j = 0; for (; j < numOps; j++) { int operationType = deterministicRandom()->randomInt(0, testCases.size()); - printf("%d: Selected Operation %d\n", self->operationId + 1, operationType); + fmt::println("{}: Selected Operation {}", self->operationId + 1, operationType); try { operations.push_back(testCases[operationType](++self->operationId, self, tr)); } catch (Error& e) { @@ -1292,7 +1293,7 @@ struct FuzzApiCorrectnessWorkload : TestWorkload { TestWatch(unsigned int id, FuzzApiCorrectnessWorkload* workload, Reference tr) : BaseTest(id, workload, "TestWatch") { key = makeKey(); - printf("Watching: %d %s\n", key.size(), printable(key.substr(0, std::min(key.size(), 20))).c_str()); + fmt::println("Watching: {} {}", key.size(), printable(key.substr(0, std::min(key.size(), 20)))); contract = { std::make_pair(error_code_key_too_large, key.size() > getMaxWriteKeySize(key, true) ? ExceptionContract::Always diff --git a/fdbserver/workloads/GetMappedRange.cpp b/fdbserver/workloads/GetMappedRange.cpp index 9554e0d9ab4..f2b9cf5ae45 100644 --- a/fdbserver/workloads/GetMappedRange.cpp +++ b/fdbserver/workloads/GetMappedRange.cpp @@ -29,6 +29,7 @@ #include "flow/IRandom.h" #include "flow/flow.h" #include "flow/CoroUtils.h" +#include "fmt/format.h" const Value EMPTY = Tuple().pack(); ValueRef SOMETHING = "SOMETHING"_sr; @@ -83,10 +84,12 @@ struct GetMappedRangeWorkload : ApiWorkload { return Future(); } - static Key primaryKey(int i) { return Key(format("primary-key-of-record-%08d", i)); } - static Key indexKey(int i) { return Key(format("index-key-of-record-%08d", i)); } - static Value dataOfRecord(int i) { return Key(format("data-of-record-%08d", i)); } - static Value dataOfRecord(int i, int split) { return Key(format("data-of-record-%08d-split-%08d", i, split)); } + static Key primaryKey(int i) { return Key(fmt::format("primary-key-of-record-{:08}", i)); } + static Key indexKey(int i) { return Key(fmt::format("index-key-of-record-{:08}", i)); } + static Value dataOfRecord(int i) { return Key(fmt::format("data-of-record-{:08}", i)); } + static Value dataOfRecord(int i, int split) { + return Key(fmt::format("data-of-record-{:08}-split-{:08}", i, split)); + } static Key indexEntryKey(int i) { return Tuple::makeTuple(prefix, INDEX, indexKey(i), primaryKey(i)).pack(); } static Key recordKey(int i) { return Tuple::makeTuple(prefix, RECORD, primaryKey(i)).pack(); } diff --git a/fdbserver/workloads/GetRangeStream.cpp b/fdbserver/workloads/GetRangeStream.cpp index 313f90bc47d..6c34114a476 100644 --- a/fdbserver/workloads/GetRangeStream.cpp +++ b/fdbserver/workloads/GetRangeStream.cpp @@ -22,6 +22,7 @@ #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/workloads/BulkSetup.h" +#include "fmt/format.h" struct GetRangeStream : TestWorkload { static constexpr auto NAME = "GetRangeStream"; @@ -55,9 +56,9 @@ struct GetRangeStream : TestWorkload { co_await delay(1); double after = g_network->now(); if (after > before) { - printf("throughput: %g bytes/s, next: %s\n", - (bytesRead.getValue() - last) / (after - before), - printable(*next).c_str()); + fmt::println("throughput: {:g} bytes/s, next: {}", + (bytesRead.getValue() - last) / (after - before), + printable(*next)); } } } @@ -75,7 +76,7 @@ struct GetRangeStream : TestWorkload { GetRangeLimits(GetRangeLimits::ROW_LIMIT_UNLIMITED, CLIENT_KNOBS->REPLY_BYTE_LIMIT)); for (const auto& [k, v] : range) { if (printKVPairs) { - printf("%s -> %s\n", printable(k).c_str(), printable(v).c_str()); + fmt::println("{} -> {}", printable(k), printable(v)); } bytesRead += k.size() + v.size(); } @@ -106,7 +107,7 @@ struct GetRangeStream : TestWorkload { Standalone range = co_await results.getFuture(); for (const auto& [k, v] : range) { if (printKVPairs) { - printf("%s -> %s\n", printable(k).c_str(), printable(v).c_str()); + fmt::println("{} -> {}", printable(k), printable(v)); } bytesRead += k.size() + v.size(); } diff --git a/fdbserver/workloads/HTTPKeyValueStore.cpp b/fdbserver/workloads/HTTPKeyValueStore.cpp index cb55d98faa8..cbb87c6c2c4 100644 --- a/fdbserver/workloads/HTTPKeyValueStore.cpp +++ b/fdbserver/workloads/HTTPKeyValueStore.cpp @@ -27,6 +27,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include #include +#include "fmt/format.h" /* * Implements a basic put/get key-value store over HTTP to test the http client and simulated server code. @@ -51,7 +52,7 @@ struct SimHTTPKVStore : NonCopyable, ReferenceCounted { ASSERT(clientId < maxClients); if (seqNo < lastClientSeqnos[clientId]) { if (DEBUG_HTTPKV) { - fmt::print("Client {0} SeqNo {1} < {2}\n", clientId, seqNo, lastClientSeqnos[clientId]); + fmt::println("Client {0} SeqNo {1} < {2}", clientId, seqNo, lastClientSeqnos[clientId]); } // out of order retransmit, ignore return false; @@ -69,7 +70,7 @@ void httpKVProcessPut(Reference kvStore, kvStore->data[key] = req->data.content; if (DEBUG_HTTPKV) { - fmt::print("KV:put {0} = {1}\n", key, req->data.content); + fmt::println("KV:put {0} = {1}", key, req->data.content); } response->code = 200; @@ -86,7 +87,7 @@ void httpKVProcessGet(Reference kvStore, ASSERT(it != kvStore->data.end()); if (DEBUG_HTTPKV) { - fmt::print("KV:get {0} = {1}\n", key, it->second); + fmt::println("KV:get {0} = {1}", key, it->second); } response->code = 200; @@ -304,7 +305,7 @@ struct HTTPKeyValueStoreWorkload : TestWorkload { throw err; } if (DEBUG_HTTPKV) { - fmt::print("REQ: ERROR: {0}\n", err.name()); + fmt::println("REQ: ERROR: {0}", err.name()); } if (self->conn) { self->conn->close(); @@ -327,13 +328,13 @@ struct HTTPKeyValueStoreWorkload : TestWorkload { self->activePut = active; if (DEBUG_HTTPKV) { - fmt::print("CL:put {0}:{1} = {2}\n", self->clientId, key, value); + fmt::println("CL:put {0}:{1} = {2}", self->clientId, key, value); } Reference response = co_await self->doKVRequest(self, key, value); if (DEBUG_HTTPKV) { - fmt::print("CL:put {0}:{1} = {2} DONE\n", self->clientId, key, value); + fmt::println("CL:put {0}:{1} = {2} DONE", self->clientId, key, value); } // upon success, put in map @@ -345,13 +346,13 @@ struct HTTPKeyValueStoreWorkload : TestWorkload { Future get(HTTPKeyValueStoreWorkload* self, std::string key, bool checkActive) { if (DEBUG_HTTPKV) { - fmt::print("CL:get {0}:{1}\n", self->clientId, key); + fmt::println("CL:get {0}:{1}", self->clientId, key); } Reference response = co_await self->doKVRequest(self, key, {}); if (DEBUG_HTTPKV) { - fmt::print("CL:get {0}:{1} = {2} DONE\n", self->clientId, key, response->data.content); + fmt::println("CL:get {0}:{1} = {2} DONE", self->clientId, key, response->data.content); } if (!checkActive || !self->activePut.present()) { @@ -372,12 +373,12 @@ struct HTTPKeyValueStoreWorkload : TestWorkload { if (self->clientId == 0) { TraceEvent("SimHTTPKeyValueStoreRegistering"); if (DEBUG_HTTPKV) { - fmt::print("Registering sim http kv server\n"); + fmt::println("Registering sim http kv server"); } co_await g_simulator->registerSimHTTPServer( self->hostname, self->service, makeReference()); if (DEBUG_HTTPKV) { - fmt::print("Registered sim http kv server\n"); + fmt::println("Registered sim http kv server"); } TraceEvent("SimHTTPKeyValueStoreRegistered"); } diff --git a/fdbserver/workloads/HealthMetricsApi.cpp b/fdbserver/workloads/HealthMetricsApi.cpp index 241e09e1943..f8683144611 100644 --- a/fdbserver/workloads/HealthMetricsApi.cpp +++ b/fdbserver/workloads/HealthMetricsApi.cpp @@ -21,6 +21,7 @@ #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/WorkerInterface.actor.h" +#include "fmt/format.h" // NOTE: it might be simpler to test health metrics via something // other than simulation. Testing equivalent to what this workload does can @@ -172,15 +173,15 @@ struct HealthMetricsApiWorkload : TestWorkload { gotStorageStats = true; auto storageStats = ss.second; detailedWorstStorageQueue = std::max(detailedWorstStorageQueue, storageStats.storageQueue); - traceStorageQueue.detail(format("Storage-%s", ss.first.toString().c_str()), storageStats.storageQueue); + traceStorageQueue.detail(fmt::format("Storage-{}", ss.first.toString()), storageStats.storageQueue); detailedWorstStorageDurabilityLag = std::max(detailedWorstStorageDurabilityLag, storageStats.storageDurabilityLag); - traceStorageDurabilityLag.detail(format("Storage-%s", ss.first.toString().c_str()), + traceStorageDurabilityLag.detail(fmt::format("Storage-{}", ss.first.toString()), storageStats.storageDurabilityLag); detailedWorstCpuUsage = std::max(detailedWorstCpuUsage, storageStats.cpuUsage); - traceCpuUsage.detail(format("Storage-%s", ss.first.toString().c_str()), storageStats.cpuUsage); + traceCpuUsage.detail(fmt::format("Storage-{}", ss.first.toString()), storageStats.cpuUsage); detailedWorstDiskUsage = std::max(detailedWorstDiskUsage, storageStats.diskUsage); - traceDiskUsage.detail(format("Storage-%s", ss.first.toString().c_str()), storageStats.diskUsage); + traceDiskUsage.detail(fmt::format("Storage-{}", ss.first.toString()), storageStats.diskUsage); } TraceEvent traceTLogQueue("TLogQueue"); traceTLogQueue.setMaxEventLength(10000); @@ -188,7 +189,7 @@ struct HealthMetricsApiWorkload : TestWorkload { for (const auto& ss : healthMetrics.tLogQueue) { gotTLogQueue = true; detailedWorstTLogQueue = std::max(detailedWorstTLogQueue, ss.second); - traceTLogQueue.detail(format("TLog-%s", ss.first.toString().c_str()), ss.second); + traceTLogQueue.detail(fmt::format("TLog-{}", ss.first.toString()), ss.second); } if (!gotMetrics && gotStorageStats && gotTLogQueue) { TraceEvent("HealthMetricsGotFullResult"); diff --git a/fdbserver/workloads/Increment.cpp b/fdbserver/workloads/Increment.cpp index 72f83940d8d..9e70d5ba661 100644 --- a/fdbserver/workloads/Increment.cpp +++ b/fdbserver/workloads/Increment.cpp @@ -22,6 +22,7 @@ #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/workloads/BulkSetup.h" +#include "fmt/format.h" struct Increment : TestWorkload { static constexpr auto NAME = "Increment"; @@ -68,7 +69,7 @@ struct Increment : TestWorkload { m.emplace_back("Write rows/simsec (approx)", transactions.getValue() * 4 / testDuration, Averaged::False); } - static Key intToTestKey(int i) { return StringRef(format("%016d", i)); } + static Key intToTestKey(int i) { return StringRef(fmt::format("{:016}", i)); } Future incrementClient(Database cx, Increment* self, double delay) { double lastTime = now(); @@ -144,10 +145,10 @@ struct Increment : TestWorkload { TraceEvent(SevWarnAlways, "TestFailure") .detail("Reason", "Rate below desired rate") .detail("File", __FILE__) - .detail( - "Details", - format("%.2f", - self->transactions.getMetric().value() / (self->transactionsPerSecond * self->testDuration))) + .detail("Details", + fmt::format("{:.2f}", + self->transactions.getMetric().value() / + (self->transactionsPerSecond * self->testDuration))) .detail("TransactionsAchieved", self->transactions.getMetric().value()) .detail("MinTransactionsExpected", self->testDuration * self->minExpectedTransactionsPerSecond) .detail("TransactionGoal", self->transactionsPerSecond * self->testDuration); diff --git a/fdbserver/workloads/Inventory.cpp b/fdbserver/workloads/Inventory.cpp index 3b7aa7ba2d9..ead900ff2e8 100644 --- a/fdbserver/workloads/Inventory.cpp +++ b/fdbserver/workloads/Inventory.cpp @@ -21,6 +21,7 @@ #include "fdbclient/NativeAPI.actor.h" #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" // SOMEDAY: Make this actually run on multiple clients @@ -154,7 +155,7 @@ struct InventoryTestWorkload : TestWorkload { Optional val = co_await tr->get(key); int count = !val.present() ? 0 : atoi(val.get().toString().c_str()); ASSERT(count >= 0 && count < 1000000); - tr->set(key, format("%d", count + 1)); + tr->set(key, fmt::format("{}", count + 1)); } Future inventoryTestClient(Database cx, diff --git a/fdbserver/workloads/KVStoreTest.cpp b/fdbserver/workloads/KVStoreTest.cpp index c35ccbb18c2..41b9ec31161 100644 --- a/fdbserver/workloads/KVStoreTest.cpp +++ b/fdbserver/workloads/KVStoreTest.cpp @@ -279,14 +279,14 @@ Future testKVStoreMain(KVStoreTestWorkload* workload, KVTest* ptest) { } double elapsed = timer() - cst; TraceEvent("KVStoreCount").detail("Count", count).detail("Took", elapsed); - fmt::print("Counted: {0} in {1:0.1f}s\n", count, elapsed); + fmt::println("Counted: {0} in {1:0.1f}s", count, elapsed); } if (workload->doSetup) { wr << Version(0); wr.serializeBytes(extraValue, extraBytes); - printf("Building %d nodes: ", workload->nodeCount); + fmt::print("Building {} nodes: ", workload->nodeCount); double setupBegin = timer(); Future lastCommit = Void(); for (i = 0; i < workload->nodeCount; i++) { @@ -294,7 +294,7 @@ Future testKVStoreMain(KVStoreTestWorkload* workload, KVTest* ptest) { if (!((i + 1) % 10000) || i + 1 == workload->nodeCount) { co_await lastCommit; lastCommit = test.store->commit(); - printf("ETA: %f seconds\n", (timer() - setupBegin) / i * (workload->nodeCount - i)); + fmt::println("ETA: {:f} seconds", (timer() - setupBegin) / i * (workload->nodeCount - i)); } } co_await lastCommit; diff --git a/fdbserver/workloads/LocalRatekeeper.cpp b/fdbserver/workloads/LocalRatekeeper.cpp index 68147fdf2ba..f661d8c9411 100644 --- a/fdbserver/workloads/LocalRatekeeper.cpp +++ b/fdbserver/workloads/LocalRatekeeper.cpp @@ -21,6 +21,7 @@ #include "fdbclient/FDBTypes.h" #include "fdbserver/workloads/workloads.actor.h" #include +#include "fmt/format.h" namespace { @@ -132,7 +133,7 @@ struct LocalRatekeeperWorkload : TestWorkload { Future _start(Database cx) { co_await delay(startAfter); StorageServerInterface ssi = co_await getRandomStorage(cx); - g_simulator->disableFor(format("%s/updateStorage", ssi.id().toString().c_str()), now() + blockWritesFor); + g_simulator->disableFor(fmt::format("{}/updateStorage", ssi.id().toString()), now() + blockWritesFor); Future done = delay(blockWritesFor); // not much will happen until the storage goes over the soft limit co_await delay(double(SERVER_KNOBS->STORAGE_DURABILITY_LAG_SOFT_MAX / 1e6)); diff --git a/fdbserver/workloads/Mako.cpp b/fdbserver/workloads/Mako.cpp index 4fe1e4e7b46..2a13ba7a14b 100644 --- a/fdbserver/workloads/Mako.cpp +++ b/fdbserver/workloads/Mako.cpp @@ -25,6 +25,7 @@ #include "fdbclient/ReadYourWrites.h" #include "fdbclient/zipf.h" #include "crc32/crc32c.h" +#include "fmt/format.h" enum { OP_GETREADVERSION, @@ -197,7 +198,7 @@ struct MakoWorkload : TestWorkload { auto ratesItr = ratesAtKeyCounts.begin(); for (; ratesItr != ratesAtKeyCounts.end(); ratesItr++) { m.emplace_back( - format("%lld keys imported bytes/sec", ratesItr->first), ratesItr->second, Averaged::False); + fmt::format("{} keys imported bytes/sec", ratesItr->first), ratesItr->second, Averaged::False); } } // benchmark @@ -360,7 +361,7 @@ struct MakoWorkload : TestWorkload { .detail("Percentile95", self->opLatencies[OP_GETREADVERSION].percentile(.95)) .detail("Count", self->opCounters[OP_GETREADVERSION].getValue()); - std::string ts = format("T=%04.0fs: ", elapsed); + std::string ts = fmt::format("T={:04.0f}s: ", elapsed); self->periodicMetrics.emplace_back(ts + "Transactions/sec", (self->xacts.getValue() - last_xacts) / self->periodicLoggingInterval, Averaged::False); @@ -518,7 +519,8 @@ struct MakoWorkload : TestWorkload { char* rkeyPtr = reinterpret_cast(mutateString(rkey)); randStr(rkeyPtr + self->KEYPREFIXLEN, self->keyBytes - self->KEYPREFIXLEN); for (int range_i = 0; range_i < range; ++range_i) { - format("%0.*d", rangeLen, range_i).copy(rkeyPtr + self->keyBytes - rangeLen, rangeLen); + fmt::format("{:0{}}", range_i, static_cast(rangeLen)) + .copy(rkeyPtr + self->keyBytes - rangeLen, rangeLen); if (self->latencyForLocalOperation) { double opBegin = timer(); tr.set(rkey, self->randomValue()); @@ -578,7 +580,8 @@ struct MakoWorkload : TestWorkload { std::string scr_end_key; KeyRangeRef scr_key_range_ref; for (int range_i = 0; range_i < range; ++range_i) { - format("%0.*d", rangeLen, range_i).copy(rkeyPtr + self->keyBytes - rangeLen, rangeLen); + fmt::format("{:0{}}", range_i, static_cast(rangeLen)) + .copy(rkeyPtr + self->keyBytes - rangeLen, rangeLen); if (self->latencyForLocalOperation) { double opBegin = timer(); tr.set(rkey, self->randomValue()); diff --git a/fdbserver/workloads/MemoryKeyValueStore.cpp b/fdbserver/workloads/MemoryKeyValueStore.cpp index 24b15be2911..582719afc09 100644 --- a/fdbserver/workloads/MemoryKeyValueStore.cpp +++ b/fdbserver/workloads/MemoryKeyValueStore.cpp @@ -19,6 +19,7 @@ */ #include "fdbserver/workloads/MemoryKeyValueStore.h" +#include "fmt/format.h" // Get the value associated with a key Optional MemoryKeyValueStore::get(KeyRef key) const { @@ -136,8 +137,8 @@ Key MemoryKeyValueStore::endKey() const { // Debugging function that prints all key-value pairs void MemoryKeyValueStore::printContents() const { - printf("Contents:\n"); + fmt::println("Contents:"); std::map::const_iterator mapItr; for (mapItr = store.begin(); mapItr != store.end(); mapItr++) - printf("%s\n", mapItr->first.toString().c_str()); + fmt::println("{}", mapItr->first.toString()); } diff --git a/fdbserver/workloads/MetricLogging.cpp b/fdbserver/workloads/MetricLogging.cpp index d49fc495a32..0fc277df635 100644 --- a/fdbserver/workloads/MetricLogging.cpp +++ b/fdbserver/workloads/MetricLogging.cpp @@ -22,6 +22,7 @@ #include "fdbserver/TesterInterface.actor.h" #include "flow/TDMetric.actor.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct MetricLoggingWorkload : TestWorkload { static constexpr auto NAME = "MetricLogging"; @@ -43,9 +44,9 @@ struct MetricLoggingWorkload : TestWorkload { for (int i = 0; i < metricCount; i++) { if (testBool) { - boolMetrics.push_back(BoolMetricHandle("TestBool"_sr, format("%d", i))); + boolMetrics.push_back(BoolMetricHandle("TestBool"_sr, fmt::format("{}", i))); } else { - int64Metrics.push_back(Int64MetricHandle("TestInt"_sr, format("%d", i))); + int64Metrics.push_back(Int64MetricHandle("TestInt"_sr, fmt::format("{}", i))); } } } diff --git a/fdbserver/workloads/MiniCycle.cpp b/fdbserver/workloads/MiniCycle.cpp index 62186ca3a5a..8b47994dc21 100644 --- a/fdbserver/workloads/MiniCycle.cpp +++ b/fdbserver/workloads/MiniCycle.cpp @@ -30,6 +30,7 @@ #include #include "flow/CoroUtils.h" +#include "fmt/format.h" struct MiniCycleWorkload : TestWorkload { static constexpr auto NAME = "MiniCycle"; @@ -106,7 +107,7 @@ struct MiniCycleWorkload : TestWorkload { TraceEvent(SevError, "TestFailure").detail("Reason", "There were check or cycle client errors."); cycleClients.clear(); - printf("Beginning full cycle check..."); + fmt::print("Beginning full cycle check..."); bool ret = co_await self->_checkCycle(cx->clone(), self, ok); co_return ret; } @@ -311,10 +312,10 @@ struct MiniCycleWorkload : TestWorkload { TraceEvent(SevWarnAlways, "TestFailure") .detail("Reason", "Rate below desired rate") .detail("File", __FILE__) - .detail( - "Details", - format("%.2f", - self->transactions.getMetric().value() / (self->transactionsPerSecond * self->testDuration))) + .detail("Details", + fmt::format("{:.2f}", + self->transactions.getMetric().value() / + (self->transactionsPerSecond * self->testDuration))) .detail("TransactionsAchieved", self->transactions.getMetric().value()) .detail("MinTransactionsExpected", self->testDuration * self->minExpectedTransactionsPerSecond) .detail("TransactionGoal", self->transactionsPerSecond * self->testDuration); diff --git a/fdbserver/workloads/MockDDTest.cpp b/fdbserver/workloads/MockDDTest.cpp index 0282bf61671..e9478ec6a56 100644 --- a/fdbserver/workloads/MockDDTest.cpp +++ b/fdbserver/workloads/MockDDTest.cpp @@ -19,6 +19,7 @@ */ #include "fdbserver/workloads/MockDDTest.h" +#include "fmt/format.h" KeyRange MockDDTestWorkload::getRandomRange(double offset) const { double len = deterministicRandom()->random01() * this->maxKeyspace; @@ -84,7 +85,7 @@ void MockDDTestWorkload::populateFixedStrategy() { void MockDDTestWorkload::populateMgs() { // Will the sampling structure become too large? - fmt::print("MGS Populating ...\n"); + fmt::println("MGS Populating ..."); if (keySpaceStrategy == "linear") { populateLinearStrategy(); } else if (keySpaceStrategy == "fixed") { @@ -100,7 +101,7 @@ void MockDDTestWorkload::populateMgs() { .detail("Strategy", keySpaceStrategy) .detail("EstimatedDbSize", mockDbSize) .detail("MGSReportedTotalSize", totalSize); - fmt::print("MGS Populated.\n"); + fmt::println("MGS Populated."); } Future MockDDTestWorkload::setup(Database const& cx) { diff --git a/fdbserver/workloads/MockDDTrackerShardEvaluator.cpp b/fdbserver/workloads/MockDDTrackerShardEvaluator.cpp index ff1d1616a28..900bf2d4685 100644 --- a/fdbserver/workloads/MockDDTrackerShardEvaluator.cpp +++ b/fdbserver/workloads/MockDDTrackerShardEvaluator.cpp @@ -20,6 +20,7 @@ #include "fdbserver/workloads/MockDDTest.h" #include "flow/CoroUtils.h" +#include "fmt/format.h" class MockDDTrackerShardEvaluatorWorkload : public MockDDTestWorkload { public: @@ -132,10 +133,10 @@ class MockDDTrackerShardEvaluatorWorkload : public MockDDTestWorkload { if (!enabled) return true; - fmt::print("Check phase shards count: {}\n", shards.size()); + fmt::println("Check phase shards count: {}", shards.size()); ASSERT_GE(shards.size(), checkMinShardCount); for (auto& [r, c] : rsReasonCounts) { - fmt::print("{}: {}\n", r.toString(), c); + fmt::println("{}: {}", r.toString(), c); } ASSERT_GE(rsReasonCounts[RelocateReason::SIZE_SPLIT], checkMinSizeSplit); ASSERT_GE(rsReasonCounts[RelocateReason::WRITE_SPLIT], checkMinWriteSplit); diff --git a/fdbserver/workloads/MutationLogReaderCorrectness.cpp b/fdbserver/workloads/MutationLogReaderCorrectness.cpp index 14e29bd5fa7..db74d086109 100644 --- a/fdbserver/workloads/MutationLogReaderCorrectness.cpp +++ b/fdbserver/workloads/MutationLogReaderCorrectness.cpp @@ -49,7 +49,7 @@ struct MutationLogReaderCorrectnessWorkload : TestWorkload { Value recordValue(int index) { Version v = recordVersion(index); - return StringRef(format("%lld (%llx)", static_cast(v), static_cast(v))); + return StringRef(fmt::format("{0} ({0:x})", static_cast(v))); } MutationLogReaderCorrectnessWorkload(WorkloadContext const& wcx) : TestWorkload(wcx) { @@ -78,9 +78,9 @@ struct MutationLogReaderCorrectnessWorkload : TestWorkload { Transaction tr(cx); int iStart = 0; int batchSize = 1000; - fmt::print("Records: {}\n", self->records); - fmt::print("BeginVersion: {}\n", self->beginVersion); - fmt::print("EndVersion: {}\n", self->endVersion); + fmt::println("Records: {}", self->records); + fmt::println("BeginVersion: {}", self->beginVersion); + fmt::println("EndVersion: {}", self->endVersion); while (iStart < self->records) { while (true) { @@ -126,12 +126,12 @@ struct MutationLogReaderCorrectnessWorkload : TestWorkload { if (self->debug) { if (!keyMatch) { - printf("key: %s\n", rec.key.printable().c_str()); - printf("expected key: %s\n", expectedKey.printable().c_str()); + fmt::println("key: {}", rec.key.printable()); + fmt::println("expected key: {}", expectedKey.printable()); } if (!valueMatch) { - printf("value: %s\n", rec.value.printable().c_str()); - printf("expected value: %s\n", expectedValue.printable().c_str()); + fmt::println("value: {}", rec.value.printable()); + fmt::println("expected value: {}", expectedValue.printable()); } } @@ -146,8 +146,8 @@ struct MutationLogReaderCorrectnessWorkload : TestWorkload { } } - printf("records expected: %d\n", self->records); - printf("records found: %d\n", nextExpectedRecord); + fmt::println("records expected: {}", self->records); + fmt::println("records found: {}", nextExpectedRecord); ASSERT_EQ(nextExpectedRecord, self->records); } diff --git a/fdbserver/workloads/ParallelRestore.cpp b/fdbserver/workloads/ParallelRestore.cpp index f2a08799521..c57d326469f 100644 --- a/fdbserver/workloads/ParallelRestore.cpp +++ b/fdbserver/workloads/ParallelRestore.cpp @@ -23,6 +23,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/workloads/BulkSetup.h" #include "fdbserver/RestoreWorkerInterface.actor.h" +#include "fmt/format.h" // A workload which test the correctness of backup and restore process struct RunRestoreWorkerWorkload : TestWorkload { @@ -40,15 +41,15 @@ struct RunRestoreWorkerWorkload : TestWorkload { TraceEvent("RunParallelRestoreWorkerWorkload") .detail("Start", "RestoreToolDB") .detail("Workers", num_myWorkers); - printf("RunParallelRestoreWorkerWorkload, we will start %d restore workers\n", num_myWorkers); + fmt::println("RunParallelRestoreWorkerWorkload, we will start {} restore workers", num_myWorkers); std::vector> myWorkers; myWorkers.reserve(num_myWorkers); for (int i = 0; i < num_myWorkers; ++i) { myWorkers.push_back(_restoreWorker(cx, LocalityData())); } - printf("RunParallelRestoreWorkerWorkload, wait on reply from %ld restore workers\n", myWorkers.size()); + fmt::println("RunParallelRestoreWorkerWorkload, wait on reply from {} restore workers", myWorkers.size()); worker = waitForAll(myWorkers); - printf("RunParallelRestoreWorkerWorkload, got all replies from restore workers\n"); + fmt::println("RunParallelRestoreWorkerWorkload, got all replies from restore workers"); return Void(); } diff --git a/fdbserver/workloads/Performance.cpp b/fdbserver/workloads/Performance.cpp index 97831c840fc..5acb9d2c443 100644 --- a/fdbserver/workloads/Performance.cpp +++ b/fdbserver/workloads/Performance.cpp @@ -23,6 +23,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/QuietDatabase.h" #include "flow/CoroUtils.h" +#include "fmt/format.h" // TODO: explain purpose of this workload. Obviously simulation is aimed at correctness, // not performance, so a workload literally named Performance has some explaining to do. @@ -44,14 +45,11 @@ struct PerformanceWorkload : TestWorkload { for (int i = 0; i < options.size(); i++) { if (options[i].value.size()) { savedOptions.push_back_deep(savedOptions.arena(), KeyValueRef(options[i].key, options[i].value)); - printf("saved option (%d): '%s'='%s'\n", - i, - printable(options[i].key).c_str(), - printable(options[i].value).c_str()); + fmt::println("saved option ({}): '{}'='{}'", i, printable(options[i].key), printable(options[i].value)); options[i].value = ""_sr; } } - printf("saved %d options\n", savedOptions.size()); + fmt::println("saved {} options", savedOptions.size()); } Future setup(Database const& cx) override { @@ -83,13 +81,10 @@ struct PerformanceWorkload : TestWorkload { Standalone>> opts; options.push_back_deep(options.arena(), KeyValueRef("testName"_sr, probeWorkload)); options.push_back_deep(options.arena(), - KeyValueRef("transactionsPerSecond"_sr, format("%f", transactionsPerSecond))); + KeyValueRef("transactionsPerSecond"_sr, fmt::format("{:f}", transactionsPerSecond))); for (int i = 0; i < savedOptions.size(); i++) { options.push_back_deep(options.arena(), savedOptions[i]); - printf("option [%d]: '%s'='%s'\n", - i, - printable(savedOptions[i].key).c_str(), - printable(savedOptions[i].value).c_str()); + fmt::println("option [{}]: '{}'='{}'", i, printable(savedOptions[i].key), printable(savedOptions[i].value)); } opts.push_back_deep(opts.arena(), options); return opts; @@ -99,7 +94,7 @@ struct PerformanceWorkload : TestWorkload { TraceEvent start("PerformaceSetupStarting"); for (int i = 0; i < options.size(); i++) { for (int j = 0; j < options[i].size(); j++) { - start.detail(format("Option-%d-%d", i, j).c_str(), + start.detail(fmt::format("Option-{}-{}", i, j).c_str(), printable(options[i][j].key) + "=" + printable(options[i][j].value)); } } @@ -163,7 +158,7 @@ struct PerformanceWorkload : TestWorkload { start.detail("RateTarget", tps); for (int i = 0; i < options.size(); i++) { for (int j = 0; j < options[i].size(); j++) { - start.detail(format("Option-%d-%d", i, j).c_str(), + start.detail(fmt::format("Option-{}-{}", i, j).c_str(), printable(options[i][j].key) + "=" + printable(options[i][j].value)); } } diff --git a/fdbserver/workloads/PerpetualWiggleStatsWorkload.cpp b/fdbserver/workloads/PerpetualWiggleStatsWorkload.cpp index 41f47058dfa..7b438484751 100644 --- a/fdbserver/workloads/PerpetualWiggleStatsWorkload.cpp +++ b/fdbserver/workloads/PerpetualWiggleStatsWorkload.cpp @@ -28,6 +28,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include "fdbclient/VersionedMap.h" #include "fdbclient/ReadYourWrites.h" +#include "fmt/format.h" // just compare the int part and smoothed duration is enough for the test. bool storageWiggleStatsEqual(StorageWiggleMetrics const& a, StorageWiggleMetrics const& b) { @@ -46,7 +47,7 @@ bool storageWiggleStatsEqual(StorageWiggleMetrics const& a, StorageWiggleMetrics namespace { Future IssueConfigurationChange(Database cx, std::string config, bool force) { - printf("Issuing configuration change: %s\n", config.c_str()); + fmt::println("Issuing configuration change: {}", config); ConfigurationResult res = co_await ManagementAPI::changeConfig(cx.getReference(), config, force); if (res != ConfigurationResult::SUCCESS) { co_return false; diff --git a/fdbserver/workloads/PerpetualWiggleStorageMigrationWorkload.cpp b/fdbserver/workloads/PerpetualWiggleStorageMigrationWorkload.cpp index 826bf0cca4c..4554ac0be8b 100644 --- a/fdbserver/workloads/PerpetualWiggleStorageMigrationWorkload.cpp +++ b/fdbserver/workloads/PerpetualWiggleStorageMigrationWorkload.cpp @@ -29,10 +29,11 @@ #include "fdbclient/VersionedMap.h" #include "fdbclient/ReadYourWrites.h" #include "fdbrpc/SimulatorProcessInfo.h" +#include "fmt/format.h" namespace { Future IssueConfigurationChange(Database cx, std::string config, bool force) { - printf("Issuing configuration change: %s\n", config.c_str()); + fmt::println("Issuing configuration change: {}", config); ConfigurationResult res = co_await ManagementAPI::changeConfig(cx.getReference(), config, force); if (res != ConfigurationResult::SUCCESS) { co_return false; diff --git a/fdbserver/workloads/Ping.cpp b/fdbserver/workloads/Ping.cpp index 61395713867..defc5f1e7c5 100644 --- a/fdbserver/workloads/Ping.cpp +++ b/fdbserver/workloads/Ping.cpp @@ -24,6 +24,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/WorkerInterface.actor.h" #include "fdbserver/QuietDatabase.h" +#include "fmt/format.h" struct PingWorkloadInterface { RequestStream payloadPing; @@ -105,13 +106,13 @@ struct PingWorkload : TestWorkload { while (true) { Error err; try { - Optional val = co_await tr.get(StringRef(format("Ping/Client/%d", self->clientId))); + Optional val = co_await tr.get(StringRef(fmt::format("Ping/Client/{}", self->clientId))); if (val.present()) { if (val.get() != serializedInterface) throw operation_failed(); break; } - tr.set(format("Ping/Client/%d", self->clientId), serializedInterface); + tr.set(fmt::format("Ping/Client/{}", self->clientId), serializedInterface); co_await tr.commit(); break; } catch (Error& e) { @@ -128,7 +129,7 @@ struct PingWorkload : TestWorkload { try { std::vector result; for (int i = 0; i < self->clientCount; i++) { - Optional val = co_await tr.get(StringRef(format("Ping/Client/%d", i))); + Optional val = co_await tr.get(StringRef(fmt::format("Ping/Client/{}", i))); if (!val.present()) { throw operation_failed(); } diff --git a/fdbserver/workloads/PubSubMultiples.cpp b/fdbserver/workloads/PubSubMultiples.cpp index 39719d0e918..5fc322193aa 100644 --- a/fdbserver/workloads/PubSubMultiples.cpp +++ b/fdbserver/workloads/PubSubMultiples.cpp @@ -22,6 +22,7 @@ #include "fdbserver/pubsub.h" #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct PubSubMultiplesWorkload : TestWorkload { static constexpr auto NAME = "PubSubMultiples"; @@ -48,9 +49,9 @@ struct PubSubMultiplesWorkload : TestWorkload { void getMetrics(std::vector& m) override { m.push_back(messages.getMetric()); } - Key keyForFeed(int i) { return StringRef(format("/PSM/feeds/%d", i)); } - Key keyForInbox(int i) { return StringRef(format("/PSM/inbox/%d", i)); } - Value valueForUInt(uint64_t i) { return StringRef(format("%llx", i)); } + Key keyForFeed(int i) { return StringRef(fmt::format("/PSM/feeds/{}", i)); } + Key keyForInbox(int i) { return StringRef(fmt::format("/PSM/inbox/{}", i)); } + Value valueForUInt(uint64_t i) { return StringRef(fmt::format("{:x}", i)); } Future createNodeSwath(PubSubMultiplesWorkload* self, int actor, Database cx) { PubSub ps(cx); diff --git a/fdbserver/workloads/QueuePush.cpp b/fdbserver/workloads/QueuePush.cpp index f5f2eefac36..034db3c13ce 100644 --- a/fdbserver/workloads/QueuePush.cpp +++ b/fdbserver/workloads/QueuePush.cpp @@ -24,6 +24,7 @@ #include "fdbclient/NativeAPI.actor.h" #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" const int keyBytes = 16; @@ -77,7 +78,7 @@ struct QueuePushWorkload : TestWorkload { m.emplace_back("Bytes written/sec", (writes * (keyBytes + valueBytes)) / duration, Averaged::False); } - static Key keyForIndex(int base, int offset) { return StringRef(format("%08x%08x", base, offset)); } + static Key keyForIndex(int base, int offset) { return StringRef(fmt::format("{:08x}{:08x}", base, offset)); } static std::pair valuesForKey(KeyRef value) { int base, offset; diff --git a/fdbserver/workloads/RYWPerformance.cpp b/fdbserver/workloads/RYWPerformance.cpp index 43e16d7bb41..d2bb381c11e 100644 --- a/fdbserver/workloads/RYWPerformance.cpp +++ b/fdbserver/workloads/RYWPerformance.cpp @@ -22,6 +22,7 @@ #include "fdbserver/TesterInterface.actor.h" #include "fdbclient/ReadYourWrites.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct RYWPerformanceWorkload : TestWorkload { static constexpr auto NAME = "RYWPerformance"; @@ -175,7 +176,7 @@ struct RYWPerformanceWorkload : TestWorkload { co_await tr.get(keyForIndex(nodes / 2)); } - fprintf(stderr, "%f", nodes / (timer() - startTime)); + fmt::print(stderr, "{:f}", nodes / (timer() - startTime)); co_return; } catch (Error& e) { @@ -200,7 +201,7 @@ struct RYWPerformanceWorkload : TestWorkload { co_await tr.get(keyForIndex(i)); } - fprintf(stderr, "%f", nodes / (timer() - startTime)); + fmt::print(stderr, "{:f}", nodes / (timer() - startTime)); co_return; } catch (Error& e) { @@ -225,7 +226,7 @@ struct RYWPerformanceWorkload : TestWorkload { co_await tr.getRange(KeyRangeRef(keyForIndex(0), keyForIndex(nodes)), nodes); } - fprintf(stderr, "%f", ranges / (timer() - startTime)); + fmt::print(stderr, "{:f}", ranges / (timer() - startTime)); co_return; } catch (Error& e) { @@ -253,7 +254,7 @@ struct RYWPerformanceWorkload : TestWorkload { tr.set(keyForIndex(nodes / 2), keyForIndex(i)); } - fprintf(stderr, "%f", nodes / (timer() - startTime)); + fmt::print(stderr, "{:f}", nodes / (timer() - startTime)); co_return; } catch (Error& e) { @@ -265,37 +266,37 @@ struct RYWPerformanceWorkload : TestWorkload { Future _start(Database cx) { int i{ 0 }; - fprintf(stderr, "test_get_single, "); + fmt::print(stderr, "test_get_single, "); for (i = 0; i < 14; i++) { co_await test_get_single(cx, i); if (i == 13) - fprintf(stderr, "\n"); + fmt::println(stderr, ""); else - fprintf(stderr, ", "); + fmt::print(stderr, ", "); } - fprintf(stderr, "test_get_many_sequential, "); + fmt::print(stderr, "test_get_many_sequential, "); for (i = 0; i < 14; i++) { co_await test_get_many_sequential(cx, i); if (i == 13) - fprintf(stderr, "\n"); + fmt::println(stderr, ""); else - fprintf(stderr, ", "); + fmt::print(stderr, ", "); } - fprintf(stderr, "test_get_range_basic, "); + fmt::print(stderr, "test_get_range_basic, "); for (i = 4; i < 14; i++) { co_await test_get_range_basic(cx, i); if (i == 13) - fprintf(stderr, "\n"); + fmt::println(stderr, ""); else - fprintf(stderr, ", "); + fmt::print(stderr, ", "); } - fprintf(stderr, "test_interleaved_sets_gets, "); + fmt::print(stderr, "test_interleaved_sets_gets, "); for (i = 0; i < 14; i++) { co_await test_interleaved_sets_gets(cx, i); if (i == 13) - fprintf(stderr, "\n"); + fmt::println(stderr, ""); else - fprintf(stderr, ", "); + fmt::print(stderr, ", "); } } diff --git a/fdbserver/workloads/RandomMoveKeys.cpp b/fdbserver/workloads/RandomMoveKeys.cpp index f5f67e5a0b3..21382229d3d 100644 --- a/fdbserver/workloads/RandomMoveKeys.cpp +++ b/fdbserver/workloads/RandomMoveKeys.cpp @@ -29,6 +29,7 @@ #include "fdbserver/ServerDBInfo.h" #include "fdbserver/QuietDatabase.h" #include "flow/DeterministicRandom.h" +#include "fmt/format.h" struct MoveKeysWorkload : FailureInjectionWorkload { static constexpr auto NAME = "RandomMoveKeys"; @@ -142,8 +143,7 @@ struct MoveKeysWorkload : FailureInjectionWorkload { FlowLock fl2(1); std::string desc; for (int s = 0; s < destinationTeam.size(); s++) - desc += - format("%s (%llx),", destinationTeam[s].address().toString().c_str(), destinationTeam[s].id().first()); + desc += fmt::format("{} ({:x}),", destinationTeam[s].address().toString(), destinationTeam[s].id().first()); std::vector destinationTeamIDs; destinationTeamIDs.reserve(destinationTeam.size()); for (int s = 0; s < destinationTeam.size(); s++) diff --git a/fdbserver/workloads/RandomSelector.cpp b/fdbserver/workloads/RandomSelector.cpp index 64e04622cb2..934c7e53fb5 100644 --- a/fdbserver/workloads/RandomSelector.cpp +++ b/fdbserver/workloads/RandomSelector.cpp @@ -22,6 +22,7 @@ #include "fdbserver/TesterInterface.actor.h" #include "fdbclient/ReadYourWrites.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct RandomSelectorWorkload : TestWorkload { static constexpr auto NAME = "RandomSelector"; @@ -65,18 +66,18 @@ struct RandomSelectorWorkload : TestWorkload { } Future randomSelectorSetup(Database cx, RandomSelectorWorkload* self) { - Value myValue = StringRef(format("%d", deterministicRandom()->randomInt(0, 10000000))); + Value myValue = StringRef(fmt::format("{}", deterministicRandom()->randomInt(0, 10000000))); Transaction tr(cx); std::string clientID; - clientID = format("%08d", self->clientId); + clientID = fmt::format("{:08}", self->clientId); while (true) { Error err; try { for (int i = 0; i < self->maxOffset; i++) { - tr.set(StringRef(clientID + "a/" + format("%010d", i)), myValue); - tr.set(StringRef(clientID + "c/" + format("%010d", i)), myValue); - tr.set(StringRef(clientID + "e/" + format("%010d", i)), myValue); + tr.set(StringRef(clientID + "a/" + fmt::format("{:010}", i)), myValue); + tr.set(StringRef(clientID + "c/" + fmt::format("{:010}", i)), myValue); + tr.set(StringRef(clientID + "e/" + fmt::format("{:010}", i)), myValue); } co_await tr.commit(); break; @@ -105,7 +106,7 @@ struct RandomSelectorWorkload : TestWorkload { Reverse reverse = Reverse::False; Error error; - clientID = format("%08d", self->clientId); + clientID = fmt::format("{:08}", self->clientId); while (true) { Transaction tr(cx); @@ -118,8 +119,8 @@ struct RandomSelectorWorkload : TestWorkload { for (i = 0; i < deterministicRandom()->randomInt(self->minInitialAmount, self->maxInitialAmount + 1); i++) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); - myValue = format("%d", deterministicRandom()->randomInt(0, 10000000)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); + myValue = fmt::format("{}", deterministicRandom()->randomInt(0, 10000000)); tr.set(StringRef(clientID + "b/" + myKeyA), myValue); tr.set(StringRef(clientID + "d/" + myKeyA), myValue); //TraceEvent("RYOWInit").detail("Key",myKeyA).detail("Value",myValue); @@ -142,8 +143,8 @@ struct RandomSelectorWorkload : TestWorkload { i++) { j = deterministicRandom()->randomInt(0, 16); if (j < 3) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); - myValue = format("%d", deterministicRandom()->randomInt(0, 10000000)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); + myValue = fmt::format("{}", deterministicRandom()->randomInt(0, 10000000)); //TraceEvent("RYOWset").detail("Key",myKeyA).detail("Value",myValue); trRYOW.set(StringRef(clientID + "b/" + myKeyA), myValue); @@ -161,7 +162,7 @@ struct RandomSelectorWorkload : TestWorkload { co_await tr.onError(err); } } else if (j < 4) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); //TraceEvent("RYOWclear").detail("Key",myKeyA); trRYOW.clear(StringRef(clientID + "b/" + myKeyA)); @@ -181,8 +182,8 @@ struct RandomSelectorWorkload : TestWorkload { } else if (j < 5) { int a = deterministicRandom()->randomInt(1, self->maxKeySpace + 1); int b = deterministicRandom()->randomInt(1, self->maxKeySpace + 1); - myKeyA = format("%010d", std::min(a, b) - 1); - myKeyB = format("%010d", std::max(a, b)); + myKeyA = fmt::format("{:010}", std::min(a, b) - 1); + myKeyB = fmt::format("{:010}", std::max(a, b)); //TraceEvent("RYOWclearRange").detail("KeyA",myKeyA).detail("KeyB",myKeyB); trRYOW.clear( @@ -202,7 +203,7 @@ struct RandomSelectorWorkload : TestWorkload { co_await tr.onError(err); } } else if (j < 6) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); Optional getTest1; @@ -238,9 +239,9 @@ struct RandomSelectorWorkload : TestWorkload { } } } else if (j < 7) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); - myRandomIDKey = format("%010d", deterministicRandom()->randomInt(0, 1000000000)); - myValue = format("%d", deterministicRandom()->randomInt(0, 10000000)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); + myRandomIDKey = fmt::format("{:010}", deterministicRandom()->randomInt(0, 1000000000)); + myValue = fmt::format("{}", deterministicRandom()->randomInt(0, 10000000)); //TraceEvent("RYOWadd").detail("Key",myKeyA).detail("Value", "\\x01"); trRYOW.atomicOp(StringRef(clientID + "b/" + myKeyA), myValue, MutationRef::AddValue); @@ -266,9 +267,9 @@ struct RandomSelectorWorkload : TestWorkload { } } } else if (j < 8) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); - myRandomIDKey = format("%010d", deterministicRandom()->randomInt(0, 1000000000)); - myValue = format("%d", deterministicRandom()->randomInt(0, 10000000)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); + myRandomIDKey = fmt::format("{:010}", deterministicRandom()->randomInt(0, 1000000000)); + myValue = fmt::format("{}", deterministicRandom()->randomInt(0, 10000000)); //TraceEvent("RYOWappendIfFits").detail("Key",myKeyA).detail("Value", myValue); trRYOW.atomicOp(StringRef(clientID + "b/" + myKeyA), myValue, MutationRef::AppendIfFits); @@ -295,9 +296,9 @@ struct RandomSelectorWorkload : TestWorkload { } } } else if (j < 9) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); - myRandomIDKey = format("%010d", deterministicRandom()->randomInt(0, 1000000000)); - myValue = format("%d", deterministicRandom()->randomInt(0, 10000000)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); + myRandomIDKey = fmt::format("{:010}", deterministicRandom()->randomInt(0, 1000000000)); + myValue = fmt::format("{}", deterministicRandom()->randomInt(0, 10000000)); //TraceEvent("RYOWand").detail("Key",myKeyA).detail("Value", myValue); trRYOW.atomicOp(StringRef(clientID + "b/" + myKeyA), myValue, MutationRef::And); @@ -323,9 +324,9 @@ struct RandomSelectorWorkload : TestWorkload { } } } else if (j < 10) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); - myRandomIDKey = format("%010d", deterministicRandom()->randomInt(0, 1000000000)); - myValue = format("%d", deterministicRandom()->randomInt(0, 10000000)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); + myRandomIDKey = fmt::format("{:010}", deterministicRandom()->randomInt(0, 1000000000)); + myValue = fmt::format("{}", deterministicRandom()->randomInt(0, 10000000)); //TraceEvent("RYOWor").detail("Key",myKeyA).detail("Value", myValue); trRYOW.atomicOp(StringRef(clientID + "b/" + myKeyA), myValue, MutationRef::Or); @@ -351,9 +352,9 @@ struct RandomSelectorWorkload : TestWorkload { } } } else if (j < 11) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); - myRandomIDKey = format("%010d", deterministicRandom()->randomInt(0, 1000000000)); - myValue = format("%d", deterministicRandom()->randomInt(0, 10000000)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); + myRandomIDKey = fmt::format("{:010}", deterministicRandom()->randomInt(0, 1000000000)); + myValue = fmt::format("{}", deterministicRandom()->randomInt(0, 10000000)); //TraceEvent("RYOWxor").detail("Key",myKeyA).detail("Value", myValue); trRYOW.atomicOp(StringRef(clientID + "b/" + myKeyA), myValue, MutationRef::Xor); @@ -379,9 +380,9 @@ struct RandomSelectorWorkload : TestWorkload { } } } else if (j < 12) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); - myRandomIDKey = format("%010d", deterministicRandom()->randomInt(0, 1000000000)); - myValue = format("%d", deterministicRandom()->randomInt(0, 10000000)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); + myRandomIDKey = fmt::format("{:010}", deterministicRandom()->randomInt(0, 1000000000)); + myValue = fmt::format("{}", deterministicRandom()->randomInt(0, 10000000)); //TraceEvent("RYOWmax").detail("Key",myKeyA).detail("Value", myValue); trRYOW.atomicOp(StringRef(clientID + "b/" + myKeyA), myValue, MutationRef::Max); @@ -407,9 +408,9 @@ struct RandomSelectorWorkload : TestWorkload { } } } else if (j < 13) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); - myRandomIDKey = format("%010d", deterministicRandom()->randomInt(0, 1000000000)); - myValue = format("%d", deterministicRandom()->randomInt(0, 10000000)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); + myRandomIDKey = fmt::format("{:010}", deterministicRandom()->randomInt(0, 1000000000)); + myValue = fmt::format("{}", deterministicRandom()->randomInt(0, 10000000)); //TraceEvent("RYOWmin").detail("Key",myKeyA).detail("Value", myValue); trRYOW.atomicOp(StringRef(clientID + "b/" + myKeyA), myValue, MutationRef::Min); @@ -435,9 +436,9 @@ struct RandomSelectorWorkload : TestWorkload { } } } else if (j < 14) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); - myRandomIDKey = format("%010d", deterministicRandom()->randomInt(0, 1000000000)); - myValue = format("%d", deterministicRandom()->randomInt(0, 10000000)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); + myRandomIDKey = fmt::format("{:010}", deterministicRandom()->randomInt(0, 1000000000)); + myValue = fmt::format("{}", deterministicRandom()->randomInt(0, 10000000)); //TraceEvent("RYOWbytemin").detail("Key",myKeyA).detail("Value", myValue); trRYOW.atomicOp(StringRef(clientID + "b/" + myKeyA), myValue, MutationRef::ByteMin); @@ -463,9 +464,9 @@ struct RandomSelectorWorkload : TestWorkload { } } } else if (j < 15) { - myKeyA = format("%010d", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); - myRandomIDKey = format("%010d", deterministicRandom()->randomInt(0, 1000000000)); - myValue = format("%d", deterministicRandom()->randomInt(0, 10000000)); + myKeyA = fmt::format("{:010}", deterministicRandom()->randomInt(0, self->maxKeySpace + 1)); + myRandomIDKey = fmt::format("{:010}", deterministicRandom()->randomInt(0, 1000000000)); + myValue = fmt::format("{}", deterministicRandom()->randomInt(0, 10000000)); //TraceEvent("RYOWbytemax").detail("Key",myKeyA).detail("Value", myValue); trRYOW.atomicOp(StringRef(clientID + "b/" + myKeyA), myValue, MutationRef::ByteMax); @@ -493,8 +494,8 @@ struct RandomSelectorWorkload : TestWorkload { } else { int a = deterministicRandom()->randomInt(1, self->maxKeySpace + 1); int b = deterministicRandom()->randomInt(1, self->maxKeySpace + 1); - myKeyA = format("%010d", std::min(a, b) - 1); - myKeyB = format("%010d", std::max(a, b)); + myKeyA = fmt::format("{:010}", std::min(a, b) - 1); + myKeyB = fmt::format("{:010}", std::max(a, b)); onEqualA = deterministicRandom()->randomInt(0, 2) != 0; onEqualB = deterministicRandom()->randomInt(0, 2) != 0; offsetA = deterministicRandom()->randomInt(-1 * self->maxOffset / 2, self->maxOffset / 2); @@ -560,13 +561,13 @@ struct RandomSelectorWorkload : TestWorkload { std::string outStr1 = ""; for (int k = 0; k < getRangeTest1.size(); k++) { outStr1 = outStr1 + printable(getRangeTest1[k].key) + " " + - format("%d", getRangeTest1[k].value.size()) + " "; + fmt::format("{}", getRangeTest1[k].value.size()) + " "; } std::string outStr2 = ""; for (int k = 0; k < getRangeTest2.size(); k++) { outStr2 = outStr2 + printable(getRangeTest2[k].key) + " " + - format("%d", getRangeTest2[k].value.size()) + " "; + fmt::format("{}", getRangeTest2[k].value.size()) + " "; } TraceEvent("RanSelTestLog").detail("RYOW", outStr1).detail("Normal", outStr2); diff --git a/fdbserver/workloads/ReadHotDetection.cpp b/fdbserver/workloads/ReadHotDetection.cpp index ed227e7910b..c08007fd565 100644 --- a/fdbserver/workloads/ReadHotDetection.cpp +++ b/fdbserver/workloads/ReadHotDetection.cpp @@ -24,6 +24,7 @@ #include "fdbserver/workloads/BulkSetup.h" #include "fdbclient/ReadYourWrites.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct ReadHotDetectionWorkload : TestWorkload { static constexpr auto NAME = "ReadHotDetection"; @@ -42,7 +43,7 @@ struct ReadHotDetectionWorkload : TestWorkload { transactionsPerSecond = getOption(options, "transactionsPerSecond"_sr, 1000.0) / clientCount; actorCount = getOption(options, "actorsPerClient"_sr, transactionsPerSecond / 5); keyCount = getOption(options, "keyCount"_sr, 100); - readKey = StringRef(format("testkey%08x", deterministicRandom()->randomInt(0, keyCount))); + readKey = StringRef(fmt::format("testkey{:08x}", deterministicRandom()->randomInt(0, keyCount))); } Future setup(Database const& cx) override { @@ -55,7 +56,7 @@ struct ReadHotDetectionWorkload : TestWorkload { Error err; try { for (int i = 0; i < keyCount; i++) { - Standalone key = StringRef(format("testkey%08x", i)); + Standalone key = StringRef(fmt::format("testkey{:08x}", i)); if (key == readKey) { tr.set(key, largeValue); } else { @@ -145,9 +146,9 @@ struct ReadHotDetectionWorkload : TestWorkload { Error err; try { Optional v = co_await tr.get( - useReadKey - ? self->readKey - : StringRef(format("testkey%08x", deterministicRandom()->randomInt(0, self->keyCount)))); + useReadKey ? self->readKey + : StringRef(fmt::format("testkey{:08x}", + deterministicRandom()->randomInt(0, self->keyCount)))); break; } catch (Error& e) { err = e; diff --git a/fdbserver/workloads/ReadWrite.cpp b/fdbserver/workloads/ReadWrite.cpp index d45151aa672..151a8f352b0 100644 --- a/fdbserver/workloads/ReadWrite.cpp +++ b/fdbserver/workloads/ReadWrite.cpp @@ -33,6 +33,7 @@ #include "fdbclient/ReadYourWrites.h" #include "flow/TDMetric.actor.h" #include "flow/CoroUtils.h" +#include "fmt/format.h" struct ReadWriteCommonImpl { // trace methods @@ -178,7 +179,7 @@ Future ReadWriteCommon::tracePeriodically() { bool recordBegin = shouldRecord(std::max(now() - periodicLoggingInterval, clientBegin)); bool recordEnd = shouldRecord(now()); if (recordBegin && recordEnd) { - std::string ts = format("T=%04.0fs:", elapsed); + std::string ts = fmt::format("T={:04.0f}s:", elapsed); periodicMetrics.emplace_back( ts + "Operations/sec", (ops - last_ops) / periodicLoggingInterval, Averaged::False); @@ -300,7 +301,7 @@ void ReadWriteCommon::getMetrics(std::vector& m) { std::vector>::iterator ratesItr = ratesAtKeyCounts.begin(); for (; ratesItr != ratesAtKeyCounts.end(); ratesItr++) - m.emplace_back(format("%lld keys imported bytes/sec", ratesItr->first), ratesItr->second, Averaged::False); + m.emplace_back(fmt::format("{} keys imported bytes/sec", ratesItr->first), ratesItr->second, Averaged::False); } Standalone ReadWriteCommon::operator()(uint64_t n) { diff --git a/fdbserver/workloads/RemoveServersSafely.cpp b/fdbserver/workloads/RemoveServersSafely.cpp index 234ceba69fb..55aebff9d35 100644 --- a/fdbserver/workloads/RemoveServersSafely.cpp +++ b/fdbserver/workloads/RemoveServersSafely.cpp @@ -26,10 +26,11 @@ #include "fdbrpc/SimulatorProcessInfo.h" #include "fdbclient/ManagementAPI.actor.h" #include "flow/CoroUtils.h" +#include "fmt/format.h" template <> std::string describe(uint32_t const& item) { - return format("%d", item); + return fmt::format("{}", item); } struct RemoveServersSafelyWorkload : TestWorkload { diff --git a/fdbserver/workloads/ReportConflictingKeys.cpp b/fdbserver/workloads/ReportConflictingKeys.cpp index 09a6610770c..0aa57f724e0 100644 --- a/fdbserver/workloads/ReportConflictingKeys.cpp +++ b/fdbserver/workloads/ReportConflictingKeys.cpp @@ -24,6 +24,7 @@ #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/workloads/BulkSetup.h" +#include "fmt/format.h" // For this test to report properly buggify must be disabled (flow.h) , and failConnection must be disabled in // (sim2.actor.cpp) @@ -89,8 +90,8 @@ struct ReportConflictingKeysWorkload : TestWorkload { // 8 bytes for Cid_* suffix of each client int paddingLen = keyBytes - 8 - keyPrefix.size(); // left padding by zero, each client has different prefix - Key prefixWithClientId = StringRef(format("Cid_%04d", clientId)).withPrefix(keyPrefix); - return StringRef(format("%0*llx", paddingLen, *(uint64_t*)&p)).withPrefix(prefixWithClientId); + Key prefixWithClientId = StringRef(fmt::format("Cid_{:04}", clientId)).withPrefix(keyPrefix); + return StringRef(fmt::format("{:0{}x}", *(uint64_t*)&p, paddingLen)).withPrefix(prefixWithClientId); } void addRandomReadConflictRange(ReadYourWritesTransaction* tr, std::vector* readConflictRanges) { diff --git a/fdbserver/workloads/Restore.cpp b/fdbserver/workloads/Restore.cpp index a452908fd94..146962ab29f 100644 --- a/fdbserver/workloads/Restore.cpp +++ b/fdbserver/workloads/Restore.cpp @@ -29,6 +29,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/workloads/BulkSetup.h" #include "flow/IRandom.h" +#include "fmt/format.h" // TODO: explain the purpose of this workload and how it different from the // 20+ (literally) other backup/restore workloads. @@ -207,9 +208,9 @@ struct RestoreWorkload : TestWorkload { restoreRanges = modifiedRestoreRanges; Standalone restoreTag(backupTag.toString() + "_" + std::to_string(restoreIndex)); - printf("BackupCorrectness, backupAgent.restore is called for restoreIndex:%d tag:%s\n", - restoreIndex, - restoreTag.toString().c_str()); + fmt::println("BackupCorrectness, backupAgent.restore is called for restoreIndex:{} tag:{}", + restoreIndex, + restoreTag.toString()); TraceEvent("RW_RestoreRanges", randomID) .detail("RestoreIndex", restoreIndex) .detail("RestoreTag", printable(restoreTag)) @@ -264,11 +265,11 @@ struct RestoreWorkload : TestWorkload { .detail("BackupTag", printable(backupTag)) .detail("TaskCount", taskCount) .detail("WaitCycles", waitCycles); - printf("%.6f %-10s Wait #%4d for %lld tasks to end\n", - now(), - randomID.toString().c_str(), - waitCycles, - (long long)taskCount); + fmt::println("{:.6f} {:<10} Wait #{:4} for {} tasks to end", + now(), + randomID.toString(), + waitCycles, + (long long)taskCount); co_await delay(5.0); @@ -282,9 +283,9 @@ struct RestoreWorkload : TestWorkload { // Error if the system keyspace for the backup tag is not empty if (!agentValues.empty()) { displaySystemKeys++; - printf("BackupCorrectnessLeftOverMutationKeys: (%d) %s\n", - agentValues.size(), - printable(backupAgentKey).c_str()); + fmt::println("BackupCorrectnessLeftOverMutationKeys: ({}) {}", + agentValues.size(), + printable(backupAgentKey)); TraceEvent(SevError, "BackupCorrectnessLeftOverMutationKeys", randomID) .detail("BackupTag", printable(backupTag)) .detail("LeftOverKeys", agentValues.size()) @@ -293,12 +294,12 @@ struct RestoreWorkload : TestWorkload { TraceEvent("RW_LeftOverKey", randomID) .detail("Key", printable(StringRef(s.key.toString()))) .detail("Value", printable(StringRef(s.value.toString()))); - printf(" Key: %-50s Value: %s\n", - printable(StringRef(s.key.toString())).c_str(), - printable(StringRef(s.value.toString())).c_str()); + fmt::println(" Key: {:<50} Value: {}", + printable(StringRef(s.key.toString())), + printable(StringRef(s.value.toString()))); } } else { - printf("No left over backup agent configuration keys\n"); + fmt::println("No left over backup agent configuration keys"); } Optional latestVersion = co_await tr->get(backupLatestVersionsKey); @@ -308,7 +309,7 @@ struct RestoreWorkload : TestWorkload { .detail("BackupLatestVersionsKey", backupLatestVersionsKey.printable()) .detail("DestUidValue", destUidValue.printable()); } else { - printf("No left over backup version key\n"); + fmt::println("No left over backup version key"); } RangeResult versions = co_await tr->getRange( @@ -320,15 +321,15 @@ struct RestoreWorkload : TestWorkload { // Error if the log/mutation keyspace for the backup tag is not empty if (!logValues.empty()) { displaySystemKeys++; - printf("BackupCorrectnessLeftOverLogKeys: (%d) %s\n", - logValues.size(), - printable(backupLogValuesKey).c_str()); + fmt::println("BackupCorrectnessLeftOverLogKeys: ({}) {}", + logValues.size(), + printable(backupLogValuesKey)); TraceEvent(SevError, "BackupCorrectnessLeftOverLogKeys", randomID) .detail("BackupTag", printable(backupTag)) .detail("LeftOverKeys", logValues.size()) .detail("KeySpace", printable(backupLogValuesKey)); } else { - printf("No left over backup log keys\n"); + fmt::println("No left over backup log keys"); } } diff --git a/fdbserver/workloads/RyowCorrectness.cpp b/fdbserver/workloads/RyowCorrectness.cpp index b2bedf425b5..b864fd8a1be 100644 --- a/fdbserver/workloads/RyowCorrectness.cpp +++ b/fdbserver/workloads/RyowCorrectness.cpp @@ -24,6 +24,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/workloads/MemoryKeyValueStore.h" #include "fdbserver/workloads/ApiWorkload.h" +#include "fmt/format.h" #define TRACE_TRANSACTION 0 @@ -152,7 +153,7 @@ struct RyowCorrectnessWorkload : ApiWorkload { Key key; #if TRACE_TRANSACTION - printf("NEW_TRANSACTION\n"); + fmt::println("NEW_TRANSACTION"); #endif for (auto op : sequence) { @@ -161,14 +162,14 @@ struct RyowCorrectnessWorkload : ApiWorkload { store.set(op.beginKey, op.value); #if TRACE_TRANSACTION if (op.beginKey == debugKey) - printf("SET: %s = %d\n", printable(op.beginKey).c_str(), op.value.size()); + fmt::println("SET: {} = {}", printable(op.beginKey), op.value.size()); #endif break; case Operation::GET: pushKVPair(results, op.beginKey, store.get(op.beginKey)); #if TRACE_TRANSACTION && 0 if (op.beginKey == debugKey) - printf("GET: %s\n", printable(op.beginKey).c_str()); + fmt::println("GET: {}", printable(op.beginKey)); #endif break; case Operation::GET_RANGE_SELECTOR: @@ -182,12 +183,12 @@ struct RyowCorrectnessWorkload : ApiWorkload { results.push_back(store.getRange(KeyRangeRef(op.beginKey, op.endKey), op.limit, op.reverse)); #if TRACE_TRANSACTION if (op.beginKey <= debugKey && debugKey < op.endKey) - printf("%s: %s - %s (limit=%d, reverse=%d)\n", - op.type == Operation::GET_RANGE ? "GET_RANGE" : "GET_RANGE_SELECTOR", - printable(op.beginKey).c_str(), - printable(op.endKey).c_str(), - op.limit, - op.reverse); + fmt::println("{}: {} - {} (limit={}, reverse={})", + op.type == Operation::GET_RANGE ? "GET_RANGE" : "GET_RANGE_SELECTOR", + printable(op.beginKey), + printable(op.endKey), + op.limit, + op.reverse); #endif break; case Operation::GET_KEY: @@ -195,21 +196,21 @@ struct RyowCorrectnessWorkload : ApiWorkload { pushKVPair(results, key, Value()); #if TRACE_TRANSACTION if (key == debugKey) - printf("GET_KEY: %s = %s\n", op.beginSelector.toString().c_str(), printable(key).c_str()); + fmt::println("GET_KEY: {} = {}", op.beginSelector.toString(), printable(key)); #endif break; case Operation::CLEAR: store.clear(op.beginKey); #if TRACE_TRANSACTION if (op.beginKey == debugKey) - printf("CLEAR: %s\n", printable(op.beginKey).c_str()); + fmt::println("CLEAR: {}", printable(op.beginKey)); #endif break; case Operation::CLEAR_RANGE: store.clear(KeyRangeRef(op.beginKey, op.endKey)); #if TRACE_TRANSACTION if (op.beginKey <= debugKey && debugKey < op.endKey) - printf("CLEAR_RANGE: %s - %s\n", printable(op.beginKey).c_str(), printable(op.endKey).c_str()); + fmt::println("CLEAR_RANGE: {} - {}", printable(op.beginKey), printable(op.endKey)); #endif break; } @@ -290,24 +291,24 @@ struct RyowCorrectnessWorkload : ApiWorkload { if (!ApiWorkload::compareResults(dbResults[currentResult], storeResults[currentResult], readVersion)) { switch (op.type) { case Operation::GET: - printf("Operation GET failed: key = %s\n", printable(op.beginKey).c_str()); + fmt::println("Operation GET failed: key = {}", printable(op.beginKey)); break; case Operation::GET_RANGE: - printf("Operation GET_RANGE failed: begin = %s, end = %s, limit = %d, reverse = %d\n", - printable(op.beginKey).c_str(), - printable(op.endKey).c_str(), - op.limit, - static_cast(op.reverse)); + fmt::println("Operation GET_RANGE failed: begin = {}, end = {}, limit = {}, reverse = {}", + printable(op.beginKey), + printable(op.endKey), + op.limit, + static_cast(op.reverse)); break; case Operation::GET_RANGE_SELECTOR: - printf("Operation GET_RANGE_SELECTOR failed: begin = %s, end = %s, limit = %d, reverse = %d\n", - op.beginSelector.toString().c_str(), - op.endSelector.toString().c_str(), - op.limit, - static_cast(op.reverse)); + fmt::println("Operation GET_RANGE_SELECTOR failed: begin = {}, end = {}, limit = {}, reverse = {}", + op.beginSelector.toString(), + op.endSelector.toString(), + op.limit, + static_cast(op.reverse)); break; case Operation::GET_KEY: - printf("Operation GET_KEY failed: selector = %s\n", op.beginSelector.toString().c_str()); + fmt::println("Operation GET_KEY failed: selector = {}", op.beginSelector.toString()); break; default: break; diff --git a/fdbserver/workloads/S3ClientWorkload.cpp b/fdbserver/workloads/S3ClientWorkload.cpp index ff4b6ee0205..292d134b42a 100644 --- a/fdbserver/workloads/S3ClientWorkload.cpp +++ b/fdbserver/workloads/S3ClientWorkload.cpp @@ -36,6 +36,7 @@ #include #include #include +#include "fmt/format.h" // Test s3client operations against s3. // Run this workload with ../build_output/bin/fdbserver -r simulation -f @@ -191,7 +192,8 @@ struct S3ClientWorkload : TestWorkload { // This keeps test artifacts in the simulation directory like other workloads // Use deterministic directory name instead of random UID to ensure deterministic behavior std::string uniqueRunDir = joinPath( - simfdbDir, format("s3_workload_run_%08x_%08x", clientId, deterministicRandom()->randomInt(0, 1000000))); + simfdbDir, + fmt::format("s3_workload_run_{:08x}_{:08x}", clientId, deterministicRandom()->randomInt(0, 1000000))); try { platform::createDirectory(uniqueRunDir); TraceEvent(SevDebug, "S3ClientWorkloadCreatedRunDir").detail("Dir", uniqueRunDir); @@ -213,7 +215,8 @@ struct S3ClientWorkload : TestWorkload { ::basename(const_cast(credentials.c_str())); // Gets filename from the *new* path // Use deterministic ID based on client ID and test context instead of random UID // This ensures identical behavior across determinism check runs - std::string deterministicId = format("%08x_%08x", clientId, deterministicRandom()->randomInt(0, 1000000)); + std::string deterministicId = + fmt::format("{:08x}_{:08x}", clientId, deterministicRandom()->randomInt(0, 1000000)); std::string uniqueObjectKey = baseFilename + "_" + deterministicId; std::string file_url = addFileToUrl(uniqueObjectKey, s3Url); bool uploaded = false; // Track if upload started/succeeded diff --git a/fdbserver/workloads/SaveAndKill.cpp b/fdbserver/workloads/SaveAndKill.cpp index 706d38777d8..7160445685d 100644 --- a/fdbserver/workloads/SaveAndKill.cpp +++ b/fdbserver/workloads/SaveAndKill.cpp @@ -33,6 +33,7 @@ #undef state #include "fdbclient/SimpleIni.h" +#include "fmt/format.h" #define state #undef max #undef min @@ -64,13 +65,13 @@ struct SaveAndKillWorkload : TestWorkload { ini.SetUnicode(); ini.LoadFile(restartInfo.c_str()); - ini.SetValue("RESTORE", "isRestoring", format("%d", isRestoring).c_str()); - ini.SetValue("META", "processesPerMachine", format("%d", g_simulator->processesPerMachine).c_str()); - ini.SetValue("META", "listenersPerProcess", format("%d", g_simulator->listenersPerProcess).c_str()); - ini.SetValue("META", "desiredCoordinators", format("%d", g_simulator->desiredCoordinators).c_str()); + ini.SetValue("RESTORE", "isRestoring", fmt::format("{}", isRestoring).c_str()); + ini.SetValue("META", "processesPerMachine", fmt::format("{}", g_simulator->processesPerMachine).c_str()); + ini.SetValue("META", "listenersPerProcess", fmt::format("{}", g_simulator->listenersPerProcess).c_str()); + ini.SetValue("META", "desiredCoordinators", fmt::format("{}", g_simulator->desiredCoordinators).c_str()); ini.SetValue("META", "connectionString", g_simulator->connectionString.c_str()); - ini.SetValue("META", "testerCount", format("%d", g_simulator->testerCount).c_str()); - ini.SetValue("META", "tssMode", format("%d", g_simulator->tssMode).c_str()); + ini.SetValue("META", "testerCount", fmt::format("{}", g_simulator->testerCount).c_str()); + ini.SetValue("META", "tssMode", fmt::format("{}", static_cast(g_simulator->tssMode)).c_str()); ini.SetValue("META", "mockDNS", INetworkConnections::net()->convertMockDNSToString().c_str()); ini.SetBoolValue("META", "enableShardEncodeLocationMetadata", SERVER_KNOBS->SHARD_ENCODE_LOCATION_METADATA); ini.SetBoolValue("META", "encryptHeaderAuthTokenEnabled", FLOW_KNOBS->ENCRYPT_HEADER_AUTH_TOKEN_ENABLED); @@ -90,7 +91,7 @@ struct SaveAndKillWorkload : TestWorkload { allProcessesMap[process->dataFolder] = process; } } - ini.SetValue("META", "processCount", format("%d", allProcessesMap.size() - 1).c_str()); + ini.SetValue("META", "processCount", fmt::format("{}", allProcessesMap.size() - 1).c_str()); std::map machines; int j = 0; @@ -100,7 +101,7 @@ struct SaveAndKillWorkload : TestWorkload { if (!process->excludeFromRestarts) { if (machines.find(machineId) == machines.end()) { machines.insert(std::pair(machineId, 1)); - ini.SetValue("META", format("%d", j).c_str(), machineIdString); + ini.SetValue("META", fmt::format("{}", j).c_str(), machineIdString); ini.SetValue( machineIdString, "dcUID", @@ -110,25 +111,29 @@ struct SaveAndKillWorkload : TestWorkload { (process->locality.zoneId().present()) ? process->locality.zoneId().get().printable().c_str() : ""); - ini.SetValue(machineIdString, "mClass", format("%d", process->startingClass.classType()).c_str()); ini.SetValue(machineIdString, - format("ipAddr%d", process->address.port - 1).c_str(), + "mClass", + fmt::format("{}", static_cast(process->startingClass.classType())).c_str()); + ini.SetValue(machineIdString, + fmt::format("ipAddr{}", process->address.port - 1).c_str(), process->address.ip.toString().c_str()); - ini.SetValue( - machineIdString, format("%d", process->address.port - 1).c_str(), process->dataFolder.c_str()); ini.SetValue(machineIdString, - format("c%d", process->address.port - 1).c_str(), + fmt::format("{}", process->address.port - 1).c_str(), + process->dataFolder.c_str()); + ini.SetValue(machineIdString, + fmt::format("c{}", process->address.port - 1).c_str(), process->coordinationFolder.c_str()); j++; } else { ini.SetValue(machineIdString, - format("ipAddr%d", process->address.port - 1).c_str(), + fmt::format("ipAddr{}", process->address.port - 1).c_str(), process->address.ip.toString().c_str()); int oldValue = machines.find(machineId)->second; - ini.SetValue( - machineIdString, format("%d", process->address.port - 1).c_str(), process->dataFolder.c_str()); ini.SetValue(machineIdString, - format("c%d", process->address.port - 1).c_str(), + fmt::format("{}", process->address.port - 1).c_str(), + process->dataFolder.c_str()); + ini.SetValue(machineIdString, + fmt::format("c{}", process->address.port - 1).c_str(), process->coordinationFolder.c_str()); machines.erase(machines.find(machineId)); machines.insert(std::pair(machineId, oldValue + 1)); @@ -136,10 +141,10 @@ struct SaveAndKillWorkload : TestWorkload { } } for (auto entry = machines.begin(); entry != machines.end(); entry++) { - ini.SetValue((*entry).first.c_str(), "processes", format("%d", (*entry).second).c_str()); + ini.SetValue((*entry).first.c_str(), "processes", fmt::format("{}", (*entry).second).c_str()); } - ini.SetValue("META", "machineCount", format("%d", machines.size()).c_str()); + ini.SetValue("META", "machineCount", fmt::format("{}", machines.size()).c_str()); ini.SaveFile(restartInfo.c_str()); for (auto process = allProcessesMap.begin(); process != allProcessesMap.end(); process++) { diff --git a/fdbserver/workloads/SelectorCorrectness.cpp b/fdbserver/workloads/SelectorCorrectness.cpp index c4451718515..544daad8f41 100644 --- a/fdbserver/workloads/SelectorCorrectness.cpp +++ b/fdbserver/workloads/SelectorCorrectness.cpp @@ -22,6 +22,7 @@ #include "fdbserver/TesterInterface.actor.h" #include "fdbclient/ReadYourWrites.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct SelectorCorrectnessWorkload : TestWorkload { static constexpr auto NAME = "SelectorCorrectness"; @@ -62,7 +63,7 @@ struct SelectorCorrectnessWorkload : TestWorkload { } Future SelectorCorrectnessSetup(Database cx, SelectorCorrectnessWorkload* self) { - Value myValue = StringRef(format("%010d", deterministicRandom()->randomInt(0, 10000000))); + Value myValue = StringRef(fmt::format("{:010}", deterministicRandom()->randomInt(0, 10000000))); Transaction tr(cx); if (!self->testReadYourWrites) { @@ -70,7 +71,7 @@ struct SelectorCorrectnessWorkload : TestWorkload { Error err; try { for (int i = 0; i < self->maxKeySpace; i += 2) - tr.set(StringRef(format("%010d", i)), myValue); + tr.set(StringRef(fmt::format("{:010}", i)), myValue); co_await tr.commit(); break; @@ -84,10 +85,10 @@ struct SelectorCorrectnessWorkload : TestWorkload { Error err; try { for (int i = 0; i < self->maxKeySpace; i += 4) - tr.set(StringRef(format("%010d", i)), myValue); + tr.set(StringRef(fmt::format("{:010}", i)), myValue); for (int i = 2; i < self->maxKeySpace; i += 4) if (deterministicRandom()->random01() > 0.5) - tr.set(StringRef(format("%010d", i)), myValue); + tr.set(StringRef(fmt::format("{:010}", i)), myValue); co_await tr.commit(); break; @@ -112,7 +113,7 @@ struct SelectorCorrectnessWorkload : TestWorkload { Standalone maxKey; Reverse reverse = Reverse::False; - maxKey = Standalone(format("%010d", self->maxKeySpace + 1)); + maxKey = Standalone(fmt::format("{:010}", self->maxKeySpace + 1)); while (true) { @@ -120,12 +121,12 @@ struct SelectorCorrectnessWorkload : TestWorkload { ReadYourWritesTransaction trRYOW(cx); if (self->testReadYourWrites) { - myValue = StringRef(format("%010d", deterministicRandom()->randomInt(0, 10000000))); + myValue = StringRef(fmt::format("{:010}", deterministicRandom()->randomInt(0, 10000000))); for (int i = 2; i < self->maxKeySpace; i += 4) - trRYOW.set(StringRef(format("%010d", i)), myValue); + trRYOW.set(StringRef(fmt::format("{:010}", i)), myValue); for (int i = 0; i < self->maxKeySpace; i += 4) if (deterministicRandom()->random01() > 0.5) - trRYOW.set(StringRef(format("%010d", i)), myValue); + trRYOW.set(StringRef(fmt::format("{:010}", i)), myValue); } Error err; @@ -136,7 +137,7 @@ struct SelectorCorrectnessWorkload : TestWorkload { j = deterministicRandom()->randomInt(0, 2); if (j < 1) { int searchInt = deterministicRandom()->randomInt(0, self->maxKeySpace); - myKeyA = format("%010d", searchInt); + myKeyA = fmt::format("{:010}", searchInt); if (self->testReadYourWrites) { Optional getTest = co_await trRYOW.get(StringRef(myKeyA)); @@ -160,8 +161,8 @@ struct SelectorCorrectnessWorkload : TestWorkload { int b = deterministicRandom()->randomInt(2, 2 * self->maxKeySpace); int abmax = std::max(a, b); int abmin = std::min(a, b) - 1; - myKeyA = format("%010d", abmin); - myKeyB = format("%010d", abmax); + myKeyA = fmt::format("{:010}", abmin); + myKeyB = fmt::format("{:010}", abmax); onEqualA = deterministicRandom()->randomInt(0, 2) != 0; onEqualB = deterministicRandom()->randomInt(0, 2) != 0; offsetA = 1; //-1*deterministicRandom()->randomInt( 0, self->maxOffset ); diff --git a/fdbserver/workloads/Serializability.cpp b/fdbserver/workloads/Serializability.cpp index 2ee88af8e46..1fecbf7f6cb 100644 --- a/fdbserver/workloads/Serializability.cpp +++ b/fdbserver/workloads/Serializability.cpp @@ -23,6 +23,7 @@ #include "fdbclient/ReadYourWrites.h" #include "flow/ActorCollection.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct SerializabilityWorkload : TestWorkload { static constexpr auto NAME = "Serializability"; @@ -107,7 +108,7 @@ struct SerializabilityWorkload : TestWorkload { if (adjacentKeys) { return Key(idx ? keyPrefix + std::string(idx, '\x00') : ""); } else { - return Key(keyPrefix + format("%010d", idx)); + return Key(keyPrefix + fmt::format("{:010}", idx)); } } diff --git a/fdbserver/workloads/Sideband.cpp b/fdbserver/workloads/Sideband.cpp index 9170277dc22..8d55b84f22d 100644 --- a/fdbserver/workloads/Sideband.cpp +++ b/fdbserver/workloads/Sideband.cpp @@ -21,6 +21,7 @@ #include "fdbclient/NativeAPI.actor.h" #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct SidebandMessage { constexpr static FileIdentifier file_identifier = 11862046; @@ -96,13 +97,13 @@ struct SidebandWorkload : TestWorkload { while (true) { Error err; try { - Optional val = co_await tr.get(StringRef(format("Sideband/Client/%d", self->clientId))); + Optional val = co_await tr.get(StringRef(fmt::format("Sideband/Client/{}", self->clientId))); if (val.present()) { if (val.get() != serializedInterface) throw operation_failed(); break; } - tr.set(format("Sideband/Client/%d", self->clientId), serializedInterface); + tr.set(fmt::format("Sideband/Client/{}", self->clientId), serializedInterface); co_await tr.commit(); break; } catch (Error& e) { @@ -118,8 +119,8 @@ struct SidebandWorkload : TestWorkload { while (true) { Error err; try { - Optional val = - co_await tr.get(StringRef(format("Sideband/Client/%d", (self->clientId + 1) % self->clientCount))); + Optional val = co_await tr.get( + StringRef(fmt::format("Sideband/Client/{}", (self->clientId + 1) % self->clientCount))); if (!val.present()) { throw operation_failed(); } @@ -145,7 +146,7 @@ struct SidebandWorkload : TestWorkload { Transaction tr(cx); uint64_t key = deterministicRandom()->randomUniqueID().hash(); - Standalone messageKey(format("Sideband/Message/%llx", key)); + Standalone messageKey(fmt::format("Sideband/Message/{:x}", key)); while (true) { Error err; try { @@ -172,7 +173,7 @@ struct SidebandWorkload : TestWorkload { Future checker(SidebandWorkload* self, Database cx) { while (true) { SidebandMessage message = co_await self->interf.updates.getFuture(); - Standalone messageKey(format("Sideband/Message/%llx", message.key)); + Standalone messageKey(fmt::format("Sideband/Message/{:x}", message.key)); Transaction tr(cx); while (true) { Error err; diff --git a/fdbserver/workloads/SidebandSingle.cpp b/fdbserver/workloads/SidebandSingle.cpp index 596153c0adb..2edb492ea8f 100644 --- a/fdbserver/workloads/SidebandSingle.cpp +++ b/fdbserver/workloads/SidebandSingle.cpp @@ -22,6 +22,7 @@ #include "fdbclient/NativeAPI.actor.h" #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" /* * This workload is modelled off the Sideband workload, except it uses a single @@ -90,7 +91,7 @@ struct SidebandSingleWorkload : TestWorkload { Transaction tr(cx); uint64_t key = deterministicRandom()->randomUniqueID().hash(); - Standalone messageKey(format("Sideband/Message/%llx", key)); + Standalone messageKey(fmt::format("Sideband/Message/{:x}", key)); // first set, this is the "old" value, always retry while (true) { Error err; @@ -140,7 +141,7 @@ struct SidebandSingleWorkload : TestWorkload { while (true) { // Pair represents std::pair message = co_await self->interf.getFuture(); - Standalone messageKey(format("Sideband/Message/%llx", message.first)); + Standalone messageKey(fmt::format("Sideband/Message/{:x}", message.first)); Transaction tr(cx); while (true) { Error err; diff --git a/fdbserver/workloads/SlowTaskWorkload.cpp b/fdbserver/workloads/SlowTaskWorkload.cpp index 04c22622734..fd2f1e97fda 100644 --- a/fdbserver/workloads/SlowTaskWorkload.cpp +++ b/fdbserver/workloads/SlowTaskWorkload.cpp @@ -46,22 +46,22 @@ struct SlowTaskWorkload : TestWorkload { int64_t startProfilesOverflowed = getNumProfilesOverflowed(); int64_t startProfilesCaptured = getNumProfilesCaptured(); int64_t exc = 0; - fprintf(stderr, "Slow task starting\n"); + fmt::println(stderr, "Slow task starting"); for (int i = 0; i < 10; i++) { - fprintf(stderr, " %d\n", i); + fmt::println(stderr, " {}", i); double end = timer() + 1; while (timer() < end) { do_slow_exception_thing(&exc); } } - fmt::print(stderr, - "Slow task complete: {0} exceptions; {1} calls to dl_iterate_phdr, {2}" - " profiles disabled, {3} profiles overflowed, {4} profiles captured\n", - exc, - dl_iterate_phdr_calls - phc, - getNumProfilesDisabled() - startProfilesDisabled, - getNumProfilesOverflowed() - startProfilesOverflowed, - getNumProfilesCaptured() - startProfilesCaptured); + fmt::println(stderr, + "Slow task complete: {0} exceptions; {1} calls to dl_iterate_phdr, {2} profiles disabled, {3} " + "profiles overflowed, {4} profiles captured", + exc, + dl_iterate_phdr_calls - phc, + getNumProfilesDisabled() - startProfilesDisabled, + getNumProfilesOverflowed() - startProfilesOverflowed, + getNumProfilesCaptured() - startProfilesCaptured); } static void do_slow_exception_thing(int64_t* exc_count) { diff --git a/fdbserver/workloads/SnapTest.cpp b/fdbserver/workloads/SnapTest.cpp index 890d80c49c4..d164539a0b0 100644 --- a/fdbserver/workloads/SnapTest.cpp +++ b/fdbserver/workloads/SnapTest.cpp @@ -30,6 +30,7 @@ #include "fdbserver/WorkerInterface.actor.h" #include "fdbserver/workloads/BulkSetup.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct SnapTestWorkload : TestWorkload { static constexpr auto NAME = "SnapTest"; @@ -205,7 +206,7 @@ struct SnapTestWorkload : TestWorkload { ini.LoadFile(restartInfoLocation.c_str()); std::string uidStr = snapUID.toString(); ini.SetValue("RESTORE", "RestoreSnapUID", uidStr.c_str()); - ini.SetValue("RESTORE", "BackupFailed", format("%d", snapFailed).c_str()); + ini.SetValue("RESTORE", "BackupFailed", fmt::format("{}", snapFailed).c_str()); ini.SaveFile(restartInfoLocation.c_str()); // write the snapUID to a file auto const severity = snapFailed ? SevError : SevInfo; diff --git a/fdbserver/workloads/StatusWorkload.cpp b/fdbserver/workloads/StatusWorkload.cpp index 6b24069a8a8..991fc0819bb 100644 --- a/fdbserver/workloads/StatusWorkload.cpp +++ b/fdbserver/workloads/StatusWorkload.cpp @@ -25,6 +25,7 @@ #include "flow/UnitTest.h" #include "fdbclient/Schemas.h" #include "fdbclient/ManagementAPI.actor.h" +#include "fmt/format.h" struct StatusWorkload : TestWorkload { static constexpr auto NAME = "Status"; @@ -120,7 +121,7 @@ struct StatusWorkload : TestWorkload { result += ","; } - result += format("%f", bands[i]); + result += fmt::format("{:f}", bands[i]); } return result + "]"; @@ -142,13 +143,13 @@ struct StatusWorkload : TestWorkload { "}," "\"read\":{" + generateBands() + - format(", \"max_key_selector_offset\":%d, \"max_read_bytes\":%d},", - deterministicRandom()->randomInt(0, 10000), - deterministicRandom()->randomInt(0, 1000000)) + + fmt::format(", \"max_key_selector_offset\":{}, \"max_read_bytes\":{}}},", + deterministicRandom()->randomInt(0, 10000), + deterministicRandom()->randomInt(0, 1000000)) + "" "\"commit\":{" + generateBands() + - format(", \"max_commit_bytes\":%d", deterministicRandom()->randomInt(0, 1000000)) + + fmt::format(", \"max_commit_bytes\":{}", deterministicRandom()->randomInt(0, 1000000)) + "}" "}"; diff --git a/fdbserver/workloads/Storefront.cpp b/fdbserver/workloads/Storefront.cpp index c6ad40e085d..fe9581a37ad 100644 --- a/fdbserver/workloads/Storefront.cpp +++ b/fdbserver/workloads/Storefront.cpp @@ -22,6 +22,7 @@ #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/workloads/BulkSetup.h" +#include "fmt/format.h" // Storefront workload will maintain 2 tables: one for orders and one for items // Items table will have an entry for each item and the current total of "unfilled" orders @@ -93,9 +94,9 @@ struct StorefrontWorkload : TestWorkload { } Key keyForIndex(int n) { return itemKey(n); } - Key itemKey(int item) { return StringRef(format("/items/%016d", item)); } - Key orderKey(orderID order) { return StringRef(format("/orders/%016llx", order)); } - Value itemValue(int count) { return StringRef(format("%d", count)); } + Key itemKey(int item) { return StringRef(fmt::format("/items/{:016}", item)); } + Key orderKey(orderID order) { return StringRef(fmt::format("/orders/{:016x}", order)); } + Value itemValue(int count) { return StringRef(fmt::format("{}", count)); } Standalone operator()(int n) { return KeyValueRef(itemKey(n), itemValue(0)); } diff --git a/fdbserver/workloads/TaskBucketCorrectness.cpp b/fdbserver/workloads/TaskBucketCorrectness.cpp index 0c49b9ef204..eab658019bb 100644 --- a/fdbserver/workloads/TaskBucketCorrectness.cpp +++ b/fdbserver/workloads/TaskBucketCorrectness.cpp @@ -24,6 +24,7 @@ #include "fdbclient/TaskBucket.h" #include "fdbclient/ReadYourWrites.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct SayHelloTaskFunc : TaskFuncBase { static StringRef name; @@ -88,7 +89,7 @@ struct SayHelloTaskFunc : TaskFuncBase { SayHelloTaskFunc::version, StringRef(), deterministicRandom()->randomInt(0, 2)); - new_task->params["name"_sr] = StringRef(format("task_%d", currTaskNumber + 1)); + new_task->params["name"_sr] = StringRef(fmt::format("task_{}", currTaskNumber + 1)); new_task->params["chained"_sr] = task->params["chained"_sr]; new_task->params["subtaskCount"_sr] = task->params["subtaskCount"_sr]; Reference taskDone = futureBucket->future(tr); @@ -139,7 +140,7 @@ struct SayHelloToEveryoneTaskFunc : TaskFuncBase { for (int i = 0; i < subtaskCount; ++i) { auto new_task = makeReference( SayHelloTaskFunc::name, SayHelloTaskFunc::version, StringRef(), deterministicRandom()->randomInt(0, 2)); - new_task->params["name"_sr] = StringRef(format("task_%d", i)); + new_task->params["name"_sr] = StringRef(fmt::format("task_{}", i)); new_task->params["chained"_sr] = task->params["chained"_sr]; new_task->params["subtaskCount"_sr] = task->params["subtaskCount"_sr]; Reference taskDone = futureBucket->future(tr); @@ -225,7 +226,7 @@ struct TaskBucketCorrectnessWorkload : TestWorkload { deterministicRandom()->randomInt(0, 2)); task->params["chained"_sr] = chained ? "true"_sr : "false"_sr; - task->params["subtaskCount"_sr] = StringRef(format("%d", subtaskCount)); + task->params["subtaskCount"_sr] = StringRef(fmt::format("{}", subtaskCount)); taskBucket->addTask(tr, task); auto taskDone = makeReference( SaidHelloTaskFunc::name, SaidHelloTaskFunc::version, StringRef(), deterministicRandom()->randomInt(0, 2)); @@ -266,7 +267,7 @@ struct TaskBucketCorrectnessWorkload : TestWorkload { break; else { co_await TaskBucket::debugPrintRange( - cx, taskSubspace.key(), StringRef(format("client_%d", clientId))); + cx, taskSubspace.key(), StringRef(fmt::format("client_{}", clientId))); TraceEvent("TaskBucketCorrectness").detail("FutureIsNotEmpty", "..."); } } else { @@ -307,7 +308,7 @@ struct TaskBucketCorrectnessWorkload : TestWorkload { Future checkSayHello(Reference tr, int subTaskCount) { std::set data = { "Hello, Everyone!", "Said hello to everyone!" }; for (int i = 0; i < subTaskCount; i++) { - data.insert(format("task_%d", i)); + data.insert(fmt::format("task_{}", i)); } RangeResult values = @@ -338,7 +339,7 @@ struct TaskBucketCorrectnessWorkload : TestWorkload { WorkloadFactory TaskBucketCorrectnessWorkloadFactory; void print_subspace_key(const Subspace& subspace, int id) { - printf("%d==========%s===%d\n", id, printable(StringRef(subspace.key())).c_str(), subspace.key().size()); + fmt::println("{}=========={}==={}", id, printable(StringRef(subspace.key())), subspace.key().size()); } TEST_CASE("/fdbclient/TaskBucket/Subspace") { @@ -370,10 +371,10 @@ TEST_CASE("/fdbclient/TaskBucket/Subspace") { ASSERT(subspace_test5.key() == "abc\x01user\x00\x15\x7b"_sr); // Subspace pack - printf("%d==========%s===%d\n", 6, printable(subspace_test5.pack(t)).c_str(), subspace_test5.pack(t).size()); + fmt::println("{}=========={}==={}", 6, printable(subspace_test5.pack(t)), subspace_test5.pack(t).size()); ASSERT(subspace_test5.pack(t) == "abc\x01user\x00\x15\x7b\x01user\x00\x15\x7b"_sr); - printf("%d==========%s===%d\n", 7, printable(subspace_test5.pack(t1)).c_str(), subspace_test5.pack(t1).size()); + fmt::println("{}=========={}==={}", 7, printable(subspace_test5.pack(t1)), subspace_test5.pack(t1).size()); ASSERT(subspace_test5.pack(t1) == "abc\x01user\x00\x15\x7b\x15\x01"_sr); // Subspace getItem @@ -390,39 +391,31 @@ TEST_CASE("/fdbclient/TaskBucket/Subspace") { // pack Tuple t3 = Tuple::makeTuple(""_sr); - printf("%d==========%s===%d\n", 10, printable(subspace_test5.pack(t3)).c_str(), subspace_test5.pack(t3).size()); + fmt::println("{}=========={}==={}", 10, printable(subspace_test5.pack(t3)), subspace_test5.pack(t3).size()); ASSERT(subspace_test5.pack(t3) == subspace_test5.pack(StringRef())); ASSERT(subspace_test5.pack(t3) == "abc\x01user\x00\x15\x7b\x01\x00"_sr); - printf("%d==========%s===%d\n", - 11, - printable(subspace_test5.range(t3).begin).c_str(), - subspace_test5.range(t3).begin.size()); + fmt::println( + "{}=========={}==={}", 11, printable(subspace_test5.range(t3).begin), subspace_test5.range(t3).begin.size()); ASSERT(subspace_test5.range(t3).begin == subspace_test5.get(StringRef()).range().begin); - printf("%d==========%s===%d\n", - 12, - printable(subspace_test5.range(t3).end).c_str(), - subspace_test5.range(t3).end.size()); + fmt::println( + "{}=========={}==={}", 12, printable(subspace_test5.range(t3).end), subspace_test5.range(t3).end.size()); ASSERT(subspace_test5.range(t3).end == subspace_test5.get(StringRef()).range().end); StringRef def = "def"_sr; StringRef ghi = "ghi"_sr; t3.append(def); t3.append(ghi); - printf("%d==========%s===%d\n", 13, printable(subspace_test5.pack(t3)).c_str(), subspace_test5.pack(t3).size()); + fmt::println("{}=========={}==={}", 13, printable(subspace_test5.pack(t3)), subspace_test5.pack(t3).size()); ASSERT(subspace_test5.pack(t3) == subspace_test5.get(StringRef()).get(def).pack(ghi)); ASSERT(subspace_test5.pack(t3) == "abc\x01user\x00\x15\x7b\x01\x00\x01" "def\x00\x01ghi\x00"_sr); - printf("%d==========%s===%d\n", - 14, - printable(subspace_test5.range(t3).begin).c_str(), - subspace_test5.range(t3).begin.size()); + fmt::println( + "{}=========={}==={}", 14, printable(subspace_test5.range(t3).begin), subspace_test5.range(t3).begin.size()); ASSERT(subspace_test5.range(t3).begin == subspace_test5.get(StringRef()).get(def).get(ghi).range().begin); - printf("%d==========%s===%d\n", - 15, - printable(subspace_test5.range(t3).end).c_str(), - subspace_test5.range(t3).end.size()); + fmt::println( + "{}=========={}==={}", 15, printable(subspace_test5.range(t3).end), subspace_test5.range(t3).end.size()); ASSERT(subspace_test5.range(t3).end == subspace_test5.get(StringRef()).get(def).get(ghi).range().end); return Void(); diff --git a/fdbserver/workloads/ThreadSafety.cpp b/fdbserver/workloads/ThreadSafety.cpp index 2bb1bb0e0fd..e0d2026b4ad 100644 --- a/fdbserver/workloads/ThreadSafety.cpp +++ b/fdbserver/workloads/ThreadSafety.cpp @@ -25,6 +25,7 @@ #include "fdbclient/ThreadSafeTransaction.h" #include "fdbclient/MultiVersionTransaction.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct ThreadSafetyWorkload; @@ -166,7 +167,7 @@ struct ThreadSafetyWorkload : TestWorkload { co_await threadInfo[i]->done.getFuture(); } catch (Error& e) { success = false; - printf("Thread %d.%d failed: %s\n", clientId, i, e.name()); + fmt::println("Thread {}.{} failed: {}", clientId, i, e.name()); TraceEvent(SevError, "ThreadSafety_ThreadFailed").error(e); } @@ -198,7 +199,7 @@ struct ThreadSafetyWorkload : TestWorkload { } Key getRandomKey(DeterministicRandom& random) { - return StringRef(format("ThreadSafetyKey%010d", random.randomInt(0, numKeys))); + return StringRef(fmt::format("ThreadSafetyKey{:010}", random.randomInt(0, numKeys))); } void runTest(ThreadInfo* info) { diff --git a/fdbserver/workloads/Throttling.cpp b/fdbserver/workloads/Throttling.cpp index 50cc86e2eeb..d328a6f7258 100644 --- a/fdbserver/workloads/Throttling.cpp +++ b/fdbserver/workloads/Throttling.cpp @@ -24,6 +24,7 @@ #include "fdbclient/ReadYourWrites.h" #include "fdbclient/Schemas.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct TokenBucket { static constexpr const double addTokensInterval = 0.1; @@ -92,7 +93,7 @@ struct ThrottlingWorkload : KVWorkload { } static Value getRandomValue() { - return Standalone(format("Value/%d", deterministicRandom()->randomInt(0, 10e6))); + return Standalone(fmt::format("Value/{}", deterministicRandom()->randomInt(0, 10e6))); } Future clientActor(Database cx) { diff --git a/fdbserver/workloads/Throughput.cpp b/fdbserver/workloads/Throughput.cpp index 282fba75ae0..71b73b2adea 100644 --- a/fdbserver/workloads/Throughput.cpp +++ b/fdbserver/workloads/Throughput.cpp @@ -25,6 +25,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include "flow/ActorCollection.h" #include "fdbrpc/Smoother.h" +#include "fmt/format.h" struct ITransactor : ReferenceCounted { struct Stats { @@ -267,7 +268,7 @@ struct MeasurePeriodically : IMeasurer { } void nextPeriod(double t) { // output stats - std::string prefix = format("T=%04.0fs:", t); + std::string prefix = fmt::format("T={:04.0f}s:", t); std::vector m; msp.getMetrics(m); for (auto i = m.begin(); i != m.end(); ++i) diff --git a/fdbserver/workloads/TriggerRecovery.cpp b/fdbserver/workloads/TriggerRecovery.cpp index d495abb0760..268d471c796 100644 --- a/fdbserver/workloads/TriggerRecovery.cpp +++ b/fdbserver/workloads/TriggerRecovery.cpp @@ -24,6 +24,7 @@ #include "fdbclient/StatusClient.h" #include "fdbclient/ManagementAPI.actor.h" #include "fdbclient/RunRYWTransaction.actor.h" +#include "fmt/format.h" struct TriggerRecoveryLoopWorkload : TestWorkload { static constexpr auto NAME = "TriggerRecoveryLoop"; @@ -87,7 +88,7 @@ struct TriggerRecoveryLoopWorkload : TestWorkload { ? self->originalNumOfResolvers.get() + 1 : self->originalNumOfResolvers.get(); } - StringRef configStr(format("resolvers=%d", numResolversToSet)); + StringRef configStr(fmt::format("resolvers={}", numResolversToSet)); while (true) { Optional conf; ConfigurationResult r = co_await ManagementAPI::changeConfig(cx.getReference(), { configStr }, conf, true); diff --git a/fdbserver/workloads/TxnTimeout.cpp b/fdbserver/workloads/TxnTimeout.cpp index dc075929b6a..fa3cebadf9d 100644 --- a/fdbserver/workloads/TxnTimeout.cpp +++ b/fdbserver/workloads/TxnTimeout.cpp @@ -27,6 +27,7 @@ #include "flow/Trace.h" #include "flow/flow.h" #include "flow/genericactors.actor.h" +#include "fmt/format.h" struct TxnTimeout : TestWorkload { static constexpr auto NAME = "TxnTimeout"; @@ -100,7 +101,7 @@ struct TxnTimeout : TestWorkload { // Format: "txntimeout_c{clientId}_a{actorIdx}_n{nodeIdx}" // This ensures the same key is used during populate and transaction phases static Key makeKey(int clientId, int actorIdx, int nodeIdx) { - return Key(format("txntimeout_c%d_a%d_n%d", clientId, actorIdx, nodeIdx)); + return Key(fmt::format("txntimeout_c{}_a{}_n{}", clientId, actorIdx, nodeIdx)); } // Initializes the database with test data for each actor to operate on diff --git a/fdbserver/workloads/UnitPerf.cpp b/fdbserver/workloads/UnitPerf.cpp index 44f296bbd07..91d1ae8ea6f 100644 --- a/fdbserver/workloads/UnitPerf.cpp +++ b/fdbserver/workloads/UnitPerf.cpp @@ -21,6 +21,7 @@ #include "fdbrpc/ActorFuzz.h" #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" Future sleepyActor(double interval, int* counter) { while (true) { @@ -30,7 +31,7 @@ Future sleepyActor(double interval, int* counter) { } Future unitPerfTest() { - printf("\n"); + fmt::println(""); int counter = 0; std::vector> sleepy; @@ -41,9 +42,9 @@ Future unitPerfTest() { co_await delay(10); sleepy.clear(); TraceEvent("Completed").detail("Count", counter); - printf("Completed: %d\n", counter); + fmt::println("Completed: {}", counter); - printf("\n"); + fmt::println(""); } struct UnitPerfWorkload : TestWorkload { diff --git a/fdbserver/workloads/UnitTests.cpp b/fdbserver/workloads/UnitTests.cpp index ba72a64f73f..3d046f16646 100644 --- a/fdbserver/workloads/UnitTests.cpp +++ b/fdbserver/workloads/UnitTests.cpp @@ -20,6 +20,7 @@ #include "fdbserver/workloads/workloads.actor.h" #include "flow/UnitTest.h" +#include "fmt/format.h" void forceLinkIndexedSetTests(); void forceLinkDequeTests(); @@ -168,7 +169,7 @@ struct UnitTestWorkload : TestWorkload { return std::string_view(lhs->name) < std::string_view(rhs->name); }); - fprintf(stdout, "Found %zu tests\n", tests.size()); + fmt::println(stdout, "Found {} tests", tests.size()); if (tests.size() == 0) { TraceEvent(SevError, "NoMatchingUnitTests") @@ -185,7 +186,7 @@ struct UnitTestWorkload : TestWorkload { std::vector::iterator t; for (t = tests.begin(); t != tests.end(); ++t) { UnitTest* test = *t; - printf("Testing %s\n", test->name); + fmt::println("Testing {}", test->name); TraceEvent(SevInfo, "RunningUnitTest") .detail("Name", test->name) diff --git a/fdbserver/workloads/Watches.cpp b/fdbserver/workloads/Watches.cpp index 7ad8b8cbbf9..250dbae5dad 100644 --- a/fdbserver/workloads/Watches.cpp +++ b/fdbserver/workloads/Watches.cpp @@ -25,6 +25,7 @@ #include "flow/Coroutines.h" #include "flow/DeterministicRandom.h" #include "fdbserver/workloads/workloads.actor.h" +#include "fmt/format.h" struct WatchesWorkload : TestWorkload { static constexpr auto NAME = "Watches"; @@ -110,7 +111,7 @@ struct WatchesWorkload : TestWorkload { while (extraLoc < extraNodes) { co_await cx.run([&](Transaction* tr) -> Future { for (int i = 0; i < 1000 && extraLoc + i < extraNodes; i++) { - Key extraKey = KeyRef(watchKey.toString() + format("%d", extraLoc + i)); + Key extraKey = KeyRef(watchKey.toString() + fmt::format("{}", extraLoc + i)); Value extraValue = ValueRef(std::string(100, '.')); tr->set(extraKey, extraValue); // TraceEvent("WatcherInitialSetupExtra").detail("Key", extraKey).detail("Value", extraValue); diff --git a/fdbserver/workloads/WorkerErrors.cpp b/fdbserver/workloads/WorkerErrors.cpp index f87c4fa7029..404365725a7 100644 --- a/fdbserver/workloads/WorkerErrors.cpp +++ b/fdbserver/workloads/WorkerErrors.cpp @@ -25,6 +25,7 @@ #include "fdbserver/WorkerInterface.actor.h" #include "fdbserver/QuietDatabase.h" #include "fdbserver/ServerDBInfo.h" +#include "fmt/format.h" struct WorkerErrorsWorkload : TestWorkload { static constexpr auto NAME = "WorkerErrors"; @@ -56,7 +57,7 @@ struct WorkerErrorsWorkload : TestWorkload { std::vector workers = co_await getWorkers(dbInfo); std::vector errors = co_await latestEventOnWorkers(workers); for (auto e : errors) { - printf("%s\n", e.toString().c_str()); + fmt::println("{}", e.toString()); } } diff --git a/fdbserver/workloads/WriteDuringRead.cpp b/fdbserver/workloads/WriteDuringRead.cpp index 3e3909d66ae..47daad0bdf1 100644 --- a/fdbserver/workloads/WriteDuringRead.cpp +++ b/fdbserver/workloads/WriteDuringRead.cpp @@ -28,6 +28,7 @@ #include "fdbclient/Atomic.h" #include "flow/ApiVersion.h" #include "flow/CoroUtils.h" +#include "fmt/format.h" struct WriteDuringReadWorkload : TestWorkload { static constexpr auto NAME = "WriteDuringRead"; @@ -714,7 +715,7 @@ struct WriteDuringReadWorkload : TestWorkload { if (adjacentKeys) { return Key(keyPrefix + (idx ? std::string(idx, '\x00') : "")); } else { - return Key(keyPrefix + format("%010d", idx)); + return Key(keyPrefix + fmt::format("{:010}", idx)); } } diff --git a/fdbserver/workloads/workloads.cpp b/fdbserver/workloads/workloads.cpp index fc785a15103..94dce0d3e0a 100644 --- a/fdbserver/workloads/workloads.cpp +++ b/fdbserver/workloads/workloads.cpp @@ -23,6 +23,7 @@ #include "flow/flow.h" #include "fdbclient/FDBTypes.h" #include "fdbclient/DataDistributionConfig.actor.h" +#include "fmt/format.h" Future customShardConfigWorkload(Database const& cxUnsafe) { auto cx = cxUnsafe; @@ -96,13 +97,13 @@ Future customShardConfigWorkload(Database const& cxUnsafe) { if (verbose) { if (verify.present()) { - fmt::print("'{}' is in '{}' to '{}' with config {}\n", - query.printable(), - verify->range.begin, - verify->range.end, - verify->value.toString()); + fmt::println("'{}' is in '{}' to '{}' with config {}", + query.printable(), + verify->range.begin, + verify->range.end, + verify->value.toString()); } else { - fmt::print("'{}' is not in a range in the config\n", query.printable()); + fmt::println("'{}' is not in a range in the config", query.printable()); } }