Use atomic rename

pull/5817/head
Chocobozzz 2023-05-16 10:06:07 +02:00
parent 0d6a8289fb
commit 49b80bd9e1
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 4 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import { move, writeJson } from 'fs-extra' import { rename, writeJson } from 'fs-extra'
import PQueue from 'p-queue' import PQueue from 'p-queue'
import { basename } from 'path' import { basename } from 'path'
import { mapToJSON } from '@server/helpers/core-utils' import { mapToJSON } from '@server/helpers/core-utils'
@ -72,9 +72,9 @@ class LiveSegmentShaStore {
private writeToDisk () { private writeToDisk () {
return this.writeQueue.add(async () => { return this.writeQueue.add(async () => {
// Atomic write // Atomic write: use rename instead of move that is not atomic
await writeJson(this.sha256PathTMP, mapToJSON(this.segmentsSha256)) await writeJson(this.sha256PathTMP, mapToJSON(this.segmentsSha256))
await move(this.sha256PathTMP, this.sha256Path, { overwrite: true }) await rename(this.sha256PathTMP, this.sha256Path)
if (this.sendToObjectStorage) { if (this.sendToObjectStorage) {
const url = await storeHLSFileFromPath(this.streamingPlaylist, this.sha256Path) const url = await storeHLSFileFromPath(this.streamingPlaylist, this.sha256Path)

View File

@ -278,7 +278,7 @@ async function uploadToStorage (options: {
logger.debug( logger.debug(
'Completed %s%s in bucket %s', 'Completed %s%s in bucket %s',
bucketInfo.PREFIX, objectStorageKey, bucketInfo.BUCKET_NAME, lTags() bucketInfo.PREFIX, objectStorageKey, bucketInfo.BUCKET_NAME, { ...lTags(), reseponseMetadata: response.$metadata }
) )
return getInternalUrl(bucketInfo, objectStorageKey) return getInternalUrl(bucketInfo, objectStorageKey)