diff --git a/fdbclient/AsyncFileBlobStore.actor.cpp b/fdbclient/AsyncFileBlobStore.actor.cpp index 9dd87263dd..a12317f8f8 100644 --- a/fdbclient/AsyncFileBlobStore.actor.cpp +++ b/fdbclient/AsyncFileBlobStore.actor.cpp @@ -23,7 +23,7 @@ #include "flow/UnitTest.h" #include "flow/actorcompiler.h" // has to be last include -Future AsyncFileBlobStoreRead::size() { +Future AsyncFileBlobStoreRead::size() const { if(!m_size.isValid()) m_size = m_bstore->objectSize(m_bucket, m_object); return m_size; diff --git a/fdbclient/AsyncFileBlobStore.actor.h b/fdbclient/AsyncFileBlobStore.actor.h index 980e211a98..a8a422ade0 100644 --- a/fdbclient/AsyncFileBlobStore.actor.h +++ b/fdbclient/AsyncFileBlobStore.actor.h @@ -92,7 +92,7 @@ public: MD5_CTX content_md5_buf; }; - virtual Future read( void *data, int length, int64_t offset ) { throw file_not_readable(); } + Future read(void* data, int length, int64_t offset) override { throw file_not_readable(); } ACTOR static Future write_impl(Reference f, const uint8_t *data, int length) { state Part *p = f->m_parts.back().getPtr(); @@ -115,7 +115,7 @@ public: return Void(); } - virtual Future write( void const *data, int length, int64_t offset ) { + Future write(void const* data, int length, int64_t offset) override { if(offset != m_cursor) throw non_sequential_op(); m_cursor += length; @@ -123,7 +123,7 @@ public: return m_error.getFuture() || write_impl(Reference::addRef(this), (const uint8_t *)data, length); } - virtual Future truncate( int64_t size ) { + Future truncate(int64_t size) override { if(size != m_cursor) return non_sequential_op(); return Void(); @@ -182,25 +182,25 @@ public: // their size. So in the case of a write buffer that does not meet the part minimum size the part could be sent // but then if there is any more data written then that part needs to be sent again in its entirety. So a client // that calls flush often could generate far more blob store write traffic than they intend to. - virtual Future flush() { return Void(); } + Future flush() override { return Void(); } - virtual Future size() { return m_cursor; } + Future size() const override { return m_cursor; } - virtual Future readZeroCopy( void** data, int* length, int64_t offset ) { + Future readZeroCopy(void** data, int* length, int64_t offset) override { TraceEvent(SevError, "ReadZeroCopyNotSupported").detail("FileType", "BlobStoreWrite"); return platform_error(); } - virtual void releaseZeroCopy( void* data, int length, int64_t offset ) {} + void releaseZeroCopy(void* data, int length, int64_t offset) override {} - virtual int64_t debugFD() { return -1; } + int64_t debugFD() const override { return -1; } - virtual ~AsyncFileBlobStoreWrite() { + ~AsyncFileBlobStoreWrite() override { m_upload_id.cancel(); m_finished.cancel(); m_parts.clear(); // Contains futures } - virtual std::string getFilename() { return m_object; } + std::string getFilename() const override { return m_object; } private: Reference m_bstore; @@ -267,7 +267,7 @@ public: virtual Future sync() { return Void(); } virtual Future flush() { return Void(); } - virtual Future size(); + Future size() const override; virtual Future readZeroCopy( void** data, int* length, int64_t offset ) { TraceEvent(SevError, "ReadZeroCopyNotSupported").detail("FileType", "BlobStoreRead"); @@ -275,16 +275,16 @@ public: } virtual void releaseZeroCopy( void* data, int length, int64_t offset ) {} - virtual int64_t debugFD() { return -1; } + virtual int64_t debugFD() const override { return -1; } - virtual std::string getFilename() { return m_object; } + std::string getFilename() const override { return m_object; } virtual ~AsyncFileBlobStoreRead() {} Reference m_bstore; std::string m_bucket; std::string m_object; - Future m_size; + mutable Future m_size; AsyncFileBlobStoreRead(Reference bstore, std::string bucket, std::string object) : m_bstore(bstore), m_bucket(bucket), m_object(object) { diff --git a/fdbrpc/AsyncFileCached.actor.h b/fdbrpc/AsyncFileCached.actor.h index 28d4e61ff4..8037e652a9 100644 --- a/fdbrpc/AsyncFileCached.actor.h +++ b/fdbrpc/AsyncFileCached.actor.h @@ -219,17 +219,11 @@ public: return waitAndSync( this, flush() ); } - virtual Future size() { - return length; - } + Future size() const override { return length; } - virtual int64_t debugFD() { - return uncached->debugFD(); - } + int64_t debugFD() const override { return uncached->debugFD(); } - virtual std::string getFilename() { - return filename; - } + std::string getFilename() const override { return filename; } virtual void addref() { ReferenceCounted::addref(); diff --git a/fdbrpc/AsyncFileEIO.actor.h b/fdbrpc/AsyncFileEIO.actor.h index 4284c1a427..36988c43a4 100644 --- a/fdbrpc/AsyncFileEIO.actor.h +++ b/fdbrpc/AsyncFileEIO.actor.h @@ -115,7 +115,7 @@ public: virtual void addref() { ReferenceCounted::addref(); } virtual void delref() { ReferenceCounted::delref(); } - virtual int64_t debugFD() { return fd; } + int64_t debugFD() const override { return fd; } virtual Future read( void* data, int length, int64_t offset ) { ++countFileLogicalReads; @@ -147,14 +147,12 @@ public: return fsync; } - virtual Future size() { + Future size() const override { ++countFileLogicalReads; ++countLogicalReads; return size_impl(fd); } - virtual std::string getFilename() { - return filename; - } + std::string getFilename() const override { return filename; } ACTOR static Future async_fsync_parent( std::string filename ) { std::string folder = parentDirectory( filename ); @@ -227,11 +225,11 @@ private: int fd, flags; Reference err; std::string filename; - Int64MetricHandle countFileLogicalWrites; - Int64MetricHandle countFileLogicalReads; + mutable Int64MetricHandle countFileLogicalWrites; + mutable Int64MetricHandle countFileLogicalReads; - Int64MetricHandle countLogicalWrites; - Int64MetricHandle countLogicalReads; + mutable Int64MetricHandle countLogicalWrites; + mutable Int64MetricHandle countLogicalReads; AsyncFileEIO( int fd, int flags, std::string const& filename ) : fd(fd), flags(flags), filename(filename), err(new ErrorInfo) { if( !g_network->isSimulated() ) { diff --git a/fdbrpc/AsyncFileKAIO.actor.h b/fdbrpc/AsyncFileKAIO.actor.h index 6f9f781862..d83dc4fac5 100644 --- a/fdbrpc/AsyncFileKAIO.actor.h +++ b/fdbrpc/AsyncFileKAIO.actor.h @@ -340,13 +340,9 @@ public: return fsync; } - virtual Future size() { return nextFileSize; } - virtual int64_t debugFD() { - return fd; - } - virtual std::string getFilename() { - return filename; - } + Future size() const override { return nextFileSize; } + int64_t debugFD() const override { return fd; } + std::string getFilename() const override { return filename; } ~AsyncFileKAIO() { close(fd); diff --git a/fdbrpc/AsyncFileNonDurable.actor.h b/fdbrpc/AsyncFileNonDurable.actor.h index 7e8e551b3e..76f56ce23c 100644 --- a/fdbrpc/AsyncFileNonDurable.actor.h +++ b/fdbrpc/AsyncFileNonDurable.actor.h @@ -111,18 +111,18 @@ public: return sendErrorOnShutdown( file->sync() ); } - Future size() { + Future size() const override { if( !file.getPtr() || g_simulator.getCurrentProcess()->shutdownSignal.getFuture().isReady() ) return io_error().asInjectedFault(); return sendErrorOnShutdown( file->size() ); } - int64_t debugFD() { + int64_t debugFD() const override { if( !file.getPtr() ) throw io_error().asInjectedFault(); return file->debugFD(); } - std::string getFilename() { + std::string getFilename() const override { if( !file.getPtr() ) throw io_error().asInjectedFault(); return file->getFilename(); @@ -137,7 +137,7 @@ public: std::string filename; //An approximation of the size of the file; .size() should be used instead of this variable in most cases - int64_t approximateSize; + mutable int64_t approximateSize; //The address of the machine that opened the file NetworkAddress openedAddress; @@ -306,17 +306,11 @@ public: } //Passes along size requests to the underlying file, augmenting with any writes past the end of the file - Future size() { - return size(this); - } + Future size() const override { return size(this); } - int64_t debugFD() { - return file->debugFD(); - } + int64_t debugFD() const override { return file->debugFD(); } - std::string getFilename() { - return file->getFilename(); - } + std::string getFilename() const override { return file->getFilename(); } //Forces a non-durable sync (some writes are not made or made incorrectly) //This is used when the file should 'die' without first completing its operations @@ -358,7 +352,7 @@ private: } //Checks if the file is killed. If so, then the current sync is completed if running and then an error is thrown - ACTOR Future checkKilled(AsyncFileNonDurable *self, std::string context) { + ACTOR static Future checkKilled(AsyncFileNonDurable const* self, std::string context) { if(self->killed.isSet()) { //TraceEvent("AsyncFileNonDurable_KilledInCheck", self->id).detail("In", context).detail("Filename", self->filename); wait(self->killComplete.getFuture()); @@ -372,14 +366,14 @@ private: //Passes along reads straight to the underlying file, waiting for any outstanding changes that could affect the results ACTOR Future onRead(AsyncFileNonDurable *self, void *data, int length, int64_t offset) { - wait(self->checkKilled(self, "Read")); + wait(checkKilled(self, "Read")); vector> priorModifications = self->getModificationsAndInsert(offset, length); wait(waitForAll(priorModifications)); state Future readFuture = self->file->read(data, length, offset); wait( success( readFuture ) || self->killed.getFuture() ); // throws if we were killed - wait(self->checkKilled(self, "ReadEnd")); + wait(checkKilled(self, "ReadEnd")); debugFileCheck("AsyncFileNonDurableRead", self->filename, data, offset, length); @@ -421,7 +415,7 @@ private: try { //TraceEvent("AsyncFileNonDurable_Write", self->id).detail("Delay", delayDuration).detail("Filename", self->filename).detail("WriteLength", length).detail("Offset", offset); - wait(self->checkKilled(self, "Write")); + wait(checkKilled(self, "Write")); Future writeEnded = wait(ownFuture); std::vector> priorModifications = self->getModificationsAndInsert(offset, length, true, writeEnded); @@ -543,7 +537,7 @@ private: try { //TraceEvent("AsyncFileNonDurable_Truncate", self->id).detail("Delay", delayDuration).detail("Filename", self->filename); - wait(self->checkKilled(self, "Truncate")); + wait(checkKilled(self, "Truncate")); Future truncateEnded = wait(ownFuture); std::vector> priorModifications = self->getModificationsAndInsert(size, -1, true, truncateEnded); @@ -600,8 +594,8 @@ private: wait(waitUntilDiskReady(self->diskParameters, 0, true) || self->killed.getFuture()); } - wait(self->checkKilled(self, durable ? "Sync" : "Kill")); - + wait(checkKilled(self, durable ? "Sync" : "Kill")); + if(!durable) self->killed.send( Void() ); @@ -653,7 +647,7 @@ private: } //A killed file cannot be allowed to report that it successfully synced else { - wait(self->checkKilled(self, "SyncEnd")); + wait(checkKilled(self, "SyncEnd")); wait(self->file->sync()); //TraceEvent("AsyncFileNonDurable_ImplSyncEnd", self->id).detail("Filename", self->filename).detail("Durable", durable); } @@ -679,13 +673,13 @@ private: } //Passes along size requests to the underlying file, augmenting with any writes past the end of the file - ACTOR Future onSize(AsyncFileNonDurable *self) { + ACTOR static Future onSize(AsyncFileNonDurable const* self) { //TraceEvent("AsyncFileNonDurable_Size", self->id).detail("Filename", self->filename); - wait(self->checkKilled(self, "Size")); + wait(checkKilled(self, "Size")); state Future sizeFuture = self->file->size(); wait( success( sizeFuture ) || self->killed.getFuture() ); - wait(self->checkKilled(self, "SizeEnd")); + wait(checkKilled(self, "SizeEnd")); //Include any modifications which extend past the end of the file uint64_t maxModification = self->pendingModifications.lastItem().begin(); @@ -693,14 +687,14 @@ private: return self->approximateSize; } - ACTOR Future size(AsyncFileNonDurable *self) { + ACTOR static Future size(AsyncFileNonDurable const* self) { state ISimulator::ProcessInfo* currentProcess = g_simulator.getCurrentProcess(); state TaskPriority currentTaskID = g_network->getCurrentTask(); wait( g_simulator.onMachine( currentProcess ) ); try { - state int64_t rep = wait( self->onSize( self ) ); + state int64_t rep = wait(onSize(self)); wait( g_simulator.onProcess( currentProcess, currentTaskID ) ); return rep; diff --git a/fdbrpc/AsyncFileReadAhead.actor.h b/fdbrpc/AsyncFileReadAhead.actor.h index cc3216ebdb..38e7b2fa41 100644 --- a/fdbrpc/AsyncFileReadAhead.actor.h +++ b/fdbrpc/AsyncFileReadAhead.actor.h @@ -165,7 +165,7 @@ public: virtual Future sync() { return Void(); } virtual Future flush() { return Void(); } - virtual Future size() { return m_f->size(); } + Future size() const override { return m_f->size(); } virtual Future readZeroCopy( void** data, int* length, int64_t offset ) { TraceEvent(SevError, "ReadZeroCopyNotSupported").detail("FileType", "ReadAheadCache"); @@ -173,9 +173,9 @@ public: } virtual void releaseZeroCopy( void* data, int length, int64_t offset ) {} - virtual int64_t debugFD() { return -1; } + int64_t debugFD() const override { return -1; } - virtual std::string getFilename() { return m_f->getFilename(); } + virtual std::string getFilename() const override { return m_f->getFilename(); } virtual ~AsyncFileReadAheadCache() { for(auto &it : m_blocks) { diff --git a/fdbrpc/AsyncFileWinASIO.actor.h b/fdbrpc/AsyncFileWinASIO.actor.h index 19b6ffcb9c..3f53b7d1d7 100644 --- a/fdbrpc/AsyncFileWinASIO.actor.h +++ b/fdbrpc/AsyncFileWinASIO.actor.h @@ -159,14 +159,12 @@ public: return Void(); } - virtual Future size() { + Future size() const override { LARGE_INTEGER s; if (!GetFileSizeEx(file.native_handle(), &s)) throw io_error(); return *(int64_t*)&s; } - virtual std::string getFilename() { - return filename; - } + std::string getFilename() const override { return filename; } ~AsyncFileWinASIO() { } diff --git a/fdbrpc/AsyncFileWriteChecker.h b/fdbrpc/AsyncFileWriteChecker.h index 64a74d24b2..242fef730d 100644 --- a/fdbrpc/AsyncFileWriteChecker.h +++ b/fdbrpc/AsyncFileWriteChecker.h @@ -60,10 +60,10 @@ public: Future sync() { return m_f->sync(); } Future flush() { return m_f->flush(); } - Future size() { return m_f->size(); } - std::string getFilename() { return m_f->getFilename(); } + Future size() const override { return m_f->size(); } + std::string getFilename() const override { return m_f->getFilename(); } void releaseZeroCopy( void* data, int length, int64_t offset ) { return m_f->releaseZeroCopy(data, length, offset); } - int64_t debugFD() { return m_f->debugFD(); } + int64_t debugFD() const override { return m_f->debugFD(); } AsyncFileWriteChecker(Reference f) : m_f(f) { // Initialize the static history budget the first time (and only the first time) a file is opened. diff --git a/fdbrpc/IAsyncFile.h b/fdbrpc/IAsyncFile.h index 764b8e6426..d02fb8368c 100644 --- a/fdbrpc/IAsyncFile.h +++ b/fdbrpc/IAsyncFile.h @@ -63,8 +63,8 @@ public: virtual Future truncate( int64_t size ) = 0; virtual Future sync() = 0; virtual Future flush() { return Void(); } // Sends previous writes to the OS if they have been buffered in memory, but does not make them power safe - virtual Future size() = 0; - virtual std::string getFilename() = 0; + virtual Future size() const = 0; + virtual std::string getFilename() const = 0; // Attempt to read the *length bytes at offset without copying. If successful, a pointer to the // requested bytes is written to *data, and the number of bytes successfully read is @@ -80,7 +80,7 @@ public: virtual Future readZeroCopy( void** data, int* length, int64_t offset ) { return io_error(); } virtual void releaseZeroCopy( void* data, int length, int64_t offset ) {} - virtual int64_t debugFD() = 0; + virtual int64_t debugFD() const = 0; }; typedef void (*runCycleFuncPtr)(); diff --git a/fdbrpc/RangeMap.h b/fdbrpc/RangeMap.h index 8407478256..d4db66c6a4 100644 --- a/fdbrpc/RangeMap.h +++ b/fdbrpc/RangeMap.h @@ -164,6 +164,11 @@ public: i.decrementNonEnd(); return iterator(i); } + const_iterator lastItem() const { + auto i(map.lastItem()); + i.decrementNonEnd(); + return const_iterator(i); + } int size() const { return map.size() - 1; } // We always have one range bounded by two entries iterator randomRange() { return iterator(map.index(deterministicRandom()->randomInt(0, map.size() - 1))); } const_iterator randomRange() const { @@ -275,4 +280,4 @@ void RangeMap::insert( const Range& keys, const map.insert(beginPair, true, mf(beginPair)); } -#endif \ No newline at end of file +#endif diff --git a/fdbrpc/sim2.actor.cpp b/fdbrpc/sim2.actor.cpp index 65299afda1..a73dc53136 100644 --- a/fdbrpc/sim2.actor.cpp +++ b/fdbrpc/sim2.actor.cpp @@ -478,7 +478,7 @@ public: virtual void addref() { ReferenceCounted::addref(); } virtual void delref() { ReferenceCounted::delref(); } - virtual int64_t debugFD() { return (int64_t)h; } + int64_t debugFD() const override { return (int64_t)h; } virtual Future read( void* data, int length, int64_t offset ) { return read_impl( this, data, length, offset ); @@ -496,13 +496,9 @@ public: return sync_impl( this ); } - virtual Future size() { - return size_impl( this ); - } + Future size() const override { return size_impl(this); } - virtual std::string getFilename() { - return actualFilename; - } + virtual std::string getFilename() const override { return actualFilename; } ~SimpleFile() { _close( h ); @@ -667,7 +663,7 @@ private: return Void(); } - ACTOR static Future size_impl( SimpleFile* self ) { + ACTOR static Future size_impl(SimpleFile const* self) { state UID opId = deterministicRandom()->randomUniqueID(); if (randLog) fprintf(randLog, "SFS1 %s %s %s\n", self->dbgId.shortString().c_str(), self->filename.c_str(), opId.shortString().c_str()); diff --git a/flow/flow.h b/flow/flow.h index 5e6ce3f3b8..5c28323b68 100644 --- a/flow/flow.h +++ b/flow/flow.h @@ -785,14 +785,14 @@ public: void sendError(const E& exc) const { sav->sendError(exc); } Future getFuture() const { sav->addFutureRef(); return Future(sav); } - bool isSet() { return sav->isSet(); } - bool canBeSet() { return sav->canBeSet(); } - bool isValid() const { return sav != NULL; } + bool isSet() const { return sav->isSet(); } + bool canBeSet() const { return sav->canBeSet(); } + bool isValid() const { return sav != nullptr; } Promise() : sav(new SAV(0, 1)) {} Promise(const Promise& rhs) : sav(rhs.sav) { sav->addPromiseRef(); } - Promise(Promise&& rhs) BOOST_NOEXCEPT : sav(rhs.sav) { rhs.sav = 0; } + Promise(Promise&& rhs) noexcept : sav(rhs.sav) { rhs.sav = 0; } ~Promise() { if (sav) sav->delPromiseRef(); }