Skip to content

Commit

Permalink
Minor master head naming improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurii Rashkovskii committed May 26, 2008
1 parent 6593374 commit 9894d45
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/strokedb/stores/file_storage.rb
@@ -1,5 +1,10 @@
module StrokeDB
RAW_HEAD_VERSION_UUID = Util.sha1_uuid("strokedb-internal:head-version").to_raw_uuid

def self.head(branch="master")
Util.sha1_uuid(branch).to_raw_uuid
end

RAW_MASTER_HEAD_VERSION_UUID = head()

class FileStorage < Storage

Expand All @@ -14,7 +19,7 @@ def save_as_head!(document, timestamp)

def find(uuid, version=nil, opts = {}, &block)
uuid_version = uuid + (version ? ".#{version}" : "")
key = uuid.to_raw_uuid + (version ? version.to_raw_uuid : RAW_HEAD_VERSION_UUID)
key = uuid.to_raw_uuid + (version ? version.to_raw_uuid : RAW_MASTER_HEAD_VERSION_UUID)
if (ptr = @uindex.find(key)) && (ptr[0,20] != "\x00" * 20) # no way ptr will be zero
raw_doc = StrokeDB::deserialize(read_at_ptr(ptr[0,20]))
unless opts[:no_instantiation]
Expand All @@ -28,7 +33,7 @@ def find(uuid, version=nil, opts = {}, &block)
end

def include?(uuid,version=nil)
key = uuid.to_raw_uuid + (version ? version.to_raw_uuid : RAW_HEAD_VERSION_UUID)
key = uuid.to_raw_uuid + (version ? version.to_raw_uuid : RAW_MASTER_HEAD_VERSION_UUID)
!@uindex.find(key).nil?
end

Expand All @@ -47,7 +52,7 @@ def each(options = {})
@uindex.each do |key, value|
timestamp = StrokeDB.deserialize(read_at_ptr(value[20,20]))
next if after && (timestamp <= after)
if key[16,16] == RAW_HEAD_VERSION_UUID || include_versions
if key[16,16] == RAW_MASTER_HEAD_VERSION_UUID || include_versions
yield Document.from_raw(options[:store],StrokeDB.deserialize(read_at_ptr(value[0,20])))
end
end
Expand All @@ -59,7 +64,7 @@ def perform_save!(document, timestamp, options = {})
ts_ptr = DistributedPointer.pack(@archive.raw_uuid,ts_position)
ptr = DistributedPointer.pack(@archive.raw_uuid,position)
uuid = document.raw_uuid
@uindex.insert(uuid + RAW_HEAD_VERSION_UUID, ptr + ts_ptr) if options[:head] || !document.is_a?(VersionedDocument)
@uindex.insert(uuid + RAW_MASTER_HEAD_VERSION_UUID, ptr + ts_ptr) if options[:head] || !document.is_a?(VersionedDocument)
@uindex.insert(uuid + document.version.to_raw_uuid, ptr + ts_ptr) unless options[:head]
rescue ArchiveVolume::VolumeCapacityExceeded
create_new_archive!
Expand Down

0 comments on commit 9894d45

Please sign in to comment.