Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Commit

Permalink
Handle operations of type n and r, as well as long fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl-Aksel Puulmann committed Aug 26, 2014
1 parent b590765 commit 9f716ac
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions lib/mongoriver/toku.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,42 @@ def self.conversion_needed(conn)
conn.server_info.has_key? "tokumxVersion"
end

def operations_for(record, conn=nil)
if record["ops"]
return record["ops"]
end
# TODO: does this need to be sorted by seq?
refs = conn.db('local').collection('oplog.refs').find({"_id.oid" => ref})
refs.map { |r| r["ops"] }.flatten
end

# TODO: query for latest, planner for latest

# 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)
# 2) h fields (unique ids) will also not be unique on multi-updates
# 3) operations marked by 'n' toku are ignored, as these do <TODO: explain>
# @see http://www.tokutek.com/2014/03/comparing-a-tokumx-and-mongodb-oplog-entry/
# @returns Array<Hash> List of mongodb oplog records.
def self.convert(record)
# TODO: handle the case of long update with reference
# TODO: handle 'n' after you figure out what that is
# TODO: handle un-multi update
result = record["ops"].each do |operation|
result = nil
def self.convert(record, conn=nil)
result = []
operations_for(record, conn).each do |operation|
case operation["op"]
when 'i'
insert_record(operation, record)
when 'ur'
update_record(operation, record)
result << insert_record(operation, record)
when 'u', 'ur'
result << update_record(operation, record)
when 'c'
command_record(operation, record)
result << command_record(operation, record)
when 'd'
remove_record(operation, record)
result << remove_record(operation, record)
when 'n'
# keepOplogAlive requests - safe to ignore?
else
# ¯\_(ツ)_/¯
# u, n
raise "Unrecognized op: #{operation["op"]} (#{record.inspect})"
end
end
end
Expand Down

0 comments on commit 9f716ac

Please sign in to comment.