Skip to content

Commit b6e6da2

Browse files
authored
Merge pull request #4378 from esl/cockroachdb-preset
Adding cockroachdb_cets preset
2 parents 938c4d0 + d05c632 commit b6e6da2

29 files changed

+899
-50
lines changed

Diff for: .circleci/template.yml

+37-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ containers:
5454
- ENV_FILE_KEY_PATH: "/tmp/sql/fake_key.pem"
5555
- ENV_FILE_KEY_DATA: "__MIM_KEY__"
5656
entrypoint: *ENTRYPOINT
57+
- &cockroachdb_container
58+
image: cockroachdb/cockroach:__COCKROACHDB_VERSION__
59+
environment:
60+
- COCKROACH_DATABASE: mongooseim
61+
- OLD_ENTRYPOINT: "chmod 777 /start.sh && /start.sh"
62+
- ENV_FILE_SETUP_PATH: "/start.sh"
63+
- ENV_FILE_SETUP_DATA: "__COCKROACHDB_SETUP__"
64+
- ENV_FILE_SQL_PATH: "/docker-entrypoint-initdb.d/init.sql"
65+
- ENV_FILE_SQL_DATA: "__COCKROACHDB_SQL__"
66+
- ENV_FILE_USER_PATH: "/docker-entrypoint-initdb.d/create_user.sql"
67+
- ENV_FILE_USER_DATA: "__COCKROACHDB_USER_SQL__"
68+
- ENV_FILE_CACERT_PATH: "/tmp/ca.key"
69+
- ENV_FILE_CACERT_DATA: "__DB_CAKEY__"
70+
- ENV_FILE_CAKEY_PATH: "/tmp/ca.crt"
71+
- ENV_FILE_CAKEY_DATA: "__DB_CACERT__"
72+
- ENV_FILE_CERT_PATH: "/tmp/client.mongooseim.crt"
73+
- ENV_FILE_CERT_DATA: "__MIM_CERT__"
74+
- ENV_FILE_KEY_PATH: "/tmp/client.mongooseim.key"
75+
- ENV_FILE_KEY_DATA: "__MIM_KEY__"
76+
entrypoint: *ENTRYPOINT
5777
- &ldap_container
5878
image: osixia/openldap:__LDAP_VERSION__
5979
environment:
@@ -185,6 +205,11 @@ executors:
185205
- image: *OTP27
186206
- *redis_container
187207
- *pgsql_container
208+
otp_27_cockroachdb_redis:
209+
docker:
210+
- image: *OTP27
211+
- *redis_container
212+
- *cockroachdb_container
188213
otp_26_ldap_redis:
189214
docker:
190215
- image: *OTP26
@@ -552,7 +577,8 @@ jobs:
552577
preset:
553578
type: enum
554579
enum: [internal_mnesia, mysql_redis, odbc_mssql_mnesia, ldap_mnesia,
555-
elasticsearch_and_cassandra_mnesia, pgsql_mnesia, pgsql_cets]
580+
elasticsearch_and_cassandra_mnesia, pgsql_mnesia, pgsql_cets,
581+
cockroachdb_cets]
556582
description: Preset to run
557583
default: internal_mnesia
558584
db:
@@ -843,6 +869,15 @@ workflows:
843869
requires:
844870
- otp_27_docker
845871
filters: *all_tags
872+
- big_tests_in_docker:
873+
name: cockroachdb_cets_27
874+
executor: otp_27_cockroachdb_redis
875+
context: mongooseim-org
876+
preset: cockroachdb_cets
877+
db: "mnesia cockroachdb cets"
878+
requires:
879+
- otp_27_docker
880+
filters: *all_tags
846881
- big_tests_in_docker:
847882
name: pgsql_cets_27
848883
executor: otp_27_pgsql_redis
@@ -966,6 +1001,7 @@ workflows:
9661001
- small_tests_27
9671002
- internal_mnesia_27
9681003
- pgsql_cets_27
1004+
- cockroachdb_cets_27
9691005
- pgsql_mnesia_27
9701006
- mysql_redis_27
9711007
- mssql_mnesia_27

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ $(DEVNODES): certs configure.out rel/vars-toml.config
5959

6060
maybe_clean_certs:
6161
if [ "$$SKIP_CERT_BUILD" != 1 ]; then \
62-
if ! openssl x509 -checkend 3600 -noout -in tools/ssl/ca/cacert.pem ; then \
62+
if ! openssl x509 -checkend 36000 -noout -in tools/ssl/ca/cacert.pem ; then \
6363
cd tools/ssl && make clean_certs; \
6464
fi \
6565
fi

Diff for: big_tests/test.config

+30
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,36 @@
265265
connection.password = \"mongooseim_secret\"
266266
connection.tls.required = true
267267
connection.tls.cacertfile = \"priv/ssl/cacert.pem\"
268+
connection.tls.server_name_indication.enabled = false"},
269+
{service_domain_db, ""},
270+
{mod_vcard, " backend = \"rdbms\"
271+
host = \"vjud.@HOST@\"\n"},
272+
{mod_roster, " backend = \"rdbms\"\n"}]},
273+
{cockroachdb_cets,
274+
[{dbs, [redis, cockroachdb]},
275+
{sm_backend, "\"cets\""},
276+
{bosh_backend, "\"cets\""},
277+
{component_backend, "\"cets\""},
278+
{s2s_backend, "\"cets\""},
279+
{stream_management_backend, cets},
280+
{auth_anonymous_backend, cets},
281+
{auth_method, "rdbms"},
282+
{internal_databases, "[internal_databases.cets]
283+
cluster_name = \"{{cluster_name}}\""},
284+
{outgoing_pools, "[outgoing_pools.redis.global_distrib]
285+
scope = \"global\"
286+
workers = 10
287+
[outgoing_pools.rdbms.default]
288+
scope = \"global\"
289+
workers = 5
290+
connection.driver = \"cockroachdb\"
291+
connection.host = \"localhost\"
292+
connection.port = 26257
293+
connection.database = \"mongooseim\"
294+
connection.username = \"mongooseim\"
295+
connection.password = \"mongooseim_secret\"
296+
connection.tls.required = true
297+
connection.tls.cacertfile = \"priv/ssl/cacert.pem\"
268298
connection.tls.server_name_indication.enabled = false"},
269299
{service_domain_db, ""},
270300
{mod_vcard, " backend = \"rdbms\"

Diff for: big_tests/tests/muc_SUITE.erl

+2-2
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,13 @@ init_per_group(disco_rsm_with_offline, Config) ->
386386
init_per_group(G, Config) when G =:= http_auth_no_server;
387387
G =:= http_auth ->
388388
PoolOpts = #{strategy => available_worker, workers => 5},
389-
ConnOpts = #{host => "http://localhost:8080", path_prefix => <<"/muc/auth/">>,
389+
ConnOpts = #{host => "http://localhost:8081", path_prefix => <<"/muc/auth/">>,
390390
request_timeout => 2000},
391391
Pool = config([outgoing_pools, http, muc_http_auth_test],
392392
#{opts => PoolOpts, conn_opts => ConnOpts}),
393393
[{ok, _Pid}] = rpc(mim(), mongoose_wpool, start_configured_pools, [[Pool]]),
394394
case G of
395-
http_auth -> http_helper:start(8080, "/muc/auth/check_password", fun handle_http_auth/1);
395+
http_auth -> http_helper:start(8081, "/muc/auth/check_password", fun handle_http_auth/1);
396396
_ -> ok
397397
end,
398398
ConfigWithModules = dynamic_modules:save_modules(host_type(), Config),

Diff for: big_tests/tests/rdbms_SUITE.erl

+4-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ binary_values() ->
226226
binary:copy(<<0>>, 100000),
227227
null
228228
] ++
229-
case is_odbc() orelse is_pgsql() of
229+
case is_odbc() orelse is_pgsql() orelse is_cockroachdb() of
230230
true ->
231231
[];
232232
false ->
@@ -1277,6 +1277,9 @@ is_pgsql() ->
12771277
is_mysql() ->
12781278
db_engine() == mysql.
12791279

1280+
is_cockroachdb() ->
1281+
db_engine() == cockroachdb.
1282+
12801283
stop_global_default_pool() ->
12811284
Pools = rpc(mim(), mongoose_config, get_opt, [outgoing_pools]),
12821285
[GlobalRdbmsPool] = [Pool || Pool = #{type := rdbms, scope := global, tag := default} <- Pools],

Diff for: doc/configuration/database-backends-configuration.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Persistent Data:
4343
* RDBMS - MongooseIM has a strong backend support for relational databases.
4444
Reliable and battle proven, they are a great choice for regular MongooseIM use cases and features like `privacy lists`, `vcards`, `roster`, `private storage`, `last activity` and `message archive`.
4545
Never loose your data.
46-
Use MySQL, MariaDB, PostgreSQL, or MS SQL Server.
46+
Use MySQL, MariaDB, PostgreSQL, CockroachDB, or MS SQL Server.
4747

4848
* Cassandra - Only for MAM (Message Archive Management).
4949

@@ -125,6 +125,35 @@ Please refer to the [RDBMS options](outgoing-connections.md#rdbms-options)
125125
and [general database options](general.md#database-settings)
126126
for more information.
127127

128+
### CockroachDB
129+
130+
**Can be used for:**
131+
132+
* users (credentials)
133+
* vcards
134+
* roster
135+
* private storage
136+
* privacy/block lists
137+
* last activity
138+
* mam (message archive management)
139+
* muc_light rooms
140+
141+
**Setup**
142+
143+
The schema files can be found in the `priv` directory.
144+
The default schema is defined in the `cockroachdb.sql` file.
145+
146+
You can use the following command to apply it on localhost:
147+
148+
```bash
149+
psql -h localhost -U user -p 26257 -c "CREATE DATABASE mongooseim;"
150+
psql -h localhost -U user -p 26257 -q -d mongooseim -f cockroachdb.sql
151+
```
152+
You should also configure the CockroachDB database in the `mongooseim.toml` file.
153+
Please refer to the [RDBMS options](outgoing-connections.md#rdbms-options)
154+
and [general database options](general.md#database-settings)
155+
for more information.
156+
128157
### Microsoft SQL Server
129158

130159
Microsoft SQL Server, sometimes called MSSQL, or Azure SQL Database.

Diff for: doc/configuration/outgoing-connections.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ For example:
7474
### RDBMS options
7575

7676
#### `outgoing_pools.rdbms.*.connection.driver`
77-
* **Syntax:** string, one of `"pgsql"`, `"mysql"` or `"odbc"` (a supported driver)
77+
* **Syntax:** string, one of `"pgsql"`, `"mysql"`, `"cockroachdb"` or `"odbc"` (a supported driver)
7878
* **Default:** none - this option is mandatory
7979
* **Example:** `driver = "psgql"`
8080

@@ -101,34 +101,34 @@ How long MongooseIM will wait for the database to answer for a query.
101101

102102
When MongooseIM fails to connect to the DB, it retries with an exponential backoff. This option limits the backoff time for faster reconnection when the DB becomes reachable again.
103103

104-
### Options for `pgsql` and `mysql`
104+
### Options for `pgsql`, `cockroachdb` and `mysql`
105105

106106
#### `outgoing_pools.rdbms.*.connection.host`
107107
* **Syntax:** string
108-
* **Default:** no default; required for `pgsql` and `mysql`
108+
* **Default:** no default; required for `pgsql`, `cockroachdb` and `mysql`
109109
* **Example:** `host = "localhost"`
110110

111111
#### `outgoing_pools.rdbms.*.connection.port`
112112
* **Syntax:** integer, between 0 and 65535
113-
* **Default:** `5432` for `pgsql`; `3306` for `mysql`
113+
* **Default:** `5432` for `pgsql`; `26257` for `cockroachdb`; `3306` for `mysql`
114114
* **Example:** `port = 5343`
115115

116116
#### `outgoing_pools.rdbms.*.connection.database`
117117
* **Syntax:** string
118-
* **Default:** no default; required for `pgsql` and `mysql`
118+
* **Default:** no default; required for `pgsql`, `cockroachdb` and `mysql`
119119
* **Example:** `database = "mim-db"`
120120

121121
#### `outgoing_pools.rdbms.*.connection.username`
122122
* **Syntax:** string
123-
* **Default:** no default; required for `pgsql` and `mysql`
123+
* **Default:** no default; required for `pgsql`, `cockroachdb` and `mysql`
124124
* **Example:** `username = "mim-user"`
125125

126126
#### `outgoing_pools.rdbms.*.connection.password`
127127
* **Syntax:** string
128-
* **Default:** no default; required for `pgsql` and `mysql`
128+
* **Default:** no default; required for `pgsql`, `cockroachdb` and `mysql`
129129
* **Example:** `password = "mim-password"`
130130

131-
To enable TLS, you need to include the [TLS section](#tls-options) in the connection options. There is one additonal option for PostgreSQL:
131+
To enable TLS, you need to include the [TLS section](#tls-options) in the connection options. There is one additonal option for PostgreSQL and CockroachDB:
132132

133133
#### `outgoing_pools.rdbms.*.connection.tls.required`
134134
* **Syntax:** boolean

Diff for: doc/migrations/6.2.1_x.x.x.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,23 @@ Stop the cluster, or individual nodes, if performing a rolling upgrade, and exec
107107
3. Add Prometheus to the [instrumentation section](../configuration/instrumentation.md).
108108
4. Configure a [listener](../listeners/listen-http.md#handler-types-prometheus-mongoose_prometheus_handler) for Prometheus.
109109

110-
Restart the node or cluster.
110+
Restart the node or cluster.
111+
112+
## Support for the new RDBMS database - CockroachDB
113+
114+
We've introduced support for a new RDBMS database, CockroachDB.
115+
116+
To configure CockroachDB, update the connection settings in your configuration file as follows:
117+
```toml
118+
[outgoing_pools.rdbms.default.connection]
119+
driver = "cockroachdb"
120+
host = "localhost"
121+
port = 26257
122+
database = "mongooseim"
123+
username = "mongooseim"
124+
password = "mongooseim_secret"
125+
```
126+
127+
Refer to the [Outgoing connections configuration doc](../configuration/outgoing-connections.md) for more information.
128+
129+
The migration script for CockroachDB , `cockroachdb.sql` is located in the [`priv/migrations`](https://github.com/esl/MongooseIM/tree/master/priv/migrations) directory.

Diff for: doc/modules/mod_mam.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ MongooseIM is compatible with MAM 0.4-1.1.0.
99

1010
Configure MAM with different storage backends:
1111

12-
* RDBMS (databases like MySQL, PostgreSQL, MS SQL Server)
12+
* RDBMS (databases like MySQL, PostgreSQL, CockroachDB, MS SQL Server)
1313
* Cassandra (NoSQL)
1414
* ElasticSearch (NoSQL)
1515

0 commit comments

Comments
 (0)