Module: StrokeDB

Defined in:
lib/strokedb/util/java_util.rb,
lib/strokedb.rb,
lib/strokedb/util.rb,
lib/strokedb/view.rb,
lib/strokedb/index.rb,
lib/strokedb/store.rb,
lib/strokedb/store.rb,
lib/strokedb/config.rb,
lib/strokedb/console.rb,
lib/strokedb/document.rb,
lib/strokedb/sync/diff.rb,
lib/strokedb/transaction.rb,
lib/strokedb/document/meta.rb,
lib/strokedb/document/slot.rb,
lib/strokedb/document/util.rb,
lib/strokedb/sync/diff/hash.rb,
lib/strokedb/document/delete.rb,
lib/strokedb/sync/chain_sync.rb,
lib/strokedb/sync/diff/array.rb,
lib/strokedb/sync/store_sync.rb,
lib/strokedb/util/attach_dsl.rb,
lib/strokedb/util/lazy_array.rb,
lib/strokedb/sync/diff/string.rb,
lib/strokedb/document/callback.rb,
lib/strokedb/document/versions.rb,
lib/strokedb/sync/diff/default.rb,
lib/strokedb/util/serialization.rb,
lib/strokedb/volumes/map_volume.rb,
lib/strokedb/stores/file_storage.rb,
lib/strokedb/stores/remote_store.rb,
lib/strokedb/volumes/block_volume.rb,
lib/strokedb/document/dsl/meta_dsl.rb,
lib/strokedb/stores/memory_storage.rb,
lib/strokedb/document/dsl/coercions.rb,
lib/strokedb/sync/lamport_timestamp.rb,
lib/strokedb/util/lazy_mapping_hash.rb,
lib/strokedb/volumes/archive_volume.rb,
lib/strokedb/document/dsl/virtualize.rb,
lib/strokedb/util/class_optimization.rb,
lib/strokedb/util/lazy_mapping_array.rb,
lib/strokedb/data_structures/skiplist.rb,
lib/strokedb/document/dsl/validations.rb,
lib/strokedb/stores/chainable_storage.rb,
lib/strokedb/document/dsl/associations.rb,
lib/strokedb/data_structures/point_query.rb,
lib/strokedb/volumes/distributed_pointer.rb,
lib/strokedb/data_structures/inverted_list.rb,
lib/strokedb/data_structures/simple_skiplist.rb,
lib/strokedb/data_structures/chunked_skiplist.rb,
lib/strokedb/stores/inverted_list_file_storage.rb,
lib/strokedb/volumes/fixed_length_skiplist_volume.rb

Overview

Some java overrides

Defined Under Namespace

Modules: Associations, ChainSync, ChainableStorage, ClassOptimization, Coercions, Console, ImmutableDocument, JsonSerializationMethod, MarshalSerializationMethod, Meta, MetaDSL, RemoteStore, Util, Validations, VersionedDocument, Virtualizations Classes: ArchiveVolume, ArraySlotValue, BlockVolume, Callback, ChunkedSkiplist, Config, DefaultSlotDiff, DistributedPointer, Document, DocumentDeletionError, DocumentReferenceValue, FileStorage, FixedLengthSkiplistVolume, HashSlotValue, InvalidDocumentError, InvalidMapVolumeError, InvalidRecordPositionError, InvalidRecordSizeError, InvertedList, InvertedListFileStorage, InvertedListIndex, LamportTimestamp, LazyArray, LazyMappingArray, LazyMappingHash, MapVolume, MemoryStorage, NoDefaultStoreError, PointQuery, SimpleSkiplist, Skiplist, Slot, SlotDiffStrategy, SlotNotFoundError, Storage, Store, Transaction, UnknownIndexTypeError, UnknownStorageTypeError, UnknownStoreTypeError

Constant Summary collapse

MAIN =

Version:

0
MAJOR =
0
MINOR =
2
PATCHLEVEL =
2
VERSION =
[MAIN.to_s, MAJOR.to_s, MINOR.to_s, PATCHLEVEL.to_s].join('.')
VERSION_STRING =
VERSION + (RUBY_PLATFORM =~ /java/ ? '-java' : '')
COVERAGE =

Coverage threshold - bump this float anytime your changes increase the spec coverage DO NOT LOWER THIS NUMBER. EVER.

92
UUID_RE =

UUID regexp (like 1e3d02cc-0769-4bd8-9113-e033b246b013)

/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/
VERSION_RE =

document version regexp

UUID_RE
XMLSCHEMA_TIME_RE =

XML Schema time format Time.now.xmlschema(6)

#=> "2008-04-27T23:39:09.920288+04:00"

Time.xmlschema(“2008-04-27T23:39:09.920288+04:00”)

#=> Sun Apr 27 19:39:09 UTC 2008
/\A\s*(-?\d+)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(\.\d*)?(Z|[+-]\d\d:\d\d)?\s*\z/i
STROKEDB_NSURL =

STROKEDB NSURL

"http://strokedb.com/"
NIL_UUID =

so called Nil UUID

"00000000-0000-0000-0000-000000000000"
RAW_NIL_UUID =
"\x00" * 16
RAW_FULL_UUID =
"\xff" * 16
OPTIMIZATIONS =
[]
View =
Meta.new do
  attr_accessor :map_with_proc
  attr_reader :reduce_with_proc

  on_initialization do |view|
    view.map_with_proc = proc {|doc, *args| doc } 
  end

  def reduce_with(&block)
    @reduce_with_proc = block
    self
  end

  def map_with(&block)
    @map_with_proc = block
    self
  end

  def emit(*args) 
    ViewCut.new(store, :view => self, :args => args, :timestamp_state => LTS.zero.counter).emit
  end

end
ViewCut =
Meta.new do

  on_new_document do |cut|
    cut.instance_eval do
      if view.is_a?(View)
        @map_with_proc = view.map_with_proc
        @reduce_with_proc = view.reduce_with_proc
      end
    end
  end

  before_save do |cut|
    view = cut.view
    view.last_cut = cut if view[:last_cut].nil? or (cut[:previous] && view.last_cut == cut.previous)
    view.save!
  end


  def emit
    mapped = []
    store.each(:after_timestamp => timestamp_state, :include_versions => view[:include_versions]) do |doc| 
      mapped << @map_with_proc.call(doc,*args) 
    end
    documents = (@reduce_with_proc ? mapped.select {|doc| @reduce_with_proc.call(doc,*args) } : mapped).map{|d| d.is_a?(Document) ? d.extend(VersionedDocument) : d}
    ViewCut.new(store, :documents => documents, :view => view, :args => args, :timestamp_state => store.timestamp.counter, :previous => timestamp_state == 0 ? nil : self)
  end
  def to_a
    documents
  end
end
StoreInfo =
Meta.new
Doc =

Console

Document
DOCREF =

Slots which contain references to another documents are matched with these regexps.

/^@##{UUID_RE}$/
VERSIONREF =
/^@##{UUID_RE}\.#{VERSION_RE}$/
PATCH_REPLACE =
'R'.freeze
PATCH_PLUS =
'+'.freeze
PATCH_MINUS =
'-'.freeze
PATCH_DIFF =
'D'.freeze
Diff =
Meta.new do

  on_initialization do |diff|
    diff.added_slots = {} unless diff[:added_slots]
    diff.removed_slots = {} unless diff[:removed_slots]
    diff.updated_slots = {} unless diff[:updated_slots] 
    diff.send!(:compute_diff) if diff.new?
  end

  def different?
    !updated_slots.empty? || !removed_slots.empty? || !added_slots.empty?
  end

  def patch!(document)
    added_slots.each_pair do |addition, value|
      document[addition] = value
    end
    removed_slots.keys.each do |removal|
      document.remove_slot!(removal)
    end
    updated_slots.each_pair do |update, value|
      if sk = strategy_class_for(update)
        document[update] = sk.patch(document[update], value)
      else
        document[update] =value
      end
    end
  end


  protected

  def compute_diff
    additions = to.slotnames - from.slotnames 
    additions.each do |addition|
      self.added_slots[addition] = to[addition]
    end
    removals = from.slotnames - to.slotnames
    removals.each do |removal|
      self.removed_slots[removal] = from[removal]
    end
    updates = (to.slotnames - additions - ['version']).select {|slotname| to[slotname] != from[slotname]}
    updates.each do |update|
      unless sk = strategy_class_for(update)
        self.updated_slots[update] = to[update]
      else
        self.updated_slots[update] = sk.diff(from[update], to[update]) 
      end
    end
  end

  def strategy_class_for(slotname)
    if from.meta && strategy = from.meta["diff_strategy_#{slotname}"]
      _strategy_class = strategy.camelize.constantize rescue nil
      return _strategy_class if _strategy_class && _strategy_class.ancestors.include?(SlotDiffStrategy)
    end
    false
  end

end
META_CACHE =
{}
DeletedDocument =
Meta.new do
  on_load do |doc|
    doc.make_immutable!
  end
  
  def undelete!
    deleted_version = versions.previous
    store.save_as_head!(deleted_version)
    store.find(uuid)
  end
end
SynchronizationReport =
Meta.new  do
  on_new_document do |report|
    report.conflicts = []
    report.added_documents = []
    report.fast_forwarded_documents = []
    report.non_matching_documents = []
  end
end
SynchronizationConflict =
Meta.new  do
  def resolve!
    # by default, do nothing
  end
end
LTS =
LamportTimestamp

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_storeObject



49
50
51
# File 'lib/strokedb.rb', line 49

def default_store
  StrokeDB.default_config.stores[:default] rescue nil
end

.default_store=(store) ⇒ Object



52
53
54
55
56
# File 'lib/strokedb.rb', line 52

def default_store=(store)
  cfg = Config.new
  cfg.stores[:default] = store
  StrokeDB.default_config = cfg
end

.serialization_method=(method_name) ⇒ Object



43
44
45
# File 'lib/strokedb/util/serialization.rb', line 43

def self.serialization_method=(method_name)
  StrokeDB.extend StrokeDB.const_get("#{method_name.to_s.camelize}SerializationMethod")
end

.use_global_default_config!Object



153
154
155
156
157
158
159
160
161
162
# File 'lib/strokedb/config.rb', line 153

def use_global_default_config!
  class << self
    def default_config
      $strokedb_default_config
    end
    def default_config=(config)
      $strokedb_default_config = config
    end
  end
end

.use_perthread_default_config!Object



143
144
145
146
147
148
149
150
151
152
# File 'lib/strokedb/config.rb', line 143

def use_perthread_default_config!
  class << self
    def default_config
      Thread.current['StrokeDB.default_config']
    end
    def default_config=(config)
      Thread.current['StrokeDB.default_config'] = config
    end
  end
end

Instance Method Details

#DEBUGObject



60
61
62
# File 'lib/strokedb.rb', line 60

def DEBUG
  yield
end