Skip to content

Commit

Permalink
fixed log replay
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Andreev committed Apr 28, 2008
1 parent e9a684c commit 4014779
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/strokedb/volumes/skiplist_volume.rb
Expand Up @@ -87,7 +87,7 @@ def error(*args); end
if File.exists?(@list_path)
@list = SimpleSkiplist.load(File.read(@list_path))
else
info "List file (#{@list_path}) not found, creating a brand new skiplist."
info "List file (#{@list_path}) was not found, creating a brand new skiplist."
@list = SimpleSkiplist.new(@params)
end

Expand Down Expand Up @@ -132,6 +132,8 @@ def insert(key, value, __level = nil)
# Read-only access remains.
def close!
dump!
@log_file.close
File.delete(@log_file.path)
self
class <<self
alias :insert :raise_volume_closed
Expand Down Expand Up @@ -194,24 +196,25 @@ def replay_log!(log_path, list)
nf = N_F
max_msg_length = MAX_LOG_MSG_LENGTH
checksum_length = CHECKSUM_LENGTH
msg_range = (0..-(1 + checksum_length))

@log_bytes = 0

File.open(@log_path, "r") do |f|
msg_length = f.read(4).unpack(nf).first rescue nil
(!msg_length || msg_length > max_msg_length) and raise LogFormatError, "Wrong WAL message length prefix!"
until f.eof?
msg_length = f.read(4).unpack(nf).first rescue nil
(!msg_length || msg_length > max_msg_length) and raise LogFormatError, "Wrong WAL message length prefix!"

msg_chk = f.read(msg_length + checksum_length)
msg = msg_chk[0, msg_length]
msg_chk = f.read(msg_length + checksum_length)
msg = msg_chk[0, msg_length]

@log_bytes += 4 + msg_length + checksum_length
@log_bytes += 4 + msg_length + checksum_length

checksum_invalid(msg, msg_chk[msg_range]) and raise LogFormatError, "WAL message checksum failure!"
checksum_invalid(msg, msg_chk[msg_length, checksum_length]) and raise LogFormatError, "WAL message checksum failure!"

key, value, level = Marshal.load(msg)
key, value, level = Marshal.load(msg)

list.insert(key, value, level)
list.insert(key, value, level)
end
end

# Log is malformed. This can happen in two situations:
Expand Down

0 comments on commit 4014779

Please sign in to comment.