Module: Rubcask::Tombstone

Extended by:
Tombstone
Included in:
Tombstone
Defined in:
lib/rubcask/tombstone.rb

Overview

The prev_file_id is stored to support merge of subset of directory files, that is currently not implemented

Constant Summary collapse

PREFIX =
"TOMBSTONE".b
PREFIX_SIZE =
PREFIX.bytesize
FILE_ID_FORMAT =
"N"
FULL_BYTE_SIZE =
PREFIX_SIZE + 4

Instance Method Summary collapse

Instance Method Details

#is_tombstone?(value) ⇒ Boolean

Parameters:

  • value (String)

    value to check

Returns:

  • (Boolean)

    true if value is a tombstone

  • false otherwise



19
20
21
# File 'lib/rubcask/tombstone.rb', line 19

def is_tombstone?(value)
  value.bytesize <= FULL_BYTE_SIZE && value.start_with?(PREFIX)
end

#new_tombstone(current_file_id, prev_file_id) ⇒ String

Creates a new tombstone value

Parameters:

  • current_file_id (Integer)

    Id of the active file

  • prev_file_id (Integer)

    Id of the file where the record is currently located

Returns:

  • (String)


27
28
29
30
# File 'lib/rubcask/tombstone.rb', line 27

def new_tombstone(current_file_id, prev_file_id)
  return PREFIX if prev_file_id == current_file_id
  PREFIX.b << [prev_file_id].pack(FILE_ID_FORMAT)
end

#tombstone_file_id(value) ⇒ Integer?

Gets file id from tombstone value

Parameters:

  • value (String)

    Tombstone value

Returns:

  • (Integer, nil)


35
36
37
38
# File 'lib/rubcask/tombstone.rb', line 35

def tombstone_file_id(value)
  return nil if value.bytesize < FULL_BYTE_SIZE
  value.byteslice(PREFIX_SIZE, 4).unpack1(FILE_ID_FORMAT)
end