File: mongos_macros.rb

package info (click to toggle)
ruby-mongo 2.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,020 kB
  • sloc: ruby: 110,810; makefile: 5
file content (24 lines) | stat: -rw-r--r-- 713 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true
# rubocop:todo all

module MongosMacros

  class << self
    attr_accessor :distinct_ran
  end
  self.distinct_ran = {}

  # Work around for SERVER-39704 when seeing a Mongo::Error::OperationFailure
  # SnapshotUnavailable error -- run the distinct command on each mongos.
  def run_mongos_distincts(db_name, collection='test')
    MongosMacros.distinct_ran[db_name] ||= ::Utils.mongos_each_direct_client do |direct_client|
      direct_client.use(db_name)[collection].distinct('foo').to_a
    end
  end

  def maybe_run_mongos_distincts(db_name, collection='test')
    if ClusterConfig.instance.topology == :sharded
      run_mongos_distincts(db_name, collection)
    end
  end
end