@milaboratories/pl-drivers 1.11.31 → 1.11.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/drivers/upload_task.cjs +18 -11
- package/dist/drivers/upload_task.cjs.map +1 -1
- package/dist/drivers/upload_task.d.ts +1 -1
- package/dist/drivers/upload_task.d.ts.map +1 -1
- package/dist/drivers/upload_task.js +18 -11
- package/dist/drivers/upload_task.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +6 -6
- package/src/drivers/upload_task.ts +16 -12
|
@@ -63,10 +63,9 @@ class UploadTask {
|
|
|
63
63
|
this.change.markChanged(`blob upload for ${plClient.resourceIdToString(this.res.id)} finished`);
|
|
64
64
|
}
|
|
65
65
|
catch (e) {
|
|
66
|
-
if (
|
|
67
|
-
this.
|
|
68
|
-
this.
|
|
69
|
-
this.change.markChanged(`blob upload for ${plClient.resourceIdToString(this.res.id)} aborted, resource was deleted`);
|
|
66
|
+
if (isTerminalUploadError(e)) {
|
|
67
|
+
this.logger.warn(`terminal error while uploading a blob: ${e}`);
|
|
68
|
+
this.change.markChanged(`blob upload for ${plClient.resourceIdToString(this.res.id)} aborted: ${e.code}`);
|
|
70
69
|
this.setDone(true);
|
|
71
70
|
return;
|
|
72
71
|
}
|
|
@@ -102,9 +101,9 @@ class UploadTask {
|
|
|
102
101
|
this.logger.warn(`deadline exceeded while getting a status of BlobImport: ${e.message}`);
|
|
103
102
|
return;
|
|
104
103
|
}
|
|
105
|
-
if (
|
|
106
|
-
this.logger.warn(`
|
|
107
|
-
this.change.markChanged(`upload status for ${plClient.resourceIdToString(this.res.id)}
|
|
104
|
+
if (isTerminalUploadError(e)) {
|
|
105
|
+
this.logger.warn(`terminal error while updating BlobImport status: ${e}, ${plClient.stringifyWithResourceId(this.res)}`);
|
|
106
|
+
this.change.markChanged(`upload status for ${plClient.resourceIdToString(this.res.id)} aborted: ${e.code}`);
|
|
108
107
|
this.setDone(true);
|
|
109
108
|
return;
|
|
110
109
|
}
|
|
@@ -258,9 +257,17 @@ function doneProgressIfExisted(alreadyExisted, status) {
|
|
|
258
257
|
}
|
|
259
258
|
return status;
|
|
260
259
|
}
|
|
261
|
-
function
|
|
262
|
-
|
|
263
|
-
|
|
260
|
+
function isTerminalUploadError(e) {
|
|
261
|
+
if (e?.name !== 'RpcError')
|
|
262
|
+
return false;
|
|
263
|
+
switch (e.code) {
|
|
264
|
+
case 'NOT_FOUND':
|
|
265
|
+
case 'ABORTED':
|
|
266
|
+
case 'ALREADY_EXISTS':
|
|
267
|
+
return true;
|
|
268
|
+
default:
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
264
271
|
}
|
|
265
272
|
function nonRecoverableError(e) {
|
|
266
273
|
return e instanceof upload.MTimeError ||
|
|
@@ -289,8 +296,8 @@ function decreaseConcurrency(logger, current, min) {
|
|
|
289
296
|
|
|
290
297
|
exports.UploadTask = UploadTask;
|
|
291
298
|
exports.isMyUpload = isMyUpload;
|
|
292
|
-
exports.isResourceWasDeletedError = isResourceWasDeletedError;
|
|
293
299
|
exports.isSignMatch = isSignMatch;
|
|
300
|
+
exports.isTerminalUploadError = isTerminalUploadError;
|
|
294
301
|
exports.isUpload = isUpload;
|
|
295
302
|
exports.nonRecoverableError = nonRecoverableError;
|
|
296
303
|
exports.uploadBlob = uploadBlob;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload_task.cjs","sources":["../../src/drivers/upload_task.ts"],"sourcesContent":["import type { Watcher } from '@milaboratories/computable';\nimport { ChangeSource } from '@milaboratories/computable';\nimport { isTimeoutError, resourceIdToString, stringifyWithResourceId } from '@milaboratories/pl-client';\nimport type * as sdk from '@milaboratories/pl-model-common';\nimport type { AsyncPoolController, MiLogger, Signer } from '@milaboratories/ts-helpers';\nimport { asyncPool, CallersCounter } from '@milaboratories/ts-helpers';\nimport type { ClientProgress, ProgressStatus } from '../clients/progress';\nimport type { ClientUpload } from '../clients/upload';\nimport { BadRequestError, MTimeError, NoFileForUploading, UnexpectedEOF } from '../clients/upload';\nimport type { ImportResourceSnapshot } from './types';\nimport { ImportFileHandleUploadData } from './types';\nimport assert from 'node:assert';\nimport { ResourceInfo } from '@milaboratories/pl-tree';\n\n/** Holds all info needed to upload a file and a status of uploading\n * and indexing. Also, has a method to update a status of the progress.\n * And holds a change source. */\nexport class UploadTask {\n private readonly change: ChangeSource = new ChangeSource();\n private readonly counter: CallersCounter = new CallersCounter();\n private nMaxUploads: number;\n private nPartsWithThisUploadSpeed = 0;\n private nPartsToIncreaseUpload = 10; // how many parts we have to wait to increase concurrency, 50 mb, 10 parts by 5 mb each.\n\n /** If this is upload progress this field will be defined */\n private uploadData?: ImportFileHandleUploadData;\n public progress: sdk.ImportProgress;\n\n /** If failed, then getting a progress is terminally failed. */\n public failed?: boolean;\n\n /** True if the blob was existed.\n * At this case, the task will show progress == 1.0. */\n private alreadyExisted = false;\n\n constructor(\n private readonly logger: MiLogger,\n private readonly clientBlob: ClientUpload,\n private readonly clientProgress: ClientProgress,\n private readonly maxNConcurrentPartsUpload: number,\n signer: Signer,\n public readonly res: ImportResourceSnapshot,\n ) {\n this.nMaxUploads = this.maxNConcurrentPartsUpload;\n const { uploadData, progress } = newProgress(res, signer);\n this.uploadData = uploadData;\n this.progress = progress;\n }\n\n public getProgress(w: Watcher, callerId: string) {\n this.incCounter(w, callerId);\n\n if (this.failed) {\n this.logger.error(`Uploading terminally failed: ${this.progress.lastError}`);\n throw new Error(this.progress.lastError);\n }\n\n return cloneProgress(this.progress);\n }\n\n public shouldScheduleUpload(): boolean {\n return isMyUpload(this.progress);\n }\n\n /** Uploads a blob if it's not BlobIndex. */\n public async uploadBlobTask() {\n try {\n await uploadBlob(\n this.logger,\n this.clientBlob,\n this.res,\n this.uploadData!,\n this.isComputableDone.bind(this),\n {\n nPartsWithThisUploadSpeed: this.nPartsWithThisUploadSpeed,\n nPartsToIncreaseUpload: this.nPartsToIncreaseUpload,\n currentSpeed: this.nMaxUploads,\n maxSpeed: this.maxNConcurrentPartsUpload,\n },\n );\n this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} finished`);\n } catch (e: any) {\n\n if (isResourceWasDeletedError(e)) {\n this.setRetriableError(e);\n this.logger.warn(`resource was deleted while uploading a blob: ${e}`);\n this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} aborted, resource was deleted`);\n this.setDone(true);\n\n return;\n }\n\n this.logger.error(`error while uploading a blob: ${e}`);\n this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} failed`);\n\n if (nonRecoverableError(e)) {\n this.setTerminalError(e);\n return;\n }\n\n this.setRetriableError(e);\n\n if (isHeadersTimeoutError(e)) {\n // we probably have a slow internet, we need to slow things a bit.\n this.nMaxUploads = decreaseConcurrency(this.logger, this.nMaxUploads, 1);\n }\n\n throw e;\n }\n }\n\n public async updateStatus() {\n try {\n // we do it with timeout in case we have slow internet.\n const status = await this.clientProgress.getStatus(this.res, { timeout: 10000 });\n\n const oldStatus = this.progress.status;\n const newStatus = doneProgressIfExisted(this.alreadyExisted, protoToStatus(status));\n this.progress.status = newStatus;\n this.setDone(status.done);\n\n if (status.done || this.progress.status.progress != oldStatus?.progress) {\n this.change.markChanged(`upload status for ${resourceIdToString(this.res.id)} changed`);\n }\n } catch (e: any) {\n this.setRetriableError(e);\n\n if (isTimeoutError(e)) {\n this.logger.warn(`deadline exceeded while getting a status of BlobImport: ${e.message}`);\n return;\n }\n\n if (isResourceWasDeletedError(e)) {\n this.logger.warn(\n `resource was not found while updating a status of BlobImport: ${e}, ${stringifyWithResourceId(this.res)}`,\n );\n this.change.markChanged(`upload status for ${resourceIdToString(this.res.id)} changed, resource not found`);\n this.setDone(true);\n return;\n }\n\n this.logger.error(`retryable error while updating a status of BlobImport: ${e}`);\n // It was a terminal error, but when a connection drops,\n // this will stop the whole task, so we make it retryable.\n // It was like that:\n // this.change.markChanged();\n // this.setTerminalError(e);\n }\n }\n\n /** Set non-terminal error, that task can be retried. */\n private setRetriableError(e: unknown) {\n this.progress.lastError = String(e);\n }\n\n /** Set a terminal error, the task will throw a error instead of a progress. */\n private setTerminalError(e: unknown) {\n this.progress.lastError = String(e);\n this.progress.done = false;\n this.failed = true;\n }\n\n public setDoneIfOutputSet(res: ImportResourceSnapshot) {\n if (isImportResourceOutputSet(res)) {\n this.setDone(true);\n this.alreadyExisted = true;\n }\n }\n\n private setDone(done: boolean) {\n this.progress.done = done;\n if (done) this.progress.lastError = undefined;\n }\n\n public incCounter(w: Watcher, callerId: string) {\n this.change.attachWatcher(w);\n this.counter.inc(callerId);\n }\n\n public decCounter(callerId: string) {\n return this.counter.dec(callerId);\n }\n\n private isComputableDone() {\n return this.counter.isZero();\n }\n}\n\n/** Uploads a blob if it's not BlobIndex. */\nexport async function uploadBlob(\n logger: MiLogger,\n clientBlob: ClientUpload,\n res: ResourceInfo,\n uploadData: ImportFileHandleUploadData,\n isDoneFn: () => boolean,\n speed: {\n nPartsWithThisUploadSpeed: number,\n nPartsToIncreaseUpload: number,\n currentSpeed: number,\n maxSpeed: number,\n },\n) {\n assert(isUpload(res), 'the upload operation can be done only for BlobUploads');\n const timeout = 10000; // 10 sec instead of standard 5 sec, things might be slow with a slow connection.\n\n if (isDoneFn()) return;\n const parts = await clientBlob.initUpload(res, { timeout });\n logger.info(\n `started to upload blob ${res.id},`\n + ` parts overall: ${parts.overall}, parts remained: ${parts.toUpload.length},`\n + ` number of concurrent uploads: ${speed.currentSpeed}`,\n );\n\n const partUploadFn = (part: bigint) => async (controller: AsyncPoolController) => {\n if (isDoneFn()) return;\n await clientBlob.partUpload(\n res,\n uploadData.localPath,\n BigInt(uploadData.modificationTime),\n part,\n parts.checksumAlgorithm,\n parts.checksumHeader,\n { timeout }\n );\n logger.info(`uploaded chunk ${part}/${parts.overall} of resource: ${res.id}`);\n\n // if we had a network freeze, it will be increased slowly.\n speed.nPartsWithThisUploadSpeed++;\n if (speed.nPartsWithThisUploadSpeed >= speed.nPartsToIncreaseUpload) {\n speed.nPartsWithThisUploadSpeed = 0;\n speed.currentSpeed = increaseConcurrency(logger, speed.currentSpeed, speed.maxSpeed);\n controller.setConcurrency(speed.currentSpeed);\n }\n };\n\n await asyncPool(speed.currentSpeed, parts.toUpload.map(partUploadFn));\n\n if (isDoneFn()) return;\n await clientBlob.finalize(res, { timeout });\n\n logger.info(`uploading of resource ${res.id} finished.`);\n}\n\nfunction newProgress(res: ImportResourceSnapshot, signer: Signer) {\n let isUploadSignMatch: boolean | undefined;\n let uploadData: ImportFileHandleUploadData | undefined;\n if (isUpload(res)) {\n uploadData = ImportFileHandleUploadData.parse(res.data);\n isUploadSignMatch = isSignMatch(signer, uploadData.localPath, uploadData.pathSignature);\n }\n\n return {\n uploadData: uploadData,\n progress: {\n done: false,\n status: undefined,\n isUpload: isUpload(res),\n isUploadSignMatch: isUploadSignMatch,\n lastError: undefined,\n } satisfies sdk.ImportProgress,\n };\n}\n\n/** Returns true if we need to upload the blob that got from this progress. */\nexport function isMyUpload(p: sdk.ImportProgress): boolean {\n return p.isUpload && (p.isUploadSignMatch ?? false);\n}\n\n/** Creates a deep copy of progress,\n * since we do not want to pass a mutable object\n * to API, it led to bugs before.\n * We do not use '...' cloning syntax\n * for the compiler to fail here if we change API. */\nfunction cloneProgress(progress: sdk.ImportProgress): sdk.ImportProgress {\n const cloned: sdk.ImportProgress = {\n done: progress.done,\n isUpload: progress.isUpload,\n isUploadSignMatch: progress.isUploadSignMatch,\n lastError: progress.lastError,\n };\n\n if (progress.status)\n cloned.status = {\n progress: progress.status.progress,\n bytesProcessed: progress.status.bytesProcessed,\n bytesTotal: progress.status.bytesTotal,\n };\n\n return progress;\n}\n\nfunction isImportResourceOutputSet(res: ImportResourceSnapshot) {\n return 'blob' in res.fields\n ? res.fields.blob !== undefined\n : res.fields.incarnation !== undefined;\n}\n\nexport function isUpload(res: ResourceInfo) {\n return res.type.name.startsWith('BlobUpload');\n}\n\nexport function isSignMatch(signer: Signer, path: string, signature: string): boolean {\n try {\n signer.verify(path, signature);\n return true;\n } catch (e) {\n return false;\n }\n}\n\nfunction protoToStatus(proto: ProgressStatus): sdk.ImportStatus {\n return {\n progress: proto.progress ?? 0,\n bytesProcessed: Number(proto.bytesProcessed),\n bytesTotal: Number(proto.bytesTotal),\n };\n}\n\n/** Special hack: if we didn't even start to upload the blob\n * to backend because the result was already there,\n * the backend does show us a status that nothing were uploaded,\n * but we need to show the client that everything is OK.\n * Thus, here we set progress to be 1.0 and all bytes are become processed. */\nfunction doneProgressIfExisted(alreadyExisted: boolean, status: sdk.ImportStatus) {\n if (alreadyExisted && status.bytesTotal != 0 && status.bytesProcessed == 0) {\n return {\n progress: 1.0,\n bytesProcessed: Number(status.bytesTotal),\n bytesTotal: Number(status.bytesTotal),\n };\n }\n\n return status;\n}\n\nexport function isResourceWasDeletedError(e: any) {\n return (\n e.name == 'RpcError'\n && (e.code == 'NOT_FOUND' || e.code == 'ABORTED' || e.code == 'ALREADY_EXISTS')\n );\n}\n\nexport function nonRecoverableError(e: any) {\n return e instanceof MTimeError ||\n e instanceof UnexpectedEOF ||\n e instanceof NoFileForUploading ||\n e instanceof BadRequestError;\n}\n\nfunction isHeadersTimeoutError(e: any) {\n return (e as Error)?.message.includes(`UND_ERR_HEADERS_TIMEOUT`);\n}\n\n/** It's called for every upload success so if everyone is succeeded, we'll double the concurrency. */\nfunction increaseConcurrency(logger: MiLogger, current: number, max: number): number {\n const newConcurrency = Math.min(current + 2, max);\n if (newConcurrency != current)\n logger.info(`uploadTask.increaseConcurrency: increased from ${current} to ${newConcurrency}`)\n\n return newConcurrency;\n}\n\n/** When a error happens, this will half the concurrency level, so the next time\n * we'll try to upload blobs slower. */\nfunction decreaseConcurrency(logger: MiLogger, current: number, min: number): number {\n const newConcurrency = Math.max(Math.round(current / 2), min);\n if (newConcurrency != current)\n logger.info(`uploadTask.decreaseConcurrency: decreased from ${current} to ${newConcurrency}`)\n\n return newConcurrency;\n}\n"],"names":["ChangeSource","CallersCounter","resourceIdToString","isTimeoutError","stringifyWithResourceId","asyncPool","ImportFileHandleUploadData","MTimeError","UnexpectedEOF","NoFileForUploading","BadRequestError"],"mappings":";;;;;;;;;AAcA;;AAEgC;MACnB,UAAU,CAAA;AAmBF,IAAA,MAAA;AACA,IAAA,UAAA;AACA,IAAA,cAAA;AACA,IAAA,yBAAA;AAED,IAAA,GAAA;AAvBD,IAAA,MAAM,GAAiB,IAAIA,uBAAY,EAAE;AACzC,IAAA,OAAO,GAAmB,IAAIC,wBAAc,EAAE;AACvD,IAAA,WAAW;IACX,yBAAyB,GAAG,CAAC;AAC7B,IAAA,sBAAsB,GAAG,EAAE,CAAC;;AAG5B,IAAA,UAAU;AACX,IAAA,QAAQ;;AAGR,IAAA,MAAM;AAEb;AACuD;IAC/C,cAAc,GAAG,KAAK;IAE9B,WAAA,CACmB,MAAgB,EAChB,UAAwB,EACxB,cAA8B,EAC9B,yBAAiC,EAClD,MAAc,EACE,GAA2B,EAAA;QAL1B,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,UAAU,GAAV,UAAU;QACV,IAAA,CAAA,cAAc,GAAd,cAAc;QACd,IAAA,CAAA,yBAAyB,GAAzB,yBAAyB;QAE1B,IAAA,CAAA,GAAG,GAAH,GAAG;AAEnB,QAAA,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,yBAAyB;AACjD,QAAA,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC;AACzD,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU;AAC5B,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ;IAC1B;IAEO,WAAW,CAAC,CAAU,EAAE,QAAgB,EAAA;AAC7C,QAAA,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,QAAQ,CAAC;AAE5B,QAAA,IAAI,IAAI,CAAC,MAAM,EAAE;AACf,YAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA,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EAAA;IACxC,OAAO,CAAC,YAAYC,iBAAU;AAC5B,QAAA,CAAC,YAAYC,oBAAa;AAC1B,QAAA,CAAC,YAAYC,yBAAkB;QAC/B,CAAC,YAAYC,sBAAe;AAChC;AAEA,SAAS,qBAAqB,CAAC,CAAM,EAAA;IACnC,OAAQ,CAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA,uBAAA,CAAyB,CAAC;AAClE;AAEA;AACA,SAAS,mBAAmB,CAAC,MAAgB,EAAE,OAAe,EAAE,GAAW,EAAA;AACzE,IAAA,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,EAAE,GAAG,CAAC;IACjD,IAAI,cAAc,IAAI,OAAO;QAC3B,MAAM,CAAC,IAAI,CAAC,CAAA,+CAAA,EAAkD,OAAO,CAAA,IAAA,EAAO,cAAc,CAAA,CAAE,CAAC;AAE/F,IAAA,OAAO,cAAc;AACvB;AAEA;AACuC;AACvC,SAAS,mBAAmB,CAAC,MAAgB,EAAE,OAAe,EAAE,GAAW,EAAA;AACzE,IAAA,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;IAC7D,IAAI,cAAc,IAAI,OAAO;QAC3B,MAAM,CAAC,IAAI,CAAC,CAAA,+CAAA,EAAkD,OAAO,CAAA,IAAA,EAAO,cAAc,CAAA,CAAE,CAAC;AAE/F,IAAA,OAAO,cAAc;AACvB;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"upload_task.cjs","sources":["../../src/drivers/upload_task.ts"],"sourcesContent":["import type { Watcher } from '@milaboratories/computable';\nimport { ChangeSource } from '@milaboratories/computable';\nimport { isTimeoutError, resourceIdToString, stringifyWithResourceId } from '@milaboratories/pl-client';\nimport type * as sdk from '@milaboratories/pl-model-common';\nimport type { AsyncPoolController, MiLogger, Signer } from '@milaboratories/ts-helpers';\nimport { asyncPool, CallersCounter } from '@milaboratories/ts-helpers';\nimport type { ClientProgress, ProgressStatus } from '../clients/progress';\nimport type { ClientUpload } from '../clients/upload';\nimport { BadRequestError, MTimeError, NoFileForUploading, UnexpectedEOF } from '../clients/upload';\nimport type { ImportResourceSnapshot } from './types';\nimport { ImportFileHandleUploadData } from './types';\nimport assert from 'node:assert';\nimport { ResourceInfo } from '@milaboratories/pl-tree';\n\n/** Holds all info needed to upload a file and a status of uploading\n * and indexing. Also, has a method to update a status of the progress.\n * And holds a change source. */\nexport class UploadTask {\n private readonly change: ChangeSource = new ChangeSource();\n private readonly counter: CallersCounter = new CallersCounter();\n private nMaxUploads: number;\n private nPartsWithThisUploadSpeed = 0;\n private nPartsToIncreaseUpload = 10; // how many parts we have to wait to increase concurrency, 50 mb, 10 parts by 5 mb each.\n\n /** If this is upload progress this field will be defined */\n private uploadData?: ImportFileHandleUploadData;\n public progress: sdk.ImportProgress;\n\n /** If failed, then getting a progress is terminally failed. */\n public failed?: boolean;\n\n /** True if the blob was existed.\n * At this case, the task will show progress == 1.0. */\n private alreadyExisted = false;\n\n constructor(\n private readonly logger: MiLogger,\n private readonly clientBlob: ClientUpload,\n private readonly clientProgress: ClientProgress,\n private readonly maxNConcurrentPartsUpload: number,\n signer: Signer,\n public readonly res: ImportResourceSnapshot,\n ) {\n this.nMaxUploads = this.maxNConcurrentPartsUpload;\n const { uploadData, progress } = newProgress(res, signer);\n this.uploadData = uploadData;\n this.progress = progress;\n }\n\n public getProgress(w: Watcher, callerId: string) {\n this.incCounter(w, callerId);\n\n if (this.failed) {\n this.logger.error(`Uploading terminally failed: ${this.progress.lastError}`);\n throw new Error(this.progress.lastError);\n }\n\n return cloneProgress(this.progress);\n }\n\n public shouldScheduleUpload(): boolean {\n return isMyUpload(this.progress);\n }\n\n /** Uploads a blob if it's not BlobIndex. */\n public async uploadBlobTask() {\n try {\n await uploadBlob(\n this.logger,\n this.clientBlob,\n this.res,\n this.uploadData!,\n this.isComputableDone.bind(this),\n {\n nPartsWithThisUploadSpeed: this.nPartsWithThisUploadSpeed,\n nPartsToIncreaseUpload: this.nPartsToIncreaseUpload,\n currentSpeed: this.nMaxUploads,\n maxSpeed: this.maxNConcurrentPartsUpload,\n },\n );\n this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} finished`);\n } catch (e: any) {\n\n if (isTerminalUploadError(e)) {\n this.logger.warn(`terminal error while uploading a blob: ${e}`);\n this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} aborted: ${e.code}`);\n this.setDone(true);\n\n return;\n }\n\n this.logger.error(`error while uploading a blob: ${e}`);\n this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} failed`);\n\n if (nonRecoverableError(e)) {\n this.setTerminalError(e);\n return;\n }\n\n this.setRetriableError(e);\n\n if (isHeadersTimeoutError(e)) {\n // we probably have a slow internet, we need to slow things a bit.\n this.nMaxUploads = decreaseConcurrency(this.logger, this.nMaxUploads, 1);\n }\n\n throw e;\n }\n }\n\n public async updateStatus() {\n try {\n // we do it with timeout in case we have slow internet.\n const status = await this.clientProgress.getStatus(this.res, { timeout: 10000 });\n\n const oldStatus = this.progress.status;\n const newStatus = doneProgressIfExisted(this.alreadyExisted, protoToStatus(status));\n this.progress.status = newStatus;\n this.setDone(status.done);\n\n if (status.done || this.progress.status.progress != oldStatus?.progress) {\n this.change.markChanged(`upload status for ${resourceIdToString(this.res.id)} changed`);\n }\n } catch (e: any) {\n this.setRetriableError(e);\n\n if (isTimeoutError(e)) {\n this.logger.warn(`deadline exceeded while getting a status of BlobImport: ${e.message}`);\n return;\n }\n\n if (isTerminalUploadError(e)) {\n this.logger.warn(\n `terminal error while updating BlobImport status: ${e}, ${stringifyWithResourceId(this.res)}`,\n );\n this.change.markChanged(`upload status for ${resourceIdToString(this.res.id)} aborted: ${e.code}`);\n this.setDone(true);\n return;\n }\n\n this.logger.error(`retryable error while updating a status of BlobImport: ${e}`);\n // It was a terminal error, but when a connection drops,\n // this will stop the whole task, so we make it retryable.\n // It was like that:\n // this.change.markChanged();\n // this.setTerminalError(e);\n }\n }\n\n /** Set non-terminal error, that task can be retried. */\n private setRetriableError(e: unknown) {\n this.progress.lastError = String(e);\n }\n\n /** Set a terminal error, the task will throw a error instead of a progress. */\n private setTerminalError(e: unknown) {\n this.progress.lastError = String(e);\n this.progress.done = false;\n this.failed = true;\n }\n\n public setDoneIfOutputSet(res: ImportResourceSnapshot) {\n if (isImportResourceOutputSet(res)) {\n this.setDone(true);\n this.alreadyExisted = true;\n }\n }\n\n private setDone(done: boolean) {\n this.progress.done = done;\n if (done) this.progress.lastError = undefined;\n }\n\n public incCounter(w: Watcher, callerId: string) {\n this.change.attachWatcher(w);\n this.counter.inc(callerId);\n }\n\n public decCounter(callerId: string) {\n return this.counter.dec(callerId);\n }\n\n private isComputableDone() {\n return this.counter.isZero();\n }\n}\n\n/** Uploads a blob if it's not BlobIndex. */\nexport async function uploadBlob(\n logger: MiLogger,\n clientBlob: ClientUpload,\n res: ResourceInfo,\n uploadData: ImportFileHandleUploadData,\n isDoneFn: () => boolean,\n speed: {\n nPartsWithThisUploadSpeed: number,\n nPartsToIncreaseUpload: number,\n currentSpeed: number,\n maxSpeed: number,\n },\n) {\n assert(isUpload(res), 'the upload operation can be done only for BlobUploads');\n const timeout = 10000; // 10 sec instead of standard 5 sec, things might be slow with a slow connection.\n\n if (isDoneFn()) return;\n const parts = await clientBlob.initUpload(res, { timeout });\n logger.info(\n `started to upload blob ${res.id},`\n + ` parts overall: ${parts.overall}, parts remained: ${parts.toUpload.length},`\n + ` number of concurrent uploads: ${speed.currentSpeed}`,\n );\n\n const partUploadFn = (part: bigint) => async (controller: AsyncPoolController) => {\n if (isDoneFn()) return;\n await clientBlob.partUpload(\n res,\n uploadData.localPath,\n BigInt(uploadData.modificationTime),\n part,\n parts.checksumAlgorithm,\n parts.checksumHeader,\n { timeout }\n );\n logger.info(`uploaded chunk ${part}/${parts.overall} of resource: ${res.id}`);\n\n // if we had a network freeze, it will be increased slowly.\n speed.nPartsWithThisUploadSpeed++;\n if (speed.nPartsWithThisUploadSpeed >= speed.nPartsToIncreaseUpload) {\n speed.nPartsWithThisUploadSpeed = 0;\n speed.currentSpeed = increaseConcurrency(logger, speed.currentSpeed, speed.maxSpeed);\n controller.setConcurrency(speed.currentSpeed);\n }\n };\n\n await asyncPool(speed.currentSpeed, parts.toUpload.map(partUploadFn));\n\n if (isDoneFn()) return;\n await clientBlob.finalize(res, { timeout });\n\n logger.info(`uploading of resource ${res.id} finished.`);\n}\n\nfunction newProgress(res: ImportResourceSnapshot, signer: Signer) {\n let isUploadSignMatch: boolean | undefined;\n let uploadData: ImportFileHandleUploadData | undefined;\n if (isUpload(res)) {\n uploadData = ImportFileHandleUploadData.parse(res.data);\n isUploadSignMatch = isSignMatch(signer, uploadData.localPath, uploadData.pathSignature);\n }\n\n return {\n uploadData: uploadData,\n progress: {\n done: false,\n status: undefined,\n isUpload: isUpload(res),\n isUploadSignMatch: isUploadSignMatch,\n lastError: undefined,\n } satisfies sdk.ImportProgress,\n };\n}\n\n/** Returns true if we need to upload the blob that got from this progress. */\nexport function isMyUpload(p: sdk.ImportProgress): boolean {\n return p.isUpload && (p.isUploadSignMatch ?? false);\n}\n\n/** Creates a deep copy of progress,\n * since we do not want to pass a mutable object\n * to API, it led to bugs before.\n * We do not use '...' cloning syntax\n * for the compiler to fail here if we change API. */\nfunction cloneProgress(progress: sdk.ImportProgress): sdk.ImportProgress {\n const cloned: sdk.ImportProgress = {\n done: progress.done,\n isUpload: progress.isUpload,\n isUploadSignMatch: progress.isUploadSignMatch,\n lastError: progress.lastError,\n };\n\n if (progress.status)\n cloned.status = {\n progress: progress.status.progress,\n bytesProcessed: progress.status.bytesProcessed,\n bytesTotal: progress.status.bytesTotal,\n };\n\n return progress;\n}\n\nfunction isImportResourceOutputSet(res: ImportResourceSnapshot) {\n return 'blob' in res.fields\n ? res.fields.blob !== undefined\n : res.fields.incarnation !== undefined;\n}\n\nexport function isUpload(res: ResourceInfo) {\n return res.type.name.startsWith('BlobUpload');\n}\n\nexport function isSignMatch(signer: Signer, path: string, signature: string): boolean {\n try {\n signer.verify(path, signature);\n return true;\n } catch (e) {\n return false;\n }\n}\n\nfunction protoToStatus(proto: ProgressStatus): sdk.ImportStatus {\n return {\n progress: proto.progress ?? 0,\n bytesProcessed: Number(proto.bytesProcessed),\n bytesTotal: Number(proto.bytesTotal),\n };\n}\n\n/** Special hack: if we didn't even start to upload the blob\n * to backend because the result was already there,\n * the backend does show us a status that nothing were uploaded,\n * but we need to show the client that everything is OK.\n * Thus, here we set progress to be 1.0 and all bytes are become processed. */\nfunction doneProgressIfExisted(alreadyExisted: boolean, status: sdk.ImportStatus) {\n if (alreadyExisted && status.bytesTotal != 0 && status.bytesProcessed == 0) {\n return {\n progress: 1.0,\n bytesProcessed: Number(status.bytesTotal),\n bytesTotal: Number(status.bytesTotal),\n };\n }\n\n return status;\n}\n\nexport function isTerminalUploadError(e: any) {\n if (e?.name !== 'RpcError') return false;\n switch (e.code) {\n case 'NOT_FOUND':\n case 'ABORTED':\n case 'ALREADY_EXISTS':\n return true;\n default:\n return false;\n }\n}\n\nexport function nonRecoverableError(e: any) {\n return e instanceof MTimeError ||\n e instanceof UnexpectedEOF ||\n e instanceof NoFileForUploading ||\n e instanceof BadRequestError;\n}\n\nfunction isHeadersTimeoutError(e: any) {\n return (e as Error)?.message.includes(`UND_ERR_HEADERS_TIMEOUT`);\n}\n\n/** It's called for every upload success so if everyone is succeeded, we'll double the concurrency. */\nfunction increaseConcurrency(logger: MiLogger, current: number, max: number): number {\n const newConcurrency = Math.min(current + 2, max);\n if (newConcurrency != current)\n logger.info(`uploadTask.increaseConcurrency: increased from ${current} to ${newConcurrency}`)\n\n return newConcurrency;\n}\n\n/** When a error happens, this will half the concurrency level, so the next time\n * we'll try to upload blobs slower. */\nfunction decreaseConcurrency(logger: MiLogger, current: number, min: number): number {\n const newConcurrency = Math.max(Math.round(current / 2), min);\n if (newConcurrency != current)\n logger.info(`uploadTask.decreaseConcurrency: decreased from ${current} to ${newConcurrency}`)\n\n return newConcurrency;\n}\n"],"names":["ChangeSource","CallersCounter","resourceIdToString","isTimeoutError","stringifyWithResourceId","asyncPool","ImportFileHandleUploadData","MTimeError","UnexpectedEOF","NoFileForUploading","BadRequestError"],"mappings":";;;;;;;;;AAcA;;AAEgC;MACnB,UAAU,CAAA;AAmBF,IAAA,MAAA;AACA,IAAA,UAAA;AACA,IAAA,cAAA;AACA,IAAA,yBAAA;AAED,IAAA,GAAA;AAvBD,IAAA,MAAM,GAAiB,IAAIA,uBAAY,EAAE;AACzC,IAAA,OAAO,GAAmB,IAAIC,wBAAc,EAAE;AACvD,IAAA,WAAW;IACX,yBAAyB,GAAG,CAAC;AAC7B,IAAA,sBAAsB,GAAG,EAAE,CAAC;;AAG5B,IAAA,UAAU;AACX,IAAA,QAAQ;;AAGR,IAAA,MAAM;AAEb;AACuD;IAC/C,cAAc,GAAG,KAAK;IAE9B,WAAA,CACmB,MAAgB,EAChB,UAAwB,EACxB,cAA8B,EAC9B,yBAAiC,EAClD,MAAc,EACE,GAA2B,EAAA;QAL1B,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,UAAU,GAAV,UAAU;QACV,IAAA,CAAA,cAAc,GAAd,cAAc;QACd,IAAA,CAAA,yBAAyB,GAAzB,yBAAyB;QAE1B,IAAA,CAAA,GAAG,GAAH,GAAG;AAEnB,QAAA,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,yBAAyB;AACjD,QAAA,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC;AACzD,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU;AAC5B,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ;IAC1B;IAEO,WAAW,CAAC,CAAU,EAAE,QAAgB,EAAA;AAC7C,QAAA,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,QAAQ,CAAC;AAE5B,QAAA,IAAI,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Progress): boolean;
|
|
57
57
|
export declare function isUpload(res: ResourceInfo): boolean;
|
|
58
58
|
export declare function isSignMatch(signer: Signer, path: string, signature: string): boolean;
|
|
59
|
-
export declare function
|
|
59
|
+
export declare function isTerminalUploadError(e: any): boolean;
|
|
60
60
|
export declare function nonRecoverableError(e: any): e is MTimeError | UnexpectedEOF | NoFileForUploading | BadRequestError;
|
|
61
61
|
//# sourceMappingURL=upload_task.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload_task.d.ts","sourceRoot":"","sources":["../../src/drivers/upload_task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAG1D,OAAO,KAAK,KAAK,GAAG,MAAM,iCAAiC,CAAC;AAC5D,OAAO,KAAK,EAAuB,QAAQ,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAExF,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,qBAAqB,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACnG,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;gCAEgC;AAChC,qBAAa,UAAU;IAmBnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,yBAAyB;aAE1B,GAAG,EAAE,sBAAsB;IAvB7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CA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G,EAAE,YAAY,EACjB,UAAU,EAAE,0BAA0B,EACtC,QAAQ,EAAE,MAAM,OAAO,EACvB,KAAK,EAAE;IACL,yBAAyB,EAAE,MAAM,CAAC;IAClC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB,iBAyCF;AAsBD,8EAA8E;AAC9E,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,cAAc,GAAG,OAAO,CAEzD;AA+BD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,YAAY,WAEzC;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAOpF;AA2BD,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,GAAG,WAU3C;AAED,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,GAAG,0EAKzC"}
|
|
@@ -61,10 +61,9 @@ class UploadTask {
|
|
|
61
61
|
this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} finished`);
|
|
62
62
|
}
|
|
63
63
|
catch (e) {
|
|
64
|
-
if (
|
|
65
|
-
this.
|
|
66
|
-
this.
|
|
67
|
-
this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} aborted, resource was deleted`);
|
|
64
|
+
if (isTerminalUploadError(e)) {
|
|
65
|
+
this.logger.warn(`terminal error while uploading a blob: ${e}`);
|
|
66
|
+
this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} aborted: ${e.code}`);
|
|
68
67
|
this.setDone(true);
|
|
69
68
|
return;
|
|
70
69
|
}
|
|
@@ -100,9 +99,9 @@ class UploadTask {
|
|
|
100
99
|
this.logger.warn(`deadline exceeded while getting a status of BlobImport: ${e.message}`);
|
|
101
100
|
return;
|
|
102
101
|
}
|
|
103
|
-
if (
|
|
104
|
-
this.logger.warn(`
|
|
105
|
-
this.change.markChanged(`upload status for ${resourceIdToString(this.res.id)}
|
|
102
|
+
if (isTerminalUploadError(e)) {
|
|
103
|
+
this.logger.warn(`terminal error while updating BlobImport status: ${e}, ${stringifyWithResourceId(this.res)}`);
|
|
104
|
+
this.change.markChanged(`upload status for ${resourceIdToString(this.res.id)} aborted: ${e.code}`);
|
|
106
105
|
this.setDone(true);
|
|
107
106
|
return;
|
|
108
107
|
}
|
|
@@ -256,9 +255,17 @@ function doneProgressIfExisted(alreadyExisted, status) {
|
|
|
256
255
|
}
|
|
257
256
|
return status;
|
|
258
257
|
}
|
|
259
|
-
function
|
|
260
|
-
|
|
261
|
-
|
|
258
|
+
function isTerminalUploadError(e) {
|
|
259
|
+
if (e?.name !== 'RpcError')
|
|
260
|
+
return false;
|
|
261
|
+
switch (e.code) {
|
|
262
|
+
case 'NOT_FOUND':
|
|
263
|
+
case 'ABORTED':
|
|
264
|
+
case 'ALREADY_EXISTS':
|
|
265
|
+
return true;
|
|
266
|
+
default:
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
262
269
|
}
|
|
263
270
|
function nonRecoverableError(e) {
|
|
264
271
|
return e instanceof MTimeError ||
|
|
@@ -285,5 +292,5 @@ function decreaseConcurrency(logger, current, min) {
|
|
|
285
292
|
return newConcurrency;
|
|
286
293
|
}
|
|
287
294
|
|
|
288
|
-
export { UploadTask, isMyUpload,
|
|
295
|
+
export { UploadTask, isMyUpload, isSignMatch, isTerminalUploadError, isUpload, nonRecoverableError, uploadBlob };
|
|
289
296
|
//# sourceMappingURL=upload_task.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload_task.js","sources":["../../src/drivers/upload_task.ts"],"sourcesContent":["import type { Watcher } from '@milaboratories/computable';\nimport { ChangeSource } from '@milaboratories/computable';\nimport { isTimeoutError, resourceIdToString, stringifyWithResourceId } from '@milaboratories/pl-client';\nimport type * as sdk from '@milaboratories/pl-model-common';\nimport type { AsyncPoolController, MiLogger, Signer } from '@milaboratories/ts-helpers';\nimport { asyncPool, CallersCounter } from '@milaboratories/ts-helpers';\nimport type { ClientProgress, ProgressStatus } from '../clients/progress';\nimport type { ClientUpload } from '../clients/upload';\nimport { BadRequestError, MTimeError, NoFileForUploading, UnexpectedEOF } from '../clients/upload';\nimport type { ImportResourceSnapshot } from './types';\nimport { ImportFileHandleUploadData } from './types';\nimport assert from 'node:assert';\nimport { ResourceInfo } from '@milaboratories/pl-tree';\n\n/** Holds all info needed to upload a file and a status of uploading\n * and indexing. Also, has a method to update a status of the progress.\n * And holds a change source. */\nexport class UploadTask {\n private readonly change: ChangeSource = new ChangeSource();\n private readonly counter: CallersCounter = new CallersCounter();\n private nMaxUploads: number;\n private nPartsWithThisUploadSpeed = 0;\n private nPartsToIncreaseUpload = 10; // how many parts we have to wait to increase concurrency, 50 mb, 10 parts by 5 mb each.\n\n /** If this is upload progress this field will be defined */\n private uploadData?: ImportFileHandleUploadData;\n public progress: sdk.ImportProgress;\n\n /** If failed, then getting a progress is terminally failed. */\n public failed?: boolean;\n\n /** True if the blob was existed.\n * At this case, the task will show progress == 1.0. */\n private alreadyExisted = false;\n\n constructor(\n private readonly logger: MiLogger,\n private readonly clientBlob: ClientUpload,\n private readonly clientProgress: ClientProgress,\n private readonly maxNConcurrentPartsUpload: number,\n signer: Signer,\n public readonly res: ImportResourceSnapshot,\n ) {\n this.nMaxUploads = this.maxNConcurrentPartsUpload;\n const { uploadData, progress } = newProgress(res, signer);\n this.uploadData = uploadData;\n this.progress = progress;\n }\n\n public getProgress(w: Watcher, callerId: string) {\n this.incCounter(w, callerId);\n\n if (this.failed) {\n this.logger.error(`Uploading terminally failed: ${this.progress.lastError}`);\n throw new Error(this.progress.lastError);\n }\n\n return cloneProgress(this.progress);\n }\n\n public shouldScheduleUpload(): boolean {\n return isMyUpload(this.progress);\n }\n\n /** Uploads a blob if it's not BlobIndex. */\n public async uploadBlobTask() {\n try {\n await uploadBlob(\n this.logger,\n this.clientBlob,\n this.res,\n this.uploadData!,\n this.isComputableDone.bind(this),\n {\n nPartsWithThisUploadSpeed: this.nPartsWithThisUploadSpeed,\n nPartsToIncreaseUpload: this.nPartsToIncreaseUpload,\n currentSpeed: this.nMaxUploads,\n maxSpeed: this.maxNConcurrentPartsUpload,\n },\n );\n this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} finished`);\n } catch (e: any) {\n\n if (isResourceWasDeletedError(e)) {\n this.setRetriableError(e);\n this.logger.warn(`resource was deleted while uploading a blob: ${e}`);\n this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} aborted, resource was deleted`);\n this.setDone(true);\n\n return;\n }\n\n this.logger.error(`error while uploading a blob: ${e}`);\n this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} failed`);\n\n if (nonRecoverableError(e)) {\n this.setTerminalError(e);\n return;\n }\n\n this.setRetriableError(e);\n\n if (isHeadersTimeoutError(e)) {\n // we probably have a slow internet, we need to slow things a bit.\n this.nMaxUploads = decreaseConcurrency(this.logger, this.nMaxUploads, 1);\n }\n\n throw e;\n }\n }\n\n public async updateStatus() {\n try {\n // we do it with timeout in case we have slow internet.\n const status = await this.clientProgress.getStatus(this.res, { timeout: 10000 });\n\n const oldStatus = this.progress.status;\n const newStatus = doneProgressIfExisted(this.alreadyExisted, protoToStatus(status));\n this.progress.status = newStatus;\n this.setDone(status.done);\n\n if (status.done || this.progress.status.progress != oldStatus?.progress) {\n this.change.markChanged(`upload status for ${resourceIdToString(this.res.id)} changed`);\n }\n } catch (e: any) {\n this.setRetriableError(e);\n\n if (isTimeoutError(e)) {\n this.logger.warn(`deadline exceeded while getting a status of BlobImport: ${e.message}`);\n return;\n }\n\n if (isResourceWasDeletedError(e)) {\n this.logger.warn(\n `resource was not found while updating a status of BlobImport: ${e}, ${stringifyWithResourceId(this.res)}`,\n );\n this.change.markChanged(`upload status for ${resourceIdToString(this.res.id)} changed, resource not found`);\n this.setDone(true);\n return;\n }\n\n this.logger.error(`retryable error while updating a status of BlobImport: ${e}`);\n // It was a terminal error, but when a connection drops,\n // this will stop the whole task, so we make it retryable.\n // It was like that:\n // this.change.markChanged();\n // this.setTerminalError(e);\n }\n }\n\n /** Set non-terminal error, that task can be retried. */\n private setRetriableError(e: unknown) {\n this.progress.lastError = String(e);\n }\n\n /** Set a terminal error, the task will throw a error instead of a progress. */\n private setTerminalError(e: unknown) {\n this.progress.lastError = String(e);\n this.progress.done = false;\n this.failed = true;\n }\n\n public setDoneIfOutputSet(res: ImportResourceSnapshot) {\n if (isImportResourceOutputSet(res)) {\n this.setDone(true);\n this.alreadyExisted = true;\n }\n }\n\n private setDone(done: boolean) {\n this.progress.done = done;\n if (done) this.progress.lastError = undefined;\n }\n\n public incCounter(w: Watcher, callerId: string) {\n this.change.attachWatcher(w);\n this.counter.inc(callerId);\n }\n\n public decCounter(callerId: string) {\n return this.counter.dec(callerId);\n }\n\n private isComputableDone() {\n return this.counter.isZero();\n }\n}\n\n/** Uploads a blob if it's not BlobIndex. */\nexport async function uploadBlob(\n logger: MiLogger,\n clientBlob: ClientUpload,\n res: ResourceInfo,\n uploadData: ImportFileHandleUploadData,\n isDoneFn: () => boolean,\n speed: {\n nPartsWithThisUploadSpeed: number,\n nPartsToIncreaseUpload: number,\n currentSpeed: number,\n maxSpeed: number,\n },\n) {\n assert(isUpload(res), 'the upload operation can be done only for BlobUploads');\n const timeout = 10000; // 10 sec instead of standard 5 sec, things might be slow with a slow connection.\n\n if (isDoneFn()) return;\n const parts = await clientBlob.initUpload(res, { timeout });\n logger.info(\n `started to upload blob ${res.id},`\n + ` parts overall: ${parts.overall}, parts remained: ${parts.toUpload.length},`\n + ` number of concurrent uploads: ${speed.currentSpeed}`,\n );\n\n const partUploadFn = (part: bigint) => async (controller: AsyncPoolController) => {\n if (isDoneFn()) return;\n await clientBlob.partUpload(\n res,\n uploadData.localPath,\n BigInt(uploadData.modificationTime),\n part,\n parts.checksumAlgorithm,\n parts.checksumHeader,\n { timeout }\n );\n logger.info(`uploaded chunk ${part}/${parts.overall} of resource: ${res.id}`);\n\n // if we had a network freeze, it will be increased slowly.\n speed.nPartsWithThisUploadSpeed++;\n if (speed.nPartsWithThisUploadSpeed >= speed.nPartsToIncreaseUpload) {\n speed.nPartsWithThisUploadSpeed = 0;\n speed.currentSpeed = increaseConcurrency(logger, speed.currentSpeed, speed.maxSpeed);\n controller.setConcurrency(speed.currentSpeed);\n }\n };\n\n await asyncPool(speed.currentSpeed, parts.toUpload.map(partUploadFn));\n\n if (isDoneFn()) return;\n await clientBlob.finalize(res, { timeout });\n\n logger.info(`uploading of resource ${res.id} finished.`);\n}\n\nfunction newProgress(res: ImportResourceSnapshot, signer: Signer) {\n let isUploadSignMatch: boolean | undefined;\n let uploadData: ImportFileHandleUploadData | undefined;\n if (isUpload(res)) {\n uploadData = ImportFileHandleUploadData.parse(res.data);\n isUploadSignMatch = isSignMatch(signer, uploadData.localPath, uploadData.pathSignature);\n }\n\n return {\n uploadData: uploadData,\n progress: {\n done: false,\n status: undefined,\n isUpload: isUpload(res),\n isUploadSignMatch: isUploadSignMatch,\n lastError: undefined,\n } satisfies sdk.ImportProgress,\n };\n}\n\n/** Returns true if we need to upload the blob that got from this progress. */\nexport function isMyUpload(p: sdk.ImportProgress): boolean {\n return p.isUpload && (p.isUploadSignMatch ?? false);\n}\n\n/** Creates a deep copy of progress,\n * since we do not want to pass a mutable object\n * to API, it led to bugs before.\n * We do not use '...' cloning syntax\n * for the compiler to fail here if we change API. */\nfunction cloneProgress(progress: sdk.ImportProgress): sdk.ImportProgress {\n const cloned: sdk.ImportProgress = {\n done: progress.done,\n isUpload: progress.isUpload,\n isUploadSignMatch: progress.isUploadSignMatch,\n lastError: progress.lastError,\n };\n\n if (progress.status)\n cloned.status = {\n progress: progress.status.progress,\n bytesProcessed: progress.status.bytesProcessed,\n bytesTotal: progress.status.bytesTotal,\n };\n\n return progress;\n}\n\nfunction isImportResourceOutputSet(res: ImportResourceSnapshot) {\n return 'blob' in res.fields\n ? res.fields.blob !== undefined\n : res.fields.incarnation !== undefined;\n}\n\nexport function isUpload(res: ResourceInfo) {\n return res.type.name.startsWith('BlobUpload');\n}\n\nexport function isSignMatch(signer: Signer, path: string, signature: string): boolean {\n try {\n signer.verify(path, signature);\n return true;\n } catch (e) {\n return false;\n }\n}\n\nfunction protoToStatus(proto: ProgressStatus): sdk.ImportStatus {\n return {\n progress: proto.progress ?? 0,\n bytesProcessed: Number(proto.bytesProcessed),\n bytesTotal: Number(proto.bytesTotal),\n };\n}\n\n/** Special hack: if we didn't even start to upload the blob\n * to backend because the result was already there,\n * the backend does show us a status that nothing were uploaded,\n * but we need to show the client that everything is OK.\n * Thus, here we set progress to be 1.0 and all bytes are become processed. */\nfunction doneProgressIfExisted(alreadyExisted: boolean, status: sdk.ImportStatus) {\n if (alreadyExisted && status.bytesTotal != 0 && status.bytesProcessed == 0) {\n return {\n progress: 1.0,\n bytesProcessed: Number(status.bytesTotal),\n bytesTotal: Number(status.bytesTotal),\n };\n }\n\n return status;\n}\n\nexport function isResourceWasDeletedError(e: any) {\n return (\n e.name == 'RpcError'\n && (e.code == 'NOT_FOUND' || e.code == 'ABORTED' || e.code == 'ALREADY_EXISTS')\n );\n}\n\nexport function nonRecoverableError(e: any) {\n return e instanceof MTimeError ||\n e instanceof UnexpectedEOF ||\n e instanceof NoFileForUploading ||\n e instanceof BadRequestError;\n}\n\nfunction isHeadersTimeoutError(e: any) {\n return (e as Error)?.message.includes(`UND_ERR_HEADERS_TIMEOUT`);\n}\n\n/** It's called for every upload success so if everyone is succeeded, we'll double the concurrency. */\nfunction increaseConcurrency(logger: MiLogger, current: number, max: number): number {\n const newConcurrency = Math.min(current + 2, max);\n if (newConcurrency != current)\n logger.info(`uploadTask.increaseConcurrency: increased from ${current} to ${newConcurrency}`)\n\n return newConcurrency;\n}\n\n/** When a error happens, this will half the concurrency level, so the next time\n * we'll try to upload blobs slower. */\nfunction decreaseConcurrency(logger: MiLogger, current: number, min: number): number {\n const newConcurrency = Math.max(Math.round(current / 2), min);\n if (newConcurrency != current)\n logger.info(`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,QAAA,CAAC,YAAY,aAAa;AAC1B,QAAA,CAAC,YAAY,kBAAkB;QAC/B,CAAC,YAAY,eAAe;AAChC;AAEA,SAAS,qBAAqB,CAAC,CAAM,EAAA;IACnC,OAAQ,CAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA,uBAAA,CAAyB,CAAC;AAClE;AAEA;AACA,SAAS,mBAAmB,CAAC,MAAgB,EAAE,OAAe,EAAE,GAAW,EAAA;AACzE,IAAA,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,EAAE,GAAG,CAAC;IACjD,IAAI,cAAc,IAAI,OAAO;QAC3B,MAAM,CAAC,IAAI,CAAC,CAAA,+CAAA,EAAkD,OAAO,CAAA,IAAA,EAAO,cAAc,CAAA,CAAE,CAAC;AAE/F,IAAA,OAAO,cAAc;AACvB;AAEA;AACuC;AACvC,SAAS,mBAAmB,CAAC,MAAgB,EAAE,OAAe,EAAE,GAAW,EAAA;AACzE,IAAA,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;IAC7D,IAAI,cAAc,IAAI,OAAO;QAC3B,MAAM,CAAC,IAAI,CAAC,CAAA,+CAAA,EAAkD,OAAO,CAAA,IAAA,EAAO,cAAc,CAAA,CAAE,CAAC;AAE/F,IAAA,OAAO,cAAc;AACvB;;;;"}
|
|
1
|
+
{"version":3,"file":"upload_task.js","sources":["../../src/drivers/upload_task.ts"],"sourcesContent":["import type { Watcher } from '@milaboratories/computable';\nimport { ChangeSource } from '@milaboratories/computable';\nimport { isTimeoutError, resourceIdToString, stringifyWithResourceId } from '@milaboratories/pl-client';\nimport type * as sdk from '@milaboratories/pl-model-common';\nimport type { AsyncPoolController, MiLogger, Signer } from '@milaboratories/ts-helpers';\nimport { asyncPool, CallersCounter } from '@milaboratories/ts-helpers';\nimport type { ClientProgress, ProgressStatus } from '../clients/progress';\nimport type { ClientUpload } from '../clients/upload';\nimport { BadRequestError, MTimeError, NoFileForUploading, UnexpectedEOF } from '../clients/upload';\nimport type { ImportResourceSnapshot } from './types';\nimport { ImportFileHandleUploadData } from './types';\nimport assert from 'node:assert';\nimport { ResourceInfo } from '@milaboratories/pl-tree';\n\n/** Holds all info needed to upload a file and a status of uploading\n * and indexing. Also, has a method to update a status of the progress.\n * And holds a change source. */\nexport class UploadTask {\n private readonly change: ChangeSource = new ChangeSource();\n private readonly counter: CallersCounter = new CallersCounter();\n private nMaxUploads: number;\n private nPartsWithThisUploadSpeed = 0;\n private nPartsToIncreaseUpload = 10; // how many parts we have to wait to increase concurrency, 50 mb, 10 parts by 5 mb each.\n\n /** If this is upload progress this field will be defined */\n private uploadData?: ImportFileHandleUploadData;\n public progress: sdk.ImportProgress;\n\n /** If failed, then getting a progress is terminally failed. */\n public failed?: boolean;\n\n /** True if the blob was existed.\n * At this case, the task will show progress == 1.0. */\n private alreadyExisted = false;\n\n constructor(\n private readonly logger: MiLogger,\n private readonly clientBlob: ClientUpload,\n private readonly clientProgress: ClientProgress,\n private readonly maxNConcurrentPartsUpload: number,\n signer: Signer,\n public readonly res: ImportResourceSnapshot,\n ) {\n this.nMaxUploads = this.maxNConcurrentPartsUpload;\n const { uploadData, progress } = newProgress(res, signer);\n this.uploadData = uploadData;\n this.progress = progress;\n }\n\n public getProgress(w: Watcher, callerId: string) {\n this.incCounter(w, callerId);\n\n if (this.failed) {\n this.logger.error(`Uploading terminally failed: ${this.progress.lastError}`);\n throw new Error(this.progress.lastError);\n }\n\n return cloneProgress(this.progress);\n }\n\n public shouldScheduleUpload(): boolean {\n return isMyUpload(this.progress);\n }\n\n /** Uploads a blob if it's not BlobIndex. */\n public async uploadBlobTask() {\n try {\n await uploadBlob(\n this.logger,\n this.clientBlob,\n this.res,\n this.uploadData!,\n this.isComputableDone.bind(this),\n {\n nPartsWithThisUploadSpeed: this.nPartsWithThisUploadSpeed,\n nPartsToIncreaseUpload: this.nPartsToIncreaseUpload,\n currentSpeed: this.nMaxUploads,\n maxSpeed: this.maxNConcurrentPartsUpload,\n },\n );\n this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} finished`);\n } catch (e: any) {\n\n if (isTerminalUploadError(e)) {\n this.logger.warn(`terminal error while uploading a blob: ${e}`);\n this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} aborted: ${e.code}`);\n this.setDone(true);\n\n return;\n }\n\n this.logger.error(`error while uploading a blob: ${e}`);\n this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} failed`);\n\n if (nonRecoverableError(e)) {\n this.setTerminalError(e);\n return;\n }\n\n this.setRetriableError(e);\n\n if (isHeadersTimeoutError(e)) {\n // we probably have a slow internet, we need to slow things a bit.\n this.nMaxUploads = decreaseConcurrency(this.logger, this.nMaxUploads, 1);\n }\n\n throw e;\n }\n }\n\n public async updateStatus() {\n try {\n // we do it with timeout in case we have slow internet.\n const status = await this.clientProgress.getStatus(this.res, { timeout: 10000 });\n\n const oldStatus = this.progress.status;\n const newStatus = doneProgressIfExisted(this.alreadyExisted, protoToStatus(status));\n this.progress.status = newStatus;\n this.setDone(status.done);\n\n if (status.done || this.progress.status.progress != oldStatus?.progress) {\n this.change.markChanged(`upload status for ${resourceIdToString(this.res.id)} changed`);\n }\n } catch (e: any) {\n this.setRetriableError(e);\n\n if (isTimeoutError(e)) {\n this.logger.warn(`deadline exceeded while getting a status of BlobImport: ${e.message}`);\n return;\n }\n\n if (isTerminalUploadError(e)) {\n this.logger.warn(\n `terminal error while updating BlobImport status: ${e}, ${stringifyWithResourceId(this.res)}`,\n );\n this.change.markChanged(`upload status for ${resourceIdToString(this.res.id)} aborted: ${e.code}`);\n this.setDone(true);\n return;\n }\n\n this.logger.error(`retryable error while updating a status of BlobImport: ${e}`);\n // It was a terminal error, but when a connection drops,\n // this will stop the whole task, so we make it retryable.\n // It was like that:\n // this.change.markChanged();\n // this.setTerminalError(e);\n }\n }\n\n /** Set non-terminal error, that task can be retried. */\n private setRetriableError(e: unknown) {\n this.progress.lastError = String(e);\n }\n\n /** Set a terminal error, the task will throw a error instead of a progress. */\n private setTerminalError(e: unknown) {\n this.progress.lastError = String(e);\n this.progress.done = false;\n this.failed = true;\n }\n\n public setDoneIfOutputSet(res: ImportResourceSnapshot) {\n if (isImportResourceOutputSet(res)) {\n this.setDone(true);\n this.alreadyExisted = true;\n }\n }\n\n private setDone(done: boolean) {\n this.progress.done = done;\n if (done) this.progress.lastError = undefined;\n }\n\n public incCounter(w: Watcher, callerId: string) {\n this.change.attachWatcher(w);\n this.counter.inc(callerId);\n }\n\n public decCounter(callerId: string) {\n return this.counter.dec(callerId);\n }\n\n private isComputableDone() {\n return this.counter.isZero();\n }\n}\n\n/** Uploads a blob if it's not BlobIndex. */\nexport async function uploadBlob(\n logger: MiLogger,\n clientBlob: ClientUpload,\n res: ResourceInfo,\n uploadData: ImportFileHandleUploadData,\n isDoneFn: () => boolean,\n speed: {\n nPartsWithThisUploadSpeed: number,\n nPartsToIncreaseUpload: number,\n currentSpeed: number,\n maxSpeed: number,\n },\n) {\n assert(isUpload(res), 'the upload operation can be done only for BlobUploads');\n const timeout = 10000; // 10 sec instead of standard 5 sec, things might be slow with a slow connection.\n\n if (isDoneFn()) return;\n const parts = await clientBlob.initUpload(res, { timeout });\n logger.info(\n `started to upload blob ${res.id},`\n + ` parts overall: ${parts.overall}, parts remained: ${parts.toUpload.length},`\n + ` number of concurrent uploads: ${speed.currentSpeed}`,\n );\n\n const partUploadFn = (part: bigint) => async (controller: AsyncPoolController) => {\n if (isDoneFn()) return;\n await clientBlob.partUpload(\n res,\n uploadData.localPath,\n BigInt(uploadData.modificationTime),\n part,\n parts.checksumAlgorithm,\n parts.checksumHeader,\n { timeout }\n );\n logger.info(`uploaded chunk ${part}/${parts.overall} of resource: ${res.id}`);\n\n // if we had a network freeze, it will be increased slowly.\n speed.nPartsWithThisUploadSpeed++;\n if (speed.nPartsWithThisUploadSpeed >= speed.nPartsToIncreaseUpload) {\n speed.nPartsWithThisUploadSpeed = 0;\n speed.currentSpeed = increaseConcurrency(logger, speed.currentSpeed, speed.maxSpeed);\n controller.setConcurrency(speed.currentSpeed);\n }\n };\n\n await asyncPool(speed.currentSpeed, parts.toUpload.map(partUploadFn));\n\n if (isDoneFn()) return;\n await clientBlob.finalize(res, { timeout });\n\n logger.info(`uploading of resource ${res.id} finished.`);\n}\n\nfunction newProgress(res: ImportResourceSnapshot, signer: Signer) {\n let isUploadSignMatch: boolean | undefined;\n let uploadData: ImportFileHandleUploadData | undefined;\n if (isUpload(res)) {\n uploadData = ImportFileHandleUploadData.parse(res.data);\n isUploadSignMatch = isSignMatch(signer, uploadData.localPath, uploadData.pathSignature);\n }\n\n return {\n uploadData: uploadData,\n progress: {\n done: false,\n status: undefined,\n isUpload: isUpload(res),\n isUploadSignMatch: isUploadSignMatch,\n lastError: undefined,\n } satisfies sdk.ImportProgress,\n };\n}\n\n/** Returns true if we need to upload the blob that got from this progress. */\nexport function isMyUpload(p: sdk.ImportProgress): boolean {\n return p.isUpload && (p.isUploadSignMatch ?? false);\n}\n\n/** Creates a deep copy of progress,\n * since we do not want to pass a mutable object\n * to API, it led to bugs before.\n * We do not use '...' cloning syntax\n * for the compiler to fail here if we change API. */\nfunction cloneProgress(progress: sdk.ImportProgress): sdk.ImportProgress {\n const cloned: sdk.ImportProgress = {\n done: progress.done,\n isUpload: progress.isUpload,\n isUploadSignMatch: progress.isUploadSignMatch,\n lastError: progress.lastError,\n };\n\n if (progress.status)\n cloned.status = {\n progress: progress.status.progress,\n bytesProcessed: progress.status.bytesProcessed,\n bytesTotal: progress.status.bytesTotal,\n };\n\n return progress;\n}\n\nfunction isImportResourceOutputSet(res: ImportResourceSnapshot) {\n return 'blob' in res.fields\n ? res.fields.blob !== undefined\n : res.fields.incarnation !== undefined;\n}\n\nexport function isUpload(res: ResourceInfo) {\n return res.type.name.startsWith('BlobUpload');\n}\n\nexport function isSignMatch(signer: Signer, path: string, signature: string): boolean {\n try {\n signer.verify(path, signature);\n return true;\n } catch (e) {\n return false;\n }\n}\n\nfunction protoToStatus(proto: ProgressStatus): sdk.ImportStatus {\n return {\n progress: proto.progress ?? 0,\n bytesProcessed: Number(proto.bytesProcessed),\n bytesTotal: Number(proto.bytesTotal),\n };\n}\n\n/** Special hack: if we didn't even start to upload the blob\n * to backend because the result was already there,\n * the backend does show us a status that nothing were uploaded,\n * but we need to show the client that everything is OK.\n * Thus, here we set progress to be 1.0 and all bytes are become processed. */\nfunction doneProgressIfExisted(alreadyExisted: boolean, status: sdk.ImportStatus) {\n if (alreadyExisted && status.bytesTotal != 0 && status.bytesProcessed == 0) {\n return {\n progress: 1.0,\n bytesProcessed: Number(status.bytesTotal),\n bytesTotal: Number(status.bytesTotal),\n };\n }\n\n return status;\n}\n\nexport function isTerminalUploadError(e: any) {\n if (e?.name !== 'RpcError') return false;\n switch (e.code) {\n case 'NOT_FOUND':\n case 'ABORTED':\n case 'ALREADY_EXISTS':\n return true;\n default:\n return false;\n }\n}\n\nexport function nonRecoverableError(e: any) {\n return e instanceof MTimeError ||\n e instanceof UnexpectedEOF ||\n e instanceof NoFileForUploading ||\n e instanceof BadRequestError;\n}\n\nfunction isHeadersTimeoutError(e: any) {\n return (e as Error)?.message.includes(`UND_ERR_HEADERS_TIMEOUT`);\n}\n\n/** It's called for every upload success so if everyone is succeeded, we'll double the concurrency. */\nfunction increaseConcurrency(logger: MiLogger, current: number, max: number): number {\n const newConcurrency = Math.min(current + 2, max);\n if (newConcurrency != current)\n logger.info(`uploadTask.increaseConcurrency: increased from ${current} to ${newConcurrency}`)\n\n return newConcurrency;\n}\n\n/** When a error happens, this will half the concurrency level, so the next time\n * we'll try to upload blobs slower. */\nfunction decreaseConcurrency(logger: MiLogger, current: number, min: number): number {\n const newConcurrency = Math.max(Math.round(current / 2), min);\n if (newConcurrency != current)\n logger.info(`uploadTask.decreaseConcurrency: decreased from ${current} to ${newConcurrency}`)\n\n return newConcurrency;\n}\n"],"names":[],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AAC,YAAY,UAAU;AAC5B,QAAA,CAAC,YAAY,aAAa;AAC1B,QAAA,CAAC,YAAY,kBAAkB;QAC/B,CAAC,YAAY,eAAe;AAChC;AAEA,SAAS,qBAAqB,CAAC,CAAM,EAAA;IACnC,OAAQ,CAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA,uBAAA,CAAyB,CAAC;AAClE;AAEA;AACA,SAAS,mBAAmB,CAAC,MAAgB,EAAE,OAAe,EAAE,GAAW,EAAA;AACzE,IAAA,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,EAAE,GAAG,CAAC;IACjD,IAAI,cAAc,IAAI,OAAO;QAC3B,MAAM,CAAC,IAAI,CAAC,CAAA,+CAAA,EAAkD,OAAO,CAAA,IAAA,EAAO,cAAc,CAAA,CAAE,CAAC;AAE/F,IAAA,OAAO,cAAc;AACvB;AAEA;AACuC;AACvC,SAAS,mBAAmB,CAAC,MAAgB,EAAE,OAAe,EAAE,GAAW,EAAA;AACzE,IAAA,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;IAC7D,IAAI,cAAc,IAAI,OAAO;QAC3B,MAAM,CAAC,IAAI,CAAC,CAAA,+CAAA,EAAkD,OAAO,CAAA,IAAA,EAAO,cAAc,CAAA,CAAE,CAAC;AAE/F,IAAA,OAAO,cAAc;AACvB;;;;"}
|
package/dist/index.cjs
CHANGED
|
@@ -51,8 +51,8 @@ exports.UploadDriver = upload$1.UploadDriver;
|
|
|
51
51
|
exports.makeBlobImportSnapshot = upload$1.makeBlobImportSnapshot;
|
|
52
52
|
exports.UploadTask = upload_task.UploadTask;
|
|
53
53
|
exports.isMyUpload = upload_task.isMyUpload;
|
|
54
|
-
exports.isResourceWasDeletedError = upload_task.isResourceWasDeletedError;
|
|
55
54
|
exports.isSignMatch = upload_task.isSignMatch;
|
|
55
|
+
exports.isTerminalUploadError = upload_task.isTerminalUploadError;
|
|
56
56
|
exports.isUpload = upload_task.isUpload;
|
|
57
57
|
exports.nonRecoverableError = upload_task.nonRecoverableError;
|
|
58
58
|
exports.uploadBlob = upload_task.uploadBlob;
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export { DownloadDriver } from './drivers/download_blob/download_blob.js';
|
|
|
8
8
|
export { DownloadBlobToURLDriver } from './drivers/download_blob_url/driver.js';
|
|
9
9
|
export { DownloadableBlobSnapshot, makeDownloadableBlobSnapshot } from './drivers/download_blob_url/snapshot.js';
|
|
10
10
|
export { UploadDriver, makeBlobImportSnapshot } from './drivers/upload.js';
|
|
11
|
-
export { UploadTask, isMyUpload,
|
|
11
|
+
export { UploadTask, isMyUpload, isSignMatch, isTerminalUploadError, isUpload, nonRecoverableError, uploadBlob } from './drivers/upload_task.js';
|
|
12
12
|
export { LogsStreamDriver } from './drivers/logs_stream.js';
|
|
13
13
|
export { LogsDriver } from './drivers/logs.js';
|
|
14
14
|
export { DownloadUrlDriver } from './drivers/download_url/driver.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milaboratories/pl-drivers",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.32",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=22"
|
|
6
6
|
},
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"undici": "~7.16.0",
|
|
33
33
|
"upath": "^2.0.1",
|
|
34
34
|
"zod": "~3.23.8",
|
|
35
|
-
"@milaboratories/computable": "2.7.5",
|
|
36
|
-
"@milaboratories/helpers": "1.12.1",
|
|
37
35
|
"@milaboratories/ts-helpers": "1.5.4",
|
|
38
|
-
"@milaboratories/pl-client": "2.16.15",
|
|
39
36
|
"@milaboratories/pl-tree": "1.8.23",
|
|
40
|
-
"@milaboratories/
|
|
37
|
+
"@milaboratories/helpers": "1.12.1",
|
|
38
|
+
"@milaboratories/pl-model-common": "1.21.10",
|
|
39
|
+
"@milaboratories/computable": "2.7.5",
|
|
40
|
+
"@milaboratories/pl-client": "2.16.15"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/decompress": "^4.2.7",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"eslint": "^9.25.1",
|
|
49
49
|
"typescript": "~5.6.3",
|
|
50
50
|
"vitest": "^4.0.16",
|
|
51
|
-
"@milaboratories/build-configs": "1.2.1",
|
|
52
51
|
"@milaboratories/eslint-config": "1.0.5",
|
|
52
|
+
"@milaboratories/build-configs": "1.2.1",
|
|
53
53
|
"@milaboratories/ts-builder": "1.2.1",
|
|
54
54
|
"@milaboratories/test-helpers": "1.1.2",
|
|
55
55
|
"@milaboratories/ts-configs": "1.2.0"
|
|
@@ -81,10 +81,9 @@ export class UploadTask {
|
|
|
81
81
|
this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} finished`);
|
|
82
82
|
} catch (e: any) {
|
|
83
83
|
|
|
84
|
-
if (
|
|
85
|
-
this.
|
|
86
|
-
this.
|
|
87
|
-
this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} aborted, resource was deleted`);
|
|
84
|
+
if (isTerminalUploadError(e)) {
|
|
85
|
+
this.logger.warn(`terminal error while uploading a blob: ${e}`);
|
|
86
|
+
this.change.markChanged(`blob upload for ${resourceIdToString(this.res.id)} aborted: ${e.code}`);
|
|
88
87
|
this.setDone(true);
|
|
89
88
|
|
|
90
89
|
return;
|
|
@@ -130,11 +129,11 @@ export class UploadTask {
|
|
|
130
129
|
return;
|
|
131
130
|
}
|
|
132
131
|
|
|
133
|
-
if (
|
|
132
|
+
if (isTerminalUploadError(e)) {
|
|
134
133
|
this.logger.warn(
|
|
135
|
-
`
|
|
134
|
+
`terminal error while updating BlobImport status: ${e}, ${stringifyWithResourceId(this.res)}`,
|
|
136
135
|
);
|
|
137
|
-
this.change.markChanged(`upload status for ${resourceIdToString(this.res.id)}
|
|
136
|
+
this.change.markChanged(`upload status for ${resourceIdToString(this.res.id)} aborted: ${e.code}`);
|
|
138
137
|
this.setDone(true);
|
|
139
138
|
return;
|
|
140
139
|
}
|
|
@@ -333,11 +332,16 @@ function doneProgressIfExisted(alreadyExisted: boolean, status: sdk.ImportStatus
|
|
|
333
332
|
return status;
|
|
334
333
|
}
|
|
335
334
|
|
|
336
|
-
export function
|
|
337
|
-
return
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
335
|
+
export function isTerminalUploadError(e: any) {
|
|
336
|
+
if (e?.name !== 'RpcError') return false;
|
|
337
|
+
switch (e.code) {
|
|
338
|
+
case 'NOT_FOUND':
|
|
339
|
+
case 'ABORTED':
|
|
340
|
+
case 'ALREADY_EXISTS':
|
|
341
|
+
return true;
|
|
342
|
+
default:
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
341
345
|
}
|
|
342
346
|
|
|
343
347
|
export function nonRecoverableError(e: any) {
|