With future Runtime releases, you will not be able anymore to use the same persistent state database/database schema for multiple independent services (see Timeframe below).
Before you update to such a Runtime version, you need to resolve this! We recommend to perform the migration as soon as possible.

Currently it is technically possible (though not recommended) to share one persistent state database/database schema between different independent services. With future Runtime releases, this will not be allowed anymore.

This means that you need to rework services that share the same persistent state database/database schema. This article describes what you need to do.

Roadmap

The latest version of PAS is PAS 24.1. The upcoming PAS version 24.2  will still come with a Runtime that has the legacy persistent state implementation, but we will provide a Runtime beta version with the changed behavior.

PAS 24.3 then will come with this changed behavior included as per standard.

When using the Deployment Wizard in the PAS Administration to deploy a service, you can select the xUML Runtime version to be used for deployment.

For this to work, your installation needs to have multiple Runtime versions installed.

What this is about

To keep it shorter and improve the readability of this text, we are using the term database schema as a synonym to database. Which of the two is the correct term in your case depends on your database system.

You have set up a persistent state database schema of which the database tables contain data of multiple (2 or more) independent services.

As this is not allowed anymore, you need to

  1. create dedicated database schemes for every single service
  2. move (first copy, then delete) the data from the shared database to the dedicated database

You can keep one of the services in the original database.

To do this, follow the procedure described below.

Prerequisites

To follow the procedure described below, you need to have at least Runtime 2019.9 installed. If your current Runtime is older than 2019.9, please update your installation to 2019.9 (at least) before performing the migration steps.

Step 1: Stop the affected services

Stop all services that are affected by this rework.

Step 2: Create a database backup

Before starting with this migration, we strongly recommend to do a database backup. This way you can rollback your changes if anything goes wrong during the migration.

Step 3: Create a new database schema for every service

For each service you need to create a separate database schema. This is done by database commands that depend on the database system you are using. It may be e.g. something like

  • CREATE SCHEMA <name of new schema> (Oracle)
    or
  • CREATE DATABASE <name of new database> (SQL Server)

Keep in mind, to also assign the needed database users that the services you are going to migrate use to connect to the database. They need read and write access to this new schema!

Next, you need to create all necessary persistent state tables to the database schema. To help you with that, the Runtime comes with scripts for every supported database (MySQL/MariaDB, Oracle and SQL Server).

  1. Go to your Runtime directory, to <path to Runtime directory>/<your OS>/resource/sql/<your DB system>/pstate.

    If you are using an older Runtime (before Runtime 2023.1), these scripts reside in <path to Runtime directory>/<your OS>.

  2. Find the script CreateSchema.sql for your database.

    The MySQL script also fits for MariaDB.

  3. Run this script for each newly created schema to create persistent state tables.

Step 4: Copy the data

Copy the data of each service to the corresponding database schema. To help you with that task, we have prepared some scripts, or you can execute the steps manually.

The owner concept

To perform the next steps, you need to be familiar with the owner concept of the PAS persistent state implementation.

  • Services are owners of persistent state objects.
  • You need to know the owner to distinguish the persistent state data.
  • The owner name is the service name as per default.
  • The owner name can be changed in the service configuration/settings:

    Configuration Section

    Key

    NameValue
    Persistent StatePersistent State: Owner:AL_PS_OWNER Service_2

    For more information on how to access the service configuration, refer to Adapting the Configuration of Containerized xUML Services for the PAS Administration, and to Adapting Integration Service Configuration for the Integration/Bridge.

This is why owner names are coded into owner IDs in a dedicated table OWNERS, e.g.

OWNER_ID

OWNER

COMPOSITE

HOST

START_TS

STOP_TS

1

Service_1

Service_1

localhost

1.715.611.721

1.715.611.807

2

Service_2

Service_2

localhost

1.715.611.815

1.715.611.875

Database items like persistent state object data is coded to the owner ID, some other items are coded to the owner name. Keep this in mind when doing the migration manually - the migration scripts (see below) already cover that.

Use the scripts

The following scripts are available:

Rework the scripts to fit your setup

At the top of each script, you'll find three variables with sample values: @old_schema, @new_schema, @owner_name. You need to replace the sample values with the actual names according to your setup.

For how to lookup the owner name, refer to The owner concept above.

ScriptContent
Script to split a MySQL/MariaDB database
Script to split an Oracle database
Script to split an SQLServer database

Split the data manually

For each service, copy the related data from the old to the new database schema. To identify the data, refer to the owner name or owner ID.

TaskTableScript
Update persistent state version
Set the current persistent state version to the newly created VERSION table.
VERSION
UPDATE <new schema>.VERSION
SET MAX_OWNER_ID =
(SELECT MAX_OWNER_ID FROM <old schema>.VERSION)
Copy owner data
Copy the owner data of the service in question.
OWNERS
INSERT INTO <new schema>.OWNERS
SELECT * FROM <old schema>.OWNERS
WHERE OWNER = <your owner name>
Copy data by owner ID
As a reference, we are using the owner id from the OWNERS table we have already copied.
Copy persistent state object dataOBJECT_DATA
INSERT INTO <new schema>.OBJECT_DATA
SELECT * FROM <old schema>.OBJECT_DATA
WHERE OWNER IN (SELECT OWNER_ID FROM <new schema>.OWNERS)
Copy externally stored persistent state attributesEXTERNAL_ATTRIBUTES
INSERT INTO <new schema>.EXTERNAL_ATTRIBUTES
SELECT * FROM <old schema>.EXTERNAL_ATTRIBUTES
WHERE OBJECT_ID IN
(SELECT OBJECT_ID FROM <new schema>.OBJECT_DATA)
Copy tokensTOKENS
INSERT INTO <new schema>.TOKENS
SELECT * FROM <old schema>.TOKENS
WHERE OWNER IN (SELECT OWNER_ID FROM <new schema>.OWNERS)
Copy pending events
EVENTS
INSERT INTO <new schema>.EVENTS
SELECT * FROM <old schema>.EVENTS
WHERE OWNER IN (SELECT OWNER_ID FROM <new schema>.OWNERS)
Copy object identifiers
OBJECT_IDENTIFIERS
INSERT INTO <new schema>.OBJECT_IDENTIFIERS
SELECT * FROM <old schema>.OBJECT_IDENTIFIERS
WHERE OWNER IN (SELECT OWNER_ID FROM <new schema>.OWNERS)
Copy history states
HISTORY_STATES
INSERT INTO <new schema>.HISTORY_STATES
SELECT * FROM <old schema>.HISTORY_STATES
WHERE OWNER IN (SELECT OWNER_ID FROM <new schema>.OWNERS)
Copy conversation locks
CONVERSATION_LOCKS
INSERT INTO <new schema>.CONVERSATION_LOCKS
SELECT * FROM <old schema>.CONVERSATION_LOCKS
WHERE OWNER IN (SELECT OWNER_ID FROM <new schema>.OWNERS)
Copy data by owner name
Set the owner name manually.
Copy object keys
OBJECT_KEYS
INSERT INTO <new schema>.OBJECT_KEYS
SELECT * FROM <old schema>.OBJECT_KEYS
WHERE OWNER = <your owner name>
Copy conversation events
CONVERSATION_EVENTS
INSERT INTO <new schema>.CONVERSATION_EVENTS
SELECT * FROM <old schema>.CONVERSATION_EVENTS
WHERE OWNER = <your owner name>

Delete the copied data

After having copied the data - either by script, or manually - you need to delete the data from the old database schema. To identify the data, refer to the owner name or owner ID.

TableScript
Delete data by owner name
Set the owner name manually.

OBJECT_KEYS

DELETE FROM <old schema>.OBJECT_KEYS
WHERE OWNER = <your owner name>

CONVERSATION_EVENTS

DELETE FROM <old schema>.CONVERSATION_EVENTS
WHERE OWNER = <your owner name>
Delete data by owner ID
As a reference, we are using the owner id from the OWNERS table we have already copied.

EXTERNAL_ATTRIBUTES

DELETE FROM <old schema>.EXTERNAL_ATTRIBUTES
WHERE OBJECT_ID IN
(SELECT OBJECT_ID FROM <new schema>.OBJECT_DATA)

CONVERSATION_LOCKS

DELETE FROM <old schema>.CONVERSATION_LOCKS
WHERE OWNER IN (SELECT OWNER_ID FROM <new schema>.OWNERS)

HISTORY_STATES

DELETE FROM <old schema>.HISTORY_STATES
WHERE OWNER IN (SELECT OWNER_ID FROM <new schema>.OWNERS)


OBJECT_IDENTIFIERS

DELETE FROM %OLD_schema%.OBJECT_IDENTIFIERS
WHERE OWNER IN (SELECT OWNER_ID FROM <new schema>.OWNERS)

EVENTS

DELETE FROM <old schema>.EVENTS
WHERE OWNER IN (SELECT OWNER_ID FROM <new schema>.OWNERS)

TOKENS

DELETE FROM <old schema>.TOKENS
WHERE OWNER IN (SELECT OWNER_ID FROM <new schema>.OWNERS)

OBJECT_DATA
DELETE FROM <old schema>.OBJECT_DATA
WHERE OWNER IN (SELECT OWNER_ID FROM <new schema>.OWNERS)
OWNERS
DELETE FROM <old schema>.OWNERS
WHERE OWNER_ID IN (SELECT OWNER_ID FROM <new schema>.OWNERS)

Step 5: Change the service configuration

After the data migration, you need to update the service configuration (settings) of the migrated services. You need to update the configured database to the new one the data has been migrated to.

You can do this in the PAS Administration or on the Integration Component (Bridge), or you can change the definitions in your MagicDraw model and redeploy it.

For more information on how to access the service configuration, refer to Adapting the Configuration of Containerized xUML Services for the PAS Administration, and to Adapting Integration Service Configuration for the Integration/Bridge.

PAS Administration
(Service)

  1. Open the service details in the PAS Administration.
  2. Go to section Configuration, and search for AL_PS_DATABASE.
  3. Change the current value of Persistent State: Database: / AL_PS_DATABASE.

PAS Integration Component
(Service)

  1. Open your service in the Integration Component (Bridge).
  2. Go to tab Settings, and select the Persistent State view.
  3. Change the entry of field Persistent State: Database:.

MagicDraw
(Model)

  1. Open the component diagram of your model.
  2. Change the Db Connection string property on the database alias.
  3. Compile and deploy the service.

Step 6: Restart the services

Reminder

Have you already assigned the needed database users that the migrated services use to connect to the database? They need read and write access!

Now you can restart the migrated services.

We recommend to test the new setup carefully.

  • No labels