diff --git a/fdbbackup/FileDecoder.actor.cpp b/fdbbackup/FileDecoder.actor.cpp index 116e61266b..953170016d 100644 --- a/fdbbackup/FileDecoder.actor.cpp +++ b/fdbbackup/FileDecoder.actor.cpp @@ -239,7 +239,7 @@ public: // However, we could have unfinished version in the buffer when EOF is true, // which means we should look for data in the next file. The caller // should call getUnfinishedBuffer() to get these left data. - bool finished() { return (eof && keyValues.empty()) || (leftover && !keyValues.empty()); } + bool finished() const { return (eof && keyValues.empty()) || (leftover && !keyValues.empty()); } std::vector&& getUnfinishedBuffer() && { return std::move(keyValues); } diff --git a/fdbclient/BackupContainerLocalDirectory.actor.cpp b/fdbclient/BackupContainerLocalDirectory.actor.cpp index 1260fad315..f5aad2cac7 100644 --- a/fdbclient/BackupContainerLocalDirectory.actor.cpp +++ b/fdbclient/BackupContainerLocalDirectory.actor.cpp @@ -30,7 +30,7 @@ namespace { class BackupFile : public IBackupFile, ReferenceCounted { public: - BackupFile(std::string fileName, Reference file, std::string finalFullPath) + BackupFile(const std::string& fileName, Reference file, const std::string& finalFullPath) : IBackupFile(fileName), m_file(file), m_finalFullPath(finalFullPath) {} Future append(const void* data, int len) { diff --git a/fdbrpc/IAsyncFile.actor.cpp b/fdbrpc/IAsyncFile.actor.cpp index 7a4854e89d..2e658e0414 100644 --- a/fdbrpc/IAsyncFile.actor.cpp +++ b/fdbrpc/IAsyncFile.actor.cpp @@ -108,7 +108,7 @@ ACTOR static Future incrementalDeleteHelper( std::string filename, bool mu return Void(); } -Future IAsyncFileSystem::incrementalDeleteFile( std::string filename, bool mustBeDurable ) { +Future IAsyncFileSystem::incrementalDeleteFile(const std::string& filename, bool mustBeDurable) { return uncancellable(incrementalDeleteHelper( filename, mustBeDurable, diff --git a/fdbrpc/IAsyncFile.h b/fdbrpc/IAsyncFile.h index 85d879e3fe..569a4f6ac6 100644 --- a/fdbrpc/IAsyncFile.h +++ b/fdbrpc/IAsyncFile.h @@ -88,17 +88,17 @@ typedef void (*runCycleFuncPtr)(); class IAsyncFileSystem { public: // Opens a file for asynchronous I/O - virtual Future< Reference > open( std::string filename, int64_t flags, int64_t mode ) = 0; + virtual Future> open(const std::string& filename, int64_t flags, int64_t mode) = 0; // Deletes the given file. If mustBeDurable, returns only when the file is guaranteed to be deleted even after a power failure. - virtual Future< Void > deleteFile( std::string filename, bool mustBeDurable ) = 0; + virtual Future deleteFile(const std::string& filename, bool mustBeDurable) = 0; // Unlinks a file and then deletes it slowly by truncating the file repeatedly. // If mustBeDurable, returns only when the file is guaranteed to be deleted even after a power failure. - virtual Future incrementalDeleteFile( std::string filename, bool mustBeDurable ); + virtual Future incrementalDeleteFile(const std::string& filename, bool mustBeDurable); // Returns the time of the last modification of the file. - virtual Future lastWriteTime( std::string filename ) = 0; + virtual Future lastWriteTime(const std::string& filename) = 0; static IAsyncFileSystem* filesystem() { return filesystem(g_network); } static runCycleFuncPtr runCycleFunc() { return reinterpret_cast(reinterpret_cast(g_network->global(INetwork::enRunCycleFunc))); } diff --git a/fdbrpc/Net2FileSystem.cpp b/fdbrpc/Net2FileSystem.cpp index d1b49e761f..9fa61f29b3 100644 --- a/fdbrpc/Net2FileSystem.cpp +++ b/fdbrpc/Net2FileSystem.cpp @@ -40,8 +40,7 @@ #include "fdbrpc/AsyncFileWriteChecker.h" // Opens a file for asynchronous I/O -Future< Reference > Net2FileSystem::open( std::string filename, int64_t flags, int64_t mode ) -{ +Future> Net2FileSystem::open(const std::string& filename, int64_t flags, int64_t mode) { #ifdef __linux__ if (checkFileSystem) { dev_t fileDeviceId = getDeviceId(filename); @@ -75,22 +74,19 @@ Future< Reference > Net2FileSystem::open( std::string filename } // Deletes the given file. If mustBeDurable, returns only when the file is guaranteed to be deleted even after a power failure. -Future< Void > Net2FileSystem::deleteFile( std::string filename, bool mustBeDurable ) -{ +Future Net2FileSystem::deleteFile(const std::string& filename, bool mustBeDurable) { return Net2AsyncFile::deleteFile(filename, mustBeDurable); } -Future< std::time_t > Net2FileSystem::lastWriteTime( std::string filename ) { +Future Net2FileSystem::lastWriteTime(const std::string& filename) { return Net2AsyncFile::lastWriteTime( filename ); } -void Net2FileSystem::newFileSystem(double ioTimeout, std::string fileSystemPath) -{ +void Net2FileSystem::newFileSystem(double ioTimeout, const std::string& fileSystemPath) { g_network->setGlobal(INetwork::enFileSystem, (flowGlobalType) new Net2FileSystem(ioTimeout, fileSystemPath)); } -Net2FileSystem::Net2FileSystem(double ioTimeout, std::string fileSystemPath) -{ +Net2FileSystem::Net2FileSystem(double ioTimeout, const std::string& fileSystemPath) { Net2AsyncFile::init(); #ifdef __linux__ if (!FLOW_KNOBS->DISABLE_POSIX_KERNEL_AIO) diff --git a/fdbrpc/Net2FileSystem.h b/fdbrpc/Net2FileSystem.h index 19cd223c5f..c69ffbe8b8 100644 --- a/fdbrpc/Net2FileSystem.h +++ b/fdbrpc/Net2FileSystem.h @@ -24,25 +24,25 @@ #include "fdbrpc/IAsyncFile.h" -class Net2FileSystem : public IAsyncFileSystem { +class Net2FileSystem final : public IAsyncFileSystem { public: // Opens a file for asynchronous I/O - virtual Future< Reference > open( std::string filename, int64_t flags, int64_t mode ); + Future> open(const std::string& filename, int64_t flags, int64_t mode) override; // Deletes the given file. If mustBeDurable, returns only when the file is guaranteed to be deleted even after a power failure. - virtual Future< Void > deleteFile( std::string filename, bool mustBeDurable ); + Future deleteFile(const std::string& filename, bool mustBeDurable) override; // Returns the time of the last modification of the file. - virtual Future< std::time_t > lastWriteTime( std::string filename ); + Future lastWriteTime(const std::string& filename) override; //void init(); static void stop(); - Net2FileSystem(double ioTimeout=0.0, std::string fileSystemPath = ""); + Net2FileSystem(double ioTimeout = 0.0, const std::string& fileSystemPath = ""); virtual ~Net2FileSystem() {} - static void newFileSystem(double ioTimeout=0.0, std::string fileSystemPath = ""); + static void newFileSystem(double ioTimeout = 0.0, const std::string& fileSystemPath = ""); #ifdef __linux__ dev_t fileSystemDeviceId; diff --git a/fdbrpc/sim2.actor.cpp b/fdbrpc/sim2.actor.cpp index b28f49bea4..6f3157da30 100644 --- a/fdbrpc/sim2.actor.cpp +++ b/fdbrpc/sim2.actor.cpp @@ -2027,8 +2027,7 @@ int sf_open( const char* filename, int flags, int convFlags, int mode ) { #endif // Opens a file for asynchronous I/O -Future< Reference > Sim2FileSystem::open( std::string filename, int64_t flags, int64_t mode ) -{ +Future> Sim2FileSystem::open(const std::string& filename, int64_t flags, int64_t mode) { ASSERT( (flags & IAsyncFile::OPEN_ATOMIC_WRITE_AND_CREATE) || !(flags & IAsyncFile::OPEN_CREATE) || StringRef(filename).endsWith(LiteralStringRef(".fdb-lock")) ); // We don't use "ordinary" non-atomic file creation right now except for folder locking, and we don't have code to simulate its unsafeness. @@ -2065,12 +2064,11 @@ Future< Reference > Sim2FileSystem::open( std::string filename } // Deletes the given file. If mustBeDurable, returns only when the file is guaranteed to be deleted even after a power failure. -Future< Void > Sim2FileSystem::deleteFile( std::string filename, bool mustBeDurable ) -{ +Future Sim2FileSystem::deleteFile(const std::string& filename, bool mustBeDurable) { return Sim2::deleteFileImpl(&g_sim2, filename, mustBeDurable); } -Future< std::time_t > Sim2FileSystem::lastWriteTime( std::string filename ) { +Future Sim2FileSystem::lastWriteTime(const std::string& filename) { // TODO: update this map upon file writes. static std::map fileWrites; if (BUGGIFY && deterministicRandom()->random01() < 0.01) { diff --git a/fdbrpc/simulator.h b/fdbrpc/simulator.h index b767e3c551..8876a90c6b 100644 --- a/fdbrpc/simulator.h +++ b/fdbrpc/simulator.h @@ -383,12 +383,12 @@ extern Future waitUntilDiskReady(Reference parameters, int class Sim2FileSystem : public IAsyncFileSystem { public: // Opens a file for asynchronous I/O - virtual Future< Reference > open( std::string filename, int64_t flags, int64_t mode ); + Future> open(const std::string& filename, int64_t flags, int64_t mode) override; // Deletes the given file. If mustBeDurable, returns only when the file is guaranteed to be deleted even after a power failure. - virtual Future< Void > deleteFile( std::string filename, bool mustBeDurable ); + Future deleteFile(const std::string& filename, bool mustBeDurable) override; - virtual Future< std::time_t > lastWriteTime( std::string filename ); + Future lastWriteTime(const std::string& filename) override; Sim2FileSystem() {}