Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3369521
D4514.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D4514.diff
View Options
diff --git a/keyserver/src/database/database.js b/keyserver/src/database/database.js
--- a/keyserver/src/database/database.js
+++ b/keyserver/src/database/database.js
@@ -13,6 +13,16 @@
const SQLStatement: SQLStatementType = SQL.SQLStatement;
+let migrationConnection;
+async function getMigrationConnection() {
+ if (migrationConnection) {
+ return migrationConnection;
+ }
+ const dbConfig = await getDBConfig();
+ migrationConnection = await mysqlPromise.createConnection(dbConfig);
+ return migrationConnection;
+}
+
let pool, databaseMonitor;
async function loadPool(): Promise<Pool> {
if (pool) {
@@ -86,6 +96,24 @@
const MYSQL_DEADLOCK_ERROR_CODE = 1213;
+type ConnectionContext = {
+ +migrationsActive?: boolean,
+};
+let connectionContext = {
+ migrationsActive: false,
+};
+
+function setConnectionContext(newContext: ConnectionContext) {
+ connectionContext = {
+ ...connectionContext,
+ ...newContext,
+ };
+ if (!connectionContext.migrationsActive && migrationConnection) {
+ migrationConnection.end();
+ migrationConnection = undefined;
+ }
+}
+
type QueryOptions = {
+triesLeft?: number,
+multipleStatements?: boolean,
@@ -98,6 +126,9 @@
const multipleStatements = options?.multipleStatements ?? false;
let connection;
+ if (connectionContext.migrationsActive) {
+ connection = await getMigrationConnection();
+ }
if (multipleStatements) {
connection = await getMultipleStatementsConnection();
}
@@ -157,6 +188,7 @@
appendSQLArray,
mergeAndConditions,
mergeOrConditions,
+ setConnectionContext,
dbQuery,
rawSQL,
};
diff --git a/keyserver/src/database/migrations.js b/keyserver/src/database/migrations.js
--- a/keyserver/src/database/migrations.js
+++ b/keyserver/src/database/migrations.js
@@ -6,7 +6,7 @@
import { getMessageForException } from 'lib/utils/errors';
import sleep from 'lib/utils/sleep';
-import { dbQuery, SQL } from './database';
+import { dbQuery, SQL, setConnectionContext } from './database';
import { fetchDBVersion, updateDBVersion } from './db-version';
import { migrations } from './migration-config';
import { setupDB } from './setup-db';
@@ -26,6 +26,7 @@
return false;
}
+ setConnectionContext({ migrationsActive: true });
for (const [idx, migration] of migrations.entries()) {
if (idx <= dbVersion) {
continue;
@@ -45,6 +46,7 @@
return false;
}
}
+ setConnectionContext({ migrationsActive: false });
return true;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 10:47 PM (22 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2586683
Default Alt Text
D4514.diff (2 KB)
Attached To
Mode
D4514: [server] Use single connection with DB for migrations
Attached
Detach File
Event Timeline
Log In to Comment