Skip to content

Commit

Permalink
NSFS | remove prev external attribute
Browse files Browse the repository at this point in the history
Signed-off-by: nadav mizrahi <[email protected]>
  • Loading branch information
nadavMiz committed Sep 18, 2024
1 parent a116848 commit 6ffaa8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 44 deletions.
41 changes: 7 additions & 34 deletions src/sdk/namespace_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const XATTR_PART_OFFSET = XATTR_NOOBAA_INTERNAL_PREFIX + 'part_offset';
const XATTR_PART_SIZE = XATTR_NOOBAA_INTERNAL_PREFIX + 'part_size';
const XATTR_PART_ETAG = XATTR_NOOBAA_INTERNAL_PREFIX + 'part_etag';
const XATTR_VERSION_ID = XATTR_NOOBAA_INTERNAL_PREFIX + 'version_id';
const XATTR_PREV_VERSION_ID = XATTR_NOOBAA_INTERNAL_PREFIX + 'prev_version_id';
const XATTR_DELETE_MARKER = XATTR_NOOBAA_INTERNAL_PREFIX + 'delete_marker';
const XATTR_DIR_CONTENT = XATTR_NOOBAA_INTERNAL_PREFIX + 'dir_content';
const XATTR_TAG = XATTR_NOOBAA_INTERNAL_PREFIX + 'tag.';
Expand Down Expand Up @@ -1314,8 +1313,7 @@ class NamespaceFS {
fs_xattr = await this._assign_part_props_to_fs_xattr(fs_context, params.size, digest, offset, fs_xattr);
}
if (!part_upload && (this._is_versioning_enabled() || this._is_versioning_suspended())) {
const cur_ver_info = await this._get_version_info(fs_context, file_path);
fs_xattr = await this._assign_versions_to_fs_xattr(fs_context, cur_ver_info, stat, params.key, fs_xattr);
fs_xattr = await this._assign_versions_to_fs_xattr(stat, fs_xattr, undefined);
}
if (!part_upload && params.storage_class) {
fs_xattr = Object.assign(fs_xattr || {}, {
Expand Down Expand Up @@ -2175,14 +2173,11 @@ class NamespaceFS {
return fs_xattr;
}

async _assign_versions_to_fs_xattr(fs_context, prev_ver_info, new_ver_stat, key, fs_xattr, delete_marker) {
if (!prev_ver_info) prev_ver_info = await this.find_max_version_past(fs_context, key);

async _assign_versions_to_fs_xattr(new_ver_stat, fs_xattr, delete_marker) {
fs_xattr = Object.assign(fs_xattr || {}, {
[XATTR_VERSION_ID]: this._get_version_id_by_mode(new_ver_stat)
});

if (prev_ver_info) fs_xattr[XATTR_PREV_VERSION_ID] = prev_ver_info.version_id_str;
if (delete_marker) fs_xattr[XATTR_DELETE_MARKER] = delete_marker;

return fs_xattr;
Expand Down Expand Up @@ -2661,7 +2656,6 @@ class NamespaceFS {
// mtimeNsBigint - modified timestmap in bigint - last time the content of the file was modified
// ino - refers to the data stored in a particular location
// delete_marker - specifies if the version is a delete marker
// prev_version_id - specifies the previous version of the wanted version
// path - specifies the path to version
// if version xattr contains version info - return info by xattr
// else - it's a null version - return stat
Expand All @@ -2676,7 +2670,6 @@ class NamespaceFS {
...(ver_info_by_xattr || stat),
version_id_str,
delete_marker: stat.xattr[XATTR_DELETE_MARKER],
prev_version_id: stat.xattr[XATTR_PREV_VERSION_ID],
path: version_path
};
} catch (err) {
Expand Down Expand Up @@ -2732,13 +2725,12 @@ class NamespaceFS {
}

/**
* @param {nb.NativeFSContext} fs_context
* @param {string} key
* @param {string} version_id
* @param {nb.NativeFSContext} fs_context
* @param {string} key
* @param {string} version_id
* @returns {Promise<{
* version_id_str: any;
* delete_marker: string;
* prev_version_id: string;
* path: any;
* mtimeNsBigint: bigint;
* ino: number;
Expand Down Expand Up @@ -2857,17 +2849,13 @@ class NamespaceFS {
// condition 2 guards on situations where we don't want to try move max version past to latest
async _promote_version_to_latest(fs_context, params, deleted_version_info, latest_ver_path) {
dbg.log1('Namespace_fs._promote_version_to_latest', params, deleted_version_info, latest_ver_path);
const deleted_latest = deleted_version_info && deleted_version_info.path === latest_ver_path;
const prev_version_id = deleted_latest && deleted_version_info.prev_version_id;

let retries = config.NSFS_RENAME_RETRIES;
for (;;) {
try {
const latest_version_info = await this._get_version_info(fs_context, latest_ver_path);
if (latest_version_info) return;
const max_past_ver_info = (prev_version_id &&
(await this.get_prev_version_info(fs_context, params.key, prev_version_id))) ||
(await this.find_max_version_past(fs_context, params.key));
const max_past_ver_info = await this.find_max_version_past(fs_context, params.key);

if (!max_past_ver_info || max_past_ver_info.delete_marker) return;
// 2 - if deleted file is a delete marker and is older than max past version - no need to promote max - return
Expand Down Expand Up @@ -3013,16 +3001,7 @@ class NamespaceFS {
}
const file_path = this._get_version_path(params.key, delete_marker_version_id);

let fs_xattr;
if (this._is_versioning_suspended() &&
(deleted_version_info?.version_id_str === NULL_VERSION_ID)) {
fs_xattr = await this._assign_versions_to_fs_xattr(fs_context, undefined,
stat, params.key, undefined, true);
} else {
// the previous version will be the deleted version
fs_xattr = await this._assign_versions_to_fs_xattr(fs_context, deleted_version_info,
stat, params.key, undefined, true);
}
const fs_xattr = await this._assign_versions_to_fs_xattr(stat, undefined, true);
if (fs_xattr) await upload_params.target_file.replacexattr(fs_context, fs_xattr);
// create .version in case we don't have it yet
await native_fs_utils._make_path_dirs(file_path, fs_context);
Expand All @@ -3042,12 +3021,6 @@ class NamespaceFS {
}
}

async get_prev_version_info(fs_context, key, prev_version_id) {
const prev_path = this._get_version_path(key, prev_version_id);
const prev_path_info = await this._get_version_info(fs_context, prev_path);
return prev_path_info;
}

// try find prev version by hint or by iterating on .versions/ dir
async find_max_version_past(fs_context, key) {
const versions_dir = path.normalize(path.join(this.bucket_path, path.dirname(key), HIDDEN_VERSIONS_PATH));
Expand Down
11 changes: 1 addition & 10 deletions src/test/unit_tests/test_bucketspace_versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ coretest.setup({});

const XATTR_INTERNAL_NOOBAA_PREFIX = 'user.noobaa.';
const XATTR_VERSION_ID = XATTR_INTERNAL_NOOBAA_PREFIX + 'version_id';
const XATTR_PREV_VERSION_ID = XATTR_INTERNAL_NOOBAA_PREFIX + 'prev_version_id';
const XATTR_DELETE_MARKER = XATTR_INTERNAL_NOOBAA_PREFIX + 'delete_marker';
const NULL_VERSION_ID = 'null';

Expand Down Expand Up @@ -916,7 +915,6 @@ mocha.describe('bucketspace namespace_fs - versioning', function() {
assert.ok(is_dm);
const version_path = path.join(suspended_full_path, '.versions', key_to_delete3 + '_' + latest_dm_version);
const version_info = await stat_and_get_all(version_path, '');
assert.equal(version_info.xattr[XATTR_PREV_VERSION_ID], prev_dm.VersionId);
assert.equal(version_info.xattr[XATTR_VERSION_ID], NULL_VERSION_ID);
});
});
Expand Down Expand Up @@ -975,8 +973,6 @@ mocha.describe('bucketspace namespace_fs - versioning', function() {
const max_version0 = await find_max_version_past(full_delete_path, key1, '');
const cur_version_id1 = await stat_and_get_version_id(full_delete_path, key1);
assert.equal(upload_res_arr[2].VersionId, cur_version_id1);
const cur_ver_info = await stat_and_get_all(full_delete_path, key1);
assert.equal(cur_ver_info.xattr[XATTR_PREV_VERSION_ID], max_version0);
const is_dm = await is_delete_marker(full_delete_path, '', key1, max_version0);
assert.ok(is_dm);

Expand Down Expand Up @@ -1292,8 +1288,6 @@ mocha.describe('bucketspace namespace_fs - versioning', function() {

const cur_version_id1 = await stat_and_get_version_id(full_delete_path, key1);
assert.equal(upload_res_arr[2].VersionId, cur_version_id1);
const cur_ver_info = await stat_and_get_all(full_delete_path, key1);
assert.equal(cur_ver_info.xattr[XATTR_PREV_VERSION_ID], max_version0);
const is_dm = await is_delete_marker(full_delete_path, '', key1, max_version0);
assert.ok(is_dm);

Expand Down Expand Up @@ -2832,13 +2826,11 @@ async function compare_version_ids(full_path, key, put_result_version_id, prev_v
}
assert.equal(new_version_id, xattr_version_id);
if (prev_version_id) {
const xattr_prev_version_id = get_version_id_by_xattr(stat, true);
if (is_enabled) {
// When versioning is Enabled the version IDs are unique.
// Hence, the new version ID must be different than the previous one.
assert.notEqual(new_version_id, prev_version_id);
}
assert.equal(xattr_prev_version_id, prev_version_id);
}
return true;
}
Expand All @@ -2847,8 +2839,7 @@ function get_version_id_by_stat(stat) {
return 'mtime-' + stat.mtimeNsBigint.toString(36) + '-ino-' + stat.ino.toString(36);
}

function get_version_id_by_xattr(stat, prev) {
if (prev) return stat && stat.xattr[XATTR_PREV_VERSION_ID];
function get_version_id_by_xattr(stat) {
return (stat && stat.xattr[XATTR_VERSION_ID]) || 'null';
}

Expand Down

0 comments on commit 6ffaa8a

Please sign in to comment.