diff options
author | Greg Studer <greg@10gen.com> | 2013-07-24 16:01:49 -0400 |
---|---|---|
committer | Greg Studer <greg@10gen.com> | 2013-08-06 09:01:52 -0400 |
commit | 3bbe57a1e825a98a0c6e2601ac87978f02faecd6 (patch) | |
tree | c0518aaf1415ccc2564122df9d4a2567bf09a757 /src/mongo/s/collection_metadata_test.cpp | |
parent | 85e79d7ad2db6fa0607957cac536d20a3738f6a5 (diff) | |
download | mongo-3bbe57a1e825a98a0c6e2601ac87978f02faecd6.tar.gz |
SERVER-8598 command to iteratively cleanup orphaned data
Diffstat (limited to 'src/mongo/s/collection_metadata_test.cpp')
-rw-r--r-- | src/mongo/s/collection_metadata_test.cpp | 128 |
1 files changed, 126 insertions, 2 deletions
diff --git a/src/mongo/s/collection_metadata_test.cpp b/src/mongo/s/collection_metadata_test.cpp index 00b8715d995..0cd7a6bd99d 100644 --- a/src/mongo/s/collection_metadata_test.cpp +++ b/src/mongo/s/collection_metadata_test.cpp @@ -24,6 +24,7 @@ #include "mongo/s/chunk_version.h" #include "mongo/s/collection_metadata.h" #include "mongo/s/metadata_loader.h" +#include "mongo/s/range_arithmetic.h" #include "mongo/s/type_chunk.h" #include "mongo/s/type_collection.h" #include "mongo/unittest/unittest.h" @@ -40,6 +41,7 @@ namespace { using mongo::CollectionType; using mongo::Date_t; using mongo::HostAndPort; + using mongo::KeyRange; using mongo::MAXKEY; using mongo::MetadataLoader; using mongo::MINKEY; @@ -47,7 +49,10 @@ namespace { using mongo::ChunkVersion; using mongo::MockConnRegistry; using mongo::MockRemoteDBServer; + using mongo::RangeVector; using mongo::Status; + using std::auto_ptr; + using std::make_pair; using std::string; using std::vector; @@ -380,6 +385,69 @@ namespace { ASSERT( cloned == NULL ); } + TEST_F(NoChunkFixture, OrphanedDataRangeBegin) { + + const CollectionMetadata& metadata = getCollMetadata(); + + KeyRange keyRange; + BSONObj lookupKey = metadata.getMinKey(); + ASSERT( metadata.getNextOrphanRange( lookupKey, &keyRange ) ); + + ASSERT( keyRange.minKey.woCompare( metadata.getMinKey() ) == 0 ); + ASSERT( keyRange.maxKey.woCompare( metadata.getMaxKey() ) == 0 ); + + // Make sure we don't have any more ranges + ASSERT( !metadata.getNextOrphanRange( keyRange.maxKey, &keyRange ) ); + } + + TEST_F(NoChunkFixture, OrphanedDataRangeMiddle) { + + const CollectionMetadata& metadata = getCollMetadata(); + + KeyRange keyRange; + BSONObj lookupKey = BSON( "a" << 20 ); + ASSERT( metadata.getNextOrphanRange( lookupKey, &keyRange ) ); + + ASSERT( keyRange.minKey.woCompare( metadata.getMinKey() ) == 0 ); + ASSERT( keyRange.maxKey.woCompare( metadata.getMaxKey() ) == 0 ); + + // Make sure we don't have any more ranges + ASSERT( !metadata.getNextOrphanRange( keyRange.maxKey, &keyRange ) ); + } + + TEST_F(NoChunkFixture, OrphanedDataRangeEnd) { + + const CollectionMetadata& metadata = getCollMetadata(); + + KeyRange keyRange; + ASSERT( !metadata.getNextOrphanRange( metadata.getMaxKey(), &keyRange ) ); + } + + TEST_F(NoChunkFixture, PendingOrphanedDataRanges) { + + string errMsg; + ChunkType chunk; + scoped_ptr<CollectionMetadata> cloned; + + chunk.setMin( BSON("a" << 10) ); + chunk.setMax( BSON("a" << 20) ); + + cloned.reset( getCollMetadata().clonePlusPending( chunk, &errMsg ) ); + ASSERT_EQUALS( errMsg, string("") ); + ASSERT( cloned != NULL ); + + KeyRange keyRange; + ASSERT( cloned->getNextOrphanRange( cloned->getMinKey(), &keyRange ) ); + ASSERT( keyRange.minKey.woCompare( cloned->getMinKey() ) == 0 ); + ASSERT( keyRange.maxKey.woCompare( BSON( "a" << 10 ) ) == 0 ); + + ASSERT( cloned->getNextOrphanRange( keyRange.maxKey, &keyRange ) ); + ASSERT( keyRange.minKey.woCompare( BSON( "a" << 20 ) ) == 0 ); + ASSERT( keyRange.maxKey.woCompare( cloned->getMaxKey() ) == 0 ); + + ASSERT( !cloned->getNextOrphanRange( keyRange.maxKey, &keyRange ) ); + } + /** * Fixture with single chunk containing: * [10->20) @@ -604,6 +672,7 @@ namespace { ASSERT( !cloned->keyIsPending(BSON( "a" << 35 )) ); } + TEST_F(SingleChunkFixture, MergeChunkSingle) { string errMsg; @@ -618,6 +687,20 @@ namespace { ASSERT( cloned == NULL ); } + TEST_F(SingleChunkFixture, ChunkOrphanedDataRanges) { + + KeyRange keyRange; + ASSERT( getCollMetadata().getNextOrphanRange( getCollMetadata().getMinKey(), &keyRange ) ); + ASSERT( keyRange.minKey.woCompare( getCollMetadata().getMinKey() ) == 0 ); + ASSERT( keyRange.maxKey.woCompare( BSON( "a" << 10 ) ) == 0 ); + + ASSERT( getCollMetadata().getNextOrphanRange( keyRange.maxKey, &keyRange ) ); + ASSERT( keyRange.minKey.woCompare( BSON( "a" << 20 ) ) == 0 ); + ASSERT( keyRange.maxKey.woCompare( getCollMetadata().getMaxKey() ) == 0 ); + + ASSERT( !getCollMetadata().getNextOrphanRange( keyRange.maxKey, &keyRange ) ); + } + /** * Fixture with single chunk containing: * [(min, min)->(max, max)) @@ -900,6 +983,49 @@ namespace { ASSERT_EQUALS( 2u, getCollMetadata().getNumChunks() ); } + TEST_F(TwoChunksWithGapCompoundKeyFixture, ChunkGapOrphanedDataRanges) { + + KeyRange keyRange; + ASSERT( getCollMetadata().getNextOrphanRange( getCollMetadata().getMinKey(), &keyRange ) ); + ASSERT( keyRange.minKey.woCompare( getCollMetadata().getMinKey() ) == 0 ); + ASSERT( keyRange.maxKey.woCompare( BSON( "a" << 10 << "b" << 0 ) ) == 0 ); + + ASSERT( getCollMetadata().getNextOrphanRange( keyRange.maxKey, &keyRange ) ); + ASSERT( keyRange.minKey.woCompare( BSON( "a" << 20 << "b" << 0 ) ) == 0 ); + ASSERT( keyRange.maxKey.woCompare( BSON( "a" << 30 << "b" << 0 ) ) == 0 ); + + ASSERT( getCollMetadata().getNextOrphanRange( keyRange.maxKey, &keyRange ) ); + ASSERT( keyRange.minKey.woCompare( BSON( "a" << 40 << "b" << 0 ) ) == 0 ); + ASSERT( keyRange.maxKey.woCompare( getCollMetadata().getMaxKey() ) == 0 ); + + ASSERT( !getCollMetadata().getNextOrphanRange( keyRange.maxKey, &keyRange ) ); + } + + TEST_F(TwoChunksWithGapCompoundKeyFixture, ChunkGapAndPendingOrphanedDataRanges) { + + string errMsg; + ChunkType chunk; + scoped_ptr<CollectionMetadata> cloned; + + chunk.setMin( BSON( "a" << 20 << "b" << 0 ) ); + chunk.setMax( BSON( "a" << 30 << "b" << 0 ) ); + + cloned.reset( getCollMetadata().clonePlusPending( chunk, &errMsg ) ); + ASSERT_EQUALS( errMsg, string("") ); + ASSERT( cloned != NULL ); + + KeyRange keyRange; + ASSERT( cloned->getNextOrphanRange( cloned->getMinKey(), &keyRange ) ); + ASSERT( keyRange.minKey.woCompare( cloned->getMinKey() ) == 0 ); + ASSERT( keyRange.maxKey.woCompare( BSON( "a" << 10 << "b" << 0 ) ) == 0 ); + + ASSERT( cloned->getNextOrphanRange( keyRange.maxKey, &keyRange ) ); + ASSERT( keyRange.minKey.woCompare( BSON( "a" << 40 << "b" << 0 ) ) == 0 ); + ASSERT( keyRange.maxKey.woCompare( cloned->getMaxKey() ) == 0 ); + + ASSERT( !cloned->getNextOrphanRange( keyRange.maxKey, &keyRange ) ); + } + /** * Fixture with chunk containing: * [min->10) , [10->20) , <gap> , [30->max) @@ -1154,6 +1280,4 @@ namespace { ASSERT_EQUALS( cloned->getShardVersion().majorVersion(), 6 ); } - - } // unnamed namespace |