Class: Mongoriver::Toku

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoriver/toku.rb

Overview

This module deals with converting TokuMX oplog records into mongodb oplogs.

Class Method Summary collapse

Class Method Details

.conversion_needed?(conn) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/mongoriver/toku.rb', line 6

def self.conversion_needed?(conn)
  conn.server_info.has_key? "tokumxVersion"
end

.convert(record, conn = nil) ⇒ Object

Convert hash representing a tokumx oplog record to mongodb oplog records.

Things to note:

1) Unlike mongo oplog, the timestamps will not be monotonically
   increasing
2) h fields (unique ids) will also not be unique on multi-updates
3) operations marked by 'n' toku are ignored, as these are non-ops


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mongoriver/toku.rb', line 30

def self.convert(record, conn=nil)
  result = []
  operations_for(record, conn).each do |operation|
    case operation["op"]
    when 'i'
      result << insert_record(operation, record)
    when 'ur'
      result << update_record(operation, record, true)
    when 'u'
      result << update_record(operation, record, false)
    when 'c'
      result << command_record(operation, record)
    when 'd'
      result << remove_record(operation, record)
    when 'n'
      # keepOplogAlive requests - safe to ignore
    else
      raise "Unrecognized op: #{operation["op"]} (#{record.inspect})"
    end
  end

  result
end

.operations_for(record, conn = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/mongoriver/toku.rb', line 10

def self.operations_for(record, conn=nil)
  if record["ops"]
    return record["ops"]
  end
  refs_coll = conn.db('local').collection('oplog.refs')
  mongo_opts = {:sort => [['seq', 1]]}

  refs = refs_coll.find({"_id.oid" => record['ref']}, mongo_opts).to_a
  refs.map { |r| r["ops"] }.flatten
end