summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-07-16 12:28:26 -0400
committerEliot Horowitz <eliot@10gen.com>2010-07-16 12:28:26 -0400
commit4882710934ace38610e936792bbd638dea7c8e91 (patch)
tree3225e38cc488b6eabd549c4d4dee078fd34af7b7
parent8efb5918eba2f99e4e0f5d567e0afacabc8eed1d (diff)
downloadmongo-4882710934ace38610e936792bbd638dea7c8e91.tar.gz
move ShardChunkVersion to util.h
-rw-r--r--s/chunk.h73
-rw-r--r--s/util.h77
2 files changed, 78 insertions, 72 deletions
diff --git a/s/chunk.h b/s/chunk.h
index cb4650d8273..1e43a3ebc3c 100644
--- a/s/chunk.h
+++ b/s/chunk.h
@@ -30,6 +30,7 @@
#include "shardkey.h"
#include "shard.h"
#include "config.h"
+#include "util.h"
namespace mongo {
@@ -40,78 +41,6 @@ namespace mongo {
class ChunkRangeMangager;
class ChunkObjUnitTest;
- struct ShardChunkVersion {
- union {
- struct {
- int _minor;
- int _major;
- };
- unsigned long long _combined;
- };
-
- ShardChunkVersion( int major=0, int minor=0 )
- : _minor(minor),_major(major){
- }
-
- ShardChunkVersion( unsigned long long ll )
- : _combined( ll ){
- }
-
- ShardChunkVersion( const BSONElement& e ){
- if ( e.type() == Date || e.type() == Timestamp ){
- _combined = e._numberLong();
- }
- else if ( e.eoo() ){
- _combined = 0;
- }
- else {
- log() << "ShardChunkVersion can't handle type (" << (int)(e.type()) << ") " << e << endl;
- assert(0);
- }
- }
-
- ShardChunkVersion incMajor() const {
- return ShardChunkVersion( _major + 1 , 0 );
- }
-
- void operator++(){
- _minor++;
- }
-
- unsigned long long toLong() const {
- return _combined;
- }
-
- bool isSet() const {
- return _combined > 0;
- }
-
- string toString() const {
- stringstream ss;
- ss << _major << "|" << _minor;
- return ss.str();
- }
-
- operator unsigned long long() const { return _combined; }
- operator string() const { return toString(); }
-
- ShardChunkVersion& operator=( const BSONElement& elem ){
- switch ( elem.type() ){
- case Timestamp:
- case NumberLong:
- case Date:
- _combined = elem._numberLong();
- break;
- case EOO:
- _combined = 0;
- break;
- default:
- assert(0);
- }
- return *this;
- }
- };
-
typedef shared_ptr<Chunk> ChunkPtr;
// key is max for each Chunk or ChunkRange
diff --git a/s/util.h b/s/util.h
index 36c99622038..3b9d332c266 100644
--- a/s/util.h
+++ b/s/util.h
@@ -20,6 +20,7 @@
#include "../pch.h"
#include "../client/dbclient.h"
+#include "../db/jsobj.h"
/**
some generic sharding utils that can be used in mongod or mongos
@@ -27,6 +28,82 @@
namespace mongo {
+ struct ShardChunkVersion {
+ union {
+ struct {
+ int _minor;
+ int _major;
+ };
+ unsigned long long _combined;
+ };
+
+ ShardChunkVersion( int major=0, int minor=0 )
+ : _minor(minor),_major(major){
+ }
+
+ ShardChunkVersion( unsigned long long ll )
+ : _combined( ll ){
+ }
+
+ ShardChunkVersion( const BSONElement& e ){
+ if ( e.type() == Date || e.type() == Timestamp ){
+ _combined = e._numberLong();
+ }
+ else if ( e.eoo() ){
+ _combined = 0;
+ }
+ else {
+ log() << "ShardChunkVersion can't handle type (" << (int)(e.type()) << ") " << e << endl;
+ assert(0);
+ }
+ }
+
+ ShardChunkVersion incMajor() const {
+ return ShardChunkVersion( _major + 1 , 0 );
+ }
+
+ void operator++(){
+ _minor++;
+ }
+
+ unsigned long long toLong() const {
+ return _combined;
+ }
+
+ bool isSet() const {
+ return _combined > 0;
+ }
+
+ string toString() const {
+ stringstream ss;
+ ss << _major << "|" << _minor;
+ return ss.str();
+ }
+ operator unsigned long long() const { return _combined; }
+ operator string() const { return toString(); }
+
+ ShardChunkVersion& operator=( const BSONElement& elem ){
+ switch ( elem.type() ){
+ case Timestamp:
+ case NumberLong:
+ case Date:
+ _combined = elem._numberLong();
+ break;
+ case EOO:
+ _combined = 0;
+ break;
+ default:
+ assert(0);
+ }
+ return *this;
+ }
+ };
+
+ inline ostream& operator<<( ostream &s , const ShardChunkVersion& v){
+ s << v._major << "|" << v._minor;
+ return s;
+ }
+
/**
* your config info for a given shard/chunk is out of date
*/