Skip to content

Commit b355ebc

Browse files
committed
Remove legacy SHA256 support, add CRC64NVME type
- Remove plain SHA256 checksum support (always use SHA256_CHUNKED) - Add CHECKSUM_TYPE_CRC64NVME to model for reading packages - Remove conditional file size logic (always 5TB now that chunked is default) - Rename config flag: chunkedChecksums -> crc64Checksums (for future use) - Delete checksums-legacy.spec.ts (plain SHA256 tests) - Clean up test mocks and suite names The catalog always computes SHA256_CHUNKED checksums for uploads. The crc64Checksums flag is reserved for future catalog-side CRC64NVME computation, but currently doesn't affect behavior.
1 parent f035d2b commit b355ebc

8 files changed

Lines changed: 21 additions & 77 deletions

File tree

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import cfg from 'constants/config'
2-
31
export const MAX_UPLOAD_SIZE = 20 * 1000 * 1000 * 1000 // 20GB
42
// XXX: keep in sync w/ the backend
53
// NOTE: these limits are lower than the actual "hard" limits on the backend
6-
export const MAX_S3_SIZE = cfg.chunkedChecksums
7-
? 5 * 10 ** 12 // 5 TB
8-
: 50 * 10 ** 9 // 50 GB
4+
export const MAX_S3_SIZE = 5 * 10 ** 12 // 5 TB
95
export const MAX_FILE_COUNT = 1000

catalog/app/model/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,17 @@ export type EntryMeta = (Types.JsonRecord & { user_meta?: Types.JsonRecord }) |
5050

5151
export const CHECKSUM_TYPE_SHA256 = 'SHA256' as const
5252
export const CHECKSUM_TYPE_SHA256_CHUNKED = 'sha2-256-chunked' as const
53+
export const CHECKSUM_TYPE_CRC64NVME = 'CRC64NVME' as const
54+
export const CHECKSUM_TYPES = [
55+
CHECKSUM_TYPE_SHA256,
56+
CHECKSUM_TYPE_SHA256_CHUNKED,
57+
CHECKSUM_TYPE_CRC64NVME,
58+
]
59+
60+
export type ChecksumType = (typeof CHECKSUM_TYPES)[number]
61+
5362
export interface Checksum {
54-
type: typeof CHECKSUM_TYPE_SHA256 | typeof CHECKSUM_TYPE_SHA256_CHUNKED
63+
type: ChecksumType
5564
value: string
5665
}
5766

catalog/app/utils/Config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export interface ConfigJson {
4343
ssoAuth: AuthMethodConfig
4444
ssoProviders: string
4545

46-
chunkedChecksums?: boolean
46+
// NOTE: does not affect anything at the moment
47+
crc64Checksums?: boolean
4748

4849
qurator?: boolean
4950

@@ -94,7 +95,7 @@ const transformConfig = (cfg: ConfigJson) => ({
9495
noOverviewImages: !!cfg.noOverviewImages,
9596
/** @deprecated */
9697
desktop: !!cfg.desktop,
97-
chunkedChecksums: !!cfg.chunkedChecksums,
98+
crc64Checksums: !!cfg.crc64Checksums,
9899
qurator: !!cfg.qurator,
99100
})
100101

catalog/app/utils/checksums/checksums-legacy.spec.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

catalog/app/utils/checksums/checksums.spec.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ import util from 'util'
44

55
import computeFileChecksumLimit from './checksums'
66

7-
jest.mock(
8-
'constants/config',
9-
jest.fn(() => ({
10-
chunkedChecksums: true,
11-
})),
12-
)
7+
jest.mock('constants/config', () => ({}))
138

149
describe('utils/checksums', () => {
15-
describe('computeFileChecksumLimit, chunked', () => {
10+
describe('computeFileChecksumLimit', () => {
1611
it('produces a correct checksum given an empty file', async () => {
1712
const file = new File([], 'empty')
1813
await expect(computeFileChecksumLimit(file)).resolves.toEqual({

catalog/app/utils/checksums/checksums.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pLimit from 'p-limit'
22

3-
import cfg from 'constants/config'
43
import * as Model from 'model'
54

65
// 8 MiB -- boto3 default: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/customizations/s3.html#boto3.s3.transfer.TransferConfig
@@ -9,7 +8,6 @@ export const MIN_PART_SIZE = 1024 ** 2 * 8
98
const MAX_PARTS = 10000 // Maximum number of parts per upload supported by S3
109

1110
export function getPartSize(fileSize: number): number | null {
12-
// use single-part upload (and plain SHA256 hash)
1311
if (fileSize < MIN_PART_SIZE) return null
1412

1513
// NOTE: in the case where fileSize is exactly equal to MIN_PART_SIZE
@@ -25,12 +23,7 @@ export function getPartSize(fileSize: number): number | null {
2523
return partSize
2624
}
2725

28-
const plain = (value: ArrayBuffer): Model.Checksum => ({
29-
value: Buffer.from(value).toString('hex'),
30-
type: Model.CHECKSUM_TYPE_SHA256,
31-
})
32-
33-
const chunked = (value: ArrayBuffer): Model.Checksum => ({
26+
const sha256Chunked = (value: ArrayBuffer): Model.Checksum => ({
3427
value: Buffer.from(value).toString('base64'),
3528
type: Model.CHECKSUM_TYPE_SHA256_CHUNKED,
3629
})
@@ -60,8 +53,6 @@ const hashBlobLimit = (blob: Blob) => blobLimit(hashBlob, blob)
6053
async function computeFileChecksum(f: File): Promise<Model.Checksum> {
6154
if (!crypto?.subtle?.digest) throw new Error('Crypto API unavailable')
6255

63-
if (!cfg.chunkedChecksums) return plain(await hashBlobLimit(f))
64-
6556
const partSize = getPartSize(f.size) ?? f.size
6657
const parts: Blob[] = []
6758

@@ -74,7 +65,7 @@ async function computeFileChecksum(f: File): Promise<Model.Checksum> {
7465

7566
const checksums = await Promise.all(parts.map(hashBlobLimit))
7667
const value = await crypto.subtle.digest('SHA-256', mergeBuffers(checksums))
77-
return chunked(value)
68+
return sha256Chunked(value)
7869
}
7970

8071
const computeFileChecksumLimit = (f: File) => fileLimit(computeFileChecksum, f)

catalog/config-schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@
8585
"desktop": {
8686
"type": "boolean"
8787
},
88-
"chunkedChecksums": {
88+
"crc64Checksums": {
8989
"type": "boolean",
90-
"description": "Whether to use chunked checksums when creating / modifying packages via the Catalog UI."
90+
"description": "Whether to use CRC64/NVME checksums when creating / modifying packages via the Catalog UI."
9191
},
9292
"build_version": {
9393
"type": "string",

catalog/config.json.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"analyticsBucket": "${ANALYTICS_BUCKET}",
1515
"serviceBucket": "${SERVICE_BUCKET}",
1616
"mode": "${CATALOG_MODE}",
17-
"chunkedChecksums": ${CHUNKED_CHECKSUMS},
17+
"crc64Checksums": ${CRC64_CHECKSUMS},
1818
"qurator": ${QURATOR},
1919
"stackVersion": "${STACK_VERSION}",
2020
"packageRoot": "${PACKAGE_ROOT}"

0 commit comments

Comments
 (0)