OS: macOS Catalina 10.15.2 and Windows 10
Docker Image: mcr.microsoft.com/mssql/server:2019-CU2-ubuntu-16.04(2019 GA has same issue)
Драйвер JDBC: com.microsoft.sqlserver: mssql-jdbc: 8.2.1.jre8 < /code> < /p>
Контекст:
Запуск базы данных в контейнере для доке https://github.com/testcontainers/testcontainers-java/ api
Поведение:
запуск базы данных идет нормально, и я получаю:
Код: Выделить всё
[01/24/2020 14:53:23:405 CST] 051 SQLServerContainer output I
2020-01-24 20:53:23.41 spid12s Clearing tempdb database.
< /code>
Я затем выполняю файл init-sqlserver.sql, чтобы включить соединение JDBC XA: < /p>
-- Create database
CREATE DATABASE TEST;
-- Enable XA connections
EXEC sp_sqljdbc_xa_install;
< /code>
и я получаю < /p>
...
[01/24/2020 14:53:23:969 CST] 051 SQLServerContainer output I
2020-01-24 20:53:23.97 spid52 Starting up database 'TEST'.
...
[01/24/2020 14:53:24:377 CST] 001 ScriptUtils executeDatabaseScript I Executed database script from resources/init-sqlserver.sql in 855 ms.
[01/24/2020 14:53:25:029 CST] 051 SQLServerContainer output I
2020-01-24 20:53:25.04 spid25s The tempdb database has 6 data file(s).
< /code>
Когда я на самом деле пытаюсь использовать соединение XA, я получаю: < /p>
[01/24/2020 14:53:47:496 CST] 051 SQLServerContainer output I
2020-01-24 20:53:47.49 spid53 Initializing Microsoft Distributed Transaction Coordinator (MS DTC) resource manager [820e1ea9-c921-4350-897e-a7534d9d1ed7] for server instance 8b0aca425794. This is an informational message only. No user action is required.
[01/24/2020 14:53:47:504 CST] 051 SQLServerContainer output I
2020-01-24 20:53:47.50 spid53 Recovery of any in-doubt distributed transactions involving Microsoft Distributed Transaction Coordinator (MS DTC) has completed. This is an informational message only. No user action is required.
[01/24/2020 14:59:44:692 CST] 051 SQLServerContainer output I
2020-01-24 20:59:44.71 spid62 Attempting to load library 'xplog70.dll' into memory. This is an informational message only. No user action is required.
[01/24/2020 14:59:44:742 CST] 051 SQLServerContainer output I
2020-01-24 20:59:44.76 spid62 Using 'xplog70.dll' version '2019.150.4003' to execute extended stored procedure 'xp_msver'. This is an informational message only; no user action is required.
< /code>
И я держусь на последней части на неопределенный срок. Вы также можете увидеть, что между двумя шагами есть около 6 минут. < /p>
Что я пытаюсь достичь в своем исходном коде: < /p>
/**
* Enlist a two-phase capable resource in a global transaction.
*/
public void getXAConnection() throws Exception {
setUpTables(ds1);
tran.begin();
try (Connection con1 = ds1.getConnection()) {
PreparedStatement pstmt = con1.prepareStatement("insert into cities values (?, ?, ?)");
pstmt.setString(1, "Wanamingo");
pstmt.setInt(2, 1086);
pstmt.setString(3, "Goodhue");
pstmt.executeUpdate();
pstmt.close();
tran.commit();
} catch (Throwable x) {
try {
tran.rollback();
} catch (Throwable t) {
}
throw x;
}
}
< /code>
Вопросы: < /p>
[list]
[*] Разве инициализация MSDTC происходит во время выполнения
EXEC sp_sqljdbc_xa_install;
Почему между сохраненными процедурами существует такая длинная задержка? < /li>
Это проблема с изображением Docker или драйвером JDBC? (Это работало на Дерби, DB2, Postgres и Oracle)
[/list]
Подробнее здесь: https://stackoverflow.com/questions/601 ... d-stored-p