Skip to content

Commit d6c2668

Browse files
committed
Add documentation for setting up a blackhole engined database
1 parent b68391e commit d6c2668

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

docs/blackhole_db_setup.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
## Steps to set up a blackhole database for local testing of the loading validator
2+
3+
As part of the validator app, records are sent to a local instance of the apel
4+
loader class, to test if they load into an apel server database correctly.
5+
This is important as some errors in a record won't be detected by the syntax
6+
validator, but will still cause a record to fail to load.
7+
8+
These records are loaded into a database with blackhole engined tables - these
9+
tables allow insert commands, but don't store any rows or data, as data is
10+
discarded on write. This allows complete checking that a record can be
11+
successfully loaded to a database, without having to deal with data being stored.
12+
13+
The local instance of the apel loader class is within `monitoring/views.py`, and
14+
uses `monitoring/validatorSettings.py` to pull configuration settings from
15+
`monitoring/settings.ini` about the blackhole validator database.
16+
17+
Steps to set up a blackhole-engined version of the apel server database:
18+
19+
1. Ensure maraidb is started and enabled:
20+
- `sudo su`
21+
- `sudo systemctl start mariadb`
22+
- `sudo systemctl enable mariadb`
23+
24+
2. Login to mariadb with root:
25+
- `mysql -u root -p`
26+
27+
3. Install the blackhole plugin, and then verify it is installed:
28+
- `INSTALL SONAME 'ha_blackhole';`
29+
- `SHOW ENGINES;` (should be a row with BLACKHOLE and support as YES).
30+
31+
4. Exit mariadb:
32+
- `exit;`
33+
34+
5. Set the global default storage engine to blackhole, so that when the database
35+
schema gets applied, tables are created with the blackhole engine:
36+
- find where your mariadb settings are stored (for me it was `/etc/my.cnf.d/`).
37+
- either edit `server.cnf` or create a new `blackhole.cnf` file (what I did).
38+
- in that file:
39+
```
40+
[mysqld]
41+
default-storage-engine=BLACKHOLE
42+
```
43+
- This config setting means that any create table statements without an engine
44+
defined will be set to a blackhole engine by default.
45+
46+
6. Restart mariadb:
47+
- `sudo systemctl restart mariadb`
48+
- Running `SHOW ENGINES;` within mariadb at this point should show the Blackhole
49+
row with support as DEFAULT;
50+
51+
7. Create the database:
52+
- `mysql -u root -p`
53+
- `CREATE DATABASE validator_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;`
54+
- `CREATE USER 'your_name'@'localhost' IDENTIFIED BY 'your_password';`
55+
- `GRANT ALL PRIVILEGES ON validator_db.* TO 'your_name'@'localhost';`
56+
- `FLUSH PRIVILEGES;`
57+
- `exit;`
58+
59+
8. Apply the apel server schema to the database:
60+
- the schema is at https://github.com/apel/apel/blob/dev/schemas/server.sql.
61+
- to do this step, I used my locally cloned version of apel as the
62+
schema file path.
63+
- `mysql -u root validator_db < path_to_apel/schemas/server.sql`
64+
65+
9. Verify the schema applied correctly, and that the correct tables use a
66+
blackhole engine:
67+
- `mysql -u your_name -p`
68+
- `SHOW DATABASES;`
69+
- `USE validator_db;`
70+
- `SHOW TABLES;` (check all tables are there)
71+
- `SHOW TABLE STATUS;` (check that all tables either have a BLACKHOLE or
72+
NULL engine)
73+
74+
10. Populate settings.ini with the following, adding in the correct values:
75+
- ```
76+
[db_validator]
77+
backend=mysql
78+
hostname=localhost
79+
name=validator_db
80+
password=
81+
port=3306
82+
username=
83+
```
84+
- these config options are picked up by the `validatorSettings.py` file.

0 commit comments

Comments
 (0)