Failed to start Corda node when connected to the Oracle database which is setup as production database - corda

My setup detail is as follows
Corda 4.6 enterprise version
Database : Oracle 12
I am doing production database setup by refering https://docs.corda.net/docs/corda-enterprise/4.6/node/operating/node-database-admin.html. I created 2 database schemas (Admin and restricted access) for each node. I updated node.conf database connection as per given in docuemntation. I also given permission to my_user to access my_admin_user
dataSourceProperties = {
dataSourceClassName = "oracle.jdbc.pool.OracleDataSource"
dataSource.url = "jdbc:oracle:thin:#<host>:<port>:<sid>"
dataSource.user = my_user
dataSource.password = "my_password"
}
database = {
schema = my_admin_user
}
However getting below error while I start nodes
2021-06-09T16:36:16,400 ERROR databaseInitialisation DatabaseInitialisation(id="rK2VjTKa";status="error";error_code="1";message="**ORA-01031: insufficient privileges** [Failed SQL: CREATE TABLE my_user.DATABASECHANGELOG (ID VARCHAR2(255) NOT NULL, AUTHOR VARCHAR2(255) NOT NULL, FILENAME VARCHAR2(255) NOT NULL, DATEEXECUTED TIMESTAMP NOT NULL, ORDEREXECUTED INTEGER NOT NULL, EXECTYPE VARCHAR2(10) NOT NULL, MD5SUM VARCHAR2(35), DESCRIPTION VARCHAR2(255), COMMENTS VARCHAR2(255), TAG VARCHAR2(255), LIQUIBASE VARCHAR2(20), CONTEXTS VARCHAR2(255), LABELS VARCHAR2(255), DEPLOYMENT_ID VARCHAR2(10))]")
2021-06-09T16:36:16,413 ERROR net.corda.node.internal.NodeStartupLogging **ORA-01031: insufficient privileges**
[Failed SQL: CREATE TABLE my_user.DATABASECHANGELOG (ID VARCHAR2(255) NOT NULL, AUTHOR VARCHAR2(255) NOT NULL, FILENAME VARCHAR2(255) NOT NULL, DATEEXECUTED TIMESTAMP NOT NULL, ORDEREXECUTED INTEGER NOT NULL, EXECTYPE VARCHAR2(10) NOT NULL, MD5SUM VARCHAR2(35), DESCRIPTION VARCHAR2(255), COMMENTS VARCHAR2(255), TAG VARCHAR2(255), LIQUIBASE VARCHAR2(20), CONTEXTS VARCHAR2(255), LABELS VARCHAR2(255), DEPLOYMENT_ID VARCHAR2(10))]

The problem has been resolved after adding following entry under dataSourceProperties in node.conf
connectionInitSql="alter session set current_schema=my_admin_user"

Related

PostgreSQL mode in flow test

is it possible to use postgresql mode in flow test?
i have try to overwrite datasource.
val nodeConfig = MockNodeConfigOverrides(
extraDataSourceProperties =
mapOf("dataSource.url"
to "jdbc:h2:mem:partya_persistence;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE")
)
nodeA = mockNet.createNode(legalName = CordaX500Name("PartyA", "London", "GB"),configOverrides = nodeConfig)
but error with startup
Unknown data type: "blob"; SQL statement:
CREATE TABLE public.node_info_party_cert (party_name NVARCHAR(255) NOT NULL, ismain BOOLEAN NOT NULL, owning_key_hash NVARCHAR(130), party_cert_binary BLOB) [50004-199] [Failed SQL: CREATE TABLE public.node_info_party_cert (party_name NVARCHAR(255) NOT NULL, ismain BOOLEAN NOT NULL, owning_key_hash NVARCHAR(130), party_cert_binary BLOB)] {changeSet=migration/node-info.changelog-init.xml::1511451595465-11::R3.Corda, databaseChangeLog=master.changelog.json}
PostgreSQL mode is not supported in the mock node, but you can use Postgres when using driver test. You can check out documentation about is here.

Corda Finance database table migration failure upgrading from Corda 3 to Corda 4

When upgrading my database from Corda 3 to Corda 4 I ran into the following error with a table from the Corda Finance :
net.corda.nodeapi.internal.persistence.CouldNotCreateDataSourceException: Could not create the DataSource: Migration failed for change set migration/cash-schema-v1.changelog-master.sql::initial_schema_for_CashSchemaV1::R3.Corda.Generated:
Reason: liquibase.exception.DatabaseException: ERROR: relation "contract_cash_states" already exists [Failed SQL: create table contract_cash_states (
output_index int4 not null,
transaction_id varchar(64) not null,
ccy_code varchar(3),
issuer_key_hash varchar(130),
issuer_ref bytea,
owner_name varchar(255),
pennies int8,
primary key (output_index, transaction_id)
)]
The table already exists and Corda is trying to create it again.
Corda Finance 3.3 did not include the migration scripts necessary for a liquibase upgrade. Running this migration script to add the migration to the liquibase tables tells Corda that the table has already been created.
INSERT INTO <database>.databasechangelog
(ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID)
VALUES ('initial_schema_for_CashSchemaV1', 'R3.Corda.Generated', 'migration/cash-schema-v1.changelog-master.sql', NOW(), 103, '7:0d961b1ab64deec263ba638e609357d0', 'sql', '', 'EXECUTED', NULL, NULL, '3.5.4', '2774745582');
INSERT INTO <database>.databasechangelog
(ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID)
VALUES ('initial_schema_for_CommercialPaperSchemaV1', 'R3.Corda.Generated', 'migration/commercial-paper-schema-v1.changelog-master.sql', NOW(), 98, '7:ee782f59d8cd3b74c7b26f5cfcba3fdd', 'sql', '', 'EXECUTED', NULL, NULL, '3.5.4', '2774745582’);

Problem in Running the example CorDapp Could not create the DataSource: Unknown data type: "İNT"

When I was trying to install and run the example CorDapp(https://docs.corda.net/tutorial-cordapp.html), there is an error
Could not create the DataSource: Unknown data type: "İNT"; SQL statement:
CREATE TABLE PUBLIC.DATABASECHANGELOG (ID VARCHAR(255) NOT NULL, AUTHOR VARCHAR(255) NOT NULL, FILENAME VARCHAR(255) NOT NULL, DATEEXECUTED TIMESTAMP NOT NULL, ORDEREXECUTED İNT NOT NULL, EXECTYPE VARCHAR(10) NOT NULL, MD5SUM VARCHAR(35), DESCRIPTION VARCHAR(255), COMMENTS VARCHAR(255), TAG VARCHAR(255), LIQUIBASE VARCHAR(20), CONTEXTS VARCHAR(255), LABELS VARCHAR(255), DEPLOYMENT_ID VARCHAR(10)) [50004-197] [Failed SQL: CREATE TABLE PUBLIC.DATABASECHANGELOG (ID VARCHAR(255) NOT NULL, AUTHOR VARCHAR(255) NOT NULL, FILENAME VARCHAR(255) NOT NULL, DATEEXECUTED TIMESTAMP NOT NULL, ORDEREXECUTED İNT NOT NULL, EXECTYPE VARCHAR(10) NOT NULL, MD5SUM VARCHAR(35), DESCRIPTION VARCHAR(255), COMMENTS VARCHAR(255), TAG VARCHAR(255), LIQUIBASE VARCHAR(20), CONTEXTS VARCHAR(255), LABELS VARCHAR(255), DEPLOYMENT_ID VARCHAR(10))]: Could not create the DataSource: Unknown data type: "İNT"; SQL statement:
CREATE TABLE PUBLIC.DATABASECHANGELOG (ID VARCHAR(255) NOT NULL, AUTHOR VARCHAR(255) NOT NULL, FILENAME VARCHAR(255) NOT NULL, DATEEXECUTED TIMESTAMP NOT NULL, ORDEREXECUTED İNT NOT NULL, EXECTYPE VARCHAR(10) NOT NULL, MD5SUM VARCHAR(35), DESCRIPTION VARCHAR(255), COMMENTS VARCHAR(255), TAG VARCHAR(255), LIQUIBASE VARCHAR(20), CONTEXTS VARCHAR(255), LABELS VARCHAR(255), DEPLOYMENT_ID VARCHAR(10)) [50004-197] [Failed SQL: CREATE TABLE PUBLIC.DATABASECHANGELOG (ID VARCHAR(255) NOT NULL, AUTHOR VARCHAR(255) NOT NULL, FILENAME VARCHAR(255) NOT NULL, DATEEXECUTED TIMESTAMP NOT NULL, ORDEREXECUTED İNT NOT NULL, EXECTYPE VARCHAR(10) NOT NULL, MD5SUM VARCHAR(35), DESCRIPTION VARCHAR(255), COMMENTS VARCHAR(255), TAG VARCHAR(255), LIQUIBASE VARCHAR(20), CONTEXTS VARCHAR(255), LABELS VARCHAR(255), DEPLOYMENT_ID VARCHAR(10))
I think the problem is when creating table DATABASECHANGELOG SQL type INT is interpreted as İNT and the create table script could not be run.
The script is in liquibase XXXX.jar file.
When I open the file including the script there is no problem with the script.
But when I run with ./gradlew deployNodes command I receive the above error.
I tried it on windows 10 and ubuntu 16.X but I encounter with the same error.
I need any help in running sample Corda application.
I am not sure how do you run into a database issue when you simply try to start the app. The H2 database is automatically populate when the nodes are built.
You can find a complete tutorial at: https://training.corda.net/prepare-and-discover/discover-example/#open-the-project

Airflow - SQL Server connection

I have a question for changing the backend connection from SQLite to SQL Server. After passing in the correct connection string for sql_alchemy_conn, I run this command: airflow initdb. I get the following error:
sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]A table can only have one timestamp column. Because table 'task_reschedule' already has one, the column 'start_date' cannot be added. (2738) (SQLExecDirectW)") [SQL: '\nCREATE TABLE task_reschedule (\n\tid INTEGER NOT NULL IDENTITY(1,1), \n\ttask_id VARCHAR(250) NOT NULL, \n\tdag_id VARCHAR(250) NOT NULL, \n\texecution_date TIMESTAMP NOT NULL, \n\ttry_number INTEGER NOT NULL, \n\tstart_date TIMESTAMP NOT NULL, \n\tend_date TIMESTAMP NOT NULL, \n\tduration INTEGER NOT NULL, \n\treschedule_date TIMESTAMP NOT NULL, \n\tPRIMARY KEY (id), \n\tCONSTRAINT task_reschedule_dag_task_date_fkey FOREIGN KEY(task_id, dag_id, execution_date) REFERENCES task_instance (task_id, dag_id, execution_date)\n)\n\n'] (Background on this error at: http://sqlalche.me/e/f405)
So this works for me:
In the file: 0a2a5b66e19d_add_task_reschedule_table.py add this:
def mysql_datetime():
return mysql.DATETIME(timezone=True)
and replace any lines which has timestamp() such as the below:
sa.Column('execution_date', timestamp(), nullable=False, server_default=None),
with this:
sa.Column('execution_date', mysql_datetime(), nullable=False, server_default=None),
Once I made this change, the above error disappears but I am not sure if there are any other unintended consequences. If so I will update here or just resort to using MySQL database.

flyway unable to init or migrate after a clean

I've just performed a clean operation, i've added a new schema one the prop file then ran clean again to remove that schema from db then when i tried to do a migrate it doesnt allow me i get the following:
Creating Metadata table: [xx].[schema_version]
Error executing statement at line 17: CREATE TABLE [xx].[schema_version] (
[version_rank] INT NOT NULL,
[installed_rank] INT NOT NULL,
[version] NVARCHAR(50) NOT NULL,
[description] NVARCHAR(200),
[type] NVARCHAR(20) NOT NULL,
[script] NVARCHAR(1000) NOT NULL,
[checksum] INT,
[installed_by] NVARCHAR(30) NOT NULL,
[installed_on] DATETIME NOT NULL DEFAULT GETDATE(),
[execution_time] INT NOT NULL,
[success] BIT NOT NULL
);
CREATE INDEX [schema_version_vr_idx] ON [xx].[schema_version] ([version_rank]);
CREATE INDEX [schema_version_ir_idx] ON [xx].[schema_version] ([installed_rank]);
CREATE INDEX [schema_version_s_idx] ON [xx].[schema_version] ([success]);
Also when i tried to initialize it sing init i get the following:
Creating Metadata table: [xx].[schema_version]
Error executing statement at line 17: CREATE TABLE [xx].[schema_version] (
[version_rank] INT NOT NULL,
[installed_rank] INT NOT NULL,
[version] NVARCHAR(50) NOT NULL,
[description] NVARCHAR(200),
[type] NVARCHAR(20) NOT NULL,
[script] NVARCHAR(1000) NOT NULL,
[checksum] INT,
[installed_by] NVARCHAR(30) NOT NULL,
[installed_on] DATETIME NOT NULL DEFAULT GETDATE(),
[execution_time] INT NOT NULL,
[success] BIT NOT NULL
);
CREATE INDEX [schema_version_vr_idx] ON [xx].[schema_version] ([version_rank]);
CREATE INDEX [schema_version_ir_idx] ON [xx].[schema_version] ([installed_rank]);
CREATE INDEX [schema_version_s_idx] ON [xx].[schema_version] ([success]);
ERROR: Occured in com.googlecode.flyway.core.dbsupport.SqlScript.execute() at line 91
ERROR: Caused by com.microsoft.sqlserver.jdbc.SQLServerException: The specified schema name "xx" either does not exist or you do not have permission to use it.
ERROR: Occured in com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError() at line 197
Please not that I've dropped all the objects and I can confirm they do not exist on my DB instance.
How can I overcome this? I am concerned when using the tool in dev and prod environment we can't just delete the db instance and start again. at this point I cant use the tool to do the migration and i dont want to delete the db to overcome this issue.
Flyway's schema creation is currently an all or nothing deal. Either all schemas are missing and then all will be created or at least one schema is present and then none will be created.
For you this means that you must either create xx yourself or drop the other schemas first.

Resources