diff options
author | Greg Studer <greg@10gen.com> | 2014-03-03 15:24:02 -0500 |
---|---|---|
committer | Greg Studer <greg@10gen.com> | 2014-03-04 17:47:20 -0500 |
commit | 8470a1f87658277856a5a5be1a5e2bc34bc50cec (patch) | |
tree | 162cca9b1162f670d453ced7de310b15a59d713a | |
parent | 33912523e40467e1a41bed60ed7e198200a040ad (diff) | |
download | mongo-8470a1f87658277856a5a5be1a5e2bc34bc50cec.tar.gz |
SERVER-12899 append "waited" field to all fsync GLE calls for 2.4 compatibility
-rw-r--r-- | src/mongo/db/commands/get_last_error.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/write_concern.cpp | 20 | ||||
-rw-r--r-- | src/mongo/db/write_concern.h | 2 |
3 files changed, 21 insertions, 3 deletions
diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp index 868af360f64..460029b6ab4 100644 --- a/src/mongo/db/commands/get_last_error.cpp +++ b/src/mongo/db/commands/get_last_error.cpp @@ -238,7 +238,7 @@ namespace mongo { WriteConcernResult wcResult; status = waitForWriteConcern( writeConcern, lastOpTime, &wcResult ); - wcResult.appendTo( &result ); + wcResult.appendTo( writeConcern, &result ); // For backward compatibility with 2.4, wtimeout returns ok : 1.0 if ( wcResult.wTimedOut ) { diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp index c52cfb545e3..18bea25ce65 100644 --- a/src/mongo/db/write_concern.cpp +++ b/src/mongo/db/write_concern.cpp @@ -78,7 +78,9 @@ namespace mongo { return Status::OK(); } - void WriteConcernResult::appendTo( BSONObjBuilder* result ) const { + void WriteConcernResult::appendTo( const WriteConcernOptions& writeConcern, + BSONObjBuilder* result ) const { + if ( syncMillis >= 0 ) result->appendNumber( "syncMillis", syncMillis ); @@ -104,6 +106,22 @@ namespace mongo { result->appendNull( "err" ); else result->append( "err", err ); + + // *** 2.4 SyncClusterConnection compatibility *** + // 2.4 expects either fsync'd files, or a "waited" field exist after running an fsync : true + // GLE, but with journaling we don't actually need to run the fsync (fsync command is + // preferred in 2.6). So we add a "waited" field if one doesn't exist. + + if ( writeConcern.syncMode == WriteConcernOptions::FSYNC ) { + + if ( fsyncFiles < 0 && ( wTime < 0 || !wTimedOut ) ) { + dassert( result->asTempObj()["waited"].eoo() ); + result->appendNumber( "waited", syncMillis ); + } + + dassert( result->asTempObj()["fsyncFiles"].numberInt() > 0 || + !result->asTempObj()["waited"].eoo() ); + } } Status waitForWriteConcern( const WriteConcernOptions& writeConcern, diff --git a/src/mongo/db/write_concern.h b/src/mongo/db/write_concern.h index 69c438d3ba3..c88404c1055 100644 --- a/src/mongo/db/write_concern.h +++ b/src/mongo/db/write_concern.h @@ -50,7 +50,7 @@ namespace mongo { err = ""; } - void appendTo( BSONObjBuilder* result ) const; + void appendTo( const WriteConcernOptions& writeConcern, BSONObjBuilder* result ) const; int syncMillis; int fsyncFiles; |