chunkio 0.1.2 → 0.1.3
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 +4 -4
- data/.github/workflows/run_rspec.yml +17 -0
- data/.rspec +0 -1
- data/README.md +11 -5
- data/ext/chunkio/chunkio.h +1 -0
- data/ext/chunkio/chunkio_chunk.c +59 -8
- data/ext/chunkio/chunkio_context.c +10 -3
- data/ext/chunkio/chunkio_stream.c +5 -2
- data/ext/chunkio/extconf.rb +1 -1
- data/lib/chunkio/chunkio.rb +0 -16
- data/lib/chunkio/version.rb +1 -1
- metadata +3 -3
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 460315c74fc22187a8a9256c91bc84e51f10f965bf3b8099afed88cbff4b34ee
|
4
|
+
data.tar.gz: 7a835dbbf371b8fbab4e60005807f03cb231f7a0f279c59539dbc36135170d4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 147c6a423b0cd1ba99d8e2449516aa28fa0b8419a5781f0f68a95e9cebbaccf5b7260fe9d1b0d983af5e5b7afc4e5ed31f500d42bbbc2e658ceea8ed8da8b8cb
|
7
|
+
data.tar.gz: 1de878786e978061335001e18ec311e0b2708ec55099d8fa1afbb072e341bbe276baa1ffd9e57883446042f433e021274bde67cf5a4cd1380477df937cf5a78c
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: Run specs
|
2
|
+
on: [push]
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
steps:
|
7
|
+
- uses: actions/checkout@v1
|
8
|
+
- name: Set up Ruby 2.6
|
9
|
+
uses: actions/setup-ruby@v1
|
10
|
+
with:
|
11
|
+
ruby-version: 2.6.x
|
12
|
+
- name: Build and test with Rake
|
13
|
+
run: |
|
14
|
+
gem install bundler
|
15
|
+
bundle install --jobs 4 --retry 3
|
16
|
+
bundle exec rake compile
|
17
|
+
bundle exec rspec
|
data/.rspec
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# ChunkI/O
|
2
2
|
|
3
|
-
|
3
|
+
[](https://github.com/ganmacs/chunkio-rb/actions)
|
4
4
|
|
5
|
-
|
5
|
+
This gem is wrapper around [ChunkI/O](https://github.com/edsiper/chunkio).
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,7 +22,13 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
```rb
|
26
|
+
require 'chunkio'
|
27
|
+
c = ChunkIO.new
|
28
|
+
c.write("test")
|
29
|
+
c.set_metadata("this is metadata")
|
30
|
+
c.close
|
31
|
+
```
|
26
32
|
|
27
33
|
## Development
|
28
34
|
|
@@ -32,4 +38,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
38
|
|
33
39
|
## Contributing
|
34
40
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ganmacs/chunkio.
|
data/ext/chunkio/chunkio.h
CHANGED
data/ext/chunkio/chunkio_chunk.c
CHANGED
@@ -4,7 +4,7 @@ VALUE cCIO_Chunk;
|
|
4
4
|
|
5
5
|
void *chunkio_chunk_free(chunkio_chunk *ch)
|
6
6
|
{
|
7
|
-
if (ch->inner) {
|
7
|
+
if (ch->inner != NULL) {
|
8
8
|
cio_chunk_sync(ch->inner);
|
9
9
|
cio_chunk_close(ch->inner, CIO_FALSE);
|
10
10
|
ch->inner = NULL;
|
@@ -16,7 +16,9 @@ void *chunkio_chunk_free(chunkio_chunk *ch)
|
|
16
16
|
static VALUE chunkio_chunk_allocate_context(VALUE klass)
|
17
17
|
{
|
18
18
|
chunkio_chunk *c = (chunkio_chunk *)xmalloc(sizeof(chunkio_chunk));
|
19
|
+
c->inner = NULL;
|
19
20
|
c->closed = 0;
|
21
|
+
c->sync_mode = 0;
|
20
22
|
return TypedData_Wrap_Struct(klass, &chunkio_chunk_type, c);
|
21
23
|
}
|
22
24
|
|
@@ -24,9 +26,15 @@ static VALUE chunkio_chunk_initialize(VALUE self, VALUE context, VALUE stream, V
|
|
24
26
|
{
|
25
27
|
struct cio_ctx *ctx = UnwrapChunkIOContext(context);
|
26
28
|
struct cio_stream *st = UnwrapChunkIOStream(stream);
|
27
|
-
const char *c_name =
|
29
|
+
const char *c_name = StringValuePtr(name);
|
30
|
+
if (strlen(c_name) == 0) {
|
31
|
+
rb_raise(rb_eStandardError, "chunk name is not allowed empty string");
|
32
|
+
}
|
28
33
|
|
29
34
|
struct cio_chunk *chunk = cio_chunk_open(ctx, st, c_name, CIO_OPEN, 1000);
|
35
|
+
if (chunk == NULL) {
|
36
|
+
rb_raise(rb_eStandardError, "Failed to create chunk");
|
37
|
+
}
|
30
38
|
|
31
39
|
((chunkio_chunk*)DATA_PTR(self))->inner = chunk;
|
32
40
|
return self;
|
@@ -77,12 +85,20 @@ static VALUE chunkio_chunk_write(VALUE self, VALUE buf)
|
|
77
85
|
{
|
78
86
|
chunkio_chunk *chunk = NULL;
|
79
87
|
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
80
|
-
ssize_t len = RSTRING_LEN(buf);
|
81
88
|
if (chunk->closed) {
|
82
89
|
rb_raise(rb_eIOError, "IO was already closed");
|
83
90
|
}
|
91
|
+
Check_Type(buf, T_STRING);
|
84
92
|
|
93
|
+
ssize_t len = RSTRING_LEN(buf);
|
85
94
|
cio_chunk_write(chunk->inner, (void *)RSTRING_PTR(buf), len);
|
95
|
+
|
96
|
+
if (chunk->sync_mode) {
|
97
|
+
int ret = cio_chunk_sync(chunk->inner);
|
98
|
+
if (ret == -1) {
|
99
|
+
rb_raise(rb_eStandardError, "failed to sync");
|
100
|
+
}
|
101
|
+
}
|
86
102
|
return INT2NUM(len);
|
87
103
|
}
|
88
104
|
|
@@ -114,11 +130,19 @@ static VALUE chunkio_chunk_set_metadata(VALUE self, VALUE buf)
|
|
114
130
|
rb_raise(rb_eIOError, "IO was already closed");
|
115
131
|
}
|
116
132
|
|
133
|
+
Check_Type(buf, T_STRING);
|
117
134
|
ssize_t len = RSTRING_LEN(buf);
|
118
135
|
int ret = cio_meta_write(chunk->inner, (void *)RSTRING_PTR(buf), len);
|
119
136
|
if (ret == -1) {
|
120
137
|
rb_raise(rb_eStandardError, "failed to set metadata");
|
121
138
|
}
|
139
|
+
|
140
|
+
if (chunk->sync_mode) {
|
141
|
+
int ret = cio_chunk_sync(chunk->inner);
|
142
|
+
if (ret == -1) {
|
143
|
+
rb_raise(rb_eStandardError, "failed to sync");
|
144
|
+
}
|
145
|
+
}
|
122
146
|
return INT2NUM(len);
|
123
147
|
}
|
124
148
|
|
@@ -139,9 +163,6 @@ static VALUE chunkio_chunk_metadata(VALUE self)
|
|
139
163
|
}
|
140
164
|
|
141
165
|
int ret = cio_meta_read(chunk->inner, &buf, &size);
|
142
|
-
if (ret == -1) {
|
143
|
-
rb_raise(rb_eStandardError, "failed to get metadata");
|
144
|
-
}
|
145
166
|
|
146
167
|
return rb_str_new(buf, size);
|
147
168
|
}
|
@@ -198,7 +219,7 @@ static VALUE chunkio_chunk_tx_begin(VALUE self)
|
|
198
219
|
|
199
220
|
int ret = cio_chunk_tx_begin(chunk->inner);
|
200
221
|
if (ret == -1) {
|
201
|
-
rb_raise(rb_eStandardError, "
|
222
|
+
rb_raise(rb_eStandardError, "Failed to begin transaction");
|
202
223
|
}
|
203
224
|
|
204
225
|
return Qnil;
|
@@ -216,6 +237,13 @@ static VALUE chunkio_chunk_tx_commit(VALUE self)
|
|
216
237
|
if (ret == -1) {
|
217
238
|
rb_raise(rb_eStandardError, "failed to commit transaction");
|
218
239
|
}
|
240
|
+
|
241
|
+
if (chunk->sync_mode) {
|
242
|
+
int ret = cio_chunk_sync(chunk->inner);
|
243
|
+
if (ret == -1) {
|
244
|
+
rb_raise(rb_eStandardError, "failed to sync");
|
245
|
+
}
|
246
|
+
}
|
219
247
|
return Qnil;
|
220
248
|
}
|
221
249
|
|
@@ -229,11 +257,32 @@ static VALUE chunkio_chunk_tx_rollback(VALUE self)
|
|
229
257
|
|
230
258
|
int ret = cio_chunk_tx_rollback(chunk->inner);
|
231
259
|
if (ret == -1) {
|
232
|
-
rb_raise(rb_eStandardError, "
|
260
|
+
rb_raise(rb_eStandardError, "Failed to rollback transaction");
|
233
261
|
}
|
234
262
|
return Qnil;
|
235
263
|
}
|
236
264
|
|
265
|
+
static VALUE chunkio_chunk_sync_mode(VALUE self) {
|
266
|
+
chunkio_chunk *chunk;
|
267
|
+
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
268
|
+
return chunk->sync_mode == 1 ? Qtrue : Qfalse;
|
269
|
+
}
|
270
|
+
|
271
|
+
static VALUE chunkio_chunk_sync_mode_assign(VALUE self, VALUE bool) {
|
272
|
+
chunkio_chunk *chunk;
|
273
|
+
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
274
|
+
|
275
|
+
if (bool == Qtrue) {
|
276
|
+
chunk->sync_mode = 1;
|
277
|
+
} else if (bool == Qfalse){
|
278
|
+
chunk->sync_mode = 0;
|
279
|
+
} else {
|
280
|
+
rb_raise(rb_eTypeError, "expected true or false");
|
281
|
+
}
|
282
|
+
|
283
|
+
return Qnil;
|
284
|
+
}
|
285
|
+
|
237
286
|
void Init_chunkio_chunk(VALUE mChunkIO)
|
238
287
|
{
|
239
288
|
cCIO_Chunk = rb_define_class_under(mChunkIO, "Chunk", rb_cObject);
|
@@ -251,5 +300,7 @@ void Init_chunkio_chunk(VALUE mChunkIO)
|
|
251
300
|
rb_define_method(cCIO_Chunk, "tx_begin", chunkio_chunk_tx_begin, 0);
|
252
301
|
rb_define_method(cCIO_Chunk, "tx_commit", chunkio_chunk_tx_commit, 0);
|
253
302
|
rb_define_method(cCIO_Chunk, "tx_rollback", chunkio_chunk_tx_rollback, 0);
|
303
|
+
rb_define_method(cCIO_Chunk, "sync_mode", chunkio_chunk_sync_mode, 0);
|
304
|
+
rb_define_method(cCIO_Chunk, "sync_mode=", chunkio_chunk_sync_mode_assign, 1);
|
254
305
|
/* rb_define_method(cCIO_Chunk, "write_at", chunkio_chunk_write_at, 2); */
|
255
306
|
}
|
@@ -39,9 +39,16 @@ static VALUE allocate_context(VALUE klass)
|
|
39
39
|
|
40
40
|
static VALUE chunkio_context_initialize(VALUE self, VALUE root)
|
41
41
|
{
|
42
|
-
char *p =
|
43
|
-
|
44
|
-
|
42
|
+
char *p = StringValuePtr(root);
|
43
|
+
if (strlen(p) == 0) {
|
44
|
+
rb_raise(rb_eStandardError, "Context root path is not allowed empty string");
|
45
|
+
}
|
46
|
+
|
47
|
+
/* permission is fixed for now */
|
48
|
+
rb_funcall(rb_const_get(rb_cObject, rb_intern("FileUtils")), rb_intern("mkdir_p"), 1, root);
|
49
|
+
|
50
|
+
/* struct cio_ctx *ctx = cio_create(p, log_cb, CIO_DEBUG, 0); /\* flag *\/ */
|
51
|
+
struct cio_ctx *ctx = cio_create(p, 0, CIO_DEBUG, 0); /* flag */
|
45
52
|
if (!ctx) {
|
46
53
|
rb_raise(rb_eStandardError, "failed to create cio_ctx");
|
47
54
|
}
|
@@ -4,7 +4,6 @@ VALUE cCIO_Stream;
|
|
4
4
|
|
5
5
|
void *chunkio_stream_free(struct cio_stream *st)
|
6
6
|
{
|
7
|
-
|
8
7
|
/*
|
9
8
|
Don't call cio_chunk_close_stream(st).
|
10
9
|
cio_chunk is freed by chunkio_chunk.
|
@@ -33,7 +32,11 @@ static VALUE allocate_stream(VALUE klass)
|
|
33
32
|
|
34
33
|
static VALUE chunkio_stream_initialize(VALUE self, VALUE context, VALUE name)
|
35
34
|
{
|
36
|
-
char *stream_name =
|
35
|
+
char *stream_name = StringValuePtr(name);
|
36
|
+
if (strlen(stream_name) == 0) {
|
37
|
+
rb_raise(rb_eStandardError, "stream_name is not allowed empty string");
|
38
|
+
}
|
39
|
+
|
37
40
|
struct cio_ctx *ctx = UnwrapChunkIOContext(context);
|
38
41
|
struct cio_stream *st = cio_stream_create(ctx, stream_name, CIO_STORE_FS); /* TODO CIO_STORE_FS */
|
39
42
|
if (!st) {
|
data/ext/chunkio/extconf.rb
CHANGED
@@ -9,7 +9,7 @@ message "Building chunkio\n"
|
|
9
9
|
recipe = MiniPortileCMake.new('chunkio', 'v0.0.1')
|
10
10
|
|
11
11
|
recipe.files << {
|
12
|
-
url: 'https://github.com/ganmacs/chunkio/tarball/
|
12
|
+
url: 'https://github.com/ganmacs/chunkio/tarball/612777c764057c53988db3899d88adce6fe742a1',
|
13
13
|
}
|
14
14
|
|
15
15
|
class << recipe
|
data/lib/chunkio/chunkio.rb
CHANGED
@@ -5,22 +5,6 @@ require 'chunkio.so'
|
|
5
5
|
module ChunkIO
|
6
6
|
class ChunkIO
|
7
7
|
def initialize(context_path:, stream_name:)
|
8
|
-
unless context_path
|
9
|
-
raise 'invalid'
|
10
|
-
end
|
11
|
-
|
12
|
-
unless stream_name
|
13
|
-
raise 'stream'
|
14
|
-
end
|
15
|
-
|
16
|
-
if context_path.empty?
|
17
|
-
raise 'context_path should be at least one char'
|
18
|
-
end
|
19
|
-
|
20
|
-
if stream_name.empty?
|
21
|
-
raise 'stream_name should be at least one char'
|
22
|
-
end
|
23
|
-
|
24
8
|
@ctx = ::ChunkIO::Context.new(context_path)
|
25
9
|
@stream = ::ChunkIO::Stream.new(@ctx, stream_name)
|
26
10
|
@chunks = []
|
data/lib/chunkio/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chunkio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuta Iwama
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mini_portile2
|
@@ -103,10 +103,10 @@ extensions:
|
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
105
|
- ".editorconfig"
|
106
|
+
- ".github/workflows/run_rspec.yml"
|
106
107
|
- ".gitignore"
|
107
108
|
- ".rspec"
|
108
109
|
- ".rubocop.yml"
|
109
|
-
- ".travis.yml"
|
110
110
|
- Gemfile
|
111
111
|
- LICENSE
|
112
112
|
- README.md
|