ilios 0.4.8 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c54ed7ca20c4e0633a57b33b41cbe2a8a9fe1c89134d92496fea61c1b5d6d0bb
4
- data.tar.gz: dbde2f3d25981a52980fb9eaf198c90aea663f1cd99b33923227ccb2fb0d76f4
3
+ metadata.gz: 1e873b74dbb71ac4a950cf02eed7f2edf1207e8e2aabfd70575643b981af4f6c
4
+ data.tar.gz: 8312031b4094cc1a8849ca87530960e8140109a520e08421ed5ef9c21418f3ce
5
5
  SHA512:
6
- metadata.gz: 2db32fe42576c2a1add3b44903c2e4b93b163f240b5adc668ecbc18ea44f1611d007737657798e11e06125e8eda86a92994716b1b6ce74231a4c6d14d901f3f9
7
- data.tar.gz: ea74e0a82689fdae39a2924c1c5feccf1a334588eb239d0bddbc0878e4811b703cc53e2c6d873a26c8c8e05b9529a1280ffc07eabd025a96a860b01a9ec6a43f
6
+ metadata.gz: 86df26c6d95ec57893a84a77e032d3380fb6f6e7f0bda23b59b8e8a8e170bea2a98c2fa1db32c9e7860220a6b3768fec3048c823c8093c23efdc87a16604d4a1
7
+ data.tar.gz: 51357dab484bf3ef443db260292c62f9f45cff02a40439d80f1ca580bcf828816bfe38db916a448a350b89b3e78ae5dafaa0ec7e1756b6a92f228070e6dcdfc2
data/Gemfile CHANGED
@@ -8,6 +8,7 @@ gemspec
8
8
  gem 'minitest', '~> 5.20'
9
9
  gem 'rake', '~> 13.0'
10
10
  gem 'rake-compiler', '~> 1.2'
11
+ gem 'rbs', '~> 3.4'
11
12
  gem 'rubocop', '~> 1.57'
12
13
  gem 'rubocop-minitest', '~> 0.33.0'
13
14
  gem 'rubocop-performance', '~> 1.19'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Watson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Ilios
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/ilios.svg)](https://badge.fury.io/rb/ilios)
4
+ [![CI](https://github.com/Watson1978/ilios/actions/workflows/CI.yml/badge.svg)](https://github.com/Watson1978/ilios/actions/workflows/CI.yml)
5
+
3
6
  Ilios that Cassandra driver written by C language for Ruby using [DataStax C/C++ Driver](https://github.com/datastax/cpp-driver).
4
7
 
5
8
  ## Installation
data/Rakefile CHANGED
@@ -14,3 +14,13 @@ end
14
14
  Rake::TestTask.new do |task|
15
15
  task.pattern = 'test/test_*.rb'
16
16
  end
17
+
18
+ namespace :rbs do
19
+ desc 'Validate RBS definitions'
20
+ task :validate do
21
+ all_sigs = Dir.glob('sig').map { |dir| "-I #{dir}" }.join(' ')
22
+ sh("bundle exec rbs #{all_sigs} validate") do |ok, _|
23
+ abort('one or more rbs validate failed') unless ok
24
+ end
25
+ end
26
+ end
data/docker-compose.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  version: '3'
2
2
  services:
3
3
  cassandra:
4
- image: cassandra:5
4
+ image: cassandra:4
5
5
  ports:
6
6
  - 9042:9042
7
7
  volumes:
data/ext/ilios/cluster.c CHANGED
@@ -49,6 +49,7 @@ static VALUE cluster_connect(VALUE self)
49
49
  {
50
50
  CassandraSession *cassandra_session;
51
51
  CassandraCluster *cassandra_cluster;
52
+ CassFuture* connect_future;
52
53
  VALUE cassandra_session_obj;
53
54
  const char *keyspace = "";
54
55
 
@@ -60,16 +61,18 @@ static VALUE cluster_connect(VALUE self)
60
61
  cassandra_session_obj = CREATE_SESSION(cassandra_session);
61
62
  cassandra_session->cluster_obj = self;
62
63
  cassandra_session->session = cass_session_new();
63
- cassandra_session->connect_future = cass_session_connect_keyspace(cassandra_session->session, cassandra_cluster->cluster, keyspace);
64
- nogvl_future_wait(cassandra_session->connect_future);
64
+ connect_future = cass_session_connect_keyspace(cassandra_session->session, cassandra_cluster->cluster, keyspace);
65
+ nogvl_future_wait(connect_future);
65
66
 
66
- if (cass_future_error_code(cassandra_session->connect_future) != CASS_OK) {
67
+ if (cass_future_error_code(connect_future) != CASS_OK) {
67
68
  char error[4096] = { 0 };
68
69
 
69
- strncpy(error, cass_error_desc(cass_future_error_code(cassandra_session->connect_future)), sizeof(error) - 1);
70
+ strncpy(error, cass_error_desc(cass_future_error_code(connect_future)), sizeof(error) - 1);
71
+ cass_future_free(connect_future);
70
72
  rb_raise(eConnectError, "Unable to connect: %s", error);
71
73
  return Qnil;
72
74
  }
75
+ cass_future_free(connect_future);
73
76
 
74
77
  return cassandra_session_obj;
75
78
  }
data/ext/ilios/extconf.rb CHANGED
@@ -4,7 +4,6 @@ require File.expand_path('../../lib/ilios/version', __dir__)
4
4
  require 'fileutils'
5
5
  require 'mini_portile2'
6
6
  require 'mkmf'
7
- require 'native-package-installer'
8
7
 
9
8
  have_func('malloc_usable_size')
10
9
  have_func('malloc_size')
@@ -24,6 +23,7 @@ def num_cpu_cores
24
23
  end
25
24
 
26
25
  return 1 if cores <= 0
26
+
27
27
  cores >= 7 ? MAX_CORES : cores
28
28
  end
29
29
 
@@ -40,25 +40,9 @@ module LibuvInstaller
40
40
  end
41
41
 
42
42
  def self.install
43
- return if install_from_package
44
-
45
43
  install_from_source
46
44
  end
47
45
 
48
- def self.install_from_package
49
- NativePackageInstaller.install(
50
- alpine_linux: 'libuv-dev',
51
- alt_linux: 'libuv',
52
- arch_linux: 'libuv',
53
- debian: 'libuv1-dev',
54
- freebsd: 'libuv',
55
- gentoo_linux: 'libuv',
56
- homebrew: 'libuv',
57
- macports: 'libuv',
58
- redhat: 'libuv-devel'
59
- )
60
- end
61
-
62
46
  def self.install_from_source
63
47
  unless File.exist?(LIBUV_INSTALL_PATH)
64
48
  libuv_recipe = LibuvRecipe.new('libuv', Ilios::LIBUV_VERSION, make_command: "make -j #{num_cpu_cores}")
@@ -158,4 +142,7 @@ else
158
142
  CassandraDriverInstaller.install
159
143
  end
160
144
 
145
+ $CPPFLAGS += " #{ENV['CPPFLAGS']}"
146
+ $LDFLAGS += " #{ENV['LDFLAGS']}"
147
+
161
148
  create_makefile('ilios')
data/ext/ilios/future.c CHANGED
@@ -195,31 +195,12 @@ VALUE future_create(CassFuture *future, VALUE session, future_kind kind)
195
195
  return cassandra_future_obj;
196
196
  }
197
197
 
198
- /**
199
- * Run block when future resolves to a value.
200
- *
201
- * @yieldparam value [Cassandra::Statement, Cassandra::Result] A value.
202
- * Yields +Cassandra::Statement+ object when future was created by +Cassandra::Session#prepare_async+.
203
- * Yields +Cassandra::Result+ object when future was created by +Cassandra::Session#execute_async+.
204
- * @return [Cassandra::Future] self.
205
- * @raise [Cassandra::ExecutionError] If this method will be called twice.
206
- * @raise [ArgumentError] If no block was given.
207
- */
208
- static VALUE future_on_success(VALUE self)
198
+ static VALUE future_on_success_synchronize(VALUE future)
209
199
  {
210
200
  CassandraFuture *cassandra_future;
211
201
  bool wakeup_thread = false;
212
202
 
213
- GET_FUTURE(self, cassandra_future);
214
-
215
- if (cassandra_future->on_success_block) {
216
- rb_raise(eExecutionError, "It should not call twice");
217
- }
218
- if (!rb_block_given_p()) {
219
- rb_raise(rb_eArgError, "no block given");
220
- }
221
-
222
- rb_mutex_lock(cassandra_future->proc_mutex);
203
+ GET_FUTURE(future, cassandra_future);
223
204
 
224
205
  if (!cassandra_future->on_failure_block) {
225
206
  // Invoke the callback with thread pool only once
@@ -229,44 +210,52 @@ static VALUE future_on_success(VALUE self)
229
210
  cassandra_future->on_success_block = rb_block_proc();
230
211
 
231
212
  if (cass_future_ready(cassandra_future->future)) {
232
- rb_mutex_unlock(cassandra_future->proc_mutex);
233
213
  uv_sem_post(&cassandra_future->sem);
234
214
  if (cass_future_error_code(cassandra_future->future) == CASS_OK) {
235
215
  future_result_success_yield(cassandra_future);
236
216
  }
237
- return self;
217
+ return future;
238
218
  }
239
219
 
240
220
  if (wakeup_thread) {
241
- future_queue_push(future_thread_pool_get(cassandra_future), self);
221
+ future_queue_push(future_thread_pool_get(cassandra_future), future);
242
222
  }
243
- rb_mutex_unlock(cassandra_future->proc_mutex);
244
223
 
245
- return self;
224
+ return future;
246
225
  }
247
226
 
248
227
  /**
249
- * Run block when future resolves to error.
228
+ * Run block when future resolves to a value.
250
229
  *
230
+ * @yieldparam value [Cassandra::Statement, Cassandra::Result] A value.
231
+ * Yields +Cassandra::Statement+ object when future was created by +Cassandra::Session#prepare_async+.
232
+ * Yields +Cassandra::Result+ object when future was created by +Cassandra::Session#execute_async+.
251
233
  * @return [Cassandra::Future] self.
252
234
  * @raise [Cassandra::ExecutionError] If this method will be called twice.
253
235
  * @raise [ArgumentError] If no block was given.
254
236
  */
255
- static VALUE future_on_failure(VALUE self)
237
+ static VALUE future_on_success(VALUE self)
256
238
  {
257
239
  CassandraFuture *cassandra_future;
258
- bool wakeup_thread = false;
259
240
 
260
241
  GET_FUTURE(self, cassandra_future);
261
242
 
262
- if (cassandra_future->on_failure_block) {
243
+ if (cassandra_future->on_success_block) {
263
244
  rb_raise(eExecutionError, "It should not call twice");
264
245
  }
265
246
  if (!rb_block_given_p()) {
266
247
  rb_raise(rb_eArgError, "no block given");
267
248
  }
268
249
 
269
- rb_mutex_lock(cassandra_future->proc_mutex);
250
+ return rb_mutex_synchronize(cassandra_future->proc_mutex, future_on_success_synchronize, self);
251
+ }
252
+
253
+ static VALUE future_on_failure_synchronize(VALUE future)
254
+ {
255
+ CassandraFuture *cassandra_future;
256
+ bool wakeup_thread = false;
257
+
258
+ GET_FUTURE(future, cassandra_future);
270
259
 
271
260
  if (!cassandra_future->on_success_block) {
272
261
  // Invoke the callback with thread pool only once
@@ -276,20 +265,41 @@ static VALUE future_on_failure(VALUE self)
276
265
  cassandra_future->on_failure_block = rb_block_proc();
277
266
 
278
267
  if (cass_future_ready(cassandra_future->future)) {
279
- rb_mutex_unlock(cassandra_future->proc_mutex);
280
268
  uv_sem_post(&cassandra_future->sem);
281
269
  if (cass_future_error_code(cassandra_future->future) != CASS_OK) {
282
270
  future_result_failure_yield(cassandra_future);
283
271
  }
284
- return self;
272
+ return future;
285
273
  }
286
274
 
287
275
  if (wakeup_thread) {
288
- future_queue_push(future_thread_pool_get(cassandra_future), self);
276
+ future_queue_push(future_thread_pool_get(cassandra_future), future);
289
277
  }
290
- rb_mutex_unlock(cassandra_future->proc_mutex);
291
278
 
292
- return self;
279
+ return future;
280
+ }
281
+
282
+ /**
283
+ * Run block when future resolves to error.
284
+ *
285
+ * @return [Cassandra::Future] self.
286
+ * @raise [Cassandra::ExecutionError] If this method will be called twice.
287
+ * @raise [ArgumentError] If no block was given.
288
+ */
289
+ static VALUE future_on_failure(VALUE self)
290
+ {
291
+ CassandraFuture *cassandra_future;
292
+
293
+ GET_FUTURE(self, cassandra_future);
294
+
295
+ if (cassandra_future->on_failure_block) {
296
+ rb_raise(eExecutionError, "It should not call twice");
297
+ }
298
+ if (!rb_block_given_p()) {
299
+ rb_raise(rb_eArgError, "no block given");
300
+ }
301
+
302
+ return rb_mutex_synchronize(cassandra_future->proc_mutex, future_on_failure_synchronize, self);
293
303
  }
294
304
 
295
305
  /**
@@ -303,16 +313,18 @@ static VALUE future_await(VALUE self)
303
313
 
304
314
  GET_FUTURE(self, cassandra_future);
305
315
 
316
+ rb_mutex_lock(cassandra_future->proc_mutex);
306
317
  if (cassandra_future->already_waited) {
318
+ rb_mutex_unlock(cassandra_future->proc_mutex);
307
319
  return self;
308
320
  }
321
+ cassandra_future->already_waited = true;
322
+ rb_mutex_unlock(cassandra_future->proc_mutex);
309
323
 
324
+ nogvl_future_wait(cassandra_future->future);
310
325
  if (cassandra_future->on_success_block || cassandra_future->on_failure_block) {
311
326
  nogvl_sem_wait(&cassandra_future->sem);
312
- } else {
313
- nogvl_future_wait(cassandra_future->future);
314
327
  }
315
- cassandra_future->already_waited = true;
316
328
  return self;
317
329
  }
318
330
 
data/ext/ilios/ilios.c CHANGED
@@ -58,6 +58,18 @@ static void ilios_free(void *ptr)
58
58
  }
59
59
  }
60
60
 
61
+ /**
62
+ * Sets the log level.
63
+ * Default is +LOG_ERROR+.
64
+ *
65
+ * @return [Cassandra] self.
66
+ */
67
+ static VALUE cassandra_set_log_level(VALUE self, VALUE log_level)
68
+ {
69
+ cass_log_set_level(NUM2INT(log_level));
70
+ return self;
71
+ }
72
+
61
73
  void Init_ilios(void)
62
74
  {
63
75
  rb_ext_ractor_safe(true);
@@ -83,6 +95,15 @@ void Init_ilios(void)
83
95
  id_report_on_exception = rb_intern("report_on_exception=");
84
96
  sym_unsupported_column_type = ID2SYM(rb_intern("unsupported_column_type"));
85
97
 
98
+ rb_define_module_function(mCassandra, "log_level", cassandra_set_log_level, 1);
99
+ rb_define_const(mCassandra, "LOG_DISABLED", INT2NUM(CASS_LOG_DISABLED));
100
+ rb_define_const(mCassandra, "LOG_CRITICAL", INT2NUM(CASS_LOG_CRITICAL));
101
+ rb_define_const(mCassandra, "LOG_ERROR", INT2NUM(CASS_LOG_ERROR));
102
+ rb_define_const(mCassandra, "LOG_WARN", INT2NUM(CASS_LOG_WARN));
103
+ rb_define_const(mCassandra, "LOG_INFO", INT2NUM(CASS_LOG_INFO));
104
+ rb_define_const(mCassandra, "LOG_DEBUG", INT2NUM(CASS_LOG_DEBUG));
105
+ rb_define_const(mCassandra, "LOG_TRACE", INT2NUM(CASS_LOG_TRACE));
106
+
86
107
  Init_cluster();
87
108
  Init_session();
88
109
  Init_statement();
data/ext/ilios/ilios.h CHANGED
@@ -35,7 +35,6 @@ typedef struct
35
35
  typedef struct
36
36
  {
37
37
  CassSession* session;
38
- CassFuture* connect_future;
39
38
  VALUE cluster_obj;
40
39
  } CassandraSession;
41
40
 
data/ext/ilios/session.c CHANGED
@@ -136,9 +136,6 @@ static void session_destroy(void *ptr)
136
136
  if (cassandra_session->session) {
137
137
  cass_session_free(cassandra_session->session);
138
138
  }
139
- if (cassandra_session->connect_future) {
140
- cass_future_free(cassandra_session->connect_future);
141
- }
142
139
  xfree(cassandra_session);
143
140
  }
144
141
 
data/ilios.gemspec CHANGED
@@ -35,5 +35,4 @@ Gem::Specification.new do |spec|
35
35
  spec.extensions << 'ext/ilios/extconf.rb'
36
36
 
37
37
  spec.add_runtime_dependency('mini_portile2', '~> 2.8')
38
- spec.add_runtime_dependency('native-package-installer', '~> 1.1', '>= 1.1.9')
39
38
  end
data/lib/ilios/version.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ilios
4
- VERSION = '0.4.8'
4
+ VERSION = '0.4.10'
5
5
  public_constant :VERSION
6
6
 
7
7
  CASSANDRA_CPP_DRIVER_VERSION = '2.17.1'
8
8
  public_constant :CASSANDRA_CPP_DRIVER_VERSION
9
9
 
10
- LIBUV_VERSION = '1.47.0'
10
+ LIBUV_VERSION = '1.48.0'
11
11
  public_constant :LIBUV_VERSION
12
12
  end
data/sig/ilios.rbs CHANGED
@@ -2,7 +2,25 @@ module Ilios
2
2
  VERSION: String
3
3
 
4
4
  module Cassandra
5
+ LOG_DISABLED: Integer
6
+ LOG_CRITICAL: Integer
7
+ LOG_ERROR: Integer
8
+ LOG_WARN: Integer
9
+ LOG_INFO: Integer
10
+ LOG_DEBUG: Integer
11
+ LOG_TRACE: Integer
12
+
13
+ def self.log_level: (Integer log_level) -> self
14
+
5
15
  class Cluster
16
+ PROTOCOL_VERSION_V1: Integer
17
+ PROTOCOL_VERSION_V2: Integer
18
+ PROTOCOL_VERSION_V3: Integer
19
+ PROTOCOL_VERSION_V4: Integer
20
+ PROTOCOL_VERSION_V5: Integer
21
+ PROTOCOL_VERSION_DSEV1: Integer
22
+ PROTOCOL_VERSION_DSEV2: Integer
23
+
6
24
  def connect: () -> Ilios::Cassandra::Session
7
25
  def hosts: (Array[String]) -> self
8
26
  def port: (Integer) -> self
@@ -23,7 +41,7 @@ module Ilios
23
41
  end
24
42
 
25
43
  class Statement
26
- def bind: (Hash[Symbol, untyped] | Hash[String, untyped]) -> self
44
+ def bind: (Hash[Symbol | String, untyped]) -> self
27
45
  def page_size=: (Integer) -> self
28
46
  def idempotent=: (true | false) -> self
29
47
  end
@@ -31,7 +49,7 @@ module Ilios
31
49
  class Future
32
50
  def on_success: () { (Ilios::Cassandra::Result) -> void } -> self
33
51
  def on_failure: () { () -> void } -> self
34
- def await: () -> Ilios::Cassandra::Future
52
+ def await: () -> self
35
53
  end
36
54
 
37
55
  class Result
@@ -39,10 +57,9 @@ module Ilios
39
57
 
40
58
  include Enumerable[row_type]
41
59
 
42
- def each: () { (row_type) -> void } -> void |
43
- () -> ::Enumerator[row_type, self]
44
- def next_page: () -> Ilios::Cassandra::Result |
45
- () -> nil
60
+ def each: () { (row_type) -> void } -> void
61
+ | () -> ::Enumerator[row_type, self]
62
+ def next_page: () -> (Ilios::Cassandra::Result | nil)
46
63
  end
47
64
  end
48
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ilios
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-10 00:00:00.000000000 Z
11
+ date: 2024-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_portile2
@@ -24,26 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.8'
27
- - !ruby/object:Gem::Dependency
28
- name: native-package-installer
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.1'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 1.1.9
37
- type: :runtime
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '1.1'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 1.1.9
47
27
  description: Cassandra driver written by C language
48
28
  email:
49
29
  - watson1978@gmail.com
@@ -54,6 +34,7 @@ extra_rdoc_files: []
54
34
  files:
55
35
  - ".yardopts"
56
36
  - Gemfile
37
+ - LICENSE
57
38
  - README.md
58
39
  - Rakefile
59
40
  - docker-compose.yml
@@ -77,7 +58,7 @@ metadata:
77
58
  homepage_uri: https://github.com/Watson1978/ilios
78
59
  source_code_uri: https://github.com/Watson1978/ilios
79
60
  bug_tracker_uri: https://github.com/Watson1978/ilios/issues
80
- documentation_uri: https://www.rubydoc.info/gems/ilios/0.4.8
61
+ documentation_uri: https://www.rubydoc.info/gems/ilios/0.4.10
81
62
  rubygems_mfa_required: 'true'
82
63
  post_install_message:
83
64
  rdoc_options: []