Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSFS | versioning | copy_object - close chunkfs read stream to prevent stream being closed after stat #8526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/sdk/namespace_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1140,9 +1140,7 @@ class NamespaceFS {
// end the stream
res.end();

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

dbg.log0('NamespaceFS: read_object_stream completed file', file_path, {
Expand Down Expand Up @@ -1582,8 +1580,11 @@ class NamespaceFS {
});
chunk_fs.on('error', err1 => dbg.error('namespace_fs._upload_stream: error occured on stream ChunkFS: ', err1));
if (copy_source) {
// ChunkFS is a Transform stream, however read_object_stream expects a write stream. call resume to close the read part
chunk_fs.resume();
await this.read_object_stream(copy_source, object_sdk, chunk_fs);
} else if (params.source_params) {
chunk_fs.resume();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we need to resume() on regular upload flow?
is there a chance on upload that the readable stream will change the xattr after we assigned the version id ?

Copy link
Contributor Author

@nadavMiz nadavMiz Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because in regular upload we pipe chunkfs to the source_stream, so the readable part is used, and ends on its own. while on the copy flow we use chunkfs as write stream and ignore the read part

await params.source_ns.read_object_stream(params.source_params, object_sdk, chunk_fs);
} else {
await stream_utils.pipeline([source_stream, chunk_fs]);
Expand Down
10 changes: 10 additions & 0 deletions src/test/unit_tests/test_bucketspace_versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,16 @@ mocha.describe('bucketspace namespace_fs - versioning', function() {
const exist2 = await fs_utils.file_exists(version_path_nested);
assert.ok(exist2);
});

mocha.it('copy object version id - version matches mtime and inode', async function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we now add test_versioning_obj_suspended_copy? or it has issue with bucket cache still?
if it requires the bucket cache fix, please make sure you add it to #8391 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure I'll add it. its worth mentioning that this test is for suspended more, so will not fail in this case (in suspended mode version-id is always null and doesn't depend on mtime). the reason it failed is because the bucket cache issue, the bucket remained in enabled mode

const key = 'copied_key5.txt';
const res = await s3_uid6.copyObject({ Bucket: bucket_name, Key: key,
CopySource: `${bucket_name}/${key1}?versionId=${key1_ver1}`});
const obj_path = path.join(full_path, key);
const stat = await nb_native().fs.stat(DEFAULT_FS_CONFIG, obj_path);
const expcted_version = 'mtime-' + stat.mtimeNsBigint.toString(36) + '-ino-' + stat.ino.toString(36);
assert.equal(expcted_version, res.VersionId);
});
});

mocha.describe('copy object (latest version) - versioning suspended - nsfs copy fallback flow', function() {
Expand Down