Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed docs/migration/migration-system-design-diagram.png
Binary file not shown.
216 changes: 216 additions & 0 deletions docs/migration/migration-system-design-diagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 27 additions & 13 deletions docs/migration/ravendb-to-sql-migration-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ The migration does not move the audit instance or the monitoring instance. The a

## How the migration runs

Run `--start-data-migration` with ServiceControl stopped to copy the data it needs to open, including every failed message RavenDB last modified at or after one hour before its newest unresolved message's last-modified time. There is no upper bound. **This part is your outage**. After the command succeeds, start ServiceControl to copy the unresolved failed messages, the group comments, the event log and the archived and resolved failed messages in the background. **The migration never writes to RavenDB**.
Run `--start-data-migration` with ServiceControl stopped to copy the data it needs to open, including every failed message RavenDB last modified at or after one hour before its newest unresolved message's last-modified time. There is no upper bound. **This part is your outage**. After the command succeeds, start ServiceControl. Then start each optional category in ServicePulse, and it copies in the background. **The migration never writes to RavenDB**.

> [!IMPORTANT]
> Until ServiceControl opens, you can go back to RavenDB and lose nothing. After it opens, you cannot go back.

The migration copies the data in categories, and each category is Copying, Done, Failed or Abandoned. [The overview](ravendb-to-sql-migration-overview.md#when-something-goes-wrong-you-decide-what-happens-next) explains the categories and the states.
The migration copies the data in categories, and each category is Copying, Done, Failed or Abandoned. An optional category can also be Paused. [The overview](ravendb-to-sql-migration-overview.md#when-something-goes-wrong-you-decide-what-happens-next) explains the categories and the states.

The steps below follow this path:

Expand Down Expand Up @@ -63,10 +63,22 @@ Make sure that your setup is supported:

Get the data ready:

- Let retries finish where you can. ServiceControl stays closed until every retry-issued message, every message that holds a retry claim and every failed message of any status that RavenDB last modified at or after one hour before the newest unresolved message's last-modified time is copied. A retry-issued message never ages out. There is no upper bound on the recent set. A retry, archive or resolve after the newest unresolved message's last-modified time counts too and can lengthen the outage. Older unresolved messages without a claim copy after ServiceControl opens, so a large unresolved backlog does not lengthen the outage, but it does lengthen the background copy. The cutoff is the newest unresolved message's last-modified time minus one hour. It stays the same across restarts and retries unless RavenDB expiration removes that message. Expiration can move the cutoff earlier or leave no unresolved message. With no unresolved message only the retry-issued messages and claim holders copy. Archived and resolved messages outside the recent set that hold no claim copy only after ServiceControl opens, when you start that copy in ServicePulse. The exception is a RavenDB index that is broken or leaves out some failed messages: then the copy reads every failed message during the outage, logs a warning, and a large archive makes the outage longer too.
- Run `--import-failed-errors` while the instance is still on RavenDB. A failed error import is a message that ServiceControl took off the error queue but failed to store. The migration copies these either way, but imported ones arrive as ordinary failed messages.
- Let retry, archive and unarchive operations finish on RavenDB before stopping ServiceControl. The offline command refuses persisted batches, the retry forwarding marker, and archive or unarchive operation documents. Stopping ServiceControl leaves unfinished work persisted.
- Back up both RavenDB databases before step 4, because RavenDB is your only way back if the migration fails. If you do not back them up, disable expiration on the primary database after ServiceControl last runs on RavenDB, because every start on RavenDB turns it back on.
- Let retries finish where you can. The outage copies these failed messages, however many there are:
- every retry-issued message, whatever its age
- every message that holds a retry claim, whatever its age
- every message, in any status, that changed less than an hour before the newest unresolved message changed, or after it

A retry, archive or resolve after the newest failure lands in that set too, so it makes the outage longer. Other older messages copy after ServiceControl opens, once you start their copy in ServicePulse. The overview explains [how the cutoff is found](ravendb-to-sql-migration-overview.md#recent-errors), and the one case where a large archive makes the outage longer.
- Run `--import-failed-errors` while the instance is still on RavenDB. These are messages that ServiceControl took off the error queue but could not store. The migration copies them either way, but imported ones arrive as ordinary failed messages.
- Let retry, archive and unarchive operations finish on RavenDB before you stop ServiceControl. The offline command refuses to copy while any of this work is unfinished, and stopping ServiceControl does not finish it.
- Turn off document expiration on the primary RavenDB database. This is not mandatory, but is recommended, because it gives a steadier copy. The migration never changes RavenDB, so expiration keeps deleting old messages and event log items during the copy. That can skip a message, or stop a category until you retry it. A normal start on RavenDB turns expiration back on, so do this after ServiceControl last runs on RavenDB, which is after step 3 if you run it:
1. Stop ServiceControl.
2. For an embedded database, start ServiceControl with `--maint`, with `ServiceControl/StorageType` still set to RavenDB. Maintenance mode runs RavenDB so that Studio can reach it, and it does not turn expiration back on.
3. In RavenDB Studio, [turn off document expiration](https://docs.ravendb.net/6.2/studio/database/settings/document-expiration) for the primary database. This is not mandatory, but is recommended, because it gives a steadier copy
4. [Backup RavenDB](https://docs.particular.net/servicecontrol/storage/ravendb/backup-sc-database).
5. Stop maintenance mode.

If you go back to RavenDB later, the next normal start turns expiration on again.

Keep these settings as they are:

Expand Down Expand Up @@ -101,14 +113,14 @@ In an environment variable, you can leave out the `SERVICECONTROL_` prefix. You
1. Create a new database on SQL Server or PostgreSQL.
2. In the configuration of the instance, set `ServiceControl/StorageType` to `SQLServer` or `PostgreSQL`.
3. Set `ServiceControl/Database/ConnectionString` to the new database.
4. Set `ServiceControl/MessageBody/StorageType` to `FileSystem`, `AzureBlob` or `S3`, and set the settings for that storage type. Give the message body storage at least as much free space as the RavenDB primary database uses on disk today. RavenDB keeps the bodies inside that database, so its size is more than the copy will write.
4. Set `ServiceControl/MessageBody/StorageType` to `FileSystem`, `AzureBlob` or `S3`, and set the settings for that storage type.
5. Run `ServiceControl.exe --setup`. This creates the SQL schema, which includes the table where the migration saves its progress.

## Step 3: Check the row counts

Run the offline command once before the outage, and answer no at "Start the copy?". It shows the configuration, runs the checks and counts the rows of each required category, but writes nothing to SQL. The only write is a test body that the body storage check writes and deletes. You can use the same SQL database afterwards.

1. Stop ServiceControl and every ingestion worker. The command reads RavenDB with ServiceControl stopped, and on an embedded source only one process can use the data directory.
1. Stop ServiceControl.
2. Run `ServiceControl.exe --start-data-migration`, as in [step 4](#step-4-run-the-offline-command).
3. Answer `n` at "Start the copy?".
4. Set `ServiceControl/StorageType` back to RavenDB, and start ServiceControl. Set it to `SQLServer` or `PostgreSQL` again before step 4.
Expand All @@ -132,11 +144,11 @@ Use the row counts of the required categories to plan the outage. The recent err

The command exits without starting ServiceControl. It exits with 0 when the required data is copied and verify is clean. Then start ServiceControl. It exits with 1 when you answer no or stop, a check fails, a category is Failed, or the run is cancelled. It exits with 2 when nothing is outstanding but verify found rows that the copy did not read.

Outside a container, the command logs to its own file for each run, named `migration-<yyyy-MM-dd-HHmmss>.txt`, in the log folder of the instance next to `logfile.txt`. A run started in the same second as the one before adds to its file. The console shows only the steps. When the run ends, it names its log file. An argument the command refuses prints the reason and names no log file. In a container, the log goes to the console.
Outside a container, the command logs to its own file for each run, named `migration-<yyyy-MM-dd-HHmmss>.txt`, in the log folder of the instance next to `logfile.txt`. In a container, the log goes to the console.

## Step 5: Start ServiceControl

After the offline command exits with 0, start the ServiceControl service or container. ServiceControl detects the migration from SQL checkpoints. It starts copying the unresolved failed messages and the group comments at once. It copies no other optional data until you start it in ServicePulse.
After the offline command exits with 0, start the ServiceControl service or container. ServiceControl detects the migration from SQL checkpoints. It copies no optional data until you start it in ServicePulse.

Normal startup refuses an unfinished required copy and tells you to run `--start-data-migration`; it never resumes that copy itself.

Expand All @@ -147,17 +159,19 @@ If something goes wrong, read [If something goes wrong](#if-something-goes-wrong

## Step 6: Copy the optional data in ServicePulse

The unresolved failed messages and the group comments copy in the background as soon as ServiceControl opens. They have no window and no setting turns them off, so every unresolved message is copied however old it is. Group comments appear in ServicePulse as their batches commit, after the unresolved failed messages category is Done or Abandoned.
ServiceControl copies an optional category only after you start it in ServicePulse. A started category copies in the background, and carries on after a restart.

The unresolved failed messages and the group comments have no window, so every unresolved message is copied however old it is. Group comments copy only after the unresolved failed messages category is Done or Abandoned, and appear in ServicePulse as they copy.

The other two optional categories, the event log and the archived and resolved failed messages, also copy in the background. Start each one in ServicePulse, and choose its window there: how many days back it copies. By default the window is the retention period of the instance, so everything RavenDB still holds is copied. A window longer than the retention period copies nothing extra. If you do not want a category, abandon it in ServicePulse.
The other two optional categories, the event log and the archived and resolved failed messages, have a window: how many days back the category copies. Choose it when you start the category in ServicePulse. By default the window is the retention period of the instance, so everything RavenDB still holds is copied. A window longer than the retention period copies nothing extra. If you do not want a category, abandon it in ServicePulse.

ServiceControl is open and works as usual while the optional categories copy. You can see the progress in three places:

- The ServiceControl log.
- The ServicePulse activity feed. It shows when a category fails and when RavenDB cannot be reached.
- The output of `--migration-status`. This command does not open RavenDB, so you can run it at any time.

If the copy slows down your production work, pause the category in ServicePulse and resume it later. Or raise `ServiceControl/Migration/ThrottlePauseMilliseconds` and restart. This is the pause between two background batches. The default is 100 milliseconds.
If the copy slows down your production work, raise `ServiceControl/Migration/ThrottlePauseMilliseconds` and restart. This is the pause between two background batches. The default is 100 milliseconds. To stop a category for a while, pause it in ServicePulse and resume it later. Abandon it only if you no longer want its data.

> [!IMPORTANT]
> Retry or abandon a Failed optional category in ServicePulse. No command does it. Until you do, it stays Failed, and `--migration-status` shows it.
Expand Down
Loading