Class: Ilios::Cassandra::Cluster
- Inherits:
-
Object
- Object
- Ilios::Cassandra::Cluster
- Defined in:
- ext/ilios/ilios.c
Constant Summary collapse
- PROTOCOL_VERSION_V1 =
INT2NUM(CASS_PROTOCOL_VERSION_V1)
- PROTOCOL_VERSION_V2 =
INT2NUM(CASS_PROTOCOL_VERSION_V2)
- PROTOCOL_VERSION_V3 =
INT2NUM(CASS_PROTOCOL_VERSION_V3)
- PROTOCOL_VERSION_V4 =
INT2NUM(CASS_PROTOCOL_VERSION_V4)
- PROTOCOL_VERSION_V5 =
INT2NUM(CASS_PROTOCOL_VERSION_V5)
- PROTOCOL_VERSION_DSEV1 =
INT2NUM(CASS_PROTOCOL_VERSION_DSEV1)
- PROTOCOL_VERSION_DSEV2 =
INT2NUM(CASS_PROTOCOL_VERSION_DSEV2)
- CONSISTENCY_ANY =
INT2NUM(CASS_CONSISTENCY_ANY)
- CONSISTENCY_ONE =
INT2NUM(CASS_CONSISTENCY_ONE)
- CONSISTENCY_TWO =
INT2NUM(CASS_CONSISTENCY_TWO)
- CONSISTENCY_THREE =
INT2NUM(CASS_CONSISTENCY_THREE)
- CONSISTENCY_QUORUM =
INT2NUM(CASS_CONSISTENCY_QUORUM)
- CONSISTENCY_ALL =
INT2NUM(CASS_CONSISTENCY_ALL)
- CONSISTENCY_LOCAL_QUORUM =
INT2NUM(CASS_CONSISTENCY_LOCAL_QUORUM)
- CONSISTENCY_EACH_QUORUM =
INT2NUM(CASS_CONSISTENCY_EACH_QUORUM)
- CONSISTENCY_SERIAL =
INT2NUM(CASS_CONSISTENCY_SERIAL)
- CONSISTENCY_LOCAL_SERIAL =
INT2NUM(CASS_CONSISTENCY_LOCAL_SERIAL)
- CONSISTENCY_LOCAL_ONE =
INT2NUM(CASS_CONSISTENCY_LOCAL_ONE)
Instance Method Summary collapse
- #connect ⇒ Object
- #connect_timeout(timeout_ms) ⇒ Object
- #connection_heartbeat_interval(interval_secs) ⇒ Object
- #connection_idle_timeout(timeout_secs) ⇒ Object
- #consistency(consistency) ⇒ Object
- #constant_reconnect(delay_ms) ⇒ Object
- #constant_speculative_execution_policy(constant_delay_ms, max_speculative_executions) ⇒ Object
- #core_connections_per_host(num_connections) ⇒ Object
- #credentials(username, password) ⇒ Object
- #exponential_reconnect(base_delay_ms, max_delay_ms) ⇒ Object
- #hosts(hosts) ⇒ Object
- #initialize ⇒ Object constructor
- #keyspace(keyspace) ⇒ Object
- #latency_aware_routing(enabled) ⇒ Object
- #load_balance_dc_aware(local_dc) ⇒ Object
- #load_balance_round_robin ⇒ Object
- #num_threads_io(num_threads) ⇒ Object
- #port(port) ⇒ Object
- #protocol_version(version) ⇒ Object
- #queue_size_io(queue_size) ⇒ Object
- #request_timeout(timeout_ms) ⇒ Object
- #resolve_timeout(timeout_ms) ⇒ Object
- #serial_consistency(consistency) ⇒ Object
- #tcp_keepalive(enabled, delay_secs) ⇒ Object
- #tcp_nodelay(enabled) ⇒ Object
- #token_aware_routing(enabled) ⇒ Object
- #use_schema(enabled) ⇒ Object
Constructor Details
#initialize ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'ext/ilios/cluster.c', line 61
static VALUE cluster_initialize(VALUE self)
{
CassandraCluster *cassandra_cluster;
GET_UNINITIALIZED_CLUSTER(self, cassandra_cluster);
cassandra_cluster->cluster = cass_cluster_new();
return self;
}
|
Instance Method Details
#connect ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'ext/ilios/cluster.c', line 78
static VALUE cluster_connect(VALUE self)
{
CassandraSession *cassandra_session;
CassandraCluster *cassandra_cluster;
CassFuture* connect_future;
VALUE cassandra_session_obj;
const char *keyspace = "";
GET_CLUSTER(self, cassandra_cluster);
if (cassandra_cluster->keyspace) {
keyspace = StringValueCStr(cassandra_cluster->keyspace);
}
cassandra_session_obj = CREATE_SESSION(cassandra_session);
cassandra_session->cluster_obj = self;
cassandra_session->session = cass_session_new();
connect_future = cass_session_connect_keyspace(cassandra_session->session, cassandra_cluster->cluster, keyspace);
nogvl_future_wait(connect_future);
if (cass_future_error_code(connect_future) != CASS_OK) {
VALUE error = ilios_future_error_new(eConnectError, "Unable to connect", connect_future);
cass_future_free(connect_future);
rb_exc_raise(error);
}
cass_future_free(connect_future);
return cassandra_session_obj;
}
|
#connect_timeout(timeout_ms) ⇒ Object
209 210 211 212 213 214 215 216 217 |
# File 'ext/ilios/cluster.c', line 209
static VALUE cluster_connect_timeout(VALUE self, VALUE timeout_ms)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_connect_timeout(cassandra_cluster->cluster, cluster_value_to_uint(timeout_ms, "connect_timeout"));
return self;
}
|
#connection_heartbeat_interval(interval_secs) ⇒ Object
550 551 552 553 554 555 556 557 558 |
# File 'ext/ilios/cluster.c', line 550
static VALUE cluster_connection_heartbeat_interval(VALUE self, VALUE interval_secs)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_connection_heartbeat_interval(cassandra_cluster->cluster, cluster_value_to_uint(interval_secs, "connection_heartbeat_interval"));
return self;
}
|
#connection_idle_timeout(timeout_secs) ⇒ Object
569 570 571 572 573 574 575 576 577 |
# File 'ext/ilios/cluster.c', line 569
static VALUE cluster_connection_idle_timeout(VALUE self, VALUE timeout_secs)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_connection_idle_timeout(cassandra_cluster->cluster, cluster_value_to_uint(timeout_secs, "connection_idle_timeout"));
return self;
}
|
#consistency(consistency) ⇒ Object
362 363 364 365 366 367 368 369 370 371 |
# File 'ext/ilios/cluster.c', line 362
static VALUE cluster_consistency(VALUE self, VALUE consistency)
{
CassandraCluster *cassandra_cluster;
CassConsistency consistency_value = cluster_value_to_consistency(consistency, "consistency");
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_consistency(cassandra_cluster->cluster, consistency_value);
return self;
}
|
#constant_reconnect(delay_ms) ⇒ Object
470 471 472 473 474 475 476 477 478 |
# File 'ext/ilios/cluster.c', line 470
static VALUE cluster_constant_reconnect(VALUE self, VALUE delay_ms)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_constant_reconnect(cassandra_cluster->cluster, cluster_value_to_uint64(delay_ms, "constant_reconnect"));
return self;
}
|
#constant_speculative_execution_policy(constant_delay_ms, max_speculative_executions) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'ext/ilios/cluster.c', line 262
static VALUE cluster_constant_speculative_execution_policy(VALUE self, VALUE constant_delay_ms, VALUE max_speculative_executions)
{
CassandraCluster *cassandra_cluster;
long delay = NUM2LONG(constant_delay_ms);
int max_executions = NUM2INT(max_speculative_executions);
if (delay < 0 || max_executions < 0) {
rb_raise(rb_eArgError, "Bad parameters.");
}
GET_CLUSTER(self, cassandra_cluster);
cluster_check_error(cass_cluster_set_constant_speculative_execution_policy(cassandra_cluster->cluster, delay, max_executions), "constant_speculative_execution_policy");
return self;
}
|
#core_connections_per_host(num_connections) ⇒ Object
451 452 453 454 455 456 457 458 459 |
# File 'ext/ilios/cluster.c', line 451
static VALUE cluster_core_connections_per_host(VALUE self, VALUE num_connections)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cluster_check_error(cass_cluster_set_core_connections_per_host(cassandra_cluster->cluster, cluster_value_to_uint(num_connections, "core_connections_per_host")), "core_connections_per_host");
return self;
}
|
#credentials(username, password) ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'ext/ilios/cluster.c', line 285
static VALUE cluster_credentials(VALUE self, VALUE username, VALUE password)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
// The driver copies both strings into its own memory
// (cluster_config.cpp: cass_cluster_set_credentials_n), so the Ruby
// strings do not need to be retained.
cass_cluster_set_credentials(cassandra_cluster->cluster, StringValueCStr(username), StringValueCStr(password));
return self;
}
|
#exponential_reconnect(base_delay_ms, max_delay_ms) ⇒ Object
494 495 496 497 498 499 500 501 502 |
# File 'ext/ilios/cluster.c', line 494
static VALUE cluster_exponential_reconnect(VALUE self, VALUE base_delay_ms, VALUE max_delay_ms)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cluster_check_error(cass_cluster_set_exponential_reconnect(cassandra_cluster->cluster, cluster_value_to_uint64(base_delay_ms, "exponential_reconnect base_delay_ms"), cluster_value_to_uint64(max_delay_ms, "exponential_reconnect max_delay_ms")), "exponential_reconnect");
return self;
}
|
#hosts(hosts) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'ext/ilios/cluster.c', line 114
static VALUE cluster_hosts(VALUE self, VALUE hosts)
{
CassandraCluster *cassandra_cluster;
long length;
GET_CLUSTER(self, cassandra_cluster);
Check_Type(hosts, T_ARRAY);
length = RARRAY_LEN(hosts);
if (length == 0) {
rb_raise(rb_eArgError, "No host exists.");
}
for (long i = 0; i < length && i < RARRAY_LEN(hosts); i++) {
VALUE host = rb_ary_entry(hosts, i);
cass_cluster_set_contact_points(cassandra_cluster->cluster, StringValueCStr(host));
}
return self;
}
|
#keyspace(keyspace) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 |
# File 'ext/ilios/cluster.c', line 159
static VALUE cluster_keyspace(VALUE self, VALUE keyspace)
{
CassandraCluster *cassandra_cluster;
StringValue(keyspace);
GET_CLUSTER(self, cassandra_cluster);
RB_OBJ_WRITE(self, &cassandra_cluster->keyspace, keyspace);
return self;
}
|
#latency_aware_routing(enabled) ⇒ Object
641 642 643 644 645 646 647 648 649 |
# File 'ext/ilios/cluster.c', line 641
static VALUE cluster_latency_aware_routing(VALUE self, VALUE enabled)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_latency_aware_routing(cassandra_cluster->cluster, RTEST(enabled) ? cass_true : cass_false);
return self;
}
|
#load_balance_dc_aware(local_dc) ⇒ Object
604 605 606 607 608 609 610 611 612 613 614 615 |
# File 'ext/ilios/cluster.c', line 604
static VALUE cluster_load_balance_dc_aware(VALUE self, VALUE local_dc)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
// The 3rd and 4th parameters (used_hosts_per_remote_dc and
// allow_remote_dcs_for_local_cl) are deprecated in driver 2.16, so they
// are fixed to 0/cass_false and not exposed to Ruby.
cluster_check_error(cass_cluster_set_load_balance_dc_aware(cassandra_cluster->cluster, StringValueCStr(local_dc), 0, cass_false), "load_balance_dc_aware");
return self;
}
|
#load_balance_round_robin ⇒ Object
585 586 587 588 589 590 591 592 593 |
# File 'ext/ilios/cluster.c', line 585
static VALUE cluster_load_balance_round_robin(VALUE self)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_load_balance_round_robin(cassandra_cluster->cluster);
return self;
}
|
#num_threads_io(num_threads) ⇒ Object
413 414 415 416 417 418 419 420 421 |
# File 'ext/ilios/cluster.c', line 413
static VALUE cluster_num_threads_io(VALUE self, VALUE num_threads)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cluster_check_error(cass_cluster_set_num_threads_io(cassandra_cluster->cluster, cluster_value_to_uint(num_threads, "num_threads_io")), "num_threads_io");
return self;
}
|
#port(port) ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'ext/ilios/cluster.c', line 143
static VALUE cluster_port(VALUE self, VALUE port)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cluster_check_error(cass_cluster_set_port(cassandra_cluster->cluster, NUM2INT(port)), "port");
return self;
}
|
#protocol_version(version) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'ext/ilios/cluster.c', line 186
static VALUE cluster_protocol_version(VALUE self, VALUE version)
{
CassandraCluster *cassandra_cluster;
int v = NUM2INT(version);
if (v < 0) {
rb_raise(rb_eRangeError, "Invalid protocol_version: %d", v);
}
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_protocol_version(cassandra_cluster->cluster, v);
return self;
}
|
#queue_size_io(queue_size) ⇒ Object
432 433 434 435 436 437 438 439 440 |
# File 'ext/ilios/cluster.c', line 432
static VALUE cluster_queue_size_io(VALUE self, VALUE queue_size)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cluster_check_error(cass_cluster_set_queue_size_io(cassandra_cluster->cluster, cluster_value_to_uint(queue_size, "queue_size_io")), "queue_size_io");
return self;
}
|
#request_timeout(timeout_ms) ⇒ Object
227 228 229 230 231 232 233 234 235 |
# File 'ext/ilios/cluster.c', line 227
static VALUE cluster_request_timeout(VALUE self, VALUE timeout_ms)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_request_timeout(cassandra_cluster->cluster, cluster_value_to_uint(timeout_ms, "request_timeout"));
return self;
}
|
#resolve_timeout(timeout_ms) ⇒ Object
245 246 247 248 249 250 251 252 253 |
# File 'ext/ilios/cluster.c', line 245
static VALUE cluster_resolve_timeout(VALUE self, VALUE timeout_ms)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_resolve_timeout(cassandra_cluster->cluster, cluster_value_to_uint(timeout_ms, "resolve_timeout"));
return self;
}
|
#serial_consistency(consistency) ⇒ Object
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'ext/ilios/cluster.c', line 385
static VALUE cluster_serial_consistency(VALUE self, VALUE consistency)
{
CassandraCluster *cassandra_cluster;
CassConsistency consistency_value = cluster_value_to_consistency(consistency, "serial_consistency");
// Cassandra only accepts SERIAL/LOCAL_SERIAL as a serial consistency
// level (used for lightweight transactions); any other value passes
// the generic range check above but is later rejected by the server
// at query time with an opaque error, so validate it here.
if (consistency_value != CASS_CONSISTENCY_SERIAL && consistency_value != CASS_CONSISTENCY_LOCAL_SERIAL) {
rb_raise(rb_eArgError, "Invalid serial_consistency: %"PRIsVALUE"", consistency);
}
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_serial_consistency(cassandra_cluster->cluster, consistency_value);
return self;
}
|
#tcp_keepalive(enabled, delay_secs) ⇒ Object
530 531 532 533 534 535 536 537 538 |
# File 'ext/ilios/cluster.c', line 530
static VALUE cluster_tcp_keepalive(VALUE self, VALUE enabled, VALUE delay_secs)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_tcp_keepalive(cassandra_cluster->cluster, RTEST(enabled) ? cass_true : cass_false, cluster_value_to_uint(delay_secs, "tcp_keepalive delay_secs"));
return self;
}
|
#tcp_nodelay(enabled) ⇒ Object
511 512 513 514 515 516 517 518 519 |
# File 'ext/ilios/cluster.c', line 511
static VALUE cluster_tcp_nodelay(VALUE self, VALUE enabled)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_tcp_nodelay(cassandra_cluster->cluster, RTEST(enabled) ? cass_true : cass_false);
return self;
}
|
#token_aware_routing(enabled) ⇒ Object
624 625 626 627 628 629 630 631 632 |
# File 'ext/ilios/cluster.c', line 624
static VALUE cluster_token_aware_routing(VALUE self, VALUE enabled)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_token_aware_routing(cassandra_cluster->cluster, RTEST(enabled) ? cass_true : cass_false);
return self;
}
|
#use_schema(enabled) ⇒ Object
660 661 662 663 664 665 666 667 668 |
# File 'ext/ilios/cluster.c', line 660
static VALUE cluster_use_schema(VALUE self, VALUE enabled)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_use_schema(cassandra_cluster->cluster, RTEST(enabled) ? cass_true : cass_false);
return self;
}
|