Skip to content

Commit 0fa8a6e

Browse files
committed
NSFS | fix copy_object issues
Signed-off-by: nadav mizrahi <[email protected]>
1 parent 8aefb7e commit 0fa8a6e

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

src/sdk/namespace_fs.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ class NamespaceFS {
483483
}
484484

485485
/**
486-
* @param {nb.ObjectSDK} object_sdk
486+
* @param {nb.ObjectSDK} object_sdk
487487
* @returns {nb.NativeFSContext}
488488
*/
489489
prepare_fs_context(object_sdk) {
@@ -1090,7 +1090,7 @@ class NamespaceFS {
10901090
// end the stream
10911091
res.end();
10921092

1093-
await stream_utils.wait_finished(res, { signal: object_sdk.abort_controller.signal });
1093+
await stream_utils.wait_finished(res, { readable: false, signal: object_sdk.abort_controller.signal });
10941094
object_sdk.throw_if_aborted();
10951095

10961096
dbg.log0('NamespaceFS: read_object_stream completed file', file_path, {
@@ -1209,9 +1209,7 @@ class NamespaceFS {
12091209
}
12101210

12111211
if (copy_res) {
1212-
if (copy_res === copy_status_enum.FALLBACK) {
1213-
params.copy_source.nsfs_copy_fallback();
1214-
} else {
1212+
if (copy_res !== copy_status_enum.FALLBACK) {
12151213
// open file after copy link/same inode should use read open mode
12161214
open_mode = config.NSFS_OPEN_READ_MODE;
12171215
if (copy_res === copy_status_enum.SAME_INODE) open_path = file_path;
@@ -1294,10 +1292,8 @@ class NamespaceFS {
12941292
let stat = await target_file.stat(fs_context);
12951293
this._verify_encryption(params.encryption, this._get_encryption_info(stat));
12961294

1297-
// handle xattr
1298-
// assign user xattr on non copy / copy with xattr_copy header provided
12991295
const copy_xattr = params.copy_source && params.xattr_copy;
1300-
let fs_xattr = copy_xattr ? undefined : to_fs_xattr(params.xattr);
1296+
let fs_xattr = to_fs_xattr(params.xattr);
13011297

13021298
// assign noobaa internal xattr - content type, md5, versioning xattr
13031299
if (params.content_type) {
@@ -1511,7 +1507,7 @@ class NamespaceFS {
15111507
// Can be finetuned further on if needed and inserting the Semaphore logic inside
15121508
// Instead of wrapping the whole _upload_stream function (q_buffers lives outside of the data scope of the stream)
15131509
async _upload_stream({ fs_context, params, target_file, object_sdk, offset }) {
1514-
const { source_stream } = params;
1510+
const { source_stream, copy_source } = params;
15151511
try {
15161512
// Not using async iterators with ReadableStreams due to unsettled promises issues on abort/destroy
15171513
const md5_enabled = this._is_force_md5_enabled(object_sdk);
@@ -1526,8 +1522,12 @@ class NamespaceFS {
15261522
large_buf_size: multi_buffer_pool.get_buffers_pool(undefined).buf_size
15271523
});
15281524
chunk_fs.on('error', err1 => dbg.error('namespace_fs._upload_stream: error occured on stream ChunkFS: ', err1));
1529-
await stream_utils.pipeline([source_stream, chunk_fs]);
1530-
await stream_utils.wait_finished(chunk_fs);
1525+
if (copy_source) {
1526+
await this.read_object_stream(copy_source, object_sdk, chunk_fs);
1527+
} else {
1528+
await stream_utils.pipeline([source_stream, chunk_fs]);
1529+
await stream_utils.wait_finished(chunk_fs);
1530+
}
15311531
return { digest: chunk_fs.digest, total_bytes: chunk_fs.total_bytes };
15321532
} catch (error) {
15331533
dbg.error('_upload_stream had error: ', error);
@@ -1813,6 +1813,7 @@ class NamespaceFS {
18131813
upload_params.params.xattr = create_params_parsed.xattr;
18141814
upload_params.params.storage_class = create_params_parsed.storage_class;
18151815
upload_params.digest = MD5Async && (((await MD5Async.digest()).toString('hex')) + '-' + multiparts.length);
1816+
upload_params.params.content_type = create_params_parsed.content_type;
18161817

18171818
const upload_info = await this._finish_upload(upload_params);
18181819

src/sdk/object_sdk.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class ObjectSDK {
106106
* in order to handle aborting requests gracefully. The `abort_controller` member will
107107
* be used to signal async flows that abort was detected.
108108
* @see {@link https://nodejs.org/docs/latest/api/globals.html#class-abortcontroller}
109-
* @param {import('http').IncomingMessage} req
110-
* @param {import('http').ServerResponse} res
109+
* @param {import('http').IncomingMessage} req
110+
* @param {import('http').ServerResponse} res
111111
*/
112112
setup_abort_controller(req, res) {
113113
res.once('error', err => {
@@ -158,7 +158,7 @@ class ObjectSDK {
158158
}
159159

160160
/**
161-
* @param {string} name
161+
* @param {string} name
162162
* @returns {Promise<nb.Namespace>}
163163
*/
164164
async _get_bucket_namespace(name) {
@@ -268,7 +268,7 @@ class ObjectSDK {
268268
return Boolean(fs_root_path || fs_root_path === '');
269269
}
270270

271-
// validates requests for non nsfs buckets from accounts which are nsfs_only
271+
// validates requests for non nsfs buckets from accounts which are nsfs_only
272272
has_non_nsfs_bucket_access(account, ns) {
273273
dbg.log1('validate_non_nsfs_bucket: ', account, ns?.write_resource?.resource);
274274
if (!account) return false;
@@ -524,7 +524,7 @@ class ObjectSDK {
524524
/**
525525
* Calls the op and report time and error to stats collector.
526526
* on_success can be added to update read/write stats (but on_success shouln't throw)
527-
*
527+
*
528528
* @template T
529529
* @param {{
530530
* op_name: string;
@@ -642,7 +642,7 @@ class ObjectSDK {
642642
params.content_type = source_md.content_type;
643643
}
644644
try {
645-
if (params.xattr) params.xattr = _.omitBy(params.xattr, (val, name) => name.startsWith('noobaa-namespace'));
645+
if (params.xattr) params.xattr = _.omitBy(params.xattr, (val, name) => name.startsWith?.('noobaa-namespace'));
646646
} catch (e) {
647647
dbg.log3("Got an error while trying to omitBy param.xattr:", params.xattr, "error:", e);
648648
}
@@ -658,12 +658,6 @@ class ObjectSDK {
658658
params.copy_source.bucket = actual_source_ns.get_bucket(bucket);
659659
params.copy_source.obj_id = source_md.obj_id;
660660
params.copy_source.version_id = source_md.version_id;
661-
if (source_ns instanceof NamespaceFS) {
662-
params.copy_source.nsfs_copy_fallback = () => {
663-
this._populate_nsfs_copy_fallback({ source_params, source_ns, params });
664-
params.copy_source = null;
665-
};
666-
}
667661
} else {
668662
// source cannot be copied directly (different plaforms, accounts, etc.)
669663
// set the source_stream to read from the copy source
@@ -701,9 +695,9 @@ class ObjectSDK {
701695
}
702696
}
703697

704-
// nsfs copy_object & server side copy consisted of link and a fallback to
698+
// nsfs copy_object & server side copy consisted of link and a fallback to
705699
// read stream and then upload stream
706-
// nsfs copy object when can't server side copy - fallback directly
700+
// nsfs copy object when can't server side copy - fallback directly
707701
_populate_nsfs_copy_fallback({ source_ns, params, source_params }) {
708702
const read_stream = new stream.PassThrough();
709703
source_ns.read_object_stream(source_params, this, read_stream)

src/test/system_tests/ceph_s3_tests/s3-tests-lists/nsfs_s3_tests_pending_list.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ s3tests_boto3/functional/test_s3.py::test_object_copy_to_itself_with_metadata
157157
s3tests_boto3/functional/test_s3.py::test_object_copy_canned_acl
158158
s3tests_boto3/functional/test_s3.py::test_object_copy_retaining_metadata
159159
s3tests_boto3/functional/test_s3.py::test_object_copy_replacing_metadata
160-
s3tests_boto3/functional/test_s3.py::test_object_copy_versioning_multipart_upload
161160
s3tests_boto3/functional/test_s3.py::test_list_multipart_upload
162161
s3tests_boto3/functional/test_s3.py::test_multipart_upload_missing_part
163162
s3tests_boto3/functional/test_s3.py::test_multipart_upload_incorrect_etag

0 commit comments

Comments
 (0)