From 46392dd68fa9db6cb02327f6f510288552fea1b8 Mon Sep 17 00:00:00 2001 From: Conal Smith Date: Sun, 20 Aug 2023 19:50:47 +0100 Subject: [PATCH 1/8] CORE-16318: State Manager Configuration Add new polymorphic section under the current messaging configuration section to hold state manager settings. --- .../schema/configuration/MessagingConfig.java | 26 +++++ .../messaging/1.0/corda.messaging.json | 31 ++++++ .../1.0/state-manager-db-properties.json | 101 ++++++++++++++++++ .../java/net/corda/db/schema/CordaDb.java | 3 +- .../java/net/corda/db/schema/DbSchema.java | 2 + .../statemanager/db.changelog-master.xml | 6 ++ .../state-manager-migration-v1.0.xml | 35 ++++++ gradle.properties | 2 +- 8 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/state-manager-db-properties.json create mode 100644 data/db-schema/src/main/resources/net/corda/db/schema/statemanager/db.changelog-master.xml create mode 100644 data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v1.0.xml diff --git a/data/config-schema/src/main/java/net/corda/schema/configuration/MessagingConfig.java b/data/config-schema/src/main/java/net/corda/schema/configuration/MessagingConfig.java index ff08267671..a572cbd248 100644 --- a/data/config-schema/src/main/java/net/corda/schema/configuration/MessagingConfig.java +++ b/data/config-schema/src/main/java/net/corda/schema/configuration/MessagingConfig.java @@ -78,4 +78,30 @@ private Publisher() { * producers to stay under this limit when publishing messages. */ public static final String MAX_ALLOWED_MSG_SIZE = "maxAllowedMessageSize"; + + /** + * State Manager Configuration for connecting to the underlying persistent storage. + */ + public static final class StateManager { + private StateManager() { + } + + public static final String STATE_MANAGER = "stateManager"; + public static final String TYPE = STATE_MANAGER + ".type"; + + // Database Values + public static final String DB_PROPERTIES = STATE_MANAGER + ".database"; + public static final String JDBC_USER = DB_PROPERTIES + ".user"; + public static final String JDBC_PASS = DB_PROPERTIES + ".pass"; + + public static final String JDBC_URL = DB_PROPERTIES + ".jdbc.url"; + public static final String JDBC_DRIVER = DB_PROPERTIES + "jdbc.driver"; + public static final String JDBC_DRIVER_DIRECTORY = DB_PROPERTIES + ".jdbc.directory"; + public static final String JDBC_POOL_MAX_SIZE = DB_PROPERTIES + ".pool.maxSize"; + public static final String JDBC_POOL_MIN_SIZE = DB_PROPERTIES + ".pool.minSize"; + public static final String JDBC_POOL_IDLE_TIMEOUT_SECONDS = DB_PROPERTIES + ".pool.idleTimeoutSeconds"; + public static final String JDBC_POOL_MAX_LIFETIME_SECONDS = DB_PROPERTIES + ".pool.maxLifetimeSeconds"; + public static final String JDBC_POOL_KEEP_ALIVE_TIME_SECONDS = DB_PROPERTIES + ".pool.keepAliveTimeSeconds"; + public static final String JDBC_POOL_VALIDATION_TIMEOUT_SECONDS = DB_PROPERTIES + ".pool.validationTimeoutSeconds"; + } } diff --git a/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/corda.messaging.json b/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/corda.messaging.json index 57eaf5e018..72f0be5bb6 100644 --- a/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/corda.messaging.json +++ b/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/corda.messaging.json @@ -109,6 +109,37 @@ "default": 972800, "minimum": 512000, "maximum": 8388608 + }, + "stateManager": { + "description": "Connection details for the underlying persistent storage used by the out of process State Manager.", + "type": "object", + "properties": { + "type": { + "description": "The type of state manager implementation.", + "enum": [ + "DATABASE" + ] + }, + "additionalProperties": false + }, + "$comment": "Polymorphic state manager storage connection configuration. The valid section depends on which state manager implementation is in use.", + "allOf": [ + { + "if": { + "properties": {"type": {"const": "DATABASE"}}, + "required": ["type"] + }, + "then": { + "properties": { + "databaseProperties": { + "description": "Settings to connect to the state manager database.", + "$ref": "state-manager-db-properties.json" + } + }, + "required": ["type","databaseProperties"] + } + } + ] } }, "additionalProperties": false diff --git a/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/state-manager-db-properties.json b/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/state-manager-db-properties.json new file mode 100644 index 0000000000..0be5c75e1a --- /dev/null +++ b/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/state-manager-db-properties.json @@ -0,0 +1,101 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://corda.r3.com/net/corda/schema/configuration/db/1.0/corda.db.json", + "title": "State Manager Database Configuration Schema", + "description": "Configuration schema for the database section. Note that this configuration cannot be updated dynamically through the REST endpoint.", + "type": "object", + "properties": { + "database": { + "description": "Database settings.", + "type": "object", + "default": {}, + "properties": { + "user": { + "description": "The database user.", + "type": "string" + }, + "pass": { + "description": "The database password.", + "type": "string" + }, + "jdbc": { + "description": "JDBC settings.", + "type": "object", + "default": {}, + "properties": { + "driver": { + "description": "The JDBC driver.", + "type": "string", + "default": "org.postgresql.Driver" + }, + "directory": { + "description": "The directory that contains the JDBC drivers.", + "type": "string", + "default": "/opt/jdbc-driver" + }, + "url": { + "description": "The JDBC URL.", + "type": "string", + "default": "jdbc:postgresql://state-manager-db:5432/statemanager" + } + }, + "additionalProperties": false + }, + "pool": { + "description": "Database pool settings.", + "type": "object", + "default": {}, + "properties": { + "max_size": { + "description": "The maximum database pool size.", + "type": "integer", + "minimum": 1, + "default": 10 + }, + "min_size": { + "description": "The minimum database pool size. If left null will default to the `max_size` value.", + "default": null, + "anyOf": [ + { + "type": "integer", + "minimum": 0 + }, + { + "type": "null" + } + ] + }, + "idleTimeoutSeconds": { + "description": "The maximum time (in seconds) a connection can stay idle in the pool. A value of 0 means that idle connections are never removed from the pool.", + "type": "integer", + "minimum": 0, + "default": 120 + }, + "maxLifetimeSeconds": { + "description": "The maximum time (in seconds) a connection can stay in the pool, regardless if it has been idle or has been recently used. If a connection is in-use and has reached \"maxLifetime\" timeout, it will be removed from the pool only when it becomes idle.", + "type": "integer", + "minimum": 1, + "default": 1800 + }, + "keepAliveTimeSeconds": { + "description": "The interval time (in seconds) in which connections will be tested for aliveness. Connections which are no longer alive are removed from the pool. A value of 0 means this check is disabled.", + "type": "integer", + "minimum": 0, + "default": 0 + }, + "validationTimeoutSeconds": { + "description": "The maximum time (in seconds) that the pool will wait for a connection to be validated as alive.", + "type": "integer", + "minimum": 1, + "default": 5 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + "default": {} + }, + "additionalProperties": false +} \ No newline at end of file diff --git a/data/db-schema/src/main/java/net/corda/db/schema/CordaDb.java b/data/db-schema/src/main/java/net/corda/db/schema/CordaDb.java index da35d4f137..17cad62f2c 100644 --- a/data/db-schema/src/main/java/net/corda/db/schema/CordaDb.java +++ b/data/db-schema/src/main/java/net/corda/db/schema/CordaDb.java @@ -16,7 +16,8 @@ public enum CordaDb { Uniqueness("corda-uniqueness"), Vault("corda-vault"), Crypto("corda-crypto"), - VirtualNodes("corda-virtual-nodes"); + VirtualNodes("corda-virtual-nodes"), + StateManager("corda-state-manager"); private final String persistenceUnitName; diff --git a/data/db-schema/src/main/java/net/corda/db/schema/DbSchema.java b/data/db-schema/src/main/java/net/corda/db/schema/DbSchema.java index 782d9b9754..a0956525a2 100644 --- a/data/db-schema/src/main/java/net/corda/db/schema/DbSchema.java +++ b/data/db-schema/src/main/java/net/corda/db/schema/DbSchema.java @@ -61,4 +61,6 @@ private DbSchema() { public static final String UNIQUENESS_STATE_DETAILS_TABLE = "uniqueness_state_details"; public static final String UNIQUENESS_TX_DETAILS_TABLE = "uniqueness_tx_details"; public static final String UNIQUENESS_REJECTED_TX_TABLE = "uniqueness_rejected_txs"; + + public static final String STATE_MANAGER_TABLE = "state"; } diff --git a/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/db.changelog-master.xml b/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/db.changelog-master.xml new file mode 100644 index 0000000000..6d7837e261 --- /dev/null +++ b/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/db.changelog-master.xml @@ -0,0 +1,6 @@ + + + + diff --git a/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v1.0.xml b/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v1.0.xml new file mode 100644 index 0000000000..e6e64f1181 --- /dev/null +++ b/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v1.0.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gradle.properties b/gradle.properties index c879bfa8ff..1b305ed10b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ cordaProductVersion = 5.1.0 # NOTE: update this each time this module contains a breaking change ## NOTE: currently this is a top level revision, so all API versions will line up, but this could be moved to ## a per module property in which case module versions can change independently. -cordaApiRevision = 19 +cordaApiRevision = 999 # Main kotlinVersion = 1.8.21 From b8ff13719300b78241768d9d31f94ed09f7d1df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Ramos=20Cassella?= Date: Thu, 7 Sep 2023 09:40:40 +0100 Subject: [PATCH 2/8] Remove unncesary changes --- .../messaging/1.0/state-manager-db-properties.json | 2 +- data/db-schema/src/main/java/net/corda/db/schema/CordaDb.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/state-manager-db-properties.json b/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/state-manager-db-properties.json index 0be5c75e1a..5917eb703a 100644 --- a/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/state-manager-db-properties.json +++ b/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/state-manager-db-properties.json @@ -98,4 +98,4 @@ "default": {} }, "additionalProperties": false -} \ No newline at end of file +} diff --git a/data/db-schema/src/main/java/net/corda/db/schema/CordaDb.java b/data/db-schema/src/main/java/net/corda/db/schema/CordaDb.java index 17cad62f2c..da35d4f137 100644 --- a/data/db-schema/src/main/java/net/corda/db/schema/CordaDb.java +++ b/data/db-schema/src/main/java/net/corda/db/schema/CordaDb.java @@ -16,8 +16,7 @@ public enum CordaDb { Uniqueness("corda-uniqueness"), Vault("corda-vault"), Crypto("corda-crypto"), - VirtualNodes("corda-virtual-nodes"), - StateManager("corda-state-manager"); + VirtualNodes("corda-virtual-nodes"); private final String persistenceUnitName; From 70a6b4603ab6b5b78a578483460c247b1b4db3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Ramos=20Cassella?= Date: Thu, 7 Sep 2023 10:59:47 +0100 Subject: [PATCH 3/8] Add persistence unit name to configuration --- .../net/corda/schema/configuration/MessagingConfig.java | 1 + .../messaging/1.0/state-manager-db-properties.json | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/data/config-schema/src/main/java/net/corda/schema/configuration/MessagingConfig.java b/data/config-schema/src/main/java/net/corda/schema/configuration/MessagingConfig.java index a572cbd248..de19bbdbbd 100644 --- a/data/config-schema/src/main/java/net/corda/schema/configuration/MessagingConfig.java +++ b/data/config-schema/src/main/java/net/corda/schema/configuration/MessagingConfig.java @@ -97,6 +97,7 @@ private StateManager() { public static final String JDBC_URL = DB_PROPERTIES + ".jdbc.url"; public static final String JDBC_DRIVER = DB_PROPERTIES + "jdbc.driver"; public static final String JDBC_DRIVER_DIRECTORY = DB_PROPERTIES + ".jdbc.directory"; + public static final String JDBC_PERSISTENCE_UNIT_NAME = DB_PROPERTIES + ".jdbc.persistenceUnitName"; public static final String JDBC_POOL_MAX_SIZE = DB_PROPERTIES + ".pool.maxSize"; public static final String JDBC_POOL_MIN_SIZE = DB_PROPERTIES + ".pool.minSize"; public static final String JDBC_POOL_IDLE_TIMEOUT_SECONDS = DB_PROPERTIES + ".pool.idleTimeoutSeconds"; diff --git a/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/state-manager-db-properties.json b/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/state-manager-db-properties.json index 5917eb703a..a9d1bb7617 100644 --- a/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/state-manager-db-properties.json +++ b/data/config-schema/src/main/resources/net/corda/schema/configuration/messaging/1.0/state-manager-db-properties.json @@ -36,7 +36,12 @@ "url": { "description": "The JDBC URL.", "type": "string", - "default": "jdbc:postgresql://state-manager-db:5432/statemanager" + "default": "jdbc:postgresql://state-manager-db:5432/state_manager" + }, + "persistenceUnitName": { + "description": "The persistent unit name.", + "type": "string", + "default": "corda-state-manager" } }, "additionalProperties": false From 6f69567fe51c0272554168afa27ada2e5241e258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Ramos=20Cassella?= Date: Thu, 7 Sep 2023 14:39:39 +0100 Subject: [PATCH 4/8] Review Feedback --- .../net/corda/db/schema/statemanager/db.changelog-master.xml | 2 +- .../statemanager/migration/state-manager-migration-v1.0.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/db.changelog-master.xml b/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/db.changelog-master.xml index 6d7837e261..661f940b69 100644 --- a/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/db.changelog-master.xml +++ b/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/db.changelog-master.xml @@ -2,5 +2,5 @@ - + diff --git a/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v1.0.xml b/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v1.0.xml index e6e64f1181..82a1683b24 100644 --- a/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v1.0.xml +++ b/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v1.0.xml @@ -17,7 +17,7 @@ - + From 45b66ed1b7eefbb211be92fbb13ccf87ea6caf95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Ramos=20Cassella?= Date: Thu, 7 Sep 2023 14:48:05 +0100 Subject: [PATCH 5/8] Review Feedback --- ...anager-migration-v1.0.xml => state-manager-migration-v5.1.xml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/{state-manager-migration-v1.0.xml => state-manager-migration-v5.1.xml} (100%) diff --git a/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v1.0.xml b/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v5.1.xml similarity index 100% rename from data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v1.0.xml rename to data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v5.1.xml From 84c16695936da4e616c05bac83f32858427f340c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Ramos=20Cassella?= Date: Mon, 11 Sep 2023 10:08:46 +0100 Subject: [PATCH 6/8] Fix version --- .../statemanager/migration/state-manager-migration-v5.1.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v5.1.xml b/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v5.1.xml index 82a1683b24..77380c0cff 100644 --- a/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v5.1.xml +++ b/data/db-schema/src/main/resources/net/corda/db/schema/statemanager/migration/state-manager-migration-v5.1.xml @@ -12,7 +12,7 @@ - + From 08b33e1313bddd2ebc51d7508032ae24a0089bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Ramos=20Cassella?= Date: Mon, 11 Sep 2023 12:38:09 +0100 Subject: [PATCH 7/8] Correct API Version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1b305ed10b..46577e1014 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ cordaProductVersion = 5.1.0 # NOTE: update this each time this module contains a breaking change ## NOTE: currently this is a top level revision, so all API versions will line up, but this could be moved to ## a per module property in which case module versions can change independently. -cordaApiRevision = 999 +cordaApiRevision = 20 # Main kotlinVersion = 1.8.21 From c6cfdb89cf5bc97d952747d83ae7055ed0579d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Ramos=20Cassella?= Date: Mon, 11 Sep 2023 15:14:32 +0100 Subject: [PATCH 8/8] Correct API Version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 46577e1014..c879bfa8ff 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ cordaProductVersion = 5.1.0 # NOTE: update this each time this module contains a breaking change ## NOTE: currently this is a top level revision, so all API versions will line up, but this could be moved to ## a per module property in which case module versions can change independently. -cordaApiRevision = 20 +cordaApiRevision = 19 # Main kotlinVersion = 1.8.21