roma-storage 0.4.0 → 0.4.1

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
  SHA256:
3
- metadata.gz: c4b857ef17c3024f5e685a89bb579cfcf672e0bc7a019455533fa2daccdaf49d
4
- data.tar.gz: 5ceac66c7a78a4deb3d984ef560dd6e3b5f8b70cf66da3c42fa914a92385b450
3
+ metadata.gz: e683364828401598f900c197ee7a9d4de6d911e6870fc836722ea5f2863c2986
4
+ data.tar.gz: a80f61deb26e63d8ef0a54343e82641472e55881349a56deaddf010f62291998
5
5
  SHA512:
6
- metadata.gz: 1bbacc59fea65d29c505c1fcad537e68fd9e468fe15bc4bc6f2e1dae39f66f8127851a12d6d60eb61a44a7276e3c358a81c323617596f7d0d9d2b7c64cfa0969
7
- data.tar.gz: 76c65ff78393467df8e72019ee1bcdce6a97a29a3b68806acbafdfa4b46cca8cca346fe74c7d7bda15e9fb4e5ef20f0f42c2876c0d7e7f2cd326693cc5168fd2
6
+ metadata.gz: 85fc39c8979a0990d1279b8599d5784f163adf2a3197eca743821e6bda0cd91a24f8941645b3ff575687a7e8d6989f2db42bf1ae23eb0e8ee09367ae249f9956
7
+ data.tar.gz: aa712f58b74d9cdc01c3cec7ff11562b00bcf3889f381c50c3816ad9580887c1b1b6d752d900b413a20c5a7b8a2aa76d690aba1626120f09e267a0d777a3deda
@@ -138,7 +138,28 @@ module Roma
138
138
  def unpack_data(str)
139
139
  str.unpack(PACK_TEMPLATE)
140
140
  end
141
- private :pack_header, :unpack_header, :pack_data, :unpack_data
141
+
142
+ # The fields of a packed record, without unpacking the others, which
143
+ # makes objects.
144
+ def logical_clock_of(str)
145
+ uint32_at(str, 8)
146
+ end
147
+ def expire_of(str)
148
+ uint32_at(str, 12)
149
+ end
150
+ def value_of(str)
151
+ str.byteslice(16, str.bytesize - 16)
152
+ end
153
+ def uint32_at(str, i)
154
+ (str.getbyte(i) << 24) | (str.getbyte(i + 1) << 16) | (str.getbyte(i + 2) << 8) | str.getbyte(i + 3)
155
+ end
156
+
157
+ # The unix time, without making a Time.
158
+ def now
159
+ Process.clock_gettime(Process::CLOCK_REALTIME, :second)
160
+ end
161
+ private :pack_header, :unpack_header, :pack_data, :unpack_data,
162
+ :logical_clock_of, :expire_of, :value_of, :uint32_at, :now
142
163
 
143
164
  def db_get(vn, k)
144
165
  n = @hdiv[vn]
@@ -207,11 +228,10 @@ module Roma
207
228
  buf = db_get(vn, k)
208
229
  clk = 0
209
230
  if buf
210
- data = unpack_data(buf)
211
- clk = (data[2] + 1) & 0xffffffff
231
+ clk = (logical_clock_of(buf) + 1) & 0xffffffff
212
232
  end
213
233
 
214
- ret = [vn, Time.now.to_i, clk, expt, v]
234
+ ret = [vn, now, clk, expt, v]
215
235
  return ret if db_put(vn , k, pack_data(*ret))
216
236
  nil
217
237
  end
@@ -276,10 +296,9 @@ module Roma
276
296
  def get(vn, k, d)
277
297
  buf = db_get(vn, k)
278
298
  return nil unless buf
279
- vn, _t, _clk, expt, v = unpack_data(buf)
299
+ return nil if now > expire_of(buf)
280
300
 
281
- return nil if Time.now.to_i > expt
282
- v
301
+ value_of(buf)
283
302
  end
284
303
 
285
304
  def raw(vn, k, d)
@@ -1,5 +1,5 @@
1
1
  module Roma
2
2
  module Storage
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roma-storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuya Sato