Module: Cassandra

Defined in:
lib/cassandra/udt.rb,
lib/cassandra.rb,
lib/cassandra.rb,
lib/cassandra/auth.rb,
lib/cassandra/host.rb,
lib/cassandra/time.rb,
lib/cassandra/util.rb,
lib/cassandra/uuid.rb,
lib/cassandra/index.rb,
lib/cassandra/retry.rb,
lib/cassandra/table.rb,
lib/cassandra/tuple.rb,
lib/cassandra/types.rb,
lib/cassandra/column.rb,
lib/cassandra/driver.rb,
lib/cassandra/errors.rb,
lib/cassandra/future.rb,
lib/cassandra/result.rb,
lib/cassandra/cluster.rb,
lib/cassandra/session.rb,
lib/cassandra/trigger.rb,
lib/cassandra/version.rb,
lib/cassandra/argument.rb,
lib/cassandra/function.rb,
lib/cassandra/keyspace.rb,
lib/cassandra/listener.rb,
lib/cassandra/protocol.rb,
lib/cassandra/aggregate.rb,
lib/cassandra/executors.rb,
lib/cassandra/statement.rb,
lib/cassandra/time_uuid.rb,
lib/cassandra/compression.rb,
lib/cassandra/custom_data.rb,
lib/cassandra/null_logger.rb,
lib/cassandra/protocol/v1.rb,
lib/cassandra/protocol/v3.rb,
lib/cassandra/protocol/v4.rb,
lib/cassandra/attr_boolean.rb,
lib/cassandra/reconnection.rb,
lib/cassandra/cluster/client.rb,
lib/cassandra/cluster/schema.rb,
lib/cassandra/execution/info.rb,
lib/cassandra/load_balancing.rb,
lib/cassandra/protocol/coder.rb,
lib/cassandra/uuid/generator.rb,
lib/cassandra/cluster/options.rb,
lib/cassandra/execution/trace.rb,
lib/cassandra/statements/void.rb,
lib/cassandra/cassandra_logger.rb,
lib/cassandra/cluster/metadata.rb,
lib/cassandra/cluster/registry.rb,
lib/cassandra/column_container.rb,
lib/cassandra/protocol/request.rb,
lib/cassandra/statements/batch.rb,
lib/cassandra/statements/bound.rb,
lib/cassandra/cluster/connector.rb,
lib/cassandra/execution/options.rb,
lib/cassandra/execution/profile.rb,
lib/cassandra/materialized_view.rb,
lib/cassandra/protocol/response.rb,
lib/cassandra/statements/simple.rb,
lib/cassandra/address_resolution.rb,
lib/cassandra/function_collection.rb,
lib/cassandra/statements/prepared.rb,
lib/cassandra/timestamp_generator.rb,
lib/cassandra/retry/policies/default.rb,
lib/cassandra/auth/providers/password.rb,
lib/cassandra/cluster/connection_pool.rb,
lib/cassandra/cluster/schema/fetchers.rb,
lib/cassandra/protocol/cql_byte_buffer.rb,
lib/cassandra/cluster/failed_connection.rb,
lib/cassandra/execution/profile_manager.rb,
lib/cassandra/cluster/control_connection.rb,
lib/cassandra/retry/policies/fallthrough.rb,
lib/cassandra/timestamp_generator/simple.rb,
lib/cassandra/compression/compressors/lz4.rb,
lib/cassandra/protocol/cql_protocol_handler.rb,
lib/cassandra/cluster/schema/cql_type_parser.rb,
lib/cassandra/compression/compressors/snappy.rb,
lib/cassandra/reconnection/policies/constant.rb,
lib/cassandra/cluster/schema/fqcn_type_parser.rb,
lib/cassandra/protocol/requests/batch_request.rb,
lib/cassandra/protocol/requests/query_request.rb,
lib/cassandra/address_resolution/policies/none.rb,
lib/cassandra/protocol/requests/execute_request.rb,
lib/cassandra/protocol/requests/options_request.rb,
lib/cassandra/protocol/requests/prepare_request.rb,
lib/cassandra/protocol/requests/startup_request.rb,
lib/cassandra/protocol/responses/error_response.rb,
lib/cassandra/protocol/responses/event_response.rb,
lib/cassandra/protocol/responses/ready_response.rb,
lib/cassandra/reconnection/policies/exponential.rb,
lib/cassandra/cluster/schema/partitioners/random.rb,
lib/cassandra/load_balancing/policies/white_list.rb,
lib/cassandra/protocol/requests/register_request.rb,
lib/cassandra/protocol/responses/result_response.rb,
lib/cassandra/cluster/schema/partitioners/murmur3.rb,
lib/cassandra/cluster/schema/partitioners/ordered.rb,
lib/cassandra/load_balancing/policies/round_robin.rb,
lib/cassandra/load_balancing/policies/token_aware.rb,
lib/cassandra/protocol/requests/void_query_request.rb,
lib/cassandra/protocol/requests/credentials_request.rb,
lib/cassandra/protocol/responses/supported_response.rb,
lib/cassandra/retry/policies/downgrading_consistency.rb,
lib/cassandra/protocol/requests/auth_response_request.rb,
lib/cassandra/protocol/responses/rows_result_response.rb,
lib/cassandra/protocol/responses/void_result_response.rb,
lib/cassandra/protocol/responses/auth_success_response.rb,
lib/cassandra/protocol/responses/authenticate_response.rb,
lib/cassandra/timestamp_generator/ticking_on_duplicate.rb,
lib/cassandra/cluster/schema/replication_strategies/none.rb,
lib/cassandra/protocol/responses/auth_challenge_response.rb,
lib/cassandra/protocol/responses/prepared_result_response.rb,
lib/cassandra/protocol/responses/raw_rows_result_response.rb,
lib/cassandra/address_resolution/policies/ec2_multi_region.rb,
lib/cassandra/cluster/schema/replication_strategies/simple.rb,
lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb,
lib/cassandra/protocol/responses/unprepared_error_response.rb,
lib/cassandra/protocol/responses/unavailable_error_response.rb,
lib/cassandra/protocol/responses/read_failure_error_response.rb,
lib/cassandra/protocol/responses/read_timeout_error_response.rb,
lib/cassandra/protocol/responses/schema_change_event_response.rb,
lib/cassandra/protocol/responses/set_keyspace_result_response.rb,
lib/cassandra/protocol/responses/status_change_event_response.rb,
lib/cassandra/protocol/responses/write_failure_error_response.rb,
lib/cassandra/protocol/responses/write_timeout_error_response.rb,
lib/cassandra/protocol/responses/already_exists_error_response.rb,
lib/cassandra/protocol/responses/schema_change_result_response.rb,
lib/cassandra/protocol/responses/topology_change_event_response.rb,
lib/cassandra/protocol/responses/function_failure_error_response.rb,
lib/cassandra/cluster/schema/replication_strategies/network_topology.rb

Overview

-- Copyright DataStax, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ++

Defined Under Namespace

Modules: AddressResolution, AttrBoolean, Auth, Compression, CustomData, Error, Errors, Execution, LoadBalancing, Reconnection, Retry, Statement, Statements, TimestampGenerator, Types Classes: Aggregate, Argument, Cluster, Column, ColumnContainer, Function, Future, Host, Index, Keyspace, Listener, Logger, MaterializedView, Result, Session, Table, Time, TimeUuid, Trigger, Tuple, Type, UDT, Uuid

Constant Summary collapse

CONSISTENCIES =

A list of all supported request consistencies

[:any, :one, :two, :three, :quorum, :all, :local_quorum,
:each_quorum, :serial, :local_serial, :local_one].freeze
SERIAL_CONSISTENCIES =

A list of all supported serial consistencies

[:serial, :local_serial].freeze
WRITE_TYPES =

A list of all possible write types that a Errors::WriteTimeoutError can have.

[:simple, :batch, :unlogged_batch, :counter, :batch_log].freeze
CLUSTER_OPTIONS =
[
  :address_resolution,
  :address_resolution_policy,
  :allow_beta_protocol,
  :auth_provider,
  :client_cert,
  :client_timestamps,
  :compression,
  :compressor,
  :connect_timeout,
  :connections_per_local_node,
  :connections_per_remote_node,
  :consistency,
  :credentials,
  :custom_types,
  :datacenter,
  :execution_profiles,
  :futures_factory,
  :heartbeat_interval,
  :hosts,
  :idle_timeout,
  :listeners,
  :load_balancing_policy,
  :logger,
  :nodelay,
  :reconnection_policy,
  :retry_policy,
  :page_size,
  :passphrase,
  :password,
  :port,
  :private_key,
  :protocol_version,
  :requests_per_connection,
  :schema_refresh_delay,
  :schema_refresh_timeout,
  :server_cert,
  :shuffle_replicas,
  :ssl,
  :synchronize_schema,
  :timeout,
  :trace,
  :username
].freeze
VERSION =
'3.2.4'.freeze

Class Method Summary collapse

Class Method Details

.cluster(options = {}) ⇒ Cassandra::Cluster

Creates a Cluster instance.

Examples:

Connecting to localhost

cluster = Cassandra.cluster

Configuring Cluster

cluster = Cassandra.cluster(
            username: username,
            password: password,
            hosts: ['10.0.1.1', '10.0.1.2', '10.0.1.3']
          )

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :hosts (Array<String, IPAddr>) — default: ['127.0.0.1']

    a list of initial addresses. Note that the entire list of cluster members will be discovered automatically once a connection to any hosts from the original list is successful.

  • :port (Integer) — default: 9042

    cassandra native protocol port.

  • :nodelay (Boolean) — default: true

    when set to true, disables nagle algorithm.

  • :datacenter (String) — default: nil

    name of current datacenter. First datacenter found will be assumed current by default. Note that you can skip this option if you specify only hosts from the local datacenter in :hosts option.

  • :shuffle_replicas (Boolean) — default: true

    whether replicas list found by the default Token-Aware Load Balancing Policy should be shuffled. See Token-Aware Load Balancing Policy.

  • :execution_profiles (Hash<String|Symbol, ExecutionProfile>) — default: nil
  • :connect_timeout (Numeric) — default: 10

    connection timeout in seconds. Setting value to nil will reset it to 5 seconds.

  • :timeout (Numeric) — default: 12

    request execution timeout in seconds. Setting value to nil will remove request timeout.

  • :heartbeat_interval (Numeric) — default: 30

    how often should a heartbeat be sent to determine if a connection is alive. Several things to note about this option. Only one heartbeat request will ever be outstanding on a given connection. Each heatbeat will be sent in at least :heartbeat_interval seconds after the last request has been sent on a given connection. Setting value to nil will remove connection timeout.

  • :idle_timeout (Numeric) — default: 60

    period of inactivity after which a connection is considered dead. Note that this value should be at least a few times larger than :heartbeat_interval. Setting value to nil will remove automatic connection termination.

  • :username (String) — default: none

    username to use for authentication to cassandra. Note that you must also specify :password.

  • :password (String) — default: none

    password to use for authentication to cassandra. Note that you must also specify :username.

  • :ssl (Boolean, OpenSSL::SSL::SSLContext) — default: false

    enable default ssl authentication if true (not recommended). Also accepts an initialized OpenSSL::SSL::SSLContext. Note that this option should be ignored if :server_cert, :client_cert, :private_key or :passphrase are given.

  • :server_cert (String) — default: none

    path to server certificate or certificate authority file.

  • :client_cert (String) — default: none

    path to client certificate file. Note that this option is only required when encryption is configured to require client authentication.

  • :private_key (String) — default: none

    path to client private key. Note that this option is only required when encryption is configured to require client authentication.

  • :passphrase (String) — default: none

    passphrase for private key.

  • :compression (Symbol) — default: none

    compression to use. Must be either :snappy or :lz4. Also note, that in order for compression to work, you must install 'snappy' or 'lz4-ruby' gems.

  • :load_balancing_policy (Cassandra::LoadBalancing::Policy)

    default: token aware data center aware round robin.

  • :address_resolution (Symbol) — default: :none

    a pre-configured address resolver to use. Must be one of :none or :ec2_multi_region.

  • :connections_per_local_node (Integer) — default: nil

    Number of connections to open to each local node; the value of this option directly correlates to the number of requests the client can make to the local node concurrently. When nil, the setting is 1 for nodes that use the v3 or later protocol, and 2 for nodes that use the v2 or earlier protocol.

  • :connections_per_remote_node (Integer) — default: 1

    Number of connections to open to each remote node; the value of this option directly correlates to the number of requests the client can make to the remote node concurrently.

  • :requests_per_connection (Integer) — default: nil

    Number of outstanding requests to support on one connection. Depending on the types of requests, some may get processed in parallel in the Cassandra node. When nil, the setting is 1024 for nodes that use the v3 or later protocol, and 128 for nodes that use the v2 or earlier protocol.

  • :protocol_version (Integer) — default: nil

    Version of protocol to speak to nodes. By default, this is auto-negotiated to the highest common protocol version that all nodes in :hosts speak.

  • :allow_beta_protocol (Boolean) — default: false

    whether the driver should attempt to speak to nodes with a beta version of the newest protocol (which is still under development). USE WITH CAUTION!

  • :client_timestamps (Boolean, Cassandra::TimestampGenerator) — default: false

    whether the driver should send timestamps for each executed statement and possibly which timestamp generator to use. Enabling this setting helps mitigate Cassandra cluster clock skew because the timestamp of the client machine will be used. This does not help mitigate application cluster clock skew. Also accepts an initialized TimestampGenerator, :simple (indicating an instance of Cassandra::TimestampGenerator::Simple), or :monotonic (indicating an instance of Cassandra::TimestampGenerator::TickingOnDuplicate). If set to true, it defaults to Cassandra::TimestampGenerator::Simple for all Ruby flavors except JRuby. On JRuby, it defaults to Cassandra::TimestampGenerator::TickingOnDuplicate.

  • :synchronize_schema (Boolean) — default: true

    whether the driver should automatically keep schema metadata synchronized. When enabled, the driver updates schema metadata after receiving schema change notifications from Cassandra. Setting this setting to false disables automatic schema updates. Schema metadata is used by the driver to determine cluster partitioners as well as to find partition keys and replicas of prepared statements, this information makes token aware load balancing possible. One can still refresh schema manually.

  • :schema_refresh_delay (Numeric) — default: 1

    the driver will wait for :schema_refresh_delay before fetching metadata after receiving a schema change event. This timer is restarted every time a new schema change event is received. Finally, when the timer expires or a maximum wait time of :schema_refresh_timeout has been reached, a schema refresh attempt will be made and the timeout is reset.

  • :schema_refresh_timeout (Numeric) — default: 10

    the maximum delay before automatically refreshing schema. Such delay can occur whenever multiple schema change events are continuously arriving within :schema_refresh_delay interval.

  • :reconnection_policy (Cassandra::Reconnection::Policy)

    default: Exponential. Note that the default policy is configured with (0.5, 30, 2).

  • :retry_policy (Cassandra::Retry::Policy)
  • :logger (Logger) — default: none

    logger. a Logger instance from the standard library or any object responding to standard log methods (#debug, #info, #warn, #error and #fatal).

  • :listeners (Enumerable<Cassandra::Listener>) — default: none

    initial listeners. A list of initial cluster state listeners. Note that a :load_balancing policy is automatically registered with the cluster.

  • :consistency (Symbol) — default: :local_one

    default consistency to use for all requests. Must be one of CONSISTENCIES.

  • :trace (Boolean) — default: false

    whether or not to trace all requests by default.

  • :page_size (Integer) — default: 10000

    default page size for all select queries. Set this value to nil to disable paging.

  • :credentials (Hash{String => String}) — default: none

    a hash of credentials - to be used with credentials authentication in cassandra 1.2. Note that if you specified :username and :password options, those credentials are configured automatically.

  • :auth_provider (Cassandra::Auth::Provider) — default: none

    a custom auth provider to be used with SASL authentication in cassandra 2.0. Note that if you have specified :username and :password, then a Password Provider will be used automatically.

  • :compressor (Cassandra::Compression::Compressor) — default: none

    a custom compressor. Note that if you have specified :compression, an appropriate compressor will be provided automatically.

  • :address_resolution_policy (Cassandra::AddressResolution::Policy)

    default: No Resolution Policy a custom address resolution policy. Note that if you have specified :address_resolution, an appropriate address resolution policy will be provided automatically.

  • :futures_factory (Object<#all, #error, #value, #promise>)

    default: Future a futures factory to assist with integration into existing futures library. Note that promises returned by this object must conform to Promise api, which is not yet public. Things may change, use at your own risk.

Returns:



295
296
297
# File 'lib/cassandra.rb', line 295

def self.cluster(options = {})
  cluster_async(options).get
end

.cluster_async(options = {}) ⇒ Cassandra::Future<Cassandra::Cluster>

Creates a Cluster instance.

Returns:

See Also:



305
306
307
308
309
310
311
312
313
# File 'lib/cassandra.rb', line 305

def self.cluster_async(options = {})
  options, hosts = validate_and_massage_options(options)
rescue => e
  futures = options.fetch(:futures_factory) { return Future::Error.new(e) }
  futures.error(e)
else
  driver = Driver.new(options)
  driver.connect(hosts)
end