Skip to content

Commit 59b5564

Browse files
authored
Avoid double storage counting of upload chunks (#9007)
Do not count chunk request retrires when counting up used storage. - [x] Needs datastore update after deployment
1 parent 537e3fc commit 59b5564

File tree

1 file changed

+21
-19
lines changed
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/uploading

1 file changed

+21
-19
lines changed

webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/uploading/UploadService.scala

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -281,25 +281,29 @@ class UploadService @Inject()(dataSourceService: DataSourceService,
281281
totalFileSizeInBytesOpt <- runningUploadMetadataStore.findLong(redisKeyForTotalFileSizeInBytes(uploadId))
282282
alreadyNotifiedAboutExceedingLimitOpt <- runningUploadMetadataStore.find(
283283
redisKeyForReportedTooLargeUpload(uploadId))
284-
_ <- Fox.runOptional(totalFileSizeInBytesOpt) { maxFileSize =>
285-
runningUploadMetadataStore
286-
.increaseBy(redisKeyForCurrentUploadedTotalFileSizeInBytes(uploadId), currentChunkSize)
287-
.flatMap(newTotalFileSizeInBytesOpt => {
288-
if (newTotalFileSizeInBytesOpt.getOrElse(0L) > maxFileSize) {
289-
runningUploadMetadataStore.insert(redisKeyForReportedTooLargeUpload(uploadId), "true")
290-
logger.warn(
291-
s"Received upload chunk for $datasetId that pushes total file size to ${newTotalFileSizeInBytesOpt
292-
.getOrElse(0L)}, which is more than reserved $maxFileSize. Allowing upload for now.")
293-
if (!alreadyNotifiedAboutExceedingLimitOpt.exists(s => Try(s.toBoolean).getOrElse(false))) {
294-
slackNotificationService.noticeTooLargeUploadChunkRequest(
284+
isNewChunk <- runningUploadMetadataStore.insertIntoSet(redisKeyForFileChunkSet(uploadId, filePath),
285+
String.valueOf(currentChunkNumber))
286+
_ <- Fox.runIf(isNewChunk) {
287+
Fox.runOptional(totalFileSizeInBytesOpt) { maxFileSize =>
288+
runningUploadMetadataStore
289+
.increaseBy(redisKeyForCurrentUploadedTotalFileSizeInBytes(uploadId), currentChunkSize)
290+
.flatMap(newTotalFileSizeInBytesOpt => {
291+
if (newTotalFileSizeInBytesOpt.getOrElse(0L) > maxFileSize) {
292+
runningUploadMetadataStore.insert(redisKeyForReportedTooLargeUpload(uploadId), "true")
293+
logger.warn(
295294
s"Received upload chunk for $datasetId that pushes total file size to ${newTotalFileSizeInBytesOpt
296-
.getOrElse(0L)}, which is more than reserved $maxFileSize.")
295+
.getOrElse(0L)}, which is more than reserved $maxFileSize. Allowing upload for now.")
296+
if (!alreadyNotifiedAboutExceedingLimitOpt.exists(s => Try(s.toBoolean).getOrElse(false))) {
297+
slackNotificationService.noticeTooLargeUploadChunkRequest(
298+
s"Received upload chunk for $datasetId that pushes total file size to ${newTotalFileSizeInBytesOpt
299+
.getOrElse(0L)}, which is more than reserved $maxFileSize.")
300+
}
301+
Fox.successful(())
302+
} else {
303+
Fox.successful(())
297304
}
298-
Fox.successful(())
299-
} else {
300-
Fox.successful(())
301-
}
302-
})
305+
})
306+
}
303307
}
304308
_ <- Fox.runIf(!isFileKnown) {
305309
runningUploadMetadataStore
@@ -308,8 +312,6 @@ class UploadService @Inject()(dataSourceService: DataSourceService,
308312
runningUploadMetadataStore.insert(redisKeyForFileChunkCount(uploadId, filePath),
309313
String.valueOf(totalChunkCount)))
310314
}
311-
isNewChunk <- runningUploadMetadataStore.insertIntoSet(redisKeyForFileChunkSet(uploadId, filePath),
312-
String.valueOf(currentChunkNumber))
313315
} yield
314316
if (isNewChunk) {
315317
try {

0 commit comments

Comments
 (0)