Class: Tarantool::DB
- Inherits:
-
Object
show all
- Defined in:
- lib/tarantool.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#_shard(number) ⇒ Object
-
#_tune_new_connection(con) ⇒ Object
-
#close ⇒ Object
-
#close_connection ⇒ Object
-
#each_connection ⇒ Object
-
#initialize(shards, replica_strategy, previous_shards_count, insert_to_previous_shard) ⇒ DB
constructor
-
#insert_with_shards_count ⇒ Object
-
#method_missing(name, *args, &block) ⇒ Object
-
#primary_interface ⇒ Object
-
#query ⇒ Object
-
#shards_count ⇒ Object
-
#space(space_no, fields = [], opts = {}) ⇒ Object
-
#space_array(space_no, field_types = [], opts = {}) ⇒ Object
returns regular space, where fields are named by position.
-
#space_hash(space_no, fields, opts = {}) ⇒ Object
Constructor Details
#initialize(shards, replica_strategy, previous_shards_count, insert_to_previous_shard) ⇒ DB
Returns a new instance of DB.
75
76
77
78
79
80
81
82
|
# File 'lib/tarantool.rb', line 75
def initialize(shards, replica_strategy, previous_shards_count, insert_to_previous_shard)
@shards = shards
@replica_strategy = replica_strategy
@previous_shards_count = previous_shards_count
@insert_to_previous_shard = insert_to_previous_shard
@connections = {}
@closed = false
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
118
119
120
121
122
123
124
|
# File 'lib/tarantool.rb', line 118
def method_missing(name, *args, &block)
if query.respond_to?(name)
query.send(name, *args, &block)
else
super
end
end
|
Instance Attribute Details
#closed ⇒ Object
Also known as:
closed?
Returns the value of attribute closed.
73
74
75
|
# File 'lib/tarantool.rb', line 73
def closed
@closed
end
|
#connections ⇒ Object
Returns the value of attribute connections.
73
74
75
|
# File 'lib/tarantool.rb', line 73
def connections
@connections
end
|
#previous_shards_count ⇒ Object
Returns the value of attribute previous_shards_count.
135
136
137
|
# File 'lib/tarantool.rb', line 135
def previous_shards_count
@previous_shards_count
end
|
Instance Method Details
#_shard(number) ⇒ Object
141
142
143
144
145
146
147
148
149
|
# File 'lib/tarantool.rb', line 141
def _shard(number)
@connections[number] ||= begin
@shards[number].map do |host, port|
con = IProto.get_connection(host, port, self.class::IPROTO_CONNECTION_TYPE)
_tune_new_connection(con)
con
end
end
end
|
#_tune_new_connection(con) ⇒ Object
151
152
|
# File 'lib/tarantool.rb', line 151
def _tune_new_connection(con)
end
|
#close ⇒ Object
126
127
128
129
|
# File 'lib/tarantool.rb', line 126
def close
@closed = true
close_connection
end
|
#close_connection ⇒ Object
160
161
162
163
|
# File 'lib/tarantool.rb', line 160
def close_connection
each_connection{|c| c.close}
@connections.clear
end
|
#each_connection ⇒ Object
154
155
156
157
158
|
# File 'lib/tarantool.rb', line 154
def each_connection
@connections.each do |num, replicas|
replicas.each{|r| yield r}
end
end
|
#insert_with_shards_count ⇒ Object
137
138
139
|
# File 'lib/tarantool.rb', line 137
def insert_with_shards_count
@insert_to_previous_shard && @previous_shards_count || @shards.count
end
|
#primary_interface ⇒ Object
165
166
167
|
# File 'lib/tarantool.rb', line 165
def primary_interface
raise NoMethodError, "#primary_interface should by overriden"
end
|
#query ⇒ Object
114
115
116
|
# File 'lib/tarantool.rb', line 114
def query
@query ||= self.class::Query.new(self)
end
|
#shards_count ⇒ Object
131
132
133
|
# File 'lib/tarantool.rb', line 131
def shards_count
@shards.count
end
|
#space(space_no, fields = [], opts = {}) ⇒ Object
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/tarantool.rb', line 95
def space(space_no, fields = [], opts = {})
case fields
when Array
space_array(space_no, fields, opts)
when Hash
space_hash(space_no, fields, opts)
else
raise "You should specify fields as an array or hash (got #{fields.inspect})"
end
end
|
#space_array(space_no, field_types = [], opts = {}) ⇒ Object
returns regular space, where fields are named by position
tarantool.space_block(0, [:int, :str, :int, :str], keys: [[0], [1,2]])
87
88
89
90
91
92
93
|
# File 'lib/tarantool.rb', line 87
def space_array(space_no, field_types = [], opts = {})
indexes = opts[:keys] || opts[:indexes]
shard_fields = opts[:shard_fields]
shard_proc = opts[:shard_proc]
self.class::SpaceArray.new(self, space_no, field_types, indexes,
shard_fields, shard_proc)
end
|
#space_hash(space_no, fields, opts = {}) ⇒ Object
106
107
108
109
110
111
112
|
# File 'lib/tarantool.rb', line 106
def space_hash(space_no, fields, opts = {})
indexes = opts[:keys] || opts[:indexes]
shard_fields = opts[:shard_fields]
shard_proc = opts[:shard_proc]
self.class::SpaceHash.new(self, space_no, fields, indexes,
shard_fields, shard_proc)
end
|