jstests/sharding/timeseries_shard_collection.js
// Simple shard key on the metadata field.
Simple shard key on the metadata field.
Simple shard key on the metadata field .
function metaShardKey(implicit) {
        if (!implicit) {
            assert.commandWorked(sDB.createCollection('ts', {timeseries}));
            assert.commandWorked(sDB.ts.createIndex({hostId: 1}));
            assert.commandFailedWithCode(st.s.adminCommand({
                shardCollection: 'test.ts',
                key: {'hostId': 1},
                timeseries: {timeField: 'time'},
            }),
                                         5731500);
        }
        assert.commandWorked(
            st.s.adminCommand({shardCollection: 'test.ts', key: {'hostId': 1}, timeseries}));
        validateBucketsCollectionSharded({collName: 'ts', shardKey: {meta: 1}, timeseries});
        validateViewCreated("ts");
        assert.commandWorked(
            st.s.adminCommand({split: 'test.system.buckets.ts', middle: {meta: 10}}));
        const primaryShard = st.getPrimaryShard(dbName);
        assert.commandWorked(st.s.adminCommand({
            movechunk: 'test.system.buckets.ts',
            find: {meta: 10},
            to: st.getOther(primaryShard).shardName,
            _waitForDelete: true,
        }));
        let counts = st.chunkCounts('system.buckets.ts', 'test');
        assert.eq(1, counts[st.shard0.shardName]);
        assert.eq(1, counts[st.shard1.shardName]);
        assert(sDB.ts.drop());
    }
function metaShardKey ( implicit ) { if ( ! implicit ) { assert . commandWorked ( sDB . createCollection ( 'ts' , { timeseries } ) ) ; assert . commandWorked ( sDB . ts . createIndex ( { hostId : 1 } ) ) ; assert . commandFailedWithCode ( st . s . adminCommand ( { shardCollection : 'test.ts' , key : { 'hostId' : 1 } , timeseries : { timeField : 'time' } , } ) , 5731500 ) ; } assert . commandWorked ( st . s . adminCommand ( { shardCollection : 'test.ts' , key : { 'hostId' : 1 } , timeseries } ) ) ; validateBucketsCollectionSharded ( { collName : 'ts' , shardKey : { meta : 1 } , timeseries } ) ; validateViewCreated ( "ts" ) ; assert . commandWorked ( st . s . adminCommand ( { split : 'test.system.buckets.ts' , middle : { meta : 10 } } ) ) ; const primaryShard = st . getPrimaryShard ( dbName ) ; assert . commandWorked ( st . s . adminCommand ( { movechunk : 'test.system.buckets.ts' , find : { meta : 10 } , to : st . getOther ( primaryShard ) . shardName , _waitForDelete : true , } ) ) ; let counts = st . chunkCounts ( 'system.buckets.ts' , 'test' ) ; assert . eq ( 1 , counts [ st . shard0 . shardName ] ) ; assert . eq ( 1 , counts [ st . shard1 . shardName ] ) ; assert ( sDB . ts . drop ( ) ) ; }
Simple shard key on the metadata field.
Simple shard key on the metadata field .
// Command should fail since the 'timeseries' specification does not match that existing // collection. // This index gets created as {meta: 1} on the buckets collection.