def _should_pause_write(collection_name, query): realm = _get_realm_for_collection(collection_name) shard_key = _get_query_target(collection_name, query) if shard_key: meta = _get_metadata_for_shard(realm, shard_key) return \ meta['status'] == ShardStatus.POST_MIGRATION_PAUSED_AT_DESTINATION else: paused_query = { 'realm': realm['name'], 'status': ShardStatus.POST_MIGRATION_PAUSED_AT_DESTINATION } shards_coll = _get_shards_coll() return shards_coll.find(paused_query).count() > 0
def _should_pause_write(collection_name, query): realm = _get_realm_for_collection(collection_name) shard_key = _get_query_target(collection_name, query) if shard_key: meta = _get_metadata_for_shard(realm, shard_key) return \ meta['status'] == ShardStatus.POST_MIGRATION_PAUSED_AT_DESTINATION else: paused_query = { 'realm': realm['name'], 'status': ShardStatus.POST_MIGRATION_PAUSED_AT_DESTINATION } shards_coll = _get_shards_coll() return shards_coll.find(paused_query).count() > 0
def test_get_location_ordering(self): # Exposes a bug that was found in caching and default locations api.create_realm('dummy-realm', 'some_field', 'dummy_collection', 'cluster-1/some_db') api.set_shard_at_rest('dummy-realm', 1, 'dest2/some_db') realm = metadata._get_realm_for_collection('dummy_collection') meta = metadata._get_metadata_for_shard(realm, 2) expected_meta = { 'status': metadata.ShardStatus.AT_REST, 'realm': 'dummy-realm', 'location': 'cluster-1/some_db' } self.assertEquals(meta, expected_meta) all_locations = metadata._get_all_locations_for_realm(realm) self.assertEquals([], all_locations['cluster-1/some_db'].contains) self.assertEquals([], all_locations['cluster-1/some_db'].excludes) self.assertEquals([1], all_locations['dest2/some_db'].contains) self.assertEquals([], all_locations['dest2/some_db'].excludes)
def test_get_location_ordering(self): # Exposes a bug that was found in caching and default locations api.create_realm( 'dummy-realm', 'some_field', 'dummy_collection', 'cluster-1/some_db') api.set_shard_at_rest('dummy-realm', 1, 'dest2/some_db') realm = metadata._get_realm_for_collection('dummy_collection') meta = metadata._get_metadata_for_shard(realm, 2) expected_meta = { 'status': metadata.ShardStatus.AT_REST, 'realm': 'dummy-realm', 'location': 'cluster-1/some_db' } self.assertEquals(meta, expected_meta) all_locations = metadata._get_all_locations_for_realm(realm) self.assertEquals([], all_locations['cluster-1/some_db'].contains) self.assertEquals([], all_locations['cluster-1/some_db'].excludes) self.assertEquals([1], all_locations['dest2/some_db'].contains) self.assertEquals([], all_locations['dest2/some_db'].excludes)