~ubuntu-branches/ubuntu/utopic/mongodb/utopic

« back to all changes in this revision

Viewing changes to jstests/sharding/cleanup_orphaned_cmd_hashed.js

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-07-03 09:23:46 UTC
  • mfrom: (1.3.10) (44.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20140703092346-c5bvt46wnzougyly
Tags: 1:2.6.3-0ubuntu1
* New upstream stable release:
  - Dropped patches, included upstream:
    + 0003-All-platforms-but-Windows-find-hash-in-std-tr1.patch
    + 0008-Use-system-libstemmer.patch
    + 0011-Use-a-signed-char-to-store-BSONType-enumerations.patch
    + 0001-SERVER-12064-Atomic-operations-for-gcc-non-Intel-arc.patch
    + 0002-SERVER-12065-Support-ARM-and-AArch64-builds.patch
  - d/p/*: Refreshed/rebased remaining patches.
  - Use system provided libyaml-cpp:
    + d/control: Add libyaml-cpp-dev to BD's.
    + d/rules: Enable --with-system-yaml option.
    + d/p/fix-yaml-detection.patch: Fix detection of libyaml-cpp library.
  - d/mongodb-server.mongodb.upstart: Sync changes from upstream.
  - d/control,mongodb-dev.*: Drop mongodb-dev package; it has no reverse
    dependencies and upstream no longer install header files.
  - d/NEWS: Point users to upstream upgrade documentation for upgrades
    from 2.4 to 2.6.
* Merge from Debian unstable.
* d/control: BD on libv8-3.14-dev to ensure that transitioning to new v8
  versions is a explicit action due to changes in behaviour in >= 3.25
  (LP: #1295723).
* d/mongodb-server.prerm: Dropped debug echo call from maintainer script
  (LP: #1294455).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Tests cleanup of orphaned data in hashed sharded coll via the orphaned data cleanup command
 
3
//
 
4
 
 
5
var options = { separateConfig : true, shardOptions : { verbose : 2 } };
 
6
 
 
7
var st = new ShardingTest({ shards : 2, mongos : 1, other : options });
 
8
st.stopBalancer();
 
9
 
 
10
var mongos = st.s0;
 
11
var admin = mongos.getDB( "admin" );
 
12
var shards = mongos.getCollection( "config.shards" ).find().toArray();
 
13
var coll = mongos.getCollection( "foo.bar" );
 
14
 
 
15
assert( admin.runCommand({ enableSharding : coll.getDB() + "" }).ok );
 
16
printjson( admin.runCommand({ movePrimary : coll.getDB() + "", to : shards[0]._id }) );
 
17
assert( admin.runCommand({ shardCollection : coll + "", key : { _id : "hashed" } }).ok );
 
18
 
 
19
// Create two orphaned data holes, one bounded by min or max on each shard
 
20
 
 
21
assert( admin.runCommand({ split : coll + "", middle : { _id : NumberLong(-100) } }).ok );
 
22
assert( admin.runCommand({ split : coll + "", middle : { _id : NumberLong(-50) } }).ok );
 
23
assert( admin.runCommand({ split : coll + "", middle : { _id : NumberLong(50) } }).ok );
 
24
assert( admin.runCommand({ split : coll + "", middle : { _id : NumberLong(100) } }).ok );
 
25
assert( admin.runCommand({ moveChunk : coll + "", bounds : [{ _id : NumberLong(-100) },
 
26
                                                            { _id : NumberLong(-50) }],
 
27
                                                  to : shards[1]._id,
 
28
                                                  _waitForDelete : true }).ok );
 
29
assert( admin.runCommand({ moveChunk : coll + "", bounds : [{ _id : NumberLong(50) },
 
30
                                                            { _id : NumberLong(100) }],
 
31
                                                  to : shards[0]._id,
 
32
                                                  _waitForDelete : true }).ok );
 
33
st.printShardingStatus();
 
34
 
 
35
jsTest.log( "Inserting some docs on each shard, so 1/2 will be orphaned..." );
 
36
 
 
37
for ( var s = 0; s < 2; s++ ) {
 
38
    var shardColl = ( s == 0 ? st.shard0 : st.shard1 ).getCollection( coll + "" );
 
39
    for ( var i = 0; i < 100; i++ ) shardColl.insert({ _id : i });
 
40
    assert.eq( null, shardColl.getDB().getLastError() );
 
41
}
 
42
 
 
43
assert.eq( 200, st.shard0.getCollection( coll + "" ).find().itcount() +
 
44
                st.shard1.getCollection( coll + "" ).find().itcount() );
 
45
assert.eq( 100, coll.find().itcount() );
 
46
 
 
47
jsTest.log( "Cleaning up orphaned data in hashed coll..." );
 
48
 
 
49
for ( var s = 0; s < 2; s++ ) {
 
50
    var shardAdmin = ( s == 0 ? st.shard0 : st.shard1 ).getDB( "admin" );
 
51
 
 
52
    var result = shardAdmin.runCommand({ cleanupOrphaned : coll + "" });
 
53
    while ( result.ok && result.stoppedAtKey ) {
 
54
        printjson( result );
 
55
        result = shardAdmin.runCommand({ cleanupOrphaned : coll + "",
 
56
                                         startingFromKey : result.stoppedAtKey });
 
57
    }
 
58
    
 
59
    printjson( result );
 
60
    assert( result.ok );
 
61
}
 
62
 
 
63
assert.eq( 100, st.shard0.getCollection( coll + "" ).find().itcount() +
 
64
                st.shard1.getCollection( coll + "" ).find().itcount() );
 
65
assert.eq( 100, coll.find().itcount() );
 
66
 
 
67
jsTest.log( "DONE!" );
 
68
 
 
69
st.stop();