Class: Archipelago::Dump::Site
- Inherits:
-
Object
- Object
- Archipelago::Dump::Site
- Includes:
- Archipelago::Disco::Publishable
- Defined in:
- lib/archipelago/dump.rb
Overview
The server class in the Archipipelago::Dump network.
Uses an Archipelago::Sanitation::Officer to keep track of what is needed to be done for redundancy, but Site does the actual work.
Constant Summary collapse
- CHECK_INTERVAL =
The minimum pause between checking if keys belong with us.
30
Instance Attribute Summary collapse
-
#db ⇒ Object
Returns the value of attribute db.
-
#debug_callable ⇒ Object
Returns the value of attribute debug_callable.
-
#officer ⇒ Object
Returns the value of attribute officer.
-
#persistence_provider ⇒ Object
Returns the value of attribute persistence_provider.
Attributes included from Archipelago::Disco::Camel
Instance Method Summary collapse
-
#delete!(key) ⇒ Object
Deletes
key
from the db. -
#fetch(key) ⇒ Object
Fetches all duplicates of
key
. -
#initialize(options = {}) ⇒ Site
constructor
A new instance of Site.
-
#insert!(key, values, timestamp = "\000\000\000\000") ⇒ Object
Will insert the array
values
underkey
in the db.
Methods included from Archipelago::Disco::Publishable
#_dump, append_features, #close!, #publish!, #service_id, #unpublish!, #valid?
Constructor Details
#initialize(options = {}) ⇒ Site
Returns a new instance of Site.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/archipelago/dump.rb', line 51 def initialize( = {}) initialize_publishable() # # The callable object that will get sent our debug messages if it exists. # @debug_callable = [:debug_callable] # # The provider of checksumming magic and chunk distribution. # @officer = [:officer] || (defined?(Archipelago::Sanitation::CLEANER) ? Archipelago::Sanitation::CLEANER : Archipelago::Sanitation::Officer.new) # # The database where the data lives. # @db = @persistence_provider.get_dup_tree("db") # # The minimum pause between checking if keys belong with us. # @check_interval = [:check_interval] || CHECK_INTERVAL end |
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
49 50 51 |
# File 'lib/archipelago/dump.rb', line 49 def db @db end |
#debug_callable ⇒ Object
Returns the value of attribute debug_callable.
49 50 51 |
# File 'lib/archipelago/dump.rb', line 49 def debug_callable @debug_callable end |
#officer ⇒ Object
Returns the value of attribute officer.
49 50 51 |
# File 'lib/archipelago/dump.rb', line 49 def officer @officer end |
#persistence_provider ⇒ Object
Returns the value of attribute persistence_provider.
49 50 51 |
# File 'lib/archipelago/dump.rb', line 49 def persistence_provider @persistence_provider end |
Instance Method Details
#delete!(key) ⇒ Object
Deletes key
from the db.
125 126 127 |
# File 'lib/archipelago/dump.rb', line 125 def delete!(key) return @db.delete(key) end |
#fetch(key) ⇒ Object
Fetches all duplicates of key
.
Returns [[TIMESTAMP0, VALUE0],…,[TIMESTAMPn, VALUEn]]
115 116 117 118 119 120 |
# File 'lib/archipelago/dump.rb', line 115 def fetch(key) values = @db.duplicates(key).collect do |value| [value[0...4], value[4..-1]] end return values end |
#insert!(key, values, timestamp = "\000\000\000\000") ⇒ Object
Will insert the array values
under key
in the db.
Will insert them with the timestamp
or “000000000000”.
If values with the same timestamp already exists, it will overwrite them if they are greater in number than the given values
. If they are fewer enough of the given values
will be inserted to get the same number of values in the database as in +values.
Any values with a different timestamp will be deleted.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/archipelago/dump.rb', line 87 def insert!(key, values, = "\000\000\000\000") @debug_callable.call("#{self.service_id}.insert!(#{key}, #{values.inspect}, #{.inspect}) called") if @debug_callable if (duplicates = @db.duplicates(key)).empty? values.each do |value| @db[key] = + value end else = duplicates.first[0...4] if != || duplicates.size > values.size @db.env.begin(BDB::TXN_COMMIT, @db) do |txn, db| db.delete(key) values.each do |value| db[key] = + value end end else values[0...(values.size - duplicates.size)].each do |value| @db[key] = + value end end end end |