diff options
-rw-r--r-- | jstests/noPassthroughWithMongod/sharding_balance4.js | 6 | ||||
-rw-r--r-- | jstests/sharding/features3.js | 23 | ||||
-rw-r--r-- | jstests/sharding/wbl_not_cleared.js | 51 | ||||
-rw-r--r-- | src/mongo/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/s/chunk.cpp | 1 | ||||
-rw-r--r-- | src/mongo/s/client_info.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/client_info.h | 1 | ||||
-rw-r--r-- | src/mongo/s/commands_admin.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/strategy.cpp | 1 | ||||
-rw-r--r-- | src/mongo/s/version_manager.cpp | 5 | ||||
-rw-r--r-- | src/mongo/s/writeback_listener.cpp | 191 | ||||
-rw-r--r-- | src/mongo/s/writeback_listener.h | 73 |
12 files changed, 5 insertions, 352 deletions
diff --git a/jstests/noPassthroughWithMongod/sharding_balance4.js b/jstests/noPassthroughWithMongod/sharding_balance4.js index 32fee38b22c..fa50deb7645 100644 --- a/jstests/noPassthroughWithMongod/sharding_balance4.js +++ b/jstests/noPassthroughWithMongod/sharding_balance4.js @@ -87,11 +87,7 @@ function check( msg , dontAssert ){ s.s.getDB("admin").runCommand({ setParameter : 1, logLevel : 2 }) printjson( db.foo.findOne( { _id : parseInt( x ) } ) ) - - // we will assert past this point but wait a bit to see if it is because the missing update - // was being held in the writeback roundtrip - sleep( 10000 ); - + var y = db.foo.findOne( { _id : parseInt( x ) } ) if ( y ){ diff --git a/jstests/sharding/features3.js b/jstests/sharding/features3.js index 58efd44ceac..90a4cec6479 100644 --- a/jstests/sharding/features3.js +++ b/jstests/sharding/features3.js @@ -156,27 +156,4 @@ assert(x.ok == 1 && x.numFiles > 0, "fsync failed: " + tojson(x)); x = db._adminCommand({"fsync" :1, lock:true}); assert(!x.ok, "lock should fail: " + tojson(x)); -// write back stuff -// SERVER-4194 - -function countWritebacks(curop) { - print("---------------"); - var num = 0; - for (var i = 0; i < curop.inprog.length; i++) { - var q = curop.inprog[i].query; - if (q && q.writebacklisten) { - printjson(curop.inprog[i]); - num++; - } - } - return num; -} - -x = db.currentOp(); -assert.eq(0, countWritebacks(x), "without all"); - -x = db.currentOp(true); -y = countWritebacks(x); -assert(y == 1 || y == 2, "with all: " + y); - s.stop() diff --git a/jstests/sharding/wbl_not_cleared.js b/jstests/sharding/wbl_not_cleared.js deleted file mode 100644 index 12dbfca842f..00000000000 --- a/jstests/sharding/wbl_not_cleared.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Tests whether the WBL gets reset without subsequent events. - */ - -var st = new ShardingTest({ shards : 2, mongos : 2, other : { mongosOptions : { verbose : 5 } } }); - -st.stopBalancer(); - -var mongos = st.s0; -var staleMongos = st.s1; -var admin = mongos.getDB("admin"); -var config = mongos.getDB("config"); -var shards = config.shards.find().toArray(); -var coll = mongos.getCollection("foo.bar"); - -jsTest.log("Sharding collection..."); - -printjson(admin.runCommand({ enableSharding : coll.getDB() + "" })); -printjson(admin.runCommand({ movePrimary : coll.getDB() + "", to : shards[0]._id })); -printjson(admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } })); -printjson(admin.runCommand({ split : coll + "", middle : { _id : 0 } })); -printjson(admin.runCommand({ moveChunk : coll + "", find : { _id : 0 }, to : shards[1]._id })); - -jsTest.log("Collection now sharded..."); -st.printShardingStatus(); - -jsTest.log("Making mongos stale..."); - -assert.writeOK(coll.insert({ _id : 0 })); - -// Make sure the stale mongos knows about the collection at the original version -assert.neq(null, staleMongos.getCollection(coll + "").findOne()); - -printjson(admin.runCommand({ moveChunk : coll + "", find : { _id : 0 }, to : shards[0]._id, _waitForDelete : true })); -printjson(admin.runCommand({ moveChunk : coll + "", find : { _id : 0 }, to : shards[1]._id, _waitForDelete : true })); - -jsTest.log("Running a stale insert..."); - -// duplicate _id -assert.writeError(staleMongos.getCollection(coll + "").insert({ _id : 0, dup : "key" })); - -st.printShardingStatus(); - -jsTest.log("Performing insert op on the same shard..."); - -assert.writeOK(staleMongos.getCollection(coll + "").insert({ _id : 1, key : "isOk" })); - -jsTest.log("DONE!"); - -st.stop(); - diff --git a/src/mongo/SConscript b/src/mongo/SConscript index 6a230b45b64..056890ccafe 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -752,7 +752,6 @@ mongosLibraryFiles = [ "s/s_only.cpp", "s/balance.cpp", "s/balancer_policy.cpp", - "s/writeback_listener.cpp", "s/version_manager.cpp", "s/version_mongos.cpp", "s/mongos_persistence_stubs.cpp", diff --git a/src/mongo/s/chunk.cpp b/src/mongo/s/chunk.cpp index 2f1b5ff95cc..d1478d1c274 100644 --- a/src/mongo/s/chunk.cpp +++ b/src/mongo/s/chunk.cpp @@ -35,6 +35,7 @@ #include "mongo/client/connpool.h" #include "mongo/client/dbclientcursor.h" #include "mongo/db/query/lite_parsed_query.h" +#include "mongo/db/lasterror.h" #include "mongo/db/write_concern.h" #include "mongo/platform/random.h" #include "mongo/s/chunk_diff.h" diff --git a/src/mongo/s/client_info.cpp b/src/mongo/s/client_info.cpp index 44038f0a99b..8e4a9bb69fd 100644 --- a/src/mongo/s/client_info.cpp +++ b/src/mongo/s/client_info.cpp @@ -37,6 +37,7 @@ #include "mongo/db/commands.h" #include "mongo/db/commands/server_status_metric.h" #include "mongo/db/dbmessage.h" +#include "mongo/db/lasterror.h" #include "mongo/db/stats/counters.h" #include "mongo/db/stats/timer_stats.h" #include "mongo/s/write_ops/batch_downconvert.h" @@ -46,7 +47,6 @@ #include "mongo/s/cursors.h" #include "mongo/s/grid.h" #include "mongo/s/request.h" -#include "mongo/s/writeback_listener.h" #include "mongo/server.h" #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" diff --git a/src/mongo/s/client_info.h b/src/mongo/s/client_info.h index a6fddbc8903..0f1757f42b5 100644 --- a/src/mongo/s/client_info.h +++ b/src/mongo/s/client_info.h @@ -37,7 +37,6 @@ #include "mongo/db/client_basic.h" #include "mongo/s/chunk.h" -#include "mongo/s/writeback_listener.h" #include "mongo/s/write_ops/batch_write_exec.h" #include "mongo/util/net/hostandport.h" diff --git a/src/mongo/s/commands_admin.cpp b/src/mongo/s/commands_admin.cpp index 90f8ec590c0..a94309b2d28 100644 --- a/src/mongo/s/commands_admin.cpp +++ b/src/mongo/s/commands_admin.cpp @@ -45,6 +45,7 @@ #include "mongo/db/hasher.h" #include "mongo/db/index_names.h" #include "mongo/db/query/lite_parsed_query.h" +#include "mongo/db/lasterror.h" #include "mongo/db/stats/counters.h" #include "mongo/db/wire_version.h" #include "mongo/db/write_concern.h" @@ -60,7 +61,6 @@ #include "mongo/s/type_chunk.h" #include "mongo/s/type_database.h" #include "mongo/s/type_shard.h" -#include "mongo/s/writeback_listener.h" #include "mongo/s/write_ops/batch_downconvert.h" #include "mongo/s/write_ops/batch_write_exec.h" #include "mongo/s/write_ops/batched_command_request.h" diff --git a/src/mongo/s/strategy.cpp b/src/mongo/s/strategy.cpp index 46e9e0f3663..63fe466cdc2 100644 --- a/src/mongo/s/strategy.cpp +++ b/src/mongo/s/strategy.cpp @@ -55,6 +55,7 @@ #include "mongo/s/write_ops/batch_upconvert.h" #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" +#include "mongo/util/timer.h" // error codes 8010-8040 diff --git a/src/mongo/s/version_manager.cpp b/src/mongo/s/version_manager.cpp index 4c1b85fd08a..5496dcaa5fa 100644 --- a/src/mongo/s/version_manager.cpp +++ b/src/mongo/s/version_manager.cpp @@ -38,7 +38,6 @@ #include "mongo/s/grid.h" #include "mongo/s/shard.h" #include "mongo/s/stale_exception.h" // for SendStaleConfigException -#include "mongo/s/writeback_listener.h" #include "mongo/util/log.h" namespace mongo { @@ -118,8 +117,6 @@ namespace mongo { bool VersionManager::initShardVersionCB( DBClientBase * conn_in, BSONObj& result ){ - WriteBackListener::init( *conn_in ); - bool ok; DBClientBase* conn = NULL; try { @@ -205,8 +202,6 @@ namespace mongo { bool checkShardVersion( DBClientBase * conn_in , const string& ns , ChunkManagerPtr refManager, bool authoritative , int tryNumber ) { // TODO: cache, optimize, etc... - WriteBackListener::init( *conn_in ); - DBConfigPtr conf = grid.getDBConfig( ns ); if ( ! conf ) return false; diff --git a/src/mongo/s/writeback_listener.cpp b/src/mongo/s/writeback_listener.cpp deleted file mode 100644 index 3dcb983bd45..00000000000 --- a/src/mongo/s/writeback_listener.cpp +++ /dev/null @@ -1,191 +0,0 @@ -// @file writeback_listener.cpp - -/** -* Copyright (C) 2010 10gen Inc. -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU Affero General Public License, version 3, -* as published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Affero General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* As a special exception, the copyright holders give permission to link the -* code of portions of this program with the OpenSSL library under certain -* conditions as described in each individual source file and distribute -* linked combinations including the program with the OpenSSL library. You -* must comply with the GNU Affero General Public License in all respects -* for all of the code used other than as permitted herein. If you modify -* file(s) with this exception, you may extend this exception to your -* version of the file(s), but you are not obligated to do so. If you do not -* wish to do so, delete this exception statement from your version. If you -* delete this exception statement from all source files in the program, -* then also delete it in the license file. -*/ - -#include "mongo/platform/basic.h" - -#include "writeback_listener.h" - -#include "mongo/db/auth/authorization_manager.h" -#include "mongo/db/auth/authorization_session.h" -#include "mongo/s/chunk_version.h" -#include "mongo/s/client_info.h" -#include "mongo/s/config.h" -#include "mongo/s/grid.h" -#include "mongo/s/request.h" -#include "mongo/s/server.h" -#include "mongo/s/shard.h" -#include "mongo/s/version_manager.h" -#include "mongo/util/log.h" -#include "mongo/util/timer.h" - -namespace mongo { - - MONGO_LOG_DEFAULT_COMPONENT_FILE(::mongo::logger::LogComponent::kSharding); - - unordered_map<string,WriteBackListener*> WriteBackListener::_cache; - unordered_set<string> WriteBackListener::_seenSets; - mongo::mutex WriteBackListener::_cacheLock("WriteBackListener"); - - WriteBackListener::WriteBackListener( const string& addr ) : _addr( addr ) { - _name = str::stream() << "WriteBackListener-" << addr; - log() << "creating WriteBackListener for: " << addr << " serverID: " << serverID << endl; - } - - /* static */ - void WriteBackListener::init( DBClientBase& conn ) { - - if ( conn.type() == ConnectionString::SYNC ) { - // don't want write back listeners for config servers - return; - } - - if ( conn.type() != ConnectionString::SET ) { - init( conn.getServerAddress() ); - return; - } - - const string addr = conn.getServerAddress(); - - { - scoped_lock lk( _cacheLock ); - if ( _seenSets.count( addr ) ) { - return; - } - } - // we want to do writebacks on all rs nodes - string errmsg; - ConnectionString cs = ConnectionString::parse( conn.getServerAddress() , errmsg ); - uassert( 13641 , str::stream() << "can't parse host [" << conn.getServerAddress() << "]" , cs.isValid() ); - - vector<HostAndPort> hosts = cs.getServers(); - - for ( unsigned i=0; i<hosts.size(); i++ ) - init( hosts[i].toString() ); - - scoped_lock lk( _cacheLock ); - _seenSets.insert( addr ); - - } - - /* static */ - void WriteBackListener::init( const string& host ) { - scoped_lock lk( _cacheLock ); - WriteBackListener*& l = _cache[host]; - if ( l ) - return; - l = new WriteBackListener( host ); - l->go(); - } - - void WriteBackListener::run() { - - int secsToSleep = 0; - bool needsToReloadShardInfo = false; - - while ( ! inShutdown() ) { - - if ( ! Shard::isAShardNode( _addr ) ) { - LOG(1) << _addr << " is not a shard node" << endl; - sleepsecs( 60 ); - continue; - } - - try { - if (needsToReloadShardInfo) { - // It's possible this shard was removed - Shard::reloadShardInfo(); - needsToReloadShardInfo = false; - } - - ScopedDbConnection conn(_addr); - - BSONObj result; - - { - BSONObjBuilder cmd; - cmd.appendOID( "writebacklisten" , &serverID ); // Command will block for data - if ( ! conn->runCommand( "admin" , cmd.obj() , result ) ) { - result = result.getOwned(); - log() << "writebacklisten command failed! " << result << endl; - conn.done(); - continue; - } - - } - conn.done(); - - LOG(1) << "writebacklisten result from pre-2.6 server: " << result << endl; - - BSONObj data = result.getObjectField( "data" ); - if ( data.getBoolField( "writeBack" ) ) { - string ns = data["ns"].valuestrsafe(); - - int len; // not used, but needed for next call - Message msg( (void*)data["msg"].binData( len ) , false ); - - if ( !msg.header()->valid() ) { - warning() << "invalid writeback message detected: " << result << endl; - } - } - else if ( result["noop"].trueValue() ) { - // no-op - } - else { - log() << "unknown writeBack result: " << result << endl; - } - - secsToSleep = 0; - continue; - } - catch ( std::exception& e ) { - // Attention! Do not call any method that would throw an exception - // (or assert) in this block. - - if ( inShutdown() ) { - // we're shutting down, so just clean up - return; - } - - log() << "WriteBackListener exception : " << e.what() << endl; - } - catch ( ... ) { - log() << "WriteBackListener uncaught exception!" << endl; - } - secsToSleep++; - sleepsecs(secsToSleep); - if ( secsToSleep > 10 ) - secsToSleep = 0; - } - - log() << "WriteBackListener exiting : address no longer in cluster " << _addr; - - } - -} // namespace mongo diff --git a/src/mongo/s/writeback_listener.h b/src/mongo/s/writeback_listener.h deleted file mode 100644 index 0d45ca7fb17..00000000000 --- a/src/mongo/s/writeback_listener.h +++ /dev/null @@ -1,73 +0,0 @@ -// @file writeback_listener.h - -/** -* Copyright (C) 2010 10gen Inc. -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU Affero General Public License, version 3, -* as published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Affero General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* As a special exception, the copyright holders give permission to link the -* code of portions of this program with the OpenSSL library under certain -* conditions as described in each individual source file and distribute -* linked combinations including the program with the OpenSSL library. You -* must comply with the GNU Affero General Public License in all respects -* for all of the code used other than as permitted herein. If you modify -* file(s) with this exception, you may extend this exception to your -* version of the file(s), but you are not obligated to do so. If you do not -* wish to do so, delete this exception statement from your version. If you -* delete this exception statement from all source files in the program, -* then also delete it in the license file. -*/ - -#pragma once - -#include "mongo/pch.h" - -#include "mongo/client/connpool.h" -#include "mongo/db/client.h" -#include "mongo/platform/unordered_map.h" -#include "mongo/platform/unordered_set.h" -#include "mongo/util/background.h" - -namespace mongo { - - /* - * The writeback listener takes back write attempts that were made against a wrong shard. - * (Wrong here in the sense that the target chunk moved before this mongos had a chance to - * learn so.) It is responsible for reapplying these writes to the correct shard. - * - * Runs (instantiated) on mongos. - * Currently, there is one writebacklistener per shard. - */ - class WriteBackListener : public BackgroundJob { - public: - - static void init( DBClientBase& conn ); - static void init( const std::string& host ); - - protected: - WriteBackListener( const std::string& addr ); - - std::string name() const { return _name; } - void run(); - - private: - std::string _addr; - std::string _name; - - static mongo::mutex _cacheLock; // protects _cache - static unordered_map<std::string,WriteBackListener*> _cache; // server to listener - static unordered_set<std::string> _seenSets; // cache of set urls we've seen - note this is ever expanding for order, case, changes - - }; - -} // namespace mongo |