Skip to content

Commit 6ca9018

Browse files
committed
Merge pull request #20 from duomark/master
Introduce elysium_buffering_strategy behaviour
2 parents 6150401 + 1b77a96 commit 6ca9018

15 files changed

Lines changed: 1038 additions & 1077 deletions

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dep_test_commons = git https://github.com/tigertext/test_commons master
1313
PLATFORM_OPTS := `erlc -o ebin src/elysium_compile_utils.erl ; erl -noshell -pa ebin -s elysium_compile_utils platform_opts -s init stop`
1414

1515
ERLC_OPTS := +debug_info +"{cover_enabled, true}" ${PLATFORM_OPTS}
16+
COMPILE_FIRST := elysium_buffering_audit elysium_buffering_strategy
1617

1718
# Needed for testing
1819
TEST_ERLC_OPTS := -I include $(ERLC_OPTS)

include/elysium_audit_types.hrl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-type audit_counts_ets_name() :: atom().
2+
-type audit_connection_key() :: {buffering_strategy_module(), connection_id()}.
3+
-type audit_std_counts_key() :: {buffering_strategy_module(), counts}.
4+
-type audit_custom_counts_key() :: {buffering_strategy_module(), custom_counts}.
5+
-type audit_counts_key() :: audit_std_counts_key() | audit_custom_counts_key().
6+
7+
-type audit_timestamp() :: binary().
8+
-type audit_count() :: non_neg_integer().
9+
10+
-type audit_custom_counts() :: any().
11+
-type audit_custom_event() :: atom().
12+
-type audit_count_event() :: pending_dead
13+
| pending_timeouts
14+
| session_dead
15+
| session_decay
16+
| session_timeouts
17+
| session_wrong
18+
| worker_errors
19+
| worker_timeouts.

include/elysium_types.hrl

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,68 @@
1+
%% Two ways of specifying configuration parameters, designed for high concurrency.
12
-type config_type() :: {config_mod, module()}
23
| {vbisect, vbisect:bindict()}.
34

4-
-type lb_queue_name() :: ets_buffer:buffer_name().
5-
-type audit_ets_name() :: ets_buffer:buffer_name().
6-
-type session_queue_name() :: ets_buffer:buffer_name().
7-
-type requests_queue_name() :: ets_buffer:buffer_name().
8-
-type host_list() :: [{Ip_Addr::string(), Port::pos_integer()}].
9-
-type timeout_in_ms() :: pos_integer(). %% in milliseconds
10-
-type max_sessions() :: pos_integer().
11-
-type max_retries() :: non_neg_integer().
12-
-type decay_prob() :: non_neg_integer(). %% number of chances in 1M of death
5+
%% Buffering module names are used for telemetry.
6+
-type buffering_strategy_module() :: module().
137

8+
%% There are three queues used by elsyium.
9+
-type queue_name() :: ets_buffer:buffer_name() | atom().
10+
-type lb_queue_name() :: queue_name(). % Cassandra node load balancer queue
11+
-type connection_queue_name() :: queue_name(). % Cassandra open connections queue
12+
-type requests_queue_name() :: queue_name(). % Pending requests queue
13+
14+
-type audit_ets_name() :: atom(). % Audit ets table for telemetry data
15+
16+
-type cassandra_node() :: {Ip_Or_Hostname::inet:hostname(), Port::inet:port_number()}. % Cassandra node
17+
-type host_list() :: [cassandra_node()]. % Host list used by load balancer
18+
19+
-type timeout_in_ms() :: pos_integer(). % In milliseconds
20+
-type max_retries() :: non_neg_integer().
21+
-type decay_prob() :: non_neg_integer(). % Chances in 1B of connection death
22+
23+
%% Currently Cassandra connections are seestar_sessions.
24+
-type connection_id() :: pid(). % Live process holding socket to Cassandra.
25+
-type fun_request() :: fun((connection_id(), [any()], seestar:consistency()) -> [any()]).
26+
-type query_request() :: {bare_fun, config_type(), fun_request(), [any()], seestar:consistency()}
27+
| {mod_fun, config_type(), module(), atom(), [any()], seestar:consistency()}.
28+
29+
-type cassandra_connection() :: {cassandra_node(), connection_id()}.
30+
-type connection_baton() :: {{connection_id(), reference}, erlang:timestamp()}.
31+
32+
-type pending_request_pid() :: pid().
33+
-type pending_request_baton() :: {{pending_request_pid(), reference()}, erlang:timestamp()}.
34+
35+
%% Connection count errors reported by ets_buffer, new buffering strategies may need new error types.
36+
-type connection_count_error() :: ets_buffer:buffer_error().
37+
-type max_connections() :: pos_integer() | connection_count_error().
38+
-type pending_count() :: pos_integer() | connection_count_error().
39+
40+
-type idle_status() :: {idle_connections, {connection_queue_name(),
41+
Idle::max_connections(), Max::max_connections()}}.
42+
-type pending_status() :: {pending_requests, {requests_queue_name(),
43+
pending_count(), timeout_in_ms()}}.
44+
-type status_reply() :: {status, {idle_status(), pending_status()}}.
45+
46+
-type pending_checkin() :: {boolean() | pending, {connection_queue_name(),
47+
max_connections(), max_connections()}}.
48+
49+
%% Errors when a pending request does not get a chance to return a query result.
1450
-type wait_for_session_error() :: {wait_for_session_timeout, pos_integer()}
1551
| {wait_for_session_error, any()}.
1652

53+
%% Errors when a query request fails after submitting to Cassandra.
1754
-type worker_reply_error() :: {worker_reply_timeout, pos_integer()}
1855
| {worker_reply_error, any()}.
1956

57+
%% Errors getting a connection to Cassandra.
58+
-type connection_error() :: {error, no_db_connections}.
59+
60+
%% All errors that a pending request may encounter.
2061
-type pend_request_error() :: ets_buffer:buffer_error()
2162
| wait_for_session_error()
22-
| worker_reply_error().
63+
| worker_reply_error()
64+
| connection_error().
65+
66+
%% Query_reply is a successful return; query_result contains all possible query returns.
67+
-type query_reply() :: any().
68+
-type query_result() :: pend_request_error() | query_reply().

src/elysium.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{application, elysium,
22
[
33
{description, "Elysium for Cassandra"},
4-
{vsn, "0.1.6j"},
4+
{vsn, "0.1.7"},
55
{id, "elysium"},
66
{registered, [elysium_sup, elysium_connection_sup]},
77
{applications, [kernel, stdlib]},

0 commit comments

Comments
 (0)