Skip to content

Commit 1ddb315

Browse files
committed
Add support for GLACIER_DA and forced GLACIER
Signed-off-by: Utkarsh Srivastava <[email protected]>
1 parent 581330d commit 1ddb315

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ config.STS_CORS_EXPOSE_HEADERS = 'ETag';
196196

197197
config.DENY_UPLOAD_TO_STORAGE_CLASS_STANDARD = false;
198198

199+
/**
200+
* NSFS_GLACIER_FORCE_STORAGE_CLASS when set to true
201+
* will force `GLACIER` storage class if no storage class
202+
* is provided and if `STANDARD` storage class is provided
203+
* @type {boolean}
204+
*/
205+
config.NSFS_GLACIER_FORCE_STORAGE_CLASS = false;
206+
199207
// S3_RESTORE_MAX_DAYS controls that for how many maximum number
200208
// of days an object can be restored using `restore-object` call.
201209
config.S3_RESTORE_REQUEST_MAX_DAYS = 30;

src/endpoint/s3/s3_rest.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ async function handle_request(req, res) {
107107
}
108108
http_utils.check_headers(req, headers_options);
109109

110+
// Will override the storage class if configured
111+
s3_utils.override_storage_class(req);
112+
110113
const redirect = await populate_request_additional_info_or_redirect(req);
111114
if (redirect) {
112115
res.setHeader('Location', redirect);

src/endpoint/s3/s3_utils.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const STORAGE_CLASS_STANDARD = 'STANDARD';
2020
const STORAGE_CLASS_GLACIER = 'GLACIER'; // "S3 Glacier Flexible Retrieval"
2121
/** @type {nb.StorageClass} */
2222
const STORAGE_CLASS_GLACIER_IR = 'GLACIER_IR'; // "S3 Glacier Instant Retrieval"
23+
/** @type {nb.StorageClass} */
24+
const STORAGE_CLASS_GLACIER_DA = 'GLACIER_DA'; // "DBS3 specific Storage Class"
2325

2426
const DEFAULT_S3_USER = Object.freeze({
2527
ID: '123',
@@ -382,6 +384,7 @@ function parse_storage_class(storage_class) {
382384
if (!storage_class) return STORAGE_CLASS_STANDARD;
383385
if (storage_class === STORAGE_CLASS_STANDARD) return STORAGE_CLASS_STANDARD;
384386
if (storage_class === STORAGE_CLASS_GLACIER) return STORAGE_CLASS_GLACIER;
387+
if (storage_class === STORAGE_CLASS_GLACIER_DA) return STORAGE_CLASS_GLACIER_DA;
385388
if (storage_class === STORAGE_CLASS_GLACIER_IR) return STORAGE_CLASS_GLACIER_IR;
386389
throw new Error(`No such s3 storage class ${storage_class}`);
387390
}
@@ -819,9 +822,19 @@ function parse_body_public_access_block(req) {
819822
return parsed;
820823
}
821824

825+
function override_storage_class(req) {
826+
if (
827+
config.NSFS_GLACIER_FORCE_STORAGE_CLASS &&
828+
parse_storage_class_header(req) === STORAGE_CLASS_STANDARD
829+
) {
830+
req.headers['x-amz-storage-class'] = STORAGE_CLASS_GLACIER;
831+
}
832+
}
833+
822834
exports.STORAGE_CLASS_STANDARD = STORAGE_CLASS_STANDARD;
823835
exports.STORAGE_CLASS_GLACIER = STORAGE_CLASS_GLACIER;
824836
exports.STORAGE_CLASS_GLACIER_IR = STORAGE_CLASS_GLACIER_IR;
837+
exports.STORAGE_CLASS_GLACIER_DA = STORAGE_CLASS_GLACIER_DA;
825838
exports.DEFAULT_S3_USER = DEFAULT_S3_USER;
826839
exports.DEFAULT_OBJECT_ACL = DEFAULT_OBJECT_ACL;
827840
exports.decode_chunked_upload = decode_chunked_upload;
@@ -863,5 +876,6 @@ exports.key_marker_to_cont_tok = key_marker_to_cont_tok;
863876
exports.parse_sse_c = parse_sse_c;
864877
exports.verify_string_byte_length = verify_string_byte_length;
865878
exports.parse_body_public_access_block = parse_body_public_access_block;
879+
exports.override_storage_class = override_storage_class;
866880
exports.OBJECT_ATTRIBUTES = OBJECT_ATTRIBUTES;
867881
exports.OBJECT_ATTRIBUTES_UNSUPPORTED = OBJECT_ATTRIBUTES_UNSUPPORTED;

src/sdk/namespace_fs.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3610,11 +3610,15 @@ class NamespaceFS {
36103610
}
36113611

36123612
async _is_storage_class_supported(storage_class) {
3613+
const glacier_storage_classes = [
3614+
s3_utils.STORAGE_CLASS_GLACIER,
3615+
s3_utils.STORAGE_CLASS_GLACIER_DA,
3616+
s3_utils.STORAGE_CLASS_GLACIER_IR,
3617+
];
3618+
36133619
if (!storage_class || storage_class === s3_utils.STORAGE_CLASS_STANDARD) return true;
36143620

3615-
if (storage_class === s3_utils.STORAGE_CLASS_GLACIER) {
3616-
// TODO: Upon integration with underlying systems, we should
3617-
// check if archiving is actually supported or not
3621+
if (glacier_storage_classes.includes(storage_class)) {
36183622
return config.NSFS_GLACIER_ENABLED || false;
36193623
}
36203624

src/sdk/nb.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type DigestType = 'sha1' | 'sha256' | 'sha384' | 'sha512';
1717
type CompressType = 'snappy' | 'zlib';
1818
type CipherType = 'aes-256-gcm';
1919
type ParityType = 'isa-c1' | 'isa-rs' | 'cm256';
20-
type StorageClass = 'STANDARD' | 'GLACIER' | 'GLACIER_IR';
20+
type StorageClass = 'STANDARD' | 'GLACIER' | 'GLACIER_IR' | 'GLACIER_DA';
2121
type ResourceType = 'HOSTS' | 'CLOUD' | 'INTERNAL';
2222
type NodeType =
2323
'BLOCK_STORE_S3' |

0 commit comments

Comments
 (0)