jstests/sharding/timeseries_update.js
/**
 * Wrapper on testShardedUpdate to compose tests with a given shardKey/timeseries combo.
 */
Wrapper on testShardedUpdate to compose tests with a given shardKey/timeseries combo.
Wrapper on testShardedUpdate to compose tests with a given shardKey / timeseries combo .
function testUpdates({shardKeyTimeField, shardKeyMetaFieldPath, timeseriesOptions, tests}) {
    let shardKey = {};
    if (shardKeyMetaFieldPath) {
        shardKey[shardKeyMetaFieldPath] = 1;
    }
    if (shardKeyTimeField) {
        shardKey[shardKeyTimeField] = 1;
    }
    TimeseriesTest.run((insert) => {
        const checkUpdatesMetaFieldInShardKey = (pathToMetaFieldBeingUpdated) => {
            if ((pathToMetaFieldBeingUpdated === undefined) || !shardKeyMetaFieldPath) {
                return false;
            } else if ((shardKeyMetaFieldPath === metaField) ||
                       (pathToMetaFieldBeingUpdated === "")) {
                return true;
            } else if (!Array.isArray(pathToMetaFieldBeingUpdated)) {
                pathToMetaFieldBeingUpdated = [pathToMetaFieldBeingUpdated];
            }
            for (const e of pathToMetaFieldBeingUpdated) {
                if (metaField + "." + e === shardKeyMetaFieldPath) {
                    return true;
                }
            }
            return false;
        };
        const testUpdate = (fields, additionalFields = {}) => {
            let inputs = Object.assign({}, fields, additionalFields);
            testShardedUpdate(Object.assign({}, inputs, {
                shardKey,
                insert,
                timeseries: timeseriesOptions,
                updatesMetaFieldInShardKey:
                    checkUpdatesMetaFieldInShardKey(inputs.pathToMetaFieldBeingUpdated)
            }));
        };
        tests.forEach(test => test({testUpdate}));
    }, testDB);
}
function testUpdates ( { shardKeyTimeField , shardKeyMetaFieldPath , timeseriesOptions , tests } ) { let shardKey = { } ; if ( shardKeyMetaFieldPath ) { shardKey [ shardKeyMetaFieldPath ] = 1 ; } if ( shardKeyTimeField ) { shardKey [ shardKeyTimeField ] = 1 ; } TimeseriesTest . run ( ( insert ) => { const checkUpdatesMetaFieldInShardKey = ( pathToMetaFieldBeingUpdated ) => { if ( ( pathToMetaFieldBeingUpdated === undefined ) || ! shardKeyMetaFieldPath ) { return false ; } else if ( ( shardKeyMetaFieldPath === metaField ) || ( pathToMetaFieldBeingUpdated === "" ) ) { return true ; } else if ( ! Array . isArray ( pathToMetaFieldBeingUpdated ) ) { pathToMetaFieldBeingUpdated = [ pathToMetaFieldBeingUpdated ] ; } for ( const e of pathToMetaFieldBeingUpdated ) { if ( metaField + "." + e === shardKeyMetaFieldPath ) { return true ; } } return false ; } ; const testUpdate = ( fields , additionalFields = { } ) => { let inputs = Object . assign ( { } , fields , additionalFields ) ; testShardedUpdate ( Object . assign ( { } , inputs , { shardKey , insert , timeseries : timeseriesOptions , updatesMetaFieldInShardKey : checkUpdatesMetaFieldInShardKey ( inputs . pathToMetaFieldBeingUpdated ) } ) ) ; } ; tests . forEach ( test => test ( { testUpdate } ) ) ; } , testDB ) ; }
Wrapper on testShardedUpdate to compose tests with a given shardKey/timeseries combo.
Wrapper on testShardedUpdate to compose tests with a given shardKey / timeseries combo .
// Set up the shard key for the tests. // Run a series of updates. // Helper lambda which has the extensions field set to: // - undefined if we are updating the meta field. // - the name of a subfield of meta we are updating. // - an array of names of subfields of meta we are updating. // If we do not have the meta field in the shard key, we are able to update it. // If the top-level meta field is in the shard key, we cannot update it.