tarantool16 0.0.8 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63c6f3dd4aa811b1cb867865472ca56c2ebafb90
4
- data.tar.gz: 009fceed5451625228f289889a4b000d6595e6ea
3
+ metadata.gz: 023336b8ef9383c64a2f05157b93a4184f22bcc1
4
+ data.tar.gz: e88b102d00165c541d9ff1a433e10ec54af97ada
5
5
  SHA512:
6
- metadata.gz: 52ec4a7a31e37024fc0aac40f23812d6fa0a153526fd4eb5ca017c5d8bc4ea084a590e9ed0c1c6f043a85ff7485de956657ede835f81e89cc54cbc6907b04fc8
7
- data.tar.gz: 2a82a91c5288ced4bdbe9f0e878464cc07aff7704314f398025b21785ee7a40291e5088c88144eac1f29b0a55a8864ee5900ff7a2bfe36c620c95d8a395b65fa
6
+ metadata.gz: fffa01cb78d4571c93271018b724b152cdede06f781145365d09a2792e12c732a451b1a9c663e2fa6e98eb97e1395b4fd720b89821025c6a1501fbbc214f5864
7
+ data.tar.gz: 845c92f4ccba0b1e81fe2115b578d4d450bd64f4b7b2b113da8626824a0df3d1fbd169cd52db93220e1e922553971e6cdd4f19881418aaa5778f67ba9b40fb3b
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Sokolov Yura aka funny_falcon
1
+ Copyright (c) 2014-2016 Sokolov Yura aka funny_falcon
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -29,6 +29,9 @@ require 'tarantool16'
29
29
 
30
30
  db = Tarantool16.new host:'localhost:33013'
31
31
  #db = Tarantool16.new host:'localhost:33013', user:'tester', password:'testpass'
32
+ #db = Tarantool16.new host:['tcp','localhost:33013']
33
+ #db = Tarantool16.new host:['unix','path/to.sock']
34
+ #db = Tarantool16.new unix:'path/to.sock'
32
35
 
33
36
  # select from '_space' space info about 'test' table
34
37
  # returns array of tuples as an array
@@ -71,6 +74,12 @@ tar.update(:_space, {name: 'test'}, {format: [:=, [{name: :id, type: :num}, {nam
71
74
 
72
75
  ## Changelog
73
76
 
77
+ 0.0.11 - change a way of unix socket option.
78
+ since previos scheme were introduced 12 hours ago,
79
+ i think it is still safe to change it.
80
+ 0.0.10 - a bit of fixes
81
+ 0.0.9 - Fix detection of update operation shape
82
+ Add unix socket connection.
74
83
  0.0.8 - Fix schema read from new tarantool versions
75
84
  Implement UPSERT
76
85
  0.0.7 - Implement EVAL, fix REPLACE
@@ -144,13 +144,25 @@ module Tarantool16
144
144
  Option.error(sync, e, nil)
145
145
  end
146
146
 
147
+ def _unix?
148
+ @host[0] == 'unix' || @host[0] == :unix
149
+ end
150
+
151
+ def _tcp?
152
+ @host[0] == 'tcp' || @host[0] == :tcp
153
+ end
154
+
155
+ def _unix_sock_path
156
+ @host[1]
157
+ end
158
+
147
159
  def host_port
148
- @host =~ /^(.*):([^:]+)$/
160
+ @host[1] =~ /^(.*):([^:]+)$/
149
161
  [$1, $2.to_i]
150
162
  end
151
163
 
152
164
  def _ipv6?
153
- @host.count(':') > 1
165
+ @host[1].count(':') > 1
154
166
  end
155
167
 
156
168
  def _insert(space_no, tuple, cb)
@@ -68,16 +68,23 @@ module Tarantool16
68
68
  unless could_be_connected?
69
69
  raise Disconnected, "connection is closed"
70
70
  end
71
- @socket = Socket.new((_ipv6? ? Socket::AF_INET6 : Socket::AF_INET), Socket::SOCK_STREAM)
72
- @socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
73
- @socket.sync = true
74
- sockaddr = Socket.pack_sockaddr_in(*host_port.reverse)
75
- @retry = @reconnect
76
- if @timeout
77
- _connect_nonblock(sockaddr)
71
+ if _unix?
72
+ @socket = Socket.unix(_unix_sock_path)
73
+ elsif _tcp?
74
+ @socket = Socket.new((_ipv6? ? Socket::AF_INET6 : Socket::AF_INET), Socket::SOCK_STREAM)
75
+ @socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
76
+ @socket.sync = true
77
+ sockaddr = Socket.pack_sockaddr_in(*host_port.reverse)
78
+ @retry = @reconnect
79
+ if @timeout
80
+ _connect_nonblock(sockaddr)
81
+ else
82
+ @socket.connect(sockaddr)
83
+ end
78
84
  else
79
- @socket.connect(sockaddr)
85
+ raise "unsupported host option: #{@host.inspect}"
80
86
  end
87
+
81
88
  greeting = _read(IPROTO_GREETING_SIZE)
82
89
  unless greeting && greeting.bytesize == IPROTO_GREETING_SIZE
83
90
  raise Disconnected, "mailformed greeting #{greeting.inspect}"
@@ -124,7 +131,13 @@ module Tarantool16
124
131
  req = req[n..-1]
125
132
  end
126
133
  rescue IO::WaitWritable
127
- _wait_writable(expire - now_f)
134
+ nf = now_f
135
+ if expire <= nf
136
+ raise Timeout, "response timeouted"
137
+ else
138
+ _wait_writable(expire - nf)
139
+ retry
140
+ end
128
141
  rescue Errno::EINTR
129
142
  retry
130
143
  end
@@ -192,7 +205,16 @@ module Tarantool16
192
205
  end
193
206
  end
194
207
 
195
- if defined?(Kgio)
208
+ if (RUBY_VERSION.split('.').map(&:to_i) <=> [2,1]) >= 0
209
+ EXCEPTION_FALSE = {exception: false}.freeze
210
+ def _read_nonblock(n, buf)
211
+ if buf
212
+ @socket.read_nonblock(n, buf, EXCEPTION_FALSE)
213
+ else
214
+ @socket.read_nonblock(n, EXCEPTION_FALSE)
215
+ end
216
+ end
217
+ elsif defined?(Kgio)
196
218
  def _read_nonblock(n, buf)
197
219
  return buf ? Kgio.tryread(@socket, n, buf) : Kgio.tryread(@socket, n)
198
220
  end
@@ -33,7 +33,9 @@ module Tarantool16
33
33
 
34
34
  SPACE_SCHEMA = 272
35
35
  SPACE_SPACE = 280
36
+ SPACE_VSPACE = 281
36
37
  SPACE_INDEX = 288
38
+ SPACE_VINDEX = 289
37
39
  SPACE_FUNC = 296
38
40
  SPACE_USER = 304
39
41
  SPACE_PRIV = 312
@@ -9,7 +9,6 @@ module Tarantool16
9
9
  @future = nil
10
10
  @spaces = nil
11
11
  @defined_fields = {}
12
- _fill_standard_spaces
13
12
  @conn = self.class::Connection.new(@host, @opts)
14
13
  end
15
14
 
@@ -28,14 +27,6 @@ module Tarantool16
28
27
  end
29
28
  end
30
29
 
31
- def _fill_standard_spaces
32
- rf = @defined_fields
33
- rf[SPACE_INDEX] =
34
- [%w{sid num}, %w{iid num}, %w{name str},
35
- %w{type str}, %w{unique num}, %w{part_count num},
36
- {name: 'parts', type: [:num, :str], tail: true}]
37
- end
38
-
39
30
  def _synchronized
40
31
  raise "Override #_synchronized"
41
32
  end
@@ -78,7 +69,7 @@ module Tarantool16
78
69
  _synchronized do
79
70
  _fill_spaces(r.data)
80
71
  spaces = @spaces
81
- _select(SPACE_INDEX, 0, [], 0, 2**30, :all, false, fill_indexes)
72
+ _select(SPACE_VINDEX, 0, [], 0, 2**30, :all, false, fill_indexes)
82
73
  end
83
74
  end
84
75
  end
@@ -96,7 +87,7 @@ module Tarantool16
96
87
  end
97
88
  end
98
89
  end
99
- _select(SPACE_SPACE, 0, [], 0, 2**30, :all, false, fill_spaces)
90
+ _select(SPACE_VSPACE, 0, [], 0, 2**30, :all, false, fill_spaces)
100
91
  return future
101
92
  end
102
93
  end
@@ -187,7 +178,7 @@ module Tarantool16
187
178
 
188
179
  def _update(sno, ino, key, ops, need_hash, cb)
189
180
  ino = 0 if ino.nil? && key.is_a?(Array)
190
- ops_good = ops.is_a?(Array) && ops.all?{|a| ops[1].is_a?(Integer)}
181
+ ops_good = ops.is_a?(Array) && ops.all?{|a| a[1].is_a?(Integer)}
191
182
  if sno.is_a?(Integer) && ino.is_a?(Integer) && key.is_a?(Array) && ops_good
192
183
  return conn._update(sno, ino, key, ops, cb)
193
184
  end
@@ -202,7 +193,7 @@ module Tarantool16
202
193
 
203
194
  def _upsert(sno, ino, tuple_key, ops, need_hash, cb)
204
195
  ino = 0 if ino.nil?
205
- ops_good = ops.is_a?(Array) && ops.all?{|a| ops[1].is_a?(Integer)}
196
+ ops_good = ops.is_a?(Array) && ops.all?{|a| a[1].is_a?(Integer)}
206
197
  if sno.is_a?(Integer) && ino.is_a?(Integer) && tuple_key.is_a?(Array) && ops_good
207
198
  return conn._upsert(sno, ino, tuple_key, ops, cb)
208
199
  end
@@ -1,3 +1,3 @@
1
1
  module Tarantool16
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.11"
3
3
  end
data/lib/tarantool16.rb CHANGED
@@ -5,7 +5,19 @@ module Tarantool16
5
5
  autoload :DumbDB, 'tarantool16/dumb_db'
6
6
  def self.new(opts = {})
7
7
  opts = opts.dup
8
- hosts = [opts[:host], opts[:port]].compact.join(':')
8
+ if opts[:unix] && opts[:host]
9
+ raise "`:host` and `:unix` options are mutually exclusive"
10
+ elsif opts[:unix]
11
+ hosts = ["unix", opts[:unix]]
12
+ elsif opts[:host]
13
+ host = opts[:host]
14
+ if Array === host
15
+ hosts = host
16
+ else
17
+ host = [host, opts[:port]].compact.join(':')
18
+ hosts = ["tcp", host]
19
+ end
20
+ end
9
21
  type = opts[:type] && opts[:type].to_s || 'dumb'
10
22
  case type
11
23
  when 'dumb'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tarantool16
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sokolov Yura aka funny_falcon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-25 00:00:00.000000000 Z
11
+ date: 2016-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler