Skip to content

Commit e5e6a35

Browse files
authored
Merge pull request #8526 from nadavMiz/copy-object-close-read
NSFS | versioning | copy_object - close chunkfs read stream to prevent stream being closed after stat
2 parents 412e804 + cbf7c69 commit e5e6a35

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/sdk/namespace_fs.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,9 +1140,7 @@ class NamespaceFS {
11401140
// end the stream
11411141
res.end();
11421142

1143-
// in case of transform streams such as ChunkFS there is also a readable part. since we expect write stream
1144-
// and don't care about the readable part, set readable: false
1145-
await stream_utils.wait_finished(res, { readable: false, signal: object_sdk.abort_controller.signal });
1143+
await stream_utils.wait_finished(res, { signal: object_sdk.abort_controller.signal });
11461144
object_sdk.throw_if_aborted();
11471145

11481146
dbg.log0('NamespaceFS: read_object_stream completed file', file_path, {
@@ -1581,9 +1579,15 @@ class NamespaceFS {
15811579
large_buf_size: multi_buffer_pool.get_buffers_pool(undefined).buf_size
15821580
});
15831581
chunk_fs.on('error', err1 => dbg.error('namespace_fs._upload_stream: error occured on stream ChunkFS: ', err1));
1582+
chunk_fs.on('finish', arg => dbg.error('namespace_fs._upload_stream: finish occured on stream ChunkFS: ', arg));
1583+
chunk_fs.on('close', arg => dbg.error('namespace_fs._upload_stream: close occured on stream ChunkFS: ', arg));
15841584
if (copy_source) {
1585+
// ChunkFS is a Transform stream, however read_object_stream expects a write stream. call resume to close the read part
1586+
// we need to close both read and write parts for Transform stream to properly close and release resorces
1587+
chunk_fs.resume();
15851588
await this.read_object_stream(copy_source, object_sdk, chunk_fs);
15861589
} else if (params.source_params) {
1590+
chunk_fs.resume();
15871591
await params.source_ns.read_object_stream(params.source_params, object_sdk, chunk_fs);
15881592
} else {
15891593
await stream_utils.pipeline([source_stream, chunk_fs]);

src/test/unit_tests/test_bucketspace_versioning.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,16 @@ mocha.describe('bucketspace namespace_fs - versioning', function() {
773773
assert.ok(exist2);
774774
});
775775

776+
mocha.it('copy object version id - version matches mtime and inode', async function() {
777+
const key = 'copied_key5.txt';
778+
const res = await s3_uid6.copyObject({ Bucket: bucket_name, Key: key,
779+
CopySource: `${bucket_name}/${key1}?versionId=${key1_ver1}`});
780+
const obj_path = path.join(full_path, key);
781+
const stat = await nb_native().fs.stat(DEFAULT_FS_CONFIG, obj_path);
782+
const expcted_version = 'mtime-' + stat.mtimeNsBigint.toString(36) + '-ino-' + stat.ino.toString(36);
783+
assert.equal(expcted_version, res.VersionId);
784+
});
785+
776786
mocha.it('delete object - versioning enabled - nested key (more than 1 level)- delete partial directory', async function() {
777787
const parital_nested_directory = dir_path_complete.slice(0, -1); // the directory without the last slash
778788
const folder_path_nested = path.join(nested_keys_full_path, dir_path_complete, NSFS_FOLDER_OBJECT_NAME);

0 commit comments

Comments
 (0)