Skip to content

Commit dbf13e3

Browse files
committed
docs: refine option one as the preferred one
1 parent 8542d3e commit dbf13e3

File tree

1 file changed

+46
-17
lines changed

1 file changed

+46
-17
lines changed

docs/adrs/00008-re-process-documents.md

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ in the database. We also store the original source document "as-is".
1414
When making changes to the database structure, we also have a migration process, which takes care of upgrading the
1515
database structures during an upgrade.
1616

17-
However, in some cases, changing the database structure actually means to extract more information from documents and is
18-
currently stored in the database. Or information is extracted in a different way. This requires a re-processing of
17+
However, in some cases, changing the database structure actually means extracting more information from documents than
18+
is currently stored in the database. Or information is extracted in a different way. This requires a re-processing of
1919
all documents affected by this change.
2020

2121
### Example
@@ -30,25 +30,58 @@ This ADR makes the following assumptions:
3030
* All documents are stored in the storage
3131
* It is expected that an upgrade is actually required
3232
* Running such migrations is expected to take a long time
33+
* The management of infrastructure (PostgreSQL) is not in the scope of Trustify
3334

3435
Question? Do we want to support downgrades?
3536

3637
## Decision
3738

38-
### Option 1
39+
During the migration of database structures (sea orm), we also re-process all documents (if required). This would
40+
be running during the migration job of the Helm chart and would have an impact on updates as the rollout of newer
41+
version pods would be delayed until the migration (of data) has been finished.
3942

40-
During the migration of database structures (sea orm), we also re-process all documents (when required).
43+
This would also require to prevent users from creating new documents during that time. Otherwise, we would need to
44+
re-process documents ingested during the migration time. A way of doing this could be to leverage PostgreSQL's ability
45+
to switch into read-only mode. Having mutable operations fail with a 503 (Service Unavailable) error. This would also
46+
allow for easy A/B (green/blue) database setups. Switching the main one to read-only, having the other one run the
47+
migration.
4148

42-
In order to report progress, we could write that state into a table and expose that information to the user via the UI.
49+
We could provide an endpoint to the UI, reporting the fact that the system is in read-only mode during a migration.
4350

44-
* 👎 Might serve inaccurate data for a while
45-
* 👎 Might block an upgrade if re-processing fails
4651
* 👍 Can fully migrate database (create mandatory field as optional -> re-process -> make mandatory)
52+
* 👍 Might allow for an out-of-band migration of data, before running the upgrade (even on a staging env)
53+
* 👍 Would allow to continue serving data while the process is running
4754
* 👎 Might be tricky to create a combined re-processing of multiple ones
55+
* 👎 Might block an upgrade if re-processing fails
56+
57+
We do want to support different approaches of this migration. Depending on the needs of the user, the size of the
58+
data store and the infrastructure used.
59+
60+
### Approach 1
61+
62+
The "lazy" approach, where the user just runs the migration (or the new version of the application with migrations
63+
enabled). The process will migrate schema and data. This might block the startup for a bit. But would be fast and
64+
simple for small systems.
65+
66+
### Approach 2
67+
68+
The user uses a green/blue deployment. Switching the application to use green and run migrations against blue. Once
69+
the migrations are complete, switching back to blue. Green will be read-only and mutable API calls will fail with a 503
70+
error.
71+
72+
An alternative to this could also be to configure the system first to go into "read-only mode", by using a default
73+
transaction mode of read-only.
74+
75+
## Open items
76+
77+
* [ ] How to handle unparsable or failing documents during migration?
78+
* [ ] Add a version number to the document, tracking upgrades
79+
80+
## Alternative approaches
4881

4982
### Option 2
5083

51-
We create a similar module as for the importer. Running migrations after an upgrade. Accepting that in the meantime,
84+
We create a similar module as for the importer. Running migrations after an upgrade. Accepting that in the meantime,
5285
we might service inaccurate data.
5386

5487
* 👎 Might serve inaccurate data for a while for a longer time
@@ -58,7 +91,7 @@ we might service inaccurate data.
5891

5992
### Option 3
6093

61-
We change ingestion in a way to it is possible to just re-ingest every document. Meaning, we re-ingest from the
94+
We change ingestion in a way to it is possible to just re-ingest every document. Meaning, we re-ingest from the
6295
original sources.
6396

6497
* 👎 Might serve inaccurate data for a while for a longer time
@@ -68,14 +101,10 @@ original sources.
68101
* 👎 Won't work for manual (API) uploads
69102
* 👎 Would require removing optimizations for existing documents
70103

71-
## Open items
72-
73-
74-
75-
## Alternative approaches
76-
77-
78104

79105
## Consequences
80106

81-
107+
* The migration will block the upgrade process until it is finished
108+
* Ansible and the operator will need to handle this as well
109+
* The system will become read-only during a migration
110+
* The UI needs to provide a page for monitoring the migration state. The backend needs to provide appropriate APIs.

0 commit comments

Comments
 (0)