Class: Oplogreplayer::Replayer

Inherits:
Object
  • Object
show all
Defined in:
lib/oplogreplayer/replayer.rb

Class Method Summary collapse

Class Method Details

.m2m(options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/oplogreplayer/replayer.rb', line 10

def self.m2m(options)

  config = options[:config]
  timestamp = options[:timestamp]

  log = Log4r::Logger.new('Oplogreplayer::Replayer')
  log.outputters = Log4r::StdoutOutputter.new(STDERR)
  log.level = Log4r::INFO
  self.parseConfig(@_config, config)

  sourceConfig = @_config["source"]

  connect_uri = "mongodb://"
  connect_uri += "#{sourceConfig["username"]}:#{sourceConfig["password"]}@" if sourceConfig["username"] and sourceConfig["password"]
  connect_uri += "#{sourceConfig["host"]}"
  connect_uri += "?replicaSet=#{sourceConfig["replicaSet"]}"

  log.info("Setting up client for source")
  rsClient = Mongo::MongoReplicaSetClient.from_uri(connect_uri)

  log.info("Configuring tailer")
  tailer = Mongoriver::Tailer.new([rsClient], :existing)

  log.info("Creating mongo2mongo bridge")
  bridge = Oplogreplayer::Mongobridge.new(@_config["dest"])

  log.info("Creating a stream between tailer and bridge")
  stream = Mongoriver::Stream.new(tailer, bridge)

  # If a timestamp is supplied as an argument, override.
  if timestamp
    log.info("Replaying. Timestamp provided, overriding and starting at #{timestamp}")
    stream.run_forever(timestamp)
  elsif @_config["resume"]
    log.info("Replaying. No timestamp provided but resume is enabled, will resume based on target's last timestamp")
    # otherwise, try and resume.
    # We need persistence of the oplog. Not sure whether to use local fs or destination mongo
    # destination mongo seems better suited though. I'm going to use the local db for now.
    stream.run_forever(bridge.getOplogTimestamp)
  else
    # No timestamp and no resume.... we're doing a full replay.
    log.info("Replaying. No resume and no timestamp - full oplog replay.")
    stream.run_forever()
  end
end

.parseConfig(target, configFile) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/oplogreplayer/replayer.rb', line 56

def self.parseConfig(target, configFile)
  if ! ::File.exists?(configFile)
    raise NoConfigFileError, "Config file not found: #{configFile}"
  end

  conf = YAML::load_file(configFile)
  target.merge! conf
end

.setupLoggingObject



65
66
67
# File 'lib/oplogreplayer/replayer.rb', line 65

def self.setupLogging()

end