Remove some usages of PRId64 by using fmt library

This commit is contained in:
sfc-gh-tclinkenbeard 2021-11-30 20:14:35 -08:00
parent e9567b1eeb
commit ec64890ac1
20 changed files with 119 additions and 108 deletions

View File

@ -24,6 +24,7 @@
#include <stdio.h>
#include <cinttypes>
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "flow/DeterministicRandom.h"
#include "flow/SystemMonitor.h"
#include "flow/TLSConfig.actor.h"
@ -44,7 +45,7 @@ ACTOR Future<Void> _test() {
// tr->setVersion(1);
Version ver = wait(tr->getReadVersion());
printf("%" PRId64 "\n", ver);
fmt::print("{}\n", ver);
state std::vector<Future<Version>> versions;

View File

@ -18,6 +18,7 @@
* limitations under the License.
*/
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbbackup/BackupTLSConfig.h"
#include "fdbclient/JsonBuilder.h"
#include "flow/Arena.h"
@ -2309,7 +2310,7 @@ ACTOR Future<Void> runRestore(Database db,
origDb = Database::createDatabase(originalClusterFile, Database::API_VERSION_LATEST);
Version v = wait(timeKeeperVersionFromDatetime(targetTimestamp, origDb.get()));
printf("Timestamp '%s' resolves to version %" PRId64 "\n", targetTimestamp.c_str(), v);
fmt::print("Timestamp '{0}' resolves to version {1}\n", targetTimestamp, v);
targetVersion = v;
}
@ -2336,8 +2337,9 @@ ACTOR Future<Void> runRestore(Database db,
throw restore_error();
}
if (verbose)
printf("Using target restore version %" PRId64 "\n", targetVersion);
if (verbose) {
fmt::print("Ussing target restore version {}\n", targetVersion);
}
}
if (performRestore) {
@ -2359,19 +2361,19 @@ ACTOR Future<Void> runRestore(Database db,
if (waitForDone && verbose) {
// If restore is now complete then report version restored
printf("Restored to version %" PRId64 "\n", restoredVersion);
fmt::print("Restored to version {}\n", restoredVersion);
}
} else {
state Optional<RestorableFileSet> rset = wait(bc->getRestoreSet(targetVersion, ranges));
if (!rset.present()) {
fprintf(stderr,
"Insufficient data to restore to version %" PRId64 ". Describe backup for more information.\n",
fmt::print(stderr,
"Insufficient data to restore to version {}. Describe backup for more information.\n",
targetVersion);
throw restore_invalid_version();
}
printf("Backup can be used to restore to version %" PRId64 "\n", targetVersion);
fmt::print("Backup can be used to restore to version {}\n", targetVersion);
}
} catch (Error& e) {
@ -2472,20 +2474,20 @@ ACTOR Future<Void> runFastRestoreTool(Database db,
state Optional<RestorableFileSet> rset = wait(bc->getRestoreSet(restoreVersion));
if (!rset.present()) {
fprintf(stderr, "Insufficient data to restore to version %" PRId64 "\n", restoreVersion);
fmt::print(stderr, "Insufficient data to restore to version {}\n", restoreVersion);
throw restore_invalid_version();
}
// Display the restore information, if requested
if (verbose) {
printf("[DRY RUN] Restoring backup to version: %" PRId64 "\n", restoreVersion);
printf("%s\n", description.toString().c_str());
fmt::print("[DRY RUN] Restoring backup to version: {}\n", restoreVersion);
fmt::print("{}\n", description.toString());
}
}
if (waitForDone && verbose) {
// If restore completed then report version restored
printf("Restored to version %" PRId64 "%s\n", restoreVersion, (performRestore) ? "" : " (DRY RUN)");
fmt::print("Restored to version {0}{1}\n", restoreVersion, (performRestore) ? "" : " (DRY RUN)");
}
} catch (Error& e) {
if (e.code() == error_code_actor_cancelled)
@ -2520,7 +2522,7 @@ ACTOR Future<Void> dumpBackupData(const char* name,
}
}
printf("Scanning version range %" PRId64 " to %" PRId64 "\n", beginVersion, endVersion);
fmt::print("Scanning version range {0} to {1}\n", beginVersion, endVersion);
BackupFileList files = wait(c->dumpFileList(beginVersion, endVersion));
files.toStream(stdout);
@ -2579,12 +2581,12 @@ ACTOR Future<Void> expireBackupData(const char* name,
printf("\r%s%s\n", p.c_str(), (spaces > 0 ? std::string(spaces, ' ').c_str() : ""));
if (endVersion < 0)
printf("All data before %" PRId64 " versions (%" PRId64
fmt::print("All data before {0} versions ({1}"
" days) prior to latest backup log has been deleted.\n",
-endVersion,
-endVersion / ((int64_t)24 * 3600 * CLIENT_KNOBS->CORE_VERSIONSPERSECOND));
else
printf("All data before version %" PRId64 " has been deleted.\n", endVersion);
fmt::print("All data before version {} has been deleted.\n", endVersion);
} catch (Error& e) {
if (e.code() == error_code_actor_cancelled)
throw;

View File

@ -21,6 +21,7 @@
#include <cinttypes>
#include "boost/lexical_cast.hpp"
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbcli/fdbcli.actor.h"
@ -55,7 +56,7 @@ ACTOR Future<Void> printHealthyZone(Reference<IDatabase> db) {
} else {
std::string zoneId = res[0].key.removePrefix(fdb_cli::maintenanceSpecialKeyRange.begin).toString();
int64_t seconds = static_cast<int64_t>(boost::lexical_cast<double>(res[0].value.toString()));
printf("Maintenance for zone %s will continue for %" PRId64 " seconds.\n", zoneId.c_str(), seconds);
fmt::print("Maintenance for zone {0} will continue for {1} seconds.\n", zoneId, seconds);
}
return Void();
} catch (Error& e) {

View File

@ -19,6 +19,7 @@
*/
#include "boost/lexical_cast.hpp"
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbclient/ClusterConnectionFile.h"
#include "fdbclient/NativeAPI.actor.h"
#include "fdbclient/FDBTypes.h"
@ -631,9 +632,9 @@ ACTOR Future<Void> commitTransaction(Reference<ITransaction> tr) {
wait(makeInterruptable(safeThreadFutureToFuture(tr->commit())));
auto ver = tr->getCommittedVersion();
if (ver != invalidVersion)
printf("Committed (%" PRId64 ")\n", ver);
fmt::print("Committed ({})\n", ver);
else
printf("Nothing to commit\n");
fmt::print("Nothing to commit\n");
return Void();
}

View File

@ -22,6 +22,7 @@
#include <ostream>
// FIXME: Trim this down
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "flow/Platform.actor.h"
#include "fdbclient/AsyncTaskThread.h"
#include "fdbclient/BackupContainer.h"
@ -75,13 +76,13 @@ std::string IBackupContainer::ExpireProgress::toString() const {
void BackupFileList::toStream(FILE* fout) const {
for (const RangeFile& f : ranges) {
fprintf(fout, "range %" PRId64 " %s\n", f.fileSize, f.fileName.c_str());
fmt::print(fout, "range {0} {1}\n", f.fileSize, f.fileName);
}
for (const LogFile& f : logs) {
fprintf(fout, "log %" PRId64 " %s\n", f.fileSize, f.fileName.c_str());
fmt::print(fout, "log {0} {1}\n", f.fileSize, f.fileName);
}
for (const KeyspaceSnapshotFile& f : snapshots) {
fprintf(fout, "snapshotManifest %" PRId64 " %s\n", f.totalSize, f.fileName.c_str());
fmt::print(fout, "snapshotManifest {0} {1}\n", f.totalSize, f.fileName);
}
}

View File

@ -1757,7 +1757,7 @@ ACTOR Future<Void> testBackupContainer(std::string url, Optional<std::string> en
state Version expireVersion = listing.snapshots[i].endVersion;
// Expire everything up to but not including the snapshot end version
printf("EXPIRE TO %" PRId64 "\n", expireVersion);
fmt::print("EXPIRE TO {}\n", expireVersion);
state Future<Void> f = c->expireData(expireVersion);
wait(ready(f));

View File

@ -22,6 +22,7 @@
#define FDBCLIENT_BACKUP_CONTAINER_FILESYSTEM_H
#pragma once
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbclient/BackupContainer.h"
#include "fdbclient/FDBTypes.h"
#include "flow/Trace.h"

View File

@ -18,6 +18,7 @@
* limitations under the License.
*/
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbclient/BackupAgent.actor.h"
#include "fdbclient/BackupContainer.h"
#include "fdbclient/DatabaseContext.h"
@ -5342,10 +5343,7 @@ public:
.detail("BackupContainer", bc->getURL())
.detail("BeginVersion", beginVersion)
.detail("TargetVersion", targetVersion);
fprintf(stderr,
"ERROR: Restore version %" PRId64 " is not possible from %s\n",
targetVersion,
bc->getURL().c_str());
fmt::print(stderr, "ERROR: Restore version {0} is not possible from {1}\n", targetVersion, bc->getURL());
throw restore_invalid_version();
}

View File

@ -22,6 +22,7 @@
#include <string>
#include <vector>
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbclient/Knobs.h"
#include "flow/Arena.h"
#include "fdbclient/ClusterConnectionMemoryRecord.h"
@ -1677,8 +1678,8 @@ ACTOR Future<Void> printHealthyZone(Database cx) {
printf("No ongoing maintenance.\n");
} else {
auto healthyZone = decodeHealthyZoneValue(val.get());
printf("Maintenance for zone %s will continue for %" PRId64 " seconds.\n",
healthyZone.first.toString().c_str(),
fmt::print("Maintenance for zone {0} will continue for {1} seconds.\n",
healthyZone.first.toString(),
(healthyZone.second - tr.getReadVersion().get()) / CLIENT_KNOBS->CORE_VERSIONSPERSECOND);
}
return Void();

View File

@ -21,6 +21,7 @@
#include <cinttypes>
#include <memory>
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbrpc/simulator.h"
#define BOOST_SYSTEM_NO_LIB
#define BOOST_DATE_TIME_NO_LIB
@ -589,11 +590,11 @@ private:
((uintptr_t)data % 4096 == 0 && length % 4096 == 0 && offset % 4096 == 0)); // Required by KAIO.
state UID opId = deterministicRandom()->randomUniqueID();
if (randLog)
fprintf(randLog,
"SFR1 %s %s %s %d %" PRId64 "\n",
self->dbgId.shortString().c_str(),
self->filename.c_str(),
opId.shortString().c_str(),
fmt::print(randLog,
"SFR1 {0} {1} {2} {3} {4}\n",
self->dbgId.shortString(),
self->filename,
opId.shortString(),
length,
offset);
@ -633,11 +634,11 @@ private:
state UID opId = deterministicRandom()->randomUniqueID();
if (randLog) {
uint32_t a = crc32c_append(0, data.begin(), data.size());
fprintf(randLog,
"SFW1 %s %s %s %d %d %" PRId64 "\n",
self->dbgId.shortString().c_str(),
self->filename.c_str(),
opId.shortString().c_str(),
fmt::print(randLog,
"SFW1 {0} {1} {2} {3} {4} {5}\n",
self->dbgId.shortString(),
self->filename,
opId.shortString(),
a,
data.size(),
offset);
@ -681,12 +682,8 @@ private:
ACTOR static Future<Void> truncate_impl(SimpleFile* self, int64_t size) {
state UID opId = deterministicRandom()->randomUniqueID();
if (randLog)
fprintf(randLog,
"SFT1 %s %s %s %" PRId64 "\n",
self->dbgId.shortString().c_str(),
self->filename.c_str(),
opId.shortString().c_str(),
size);
fmt::print(
randLog, "SFT1 {0} {1} {2} {3}\n", self->dbgId.shortString(), self->filename, opId.shortString(), size);
// KAIO will return EINVAL, as len==0 is an error.
if ((self->flags & IAsyncFile::OPEN_NO_AIO) == 0 && size == 0) {
@ -782,12 +779,8 @@ private:
}
if (randLog)
fprintf(randLog,
"SFS2 %s %s %s %" PRId64 "\n",
self->dbgId.shortString().c_str(),
self->filename.c_str(),
opId.shortString().c_str(),
pos);
fmt::print(
randLog, "SFS2 {0} {1} {2} {3}\n", self->dbgId.shortString(), self->filename, opId.shortString(), pos);
INJECT_FAULT(io_error, "SimpleFile::size"); // SimpleFile::size inject io_error
return pos;
@ -2091,8 +2084,8 @@ public:
}
if (randLog)
fprintf(randLog,
"T %f %d %s %" PRId64 "\n",
fmt::print(randLog,
"T {0} {1} {2} {3}\n",
this->time,
int(deterministicRandom()->peek() % 10000),
t.machine ? t.machine->name : "none",

View File

@ -19,6 +19,7 @@
*/
#include <cinttypes>
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbclient/BlobWorkerInterface.h"
#include "fdbserver/Status.h"
#include "flow/Trace.h"
@ -3361,8 +3362,8 @@ TEST_CASE("Lstatus/json/builderPerf") {
}
double elapsed = generated + serialized;
printf("RESULT: %" PRId64
" bytes %d elements %d levels %f seconds (%f gen, %f serialize) %f MB/s %f items/s\n",
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,

View File

@ -19,6 +19,7 @@
*/
#include <cinttypes>
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbserver/workloads/ApiWorkload.h"
#include "fdbclient/MultiVersionTransaction.h"
#include "flow/actorcompiler.h" // This must be the last #include.
@ -123,7 +124,7 @@ bool ApiWorkload::compareResults(VectorRef<KeyValueRef> dbResults,
for (int j = 0; j < storeResults.size(); j++)
printf("%d: %s %d\n", j, storeResults[j].key.toString().c_str(), storeResults[j].value.size());
printf("Read Version: %" PRId64 "\n", readVersion);
fmt::print("Read Version: {}\n", readVersion);
TraceEvent(SevError, format("%s_CompareSizeMismatch", description().c_str()).c_str())
.detail("ReadVer", readVersion)
@ -144,7 +145,7 @@ bool ApiWorkload::compareResults(VectorRef<KeyValueRef> dbResults,
for (int j = 0; j < storeResults.size(); j++)
printf("%d: %s %d\n", j, storeResults[j].key.toString().c_str(), storeResults[j].value.size());
printf("Read Version: %" PRId64 "\n", readVersion);
fmt::print("Read Version: {}\n", readVersion);
TraceEvent(SevError, format("%s_CompareValueMismatch", description().c_str()).c_str())
.detail("ReadVer", readVersion)

View File

@ -20,6 +20,7 @@
#include <cinttypes>
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbserver/workloads/workloads.actor.h"
#include "flow/ActorCollection.h"
#include "flow/IRandom.h"
@ -83,8 +84,9 @@ struct AsyncFileCorrectnessWorkload : public AsyncFileWorkload {
if (maxOperationSize * numSimultaneousOperations > targetFileSize * 0.25) {
targetFileSize *= (int)ceil((maxOperationSize * numSimultaneousOperations * 4.0) / targetFileSize);
printf("Target file size is insufficient to support %d simultaneous operations of size %d; changing to "
"%" PRId64 "\n",
fmt::print(
"Target file size is insufficient to support {0} simultaneous operations of size {1}; changing to "
"{2}\n",
numSimultaneousOperations,
maxOperationSize,
targetFileSize);
@ -396,12 +398,12 @@ struct AsyncFileCorrectnessWorkload : public AsyncFileWorkload {
int64_t fileSize = wait(self->fileHandle->file->size());
int64_t fileSizeChange = fileSize - self->fileSize;
if (fileSizeChange >= _PAGE_SIZE) {
printf("Reopened file increased in size by %" PRId64 " bytes (at most %d allowed)\n",
fmt::print("Reopened file increased in size by {0} bytes (at most {1} allowed)\n",
fileSizeChange,
_PAGE_SIZE - 1);
self->success = false;
} else if (fileSizeChange < 0) {
printf("Reopened file decreased in size by %" PRId64 " bytes\n", -fileSizeChange);
fmt::print("Reopened file decreased in size by {} bytes\n", -fileSizeChange);
self->success = false;
}

View File

@ -19,6 +19,7 @@
*/
#include <cinttypes>
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbserver/workloads/workloads.actor.h"
#include "fdbrpc/IAsyncFile.h"
#include "fdbclient/FDBTypes.h"
@ -113,7 +114,7 @@ struct DiskDurabilityTest : TestWorkload {
if (failed)
throw operation_failed();
printf("Verified %d/%" PRId64 " pages\n", verifyPages, size / 4096);
fmt::print("Verified {0}/{1} pages\n", verifyPages, size / 4096);
TraceEvent(SevInfo, "Verified").detail("Pages", verifyPages).detail("Of", size / 4096);
// Run

View File

@ -20,6 +20,7 @@
#include <ctime>
#include <cinttypes>
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbserver/workloads/workloads.actor.h"
#include "fdbserver/IKeyValueStore.h"
#include "flow/ActorCollection.h"
@ -278,7 +279,7 @@ ACTOR Future<Void> testKVStoreMain(KVStoreTestWorkload* workload, KVTest* ptest)
}
double elapsed = timer() - cst;
TraceEvent("KVStoreCount").detail("Count", count).detail("Took", elapsed);
printf("Counted: %" PRId64 " in %0.1fs\n", count, elapsed);
fmt::print("Counted: {0} in {1:01.f}s\n");
}
if (workload->doSetup) {

View File

@ -20,6 +20,7 @@
#include <cstdint>
#include <limits>
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbrpc/simulator.h"
#include "fdbclient/BackupAgent.actor.h"
#include "fdbclient/BackupContainer.h"
@ -78,9 +79,9 @@ struct MutationLogReaderCorrectnessWorkload : TestWorkload {
state Transaction tr(cx);
state int iStart = 0;
state int batchSize = 1000;
printf("Records: %d\n", self->records);
printf("BeginVersion: %" PRId64 "\n", self->beginVersion);
printf("EndVersion: %" PRId64 "\n", self->endVersion);
fmt::print("Records: {}\n", self->records);
fmt::print("BeginVersion: {}\n", self->beginVersion);
fmt::print("EndVersion: {}\n", self->endVersion);
while (iStart < self->records) {
loop {

View File

@ -20,6 +20,7 @@
#include <cinttypes>
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "fdbserver/workloads/workloads.actor.h"
#include "flow/SignalSafeUnwind.h"
#include "flow/actorcompiler.h" // This must be the last #include.
@ -55,9 +56,9 @@ struct SlowTaskWorkload : TestWorkload {
do_slow_exception_thing(&exc);
}
}
fprintf(stderr,
"Slow task complete: %" PRId64 " exceptions; %" PRId64 " calls to dl_iterate_phdr, %" PRId64
" profiles deferred, %" PRId64 " profiles overflowed, %" PRId64 " profiles captured\n",
fmt::print(stderr,
"Slow task complete: {0} exceptions; {1} calls to dl_iterate_phdr, {2}"
" profiles deferred, {3} profiles overflowed, {4} profiles captured\n",
exc,
dl_iterate_phdr_calls - phc,
getNumProfilesDeferred() - startProfilesDeferred,

View File

@ -18,6 +18,7 @@
* limitations under the License.
*/
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "flow/DeterministicRandom.h"
#include <cstring>
@ -78,7 +79,7 @@ int64_t DeterministicRandom::randomInt64(int64_t min, int64_t maxPlusOne) {
else
i = v + min;
if (randLog && useRandLog)
fprintf(randLog, "Rint64 %" PRId64 "\n", i);
fmt::print(randLog, "Rint64 {}\n", i);
return i;
}
@ -103,7 +104,7 @@ UID DeterministicRandom::randomUniqueID() {
x = gen64();
y = gen64();
if (randLog && useRandLog)
fprintf(randLog, "Ruid %" PRIx64 " %" PRIx64 "\n", x, y);
fmt::print(randLog, "Ruid {0} {1}\n", x, y);
return UID(x, y);
}

View File

@ -21,6 +21,7 @@
// At the moment, this file just contains tests. IndexedSet<> is a template
// and so all the important implementation is in the header file
#include "contrib/fmt-8.0.1/include/fmt/format.h"
#include "flow/IndexedSet.h"
#include "flow/IRandom.h"
#include "flow/ThreadPrimitives.h"
@ -495,8 +496,9 @@ TEST_CASE("/flow/IndexedSet/all numbers") {
auto ii = is.index(n);
int ib = ii != is.end() ? *ii : 1000000;
ASSERT(ib == b);
if (ib != b)
printf("%s %" PRId64 " %d %d %" PRId64 "\n", ib == b ? "OK" : "ERROR", n, b, ib, is.sumTo(ii));
if (ib != b) {
fmt::print("{0} {1} {2} {3} {4} {5}\n", ib == b ? "OK" : "ERROR", n, b, ib, is.sumTo(ii));
}
}
for (int i = 0; i < 100000; i++) {
@ -509,8 +511,9 @@ TEST_CASE("/flow/IndexedSet/all numbers") {
// int ntotal = int64_t(b)*(b-1)/2 - int64_t(a)*(a-1)/2;
int64_t ntotal = int64_t(b - a) * (a + b - 1) / 2;
ASSERT(itotal == ntotal);
if (itotal != ntotal)
printf("%s %" PRId64 " %" PRId64 "\n", itotal == ntotal ? "OK" : "ERROR", ntotal, itotal);
if (itotal != ntotal) {
fmt::print("{0} {1} {2}\n", itotal == ntotal ? "OK" : "ERROR", ntotal, itotal);
}
}
// double a = timer();

View File

@ -86,9 +86,9 @@ void* rte_memcpy_noinline(void* __restrict __dest, const void* __restrict __src,
}
#endif // (defined (__linux__) || defined (__FreeBSD__)) && defined(__AVX__) && !defined(MEMORY_SANITIZER)
INetwork* g_network = 0;
INetwork* g_network = nullptr;
FILE* randLog = 0;
FILE* randLog = nullptr;
thread_local Reference<IRandom> seededRandom;
Reference<IRandom> seededDebugRandom;
uint64_t debug_lastLoadBalanceResultEndpointToken = 0;