From dfe0cff3084d638892f30d7a880c4fc9947d5f9f Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Fri, 27 Feb 2009 12:51:49 -0500 Subject: [PATCH] lastmod --- s/shard.cpp | 25 ++++++++++++++++++------- s/shard.h | 8 ++++++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/s/shard.cpp b/s/shard.cpp index 46dfbd5b9e5..0924cf6e5d3 100644 --- a/s/shard.cpp +++ b/s/shard.cpp @@ -32,7 +32,7 @@ namespace mongo { void Shard::setServer( string s ){ _server = s; - _modified = true; + _markModified(); } bool Shard::contains( const BSONObj& obj ){ @@ -54,9 +54,9 @@ namespace mongo { s->_min = m.getOwned(); s->_max = _max; - s->_modified = true; - _modified = true; - + s->_markModified(); + _markModified(); + _manager->_shards.push_back( s ); _max = m.getOwned(); @@ -74,19 +74,22 @@ namespace mongo { void Shard::getFilter( BSONObjBuilder& b ){ _manager->_key.getFilter( b , _min , _max ); } - + void Shard::serialize(BSONObjBuilder& to){ to << "ns" << _ns; to << "min" << _min; to << "max" << _max; to << "server" << _server; + if ( _lastmod ) + to.appendDate( "lastmod" , _lastmod ); } - + void Shard::unserialize(const BSONObj& from){ _ns = from.getStringField( "ns" ); _min = from.getObjectField( "min" ).getOwned(); _max = from.getObjectField( "max" ).getOwned(); _server = from.getStringField( "server" ); + _lastmod = from.hasField( "lastmod" ) ? from["lastmod"].date() : 0; uassert( "Shard needs a ns" , ! _ns.empty() ); uassert( "Shard needs a server" , ! _ns.empty() ); @@ -100,6 +103,14 @@ namespace mongo { return configServer.modelServer(); } + void Shard::_markModified(){ + _modified = true; + + unsigned long long t = time(0); + t *= 1000; + _lastmod = t; + } + string Shard::toString() const { stringstream ss; ss << "shard ns:" << _ns << " server: " << _server << " min: " << _min << " max: " << _max; @@ -127,7 +138,7 @@ namespace mongo { s->_min = _key.globalMin(); s->_max = _key.globalMax(); s->_server = config->getPrimary(); - s->_modified = true; + s->_markModified(); _shards.push_back( s ); diff --git a/s/shard.h b/s/shard.h index 09f12e8fb32..3b5a1343bcb 100644 --- a/s/shard.h +++ b/s/shard.h @@ -79,15 +79,19 @@ namespace mongo { Shard( ShardManager * info ); private: + + void _markModified(); + ShardManager * _manager; string _ns; BSONObj _min; BSONObj _max; string _server; - - bool _modified; + unsigned long long _lastmod; + bool _modified; + void _split( BSONObj& middle ); friend class ShardManager;