Skip to content

Commit

Permalink
New head version marker
Browse files Browse the repository at this point in the history
Also fixes strokewiki problems in master
  • Loading branch information
yrashk committed May 22, 2008
1 parent 65dd0a7 commit c700110
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/strokedb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
require 'set'
require 'fileutils'



module StrokeDB
# Version:
MAIN = 0
Expand Down Expand Up @@ -42,9 +44,6 @@ module StrokeDB
NIL_UUID = "00000000-0000-0000-0000-000000000000"
RAW_NIL_UUID = "\x00" * 16

RAW_FULL_UUID = "\xff" * 16


class <<self
def default_store
StrokeDB.default_config.stores[:default] rescue nil
Expand Down Expand Up @@ -73,6 +72,7 @@ class NoDefaultStoreError < Exception ; end
end

require 'strokedb/nsurl'

require 'strokedb/util'
require 'strokedb/document'
require 'strokedb/config'
Expand Down
10 changes: 6 additions & 4 deletions lib/strokedb/stores/file_storage.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module StrokeDB
RAW_HEAD_VERSION_UUID = Util.sha1_uuid("strokedb-internal:head-version").to_raw_uuid

class FileStorage < Storage

def initialize(options = {})
Expand All @@ -12,7 +14,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_FULL_UUID)
key = uuid.to_raw_uuid + (version ? version.to_raw_uuid : RAW_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 @@ -26,7 +28,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_FULL_UUID)
key = uuid.to_raw_uuid + (version ? version.to_raw_uuid : RAW_HEAD_VERSION_UUID)
!@uindex.find(key).nil?
end

Expand All @@ -45,7 +47,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_FULL_UUID || include_versions
if key[16,16] == RAW_HEAD_VERSION_UUID || include_versions
yield Document.from_raw(options[:store],StrokeDB.deserialize(read_at_ptr(value[0,20])))
end
end
Expand All @@ -57,7 +59,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_FULL_UUID, ptr + ts_ptr) if options[:head] || !document.is_a?(VersionedDocument)
@uindex.insert(uuid + RAW_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 c700110

Please sign in to comment.