gnista 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +16 -1
- data/README.md +12 -9
- data/ext/gnista/gnista.c +60 -34
- data/lib/gnista/version.rb +1 -1
- data/test/test_commands.rb +19 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18a1c35381152407bbbdd6694e04424893936c13
|
4
|
+
data.tar.gz: 94f3a0363f878f04a6d2b4572a1a10b56ec93f2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5d83b90fbe736a4d9f7ae3f22c268ccd5ab1d930276fc84f78ee2f93cf51ef9c53403a503e539320f6d1fd5d9f6498ee0601e064f3c1d091b2dc67d4c520ca8
|
7
|
+
data.tar.gz: 3c5e593188384bd0f7d2e61652c35d4f04ba32e1033ee2141e4e8ac549fea19129752f28db81c87bda863ec8788df53bd3e36509cba11d905fa9e7d6e72cd01b
|
data/HISTORY.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
|
+
# Version 0.0.2
|
2
|
+
|
3
|
+
Release date 2013-09-12
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
* ```each``` in logreader now provides a __type__ parameter containing either :put or :delete.
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
|
11
|
+
* Fix memory leak on ```each/get``` failure.
|
12
|
+
* Two allocations per call instead of one each entry in ```each```.
|
13
|
+
* ```each``` in logreader returns nil instead of empty string.
|
14
|
+
|
15
|
+
|
1
16
|
# Version 0.0.1
|
2
17
|
|
3
18
|
Release date 2013-09-11
|
4
19
|
|
5
|
-
|
20
|
+
__Initial release__
|
data/README.md
CHANGED
@@ -35,7 +35,8 @@ logwriter.del "key" # delete entry
|
|
35
35
|
logwriter.flush
|
36
36
|
|
37
37
|
logreader = Gnista::Logreader.new "mylog.log"
|
38
|
-
logreader.each {|key,value| puts key, value }
|
38
|
+
logreader.each {|key,value,type| puts key, value, type }
|
39
|
+
# => "key", "value"/nil, :put/:delete
|
39
40
|
|
40
41
|
Gnista::Hash.write "mylog.hash", "mylog.log" # no preferred hash size
|
41
42
|
Gnista::Hash.write "mylog.hash", "mylog.log", 4 # 32 bit murmurhash3_x86_32
|
@@ -59,15 +60,17 @@ hash.close
|
|
59
60
|
|
60
61
|
## Contributing
|
61
62
|
|
63
|
+
__Step-by-step:__
|
64
|
+
|
65
|
+
1. Fork it
|
66
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
67
|
+
3. Write some code
|
68
|
+
4. Build and test
|
69
|
+
5. Commit your changes (`git commit -am 'Add some feature'`)
|
70
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
7. Create new Pull Request
|
72
|
+
|
62
73
|
Use the following commands to build the native extensions and test:
|
63
74
|
|
64
75
|
$ rake make
|
65
76
|
$ rake test
|
66
|
-
|
67
|
-
Then:
|
68
|
-
|
69
|
-
1. Fork it
|
70
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
71
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
72
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
73
|
-
5. Create new Pull Request
|
data/ext/gnista/gnista.c
CHANGED
@@ -7,18 +7,18 @@ typedef int bool;
|
|
7
7
|
|
8
8
|
|
9
9
|
typedef struct instance_logwriter {
|
10
|
-
|
11
|
-
|
10
|
+
sparkey_logwriter *logwriter;
|
11
|
+
int open;
|
12
12
|
} instance_logwriter;
|
13
13
|
|
14
14
|
typedef struct instance_logreader {
|
15
|
-
|
16
|
-
|
15
|
+
sparkey_logreader *logreader;
|
16
|
+
int open;
|
17
17
|
} instance_logreader;
|
18
18
|
|
19
19
|
typedef struct instance_hashreader {
|
20
|
-
|
21
|
-
|
20
|
+
sparkey_hashreader *hashreader;
|
21
|
+
int open;
|
22
22
|
} instance_hashreader;
|
23
23
|
|
24
24
|
/********************************************************************************/
|
@@ -44,7 +44,7 @@ static void dealloc_logwriter(void *p) {
|
|
44
44
|
instance_logwriter *i_logwriter = p;
|
45
45
|
|
46
46
|
if (i_logwriter->open) {
|
47
|
-
|
47
|
+
sparkey_returncode returncode;
|
48
48
|
returncode = sparkey_logwriter_close(&i_logwriter->logwriter);
|
49
49
|
|
50
50
|
if (returncode != SPARKEY_SUCCESS) {
|
@@ -57,7 +57,7 @@ static void dealloc_logwriter(void *p) {
|
|
57
57
|
|
58
58
|
static VALUE alloc_logwriter(VALUE klass) {
|
59
59
|
instance_logwriter *i_logwriter = ALLOC(instance_logwriter);
|
60
|
-
|
60
|
+
return Data_Wrap_Struct(klass, 0, dealloc_logwriter, i_logwriter);
|
61
61
|
}
|
62
62
|
|
63
63
|
static instance_logwriter* get_logwriter(VALUE self) {
|
@@ -182,7 +182,7 @@ static void dealloc_logreader(void *p) {
|
|
182
182
|
|
183
183
|
static VALUE alloc_logreader(VALUE klass) {
|
184
184
|
instance_logreader *i_logreader = ALLOC(instance_logreader);
|
185
|
-
|
185
|
+
return Data_Wrap_Struct(klass, 0, dealloc_logreader, i_logreader);
|
186
186
|
}
|
187
187
|
|
188
188
|
static instance_logreader* get_logreader(VALUE self) {
|
@@ -229,41 +229,54 @@ static VALUE method_logreader_each(VALUE self) {
|
|
229
229
|
raise_sparkey(returncode);
|
230
230
|
}
|
231
231
|
|
232
|
+
VALUE put_sym = ID2SYM(rb_intern("put"));
|
233
|
+
VALUE del_sym = ID2SYM(rb_intern("delete"));
|
234
|
+
uint8_t *keybuf = malloc(sparkey_logreader_maxkeylen(i_logreader->logreader));
|
235
|
+
uint8_t *valuebuf = malloc(sparkey_logreader_maxvaluelen(i_logreader->logreader));
|
232
236
|
while (1) {
|
233
237
|
returncode = sparkey_logiter_next(logiter, i_logreader->logreader);
|
234
238
|
|
235
239
|
if (sparkey_logiter_state(logiter) != SPARKEY_ITER_ACTIVE) {
|
236
|
-
|
240
|
+
break;
|
237
241
|
}
|
238
242
|
|
239
243
|
uint64_t wanted_keylen = sparkey_logiter_keylen(logiter);
|
240
|
-
uint8_t *keybuf = malloc(wanted_keylen);
|
241
244
|
uint64_t actual_keylen;
|
242
245
|
returncode = sparkey_logiter_fill_key(logiter, i_logreader->logreader, wanted_keylen, keybuf, &actual_keylen);
|
243
246
|
|
244
247
|
if (returncode != SPARKEY_SUCCESS) {
|
248
|
+
free(keybuf);
|
249
|
+
free(valuebuf);
|
245
250
|
raise_sparkey(returncode);
|
246
251
|
} else if (wanted_keylen != actual_keylen) {
|
252
|
+
free(keybuf);
|
253
|
+
free(valuebuf);
|
247
254
|
rb_raise(GnistaException, "Corrupted read in logreader.");
|
248
255
|
}
|
249
256
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
257
|
+
if (sparkey_logiter_type(logiter) == SPARKEY_ENTRY_PUT) {
|
258
|
+
uint64_t wanted_valuelen = sparkey_logiter_valuelen(logiter);
|
259
|
+
uint64_t actual_valuelen;
|
260
|
+
returncode = sparkey_logiter_fill_value(logiter, i_logreader->logreader, wanted_valuelen, valuebuf, &actual_valuelen);
|
261
|
+
|
262
|
+
if (returncode != SPARKEY_SUCCESS) {
|
263
|
+
free(keybuf);
|
264
|
+
free(valuebuf);
|
265
|
+
raise_sparkey(returncode);
|
266
|
+
} else if (wanted_valuelen != actual_valuelen) {
|
267
|
+
free(keybuf);
|
268
|
+
free(valuebuf);
|
269
|
+
rb_raise(GnistaException, "Corrupted read in logreader.");
|
270
|
+
}
|
271
|
+
|
272
|
+
rb_yield_values(3, rb_str_new((char *)keybuf, actual_keylen), rb_str_new((char *)valuebuf, actual_valuelen), put_sym);
|
273
|
+
} else {
|
274
|
+
rb_yield_values(3, rb_str_new((char *)keybuf, actual_keylen), Qnil, del_sym);
|
259
275
|
}
|
260
|
-
|
261
|
-
rb_yield_values(2, rb_str_new((char *)keybuf, actual_keylen), rb_str_new((char *)valuebuf, actual_valuelen));
|
262
|
-
|
263
|
-
free(keybuf);
|
264
|
-
free(valuebuf);
|
265
276
|
}
|
266
277
|
|
278
|
+
free(keybuf);
|
279
|
+
free(valuebuf);
|
267
280
|
sparkey_logiter_close(&logiter);
|
268
281
|
|
269
282
|
return Qnil;
|
@@ -294,7 +307,7 @@ static void dealloc_hashreader(void *p) {
|
|
294
307
|
|
295
308
|
static VALUE alloc_hashreader(VALUE klass) {
|
296
309
|
instance_hashreader *i_hashreader = ALLOC(instance_hashreader);
|
297
|
-
|
310
|
+
return Data_Wrap_Struct(klass, 0, dealloc_hashreader, i_hashreader);
|
298
311
|
}
|
299
312
|
|
300
313
|
static instance_hashreader* get_hashreader(VALUE self) {
|
@@ -362,48 +375,57 @@ static VALUE method_hash_each(VALUE self) {
|
|
362
375
|
instance_hashreader *i_hashreader = get_hashreader(self);
|
363
376
|
sparkey_logiter *logiter;
|
364
377
|
check_open(i_hashreader->open);
|
378
|
+
sparkey_logreader *logreader = sparkey_hash_getreader(i_hashreader->hashreader);
|
365
379
|
|
366
|
-
returncode = sparkey_logiter_create(&logiter,
|
380
|
+
returncode = sparkey_logiter_create(&logiter, logreader);
|
367
381
|
|
368
382
|
if (returncode != SPARKEY_SUCCESS) {
|
369
383
|
raise_sparkey(returncode);
|
370
384
|
}
|
371
385
|
|
386
|
+
uint8_t *keybuf = malloc(sparkey_logreader_maxkeylen(logreader));
|
387
|
+
uint8_t *valuebuf = malloc(sparkey_logreader_maxvaluelen(logreader));
|
372
388
|
while (1) {
|
373
389
|
returncode = sparkey_logiter_hashnext(logiter, i_hashreader->hashreader);
|
374
390
|
|
375
391
|
if (sparkey_logiter_state(logiter) != SPARKEY_ITER_ACTIVE) {
|
376
|
-
|
392
|
+
break;
|
377
393
|
}
|
378
394
|
|
379
395
|
uint64_t wanted_keylen = sparkey_logiter_keylen(logiter);
|
380
|
-
uint8_t *keybuf = malloc(wanted_keylen);
|
381
396
|
uint64_t actual_keylen;
|
382
397
|
returncode = sparkey_logiter_fill_key(logiter, sparkey_hash_getreader(i_hashreader->hashreader), wanted_keylen, keybuf, &actual_keylen);
|
383
398
|
|
384
399
|
if (returncode != SPARKEY_SUCCESS) {
|
400
|
+
free(keybuf);
|
401
|
+
free(valuebuf);
|
385
402
|
raise_sparkey(returncode);
|
386
403
|
} else if (wanted_keylen != actual_keylen) {
|
404
|
+
free(keybuf);
|
405
|
+
free(valuebuf);
|
387
406
|
rb_raise(GnistaException, "Corrupt entry in logreader.");
|
388
407
|
}
|
389
408
|
|
390
409
|
uint64_t wanted_valuelen = sparkey_logiter_valuelen(logiter);
|
391
|
-
uint8_t *valuebuf = malloc(wanted_valuelen);
|
392
410
|
uint64_t actual_valuelen;
|
393
411
|
returncode = sparkey_logiter_fill_value(logiter, sparkey_hash_getreader(i_hashreader->hashreader), wanted_valuelen, valuebuf, &actual_valuelen);
|
394
412
|
|
395
413
|
if (returncode != SPARKEY_SUCCESS) {
|
414
|
+
free(keybuf);
|
415
|
+
free(valuebuf);
|
396
416
|
raise_sparkey(returncode);
|
397
417
|
} else if (wanted_valuelen != actual_valuelen) {
|
418
|
+
free(keybuf);
|
419
|
+
free(valuebuf);
|
398
420
|
rb_raise(GnistaException, "Corrupt entry in logreader.");
|
399
421
|
}
|
400
422
|
|
401
423
|
rb_yield_values(2, rb_str_new((char *)keybuf, actual_keylen), rb_str_new((char *)valuebuf, actual_valuelen));
|
402
424
|
|
403
|
-
free(keybuf);
|
404
|
-
free(valuebuf);
|
405
425
|
}
|
406
426
|
|
427
|
+
free(keybuf);
|
428
|
+
free(valuebuf);
|
407
429
|
sparkey_logiter_close(&logiter);
|
408
430
|
|
409
431
|
return Qnil;
|
@@ -426,7 +448,7 @@ static VALUE method_hash_get(VALUE self, VALUE key) {
|
|
426
448
|
returncode = sparkey_hash_get(i_hashreader->hashreader, (uint8_t*)RSTRING_PTR(key), RSTRING_LEN(key), logiter);
|
427
449
|
|
428
450
|
if (sparkey_logiter_state(logiter) != SPARKEY_ITER_ACTIVE) {
|
429
|
-
|
451
|
+
return Qnil;
|
430
452
|
}
|
431
453
|
|
432
454
|
uint64_t wanted_valuelen = sparkey_logiter_valuelen(logiter);
|
@@ -435,14 +457,18 @@ static VALUE method_hash_get(VALUE self, VALUE key) {
|
|
435
457
|
returncode = sparkey_logiter_fill_value(logiter, sparkey_hash_getreader(i_hashreader->hashreader), wanted_valuelen, valuebuf, &actual_valuelen);
|
436
458
|
|
437
459
|
if (returncode != SPARKEY_SUCCESS) {
|
460
|
+
free(valuebuf);
|
438
461
|
raise_sparkey(returncode);
|
439
462
|
} else if (wanted_valuelen != actual_valuelen) {
|
463
|
+
free(valuebuf);
|
440
464
|
rb_raise(GnistaException, "Corrupt entry in hash.");
|
441
465
|
}
|
442
466
|
|
443
467
|
sparkey_logiter_close(&logiter);
|
444
468
|
|
445
|
-
|
469
|
+
VALUE v = rb_str_new((char *)valuebuf, actual_valuelen);
|
470
|
+
free(valuebuf);
|
471
|
+
return v;
|
446
472
|
}
|
447
473
|
|
448
474
|
static VALUE method_hash_maxkeylen(VALUE self) {
|
data/lib/gnista/version.rb
CHANGED
data/test/test_commands.rb
CHANGED
@@ -10,12 +10,10 @@ describe Gnista do
|
|
10
10
|
|
11
11
|
before do
|
12
12
|
@logwriter = Gnista::Logwriter.new log_path
|
13
|
-
@logreader = Gnista::Logreader.new log_path
|
14
13
|
end
|
15
14
|
|
16
15
|
after do
|
17
16
|
@logwriter.close
|
18
|
-
@logreader.close
|
19
17
|
FileUtils.rm log_path
|
20
18
|
end
|
21
19
|
|
@@ -35,20 +33,28 @@ describe Gnista do
|
|
35
33
|
|
36
34
|
it "can iterate each log entry" do
|
37
35
|
@logwriter.put "key1", "value1"
|
38
|
-
@logwriter.
|
36
|
+
@logwriter.delete "key2"
|
37
|
+
@logwriter.flush
|
38
|
+
|
39
|
+
lograder = Gnista::Logreader.new log_path
|
39
40
|
|
40
41
|
a = true
|
41
|
-
|
42
|
+
lograder.each do |key,value,type|
|
42
43
|
if a
|
43
44
|
key.must_equal "key1"
|
44
45
|
value.must_equal "value1"
|
46
|
+
type.must_equal :put
|
45
47
|
a = false
|
46
48
|
else
|
47
49
|
key.must_equal "key2"
|
48
|
-
value.
|
50
|
+
value.must_be_nil
|
51
|
+
type.must_equal :delete
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
55
|
+
a.must_equal false
|
56
|
+
|
57
|
+
lograder.close
|
52
58
|
end
|
53
59
|
|
54
60
|
it "can read hash max key/value length" do
|
@@ -84,6 +90,8 @@ describe Gnista do
|
|
84
90
|
end
|
85
91
|
end
|
86
92
|
|
93
|
+
a.must_equal false
|
94
|
+
|
87
95
|
hash.close
|
88
96
|
FileUtils.rm hash_path
|
89
97
|
end
|
@@ -122,7 +130,12 @@ describe Gnista do
|
|
122
130
|
|
123
131
|
it "can be open or closed" do
|
124
132
|
@logwriter.open?.must_equal true
|
125
|
-
|
133
|
+
|
134
|
+
logreader = Gnista::Logreader.new log_path
|
135
|
+
logreader.open?.must_equal true
|
136
|
+
logreader.close
|
137
|
+
logreader.open?.must_equal false
|
138
|
+
|
126
139
|
Gnista::Hash.write hash_path, log_path
|
127
140
|
hash = Gnista::Hash.new hash_path, log_path
|
128
141
|
hash.open?.must_equal true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gnista
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emanuel Andersson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|