Class: Scalaroid::ReplicatedDHT

Inherits:
Object
  • Object
show all
Includes:
InternalScalarisNopClose
Defined in:
lib/scalaroid/replicated_dht.rb

Overview

Non-transactional operations on the replicated DHT of Scalaris

Instance Method Summary collapse

Methods included from InternalScalarisNopClose

#close_connection, #nop

Constructor Details

#initialize(conn = JSONConnection.new()) ⇒ ReplicatedDHT

Create a new object using the given connection.



5
6
7
# File 'lib/scalaroid/replicated_dht.rb', line 5

def initialize(conn = JSONConnection.new())
  @conn = conn
end

Instance Method Details

#delete(key, timeout = 2000) ⇒ Object

Tries to delete the value at the given key.

WARNING: This function can lead to inconsistent data (e.g. deleted items can re-appear). Also when re-creating an item the version before the delete can re-appear.

returns the number of successfully deleted items use get_last_delete_result() to get more details



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/scalaroid/replicated_dht.rb', line 17

def delete(key, timeout = 2000)
  result_raw = @conn.call(:delete, [key, timeout])
  result = @conn.class.process_result_delete(result_raw)
  @lastDeleteResult = result[:results]
  if result[:success] == true
    return result[:ok]
  elsif result[:success] == :timeout
    raise TimeoutError.new(result_raw)
  else
    raise UnknownError.new(result_raw)
  end
end

#get_last_delete_resultObject

Returns the result of the last call to delete().

NOTE: This function traverses the result list returned by Scalaris and therefore takes some time to process. It is advised to store the returned result object once generated.



35
36
37
# File 'lib/scalaroid/replicated_dht.rb', line 35

def get_last_delete_result
  @conn.class.create_delete_result(@lastDeleteResult)
end