mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
sqlite: retry busy or locked backup steps
Signed-off-by: lazerg <lazerg2@gmail.com> PR-URL: https://github.com/nodejs/node/pull/66769 Fixes: https://github.com/nodejs/node/issues/66760 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
1 parent
6360b8ab53
commit
fd7dc863d0
2 files changed
+32
No files matched your search
@@ -680,6 +680,11 @@ class BackupJob : public ThreadPoolWork {
|
||||
return;
|
||||
}
|
||||
|
||||
if (backup_status_ == SQLITE_BUSY || backup_status_ == SQLITE_LOCKED) {
|
||||
this->ScheduleWork();
|
||||
return;
|
||||
}
|
||||
|
||||
int total_pages = sqlite3_backup_pagecount(backup_.get());
|
||||
int remaining_pages = sqlite3_backup_remaining(backup_.get());
|
||||
if (remaining_pages != 0) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Flags: --expose-gc
|
||||
import {
|
||||
isWindows,
|
||||
platformTimeout,
|
||||
skipIfSQLiteMissing,
|
||||
spawnPromisified,
|
||||
} from '../common/index.mjs';
|
||||
@@ -351,6 +352,32 @@ test('backup fails when path cannot be opened', async (t) => {
|
||||
});
|
||||
});
|
||||
|
||||
test('backup waits for a write transaction on the source to end', async (t) => {
|
||||
const database = makeSourceDb();
|
||||
const destDb = nextDb();
|
||||
|
||||
t.after(() => { database.close(); });
|
||||
|
||||
database.exec('BEGIN IMMEDIATE');
|
||||
database.exec("INSERT INTO data (key, value) VALUES (3, 'value-3')");
|
||||
const p = backup(database, destDb);
|
||||
setTimeout(() => database.exec('COMMIT'), platformTimeout(100));
|
||||
|
||||
await p;
|
||||
|
||||
const backupDb = new Database(destDb);
|
||||
|
||||
t.after(() => { backupDb.close(); });
|
||||
|
||||
const rows = backupDb.prepare('SELECT * FROM data').all();
|
||||
|
||||
t.assert.deepStrictEqual(rows, [
|
||||
{ __proto__: null, key: 1, value: 'value-1' },
|
||||
{ __proto__: null, key: 2, value: 'value-2' },
|
||||
{ __proto__: null, key: 3, value: 'value-3' },
|
||||
]);
|
||||
});
|
||||
|
||||
test('backup has correct name and length', (t) => {
|
||||
t.assert.strictEqual(backup.name, 'backup');
|
||||
t.assert.strictEqual(backup.length, 2);
|
||||
|
||||
Reference in new issue
Block a user