Class: StrokeDB::DistributedPointer

Inherits:
Object
  • Object
show all
Defined in:
lib/strokedb/volumes/distributed_pointer.rb

Overview

DP is for pointing to DataVolume item. It can address zillions of DataVolumes, 4 GB each.

DP is stored as a 160 bit bytestring. First 128 bits is a volume UUID. Next 32 bits is an offset in a volume (unsigned long). Hence, the limit for DataVolume size: max 4 Gb. Actually, real-world applications would have relatively small datavolumes (about 64 Mb).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid, offset) ⇒ DistributedPointer

Initialize pointer with given components.

  • uuid UUID (either raw or formatted)

  • offset is a positive integer



16
17
18
19
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 16

def initialize(uuid, offset)
  @volume_uuid = uuid.to_raw_uuid
  @offset      = offset
end

Instance Attribute Details

#offsetObject

Returns the value of attribute offset.



10
11
12
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 10

def offset
  @offset
end

#volume_uuidObject

Returns the value of attribute volume_uuid.



10
11
12
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 10

def volume_uuid
  @volume_uuid
end

Class Method Details

.pack(uuid, offset) ⇒ Object



33
34
35
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 33

def self.pack(uuid,offset)
  uuid.to_raw_uuid + [offset].pack("L")
end

.unpack(string160bit) ⇒ Object

Creates a pointer object using binary string.



23
24
25
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 23

def self.unpack(string160bit)
  new(string160bit[0, 16], string160bit[16, 4].unpack("L")[0])
end

Instance Method Details

#inspectObject Also known as: to_s

:nodoc:



37
38
39
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 37

def inspect #:nodoc:
  "#<DistributedPointer #{@volume_uuid.to_formatted_uuid}:#{@offset}>"
end

#packObject

Converts pointer object to it’s string representation.



29
30
31
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 29

def pack
  @volume_uuid + [@offset].pack("L")
end