Page MenuHomePhabricator

D4157.diff
No OneTemporary

D4157.diff

diff --git a/keyserver/src/creators/day-creator.js b/keyserver/src/creators/day-creator.js
--- a/keyserver/src/creators/day-creator.js
+++ b/keyserver/src/creators/day-creator.js
@@ -5,6 +5,8 @@
import { dbQuery, SQL } from '../database/database';
import createIDs from './id-creator';
+const MYSQL_DUPLICATE_ENTRY_FOR_KEY_ERROR_CODE = 1062;
+
async function fetchOrCreateDayID(
threadID: string,
date: string,
@@ -30,7 +32,7 @@
await dbQuery(insertQuery);
return id;
} catch (e) {
- if (e.errno !== 1062) {
+ if (e.errno !== MYSQL_DUPLICATE_ENTRY_FOR_KEY_ERROR_CODE) {
throw new ServerError('unknown_error');
}
// There's a race condition that can happen if two people start editing
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
@@ -84,6 +84,8 @@
FakeSQLResult.prototype = Array.prototype;
const fakeResult: QueryResults = (new FakeSQLResult(): any);
+const MYSQL_DEADLOCK_ERROR_CODE = 1213;
+
type QueryOptions = {
+triesLeft?: number,
+multipleStatements?: boolean,
@@ -122,7 +124,7 @@
}
return await connection.query(statement);
} catch (e) {
- if (e.errno === 1213 && triesLeft > 0) {
+ if (e.errno === MYSQL_DEADLOCK_ERROR_CODE && triesLeft > 0) {
console.log('deadlock occurred, trying again', e);
return await dbQuery(statement, { ...options, triesLeft: triesLeft - 1 });
}
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
@@ -42,11 +42,13 @@
return true;
}
+const MYSQL_TABLE_DOESNT_EXIST_ERROR_CODE = 1146;
+
async function setUpDBAndReturnVersion(): Promise<number> {
try {
return await fetchDBVersion();
} catch (e) {
- if (e.errno !== 1146) {
+ if (e.errno !== MYSQL_TABLE_DOESNT_EXIST_ERROR_CODE) {
throw e;
}
await setupDB();

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 8:01 PM (20 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2678726
Default Alt Text
D4157.diff (1 KB)

Event Timeline