(core) make sure forks with no changes are persisted

Summary:
This fixes a problem where a fork could be created, have no changes
made, and then (e.g. if worker rolled over) fail to open with a
`cannot create fork` error. Adds a test that fails priot to this diff.

Test Plan: added test

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3162
This commit is contained in:
Paul Fitzpatrick 2021-12-01 12:01:02 -05:00
parent 1425461cd8
commit a94905dd0a
2 changed files with 7 additions and 1 deletions

View File

@ -240,9 +240,12 @@ export class ChecksummedExternalStorage implements ExternalStorage {
// exist in this case, and this should fail if it does.
await fse.move(tmpPath, fname, {overwrite: false});
if (fromKey === toKey) {
// Save last S3 snapshot id observed for this key.
await this._options.latestVersion.save(toKey, downloadedSnapshotId);
// Save last S3 hash observed for this key (so if we have a version with that hash
// locally we can skip pushing it back needlessly later).
await this._options.localHash.save(toKey, checksum);
}
await this._options.localHash.save(toKey, checksum);
log.info("ext %s download: %s%s%s with checksum %s and version %s", this.label, fromKey,
snapshotId ? ` [VersionId ${snapshotId}]` : '',

View File

@ -252,6 +252,9 @@ export class HostedStorageManager implements IDocStorageManager {
*/
public async prepareFork(srcDocName: string, destDocName: string): Promise<string> {
await this.prepareLocalDoc(destDocName, srcDocName);
this.markAsChanged(destDocName); // Make sure fork is actually stored in S3, even
// if no changes are made, since we'd refuse to
// create it later.
return this.getPath(destDocName);
}