Skip to content

Commit

Permalink
move away from running expiry on interval - use fixed hh:mm
Browse files Browse the repository at this point in the history
Signed-off-by: Utkarsh Srivastava <srivastavautkarsh8097@gmail.com>
  • Loading branch information
tangledbytes committed Apr 4, 2024
1 parent 4f86f6f commit 7aa83d7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
6 changes: 3 additions & 3 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,9 @@ config.NSFS_GLACIER_MIGRATE_INTERVAL = 15 * 60 * 1000;
// of `manage_nsfs glacier restore`
config.NSFS_GLACIER_RESTORE_INTERVAL = 15 * 60 * 1000;

// NSFS_GLACIER_EXPIRY_INTERVAL indicates the interval between runs
// of `manage_nsfs glacier expiry`
config.NSFS_GLACIER_EXPIRY_INTERVAL = 12 * 60 * 60 * 1000;
// NSFS_GLACIER_EXPIRY_RUN_TIME must be of the format hh:mm which specifies
// when NooBaa should allow running glacier expiry process
config.NSFS_GLACIER_EXPIRY_RUN_TIME = '03:00';

/** @type {'UTC' | 'LOCAL'} */
config.NSFS_GLACIER_EXPIRY_TZ = 'LOCAL';
Expand Down
34 changes: 30 additions & 4 deletions src/manage_nsfs/manage_nsfs_glacier.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,38 @@ async function process_expiry() {
const fs_context = native_fs_utils.get_process_fs_context();

await lock_and_run(fs_context, SCAN_LOCK, async () => {
if (!(await time_exceeded(fs_context, config.NSFS_GLACIER_EXPIRY_INTERVAL, GlacierBackend.EXPIRY_TIMESTAMP_FILE))) return;
const backend = getGlacierBackend();
if (
await backend.low_free_space() ||
is_desired_time(new Date(), config.NSFS_GLACIER_EXPIRY_RUN_TIME)
) {
await backend.expiry(fs_context);
}
});
}

/**
* is_desired_time returns true if the given time matches with
* the desired time
* @param {Date} current
* @param {string} desire time in format 'hh:mm'
* @returns {Boolean}
*/
function is_desired_time(current, desire) {
const current_hour = current.getHours();
const current_min = current.getMinutes();

const [desired_hour, desired_min] = desire.split(':').map(Number);
if (
isNaN(desired_hour) ||
isNaN(desired_min) ||
(desired_hour < 0 || desired_hour >= 24) ||
(desired_min < 0 || desired_min >= 60)
) {
throw new Error('invalid `NSFS_GLACIER_EXPIRY_RUN_TIME` - must be hh:mm');
}

await getGlacierBackend().expiry(fs_context);
await record_current_time(fs_context, GlacierBackend.EXPIRY_TIMESTAMP_FILE);
});
return desired_hour === current_hour && desired_min === current_min;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/sdk/nsfs_glacier_backend/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class GlacierBackend {
// confuses these files with the WAL files.
static MIGRATE_TIMESTAMP_FILE = 'migrate.timestamp';
static RESTORE_TIMESTAMP_FILE = 'restore.timestamp';
static EXPIRY_TIMESTAMP_FILE = 'expiry.timestamp';

/**
* XATTR_RESTORE_REQUEST is set to a NUMBER (expiry days) by `restore_object` when
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/nsfs_glacier_backend/tapecloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class TapeCloudGlacierBackend extends GlacierBackend {

async low_free_space() {
const result = await exec(get_bin_path(LOW_FREE_SPACE_SCRIPT), { return_stdout: true });
return result.toLowerCase() === 'true';
return result.toLowerCase().trim() === 'true';
}

// ============= PRIVATE FUNCTIONS =============
Expand Down

0 comments on commit 7aa83d7

Please sign in to comment.