Skip to content

Commit

Permalink
Merge pull request noobaa#7848 from tangledbytes/utkarsh/fix/fix-wal-…
Browse files Browse the repository at this point in the history
…processing

[NC | NSFS] Fix WAL processing failure
  • Loading branch information
tangledbytes authored Mar 7, 2024
2 parents b9ef36c + cf44761 commit 3afa670
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 69 deletions.
16 changes: 6 additions & 10 deletions src/manage_nsfs/manage_nsfs_glacier.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ const native_fs_utils = require('../util/native_fs_utils');
const CLUSTER_LOCK = 'cluster.lock';
const SCAN_LOCK = 'scan.lock';

const RESTORE_TIMESTAMP_FILE = 'restore.timestamp';
const MIGRATE_TIMESTAMP_FILE = 'migrate.timestamp';
const EXPIRY_TIMESTAMP_FILE = 'expiry.timestamp';

async function process_migrations() {
const fs_context = native_fs_utils.get_process_fs_context();

Expand All @@ -24,10 +20,10 @@ async function process_migrations() {

if (
await backend.low_free_space() ||
await time_exceeded(fs_context, config.NSFS_GLACIER_MIGRATE_INTERVAL, MIGRATE_TIMESTAMP_FILE)
await time_exceeded(fs_context, config.NSFS_GLACIER_MIGRATE_INTERVAL, GlacierBackend.MIGRATE_TIMESTAMP_FILE)
) {
await run_glacier_migrations(fs_context, backend);
await record_current_time(fs_context, MIGRATE_TIMESTAMP_FILE);
await record_current_time(fs_context, GlacierBackend.MIGRATE_TIMESTAMP_FILE);
}
});
}
Expand Down Expand Up @@ -57,12 +53,12 @@ async function process_restores() {

if (
await backend.low_free_space() ||
!(await time_exceeded(fs_context, config.NSFS_GLACIER_RESTORE_INTERVAL, RESTORE_TIMESTAMP_FILE))
!(await time_exceeded(fs_context, config.NSFS_GLACIER_RESTORE_INTERVAL, GlacierBackend.RESTORE_TIMESTAMP_FILE))
) return;


await run_glacier_restore(fs_context, backend);
await record_current_time(fs_context, RESTORE_TIMESTAMP_FILE);
await record_current_time(fs_context, GlacierBackend.RESTORE_TIMESTAMP_FILE);
});
}

Expand All @@ -87,11 +83,11 @@ 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, EXPIRY_TIMESTAMP_FILE))) return;
if (!(await time_exceeded(fs_context, config.NSFS_GLACIER_EXPIRY_INTERVAL, GlacierBackend.EXPIRY_TIMESTAMP_FILE))) return;


await getGlacierBackend().expiry(fs_context);
await record_current_time(fs_context, EXPIRY_TIMESTAMP_FILE);
await record_current_time(fs_context, GlacierBackend.EXPIRY_TIMESTAMP_FILE);
});
}

Expand Down
22 changes: 9 additions & 13 deletions src/manage_nsfs/manage_nsfs_help_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,19 @@ Flags:

const GLACIER_OPTIONS = `
Usage:
manage_nsfs glacier <migrate | restore | expiry> [options]
`;
glacier <action> [flags]
const GLACIER_MIGRATE_OPTIONS = `
Glacier Migrate Options:
--interval <interval> (default none) Run the operation if "interval" milliseconds have passed since last run
List of actions supported:
migrate
restore
expiry
`;

const GLACIER_RESTORE_OPTIONS = `
Glacier Restore Options:
--interval <interval> (default none) Run the operation if "interval" milliseconds have passed since last run
`;
const GLACIER_MIGRATE_OPTIONS = ``;

const GLACIER_EXPIRY_OPTIONS = `
Glacier Expiry Options:
--interval <interval> (default none) Run the operation if "interval" milliseconds have passed since last run
`;
const GLACIER_RESTORE_OPTIONS = ``;

const GLACIER_EXPIRY_OPTIONS = ``;

/**
* print_usage would print the help according to the arguments that were passed
Expand Down
36 changes: 22 additions & 14 deletions src/native/fs/fs_napi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ struct AutoCloser
: _worker(worker), _fd(fd) {}
~AutoCloser()
{
if (_fd) {
if (_fd >= 0) {
int r = close(_fd);
if (r) _worker->SetSyscallError();
}
Expand Down Expand Up @@ -1341,7 +1341,7 @@ struct FileWrap : public Napi::ObjectWrap<FileWrap>
}
FileWrap(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<FileWrap>(info)
, _fd(0)
, _fd(-1)
{
}
~FileWrap()
Expand All @@ -1350,7 +1350,7 @@ struct FileWrap : public Napi::ObjectWrap<FileWrap>
LOG("FS::FileWrap::dtor: file not closed " << DVAL(_path) << DVAL(_fd));
int r = ::close(_fd);
if (r) LOG("FS::FileWrap::dtor: file close failed " << DVAL(_path) << DVAL(_fd) << DVAL(r));
_fd = 0;
_fd = -1;
}
}
Napi::Value close(const Napi::CallbackInfo& info);
Expand All @@ -1376,7 +1376,7 @@ struct FileOpen : public FSWorker
mode_t _mode;
FileOpen(const Napi::CallbackInfo& info)
: FSWorker(info)
, _fd(0)
, _fd(-1)
, _flags(0)
, _mode(0666)
{
Expand Down Expand Up @@ -1417,10 +1417,12 @@ struct FileClose : public FSWrapWorker<FileWrap>
virtual void Work()
{
int fd = _wrap->_fd;
std::string path = _wrap->_path;
int r = close(fd);
if (r) SetSyscallError();
_wrap->_fd = 0;
if (fd >= 0) {
std::string path = _wrap->_path;
int r = close(fd);
if (r) SetSyscallError();
_wrap->_fd = -1;
}
}
};

Expand Down Expand Up @@ -1570,6 +1572,7 @@ struct FileReplacexattr : public FSWrapWorker<FileWrap>
virtual void Work()
{
int fd = _wrap->_fd;
CHECK_WRAP_FD(fd);

if (_prefix != "") {
SYSCALL_OR_RETURN(clear_xattr(fd, _prefix));
Expand All @@ -1587,7 +1590,7 @@ struct LinkFileAt : public FSWrapWorker<FileWrap>
int _replace_fd;
LinkFileAt(const Napi::CallbackInfo& info)
: FSWrapWorker<FileWrap>(info)
, _replace_fd(0)
, _replace_fd(-1)
{
_filepath = info[1].As<Napi::String>();
if (info.Length() > 2 && !info[2].IsUndefined()) {
Expand All @@ -1597,12 +1600,15 @@ struct LinkFileAt : public FSWrapWorker<FileWrap>
}
virtual void Work()
{
int fd = _wrap->_fd;
CHECK_WRAP_FD(fd);

// gpfs_linkat() is the same as Linux linkat() but we need a new function because
// Linux will fail the linkat() if the file already exist and we want to replace it if it existed.
if (_replace_fd == 0) {
SYSCALL_OR_RETURN(dlsym_gpfs_linkat(_wrap->_fd, "", AT_FDCWD, _filepath.c_str(), AT_EMPTY_PATH));
if (_replace_fd >= 0) {
SYSCALL_OR_RETURN(dlsym_gpfs_linkatif(fd, "", AT_FDCWD, _filepath.c_str(), AT_EMPTY_PATH, _replace_fd));
} else {
SYSCALL_OR_RETURN(dlsym_gpfs_linkatif(_wrap->_fd, "", AT_FDCWD, _filepath.c_str(), AT_EMPTY_PATH, _replace_fd));
SYSCALL_OR_RETURN(dlsym_gpfs_linkat(fd, "", AT_FDCWD, _filepath.c_str(), AT_EMPTY_PATH));
}
}
};
Expand All @@ -1613,7 +1619,7 @@ struct UnlinkFileAt : public FSWrapWorker<FileWrap>
int _delete_fd;
UnlinkFileAt(const Napi::CallbackInfo& info)
: FSWrapWorker<FileWrap>(info)
, _delete_fd(0)
, _delete_fd(-1)
{
_filepath = info[1].As<Napi::String>();
if (info.Length() > 2 && !info[2].IsUndefined()) {
Expand All @@ -1623,7 +1629,9 @@ struct UnlinkFileAt : public FSWrapWorker<FileWrap>
}
virtual void Work()
{
SYSCALL_OR_RETURN(dlsym_gpfs_unlinkat(_wrap->_fd, _filepath.c_str(), _delete_fd));
int fd = _wrap->_fd;
CHECK_WRAP_FD(fd);
SYSCALL_OR_RETURN(dlsym_gpfs_unlinkat(fd, _filepath.c_str(), _delete_fd));
}
};

Expand Down
16 changes: 14 additions & 2 deletions src/sdk/nsfs_glacier_backend/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
const nb_native = require('../../util/nb_native');

class GlacierBackend {
static MIGRATE_TIMESTAMP_FILE = 'timestamp.migrate';
static RESTORE_TIMESTAMP_FILE = 'timestamp.restore';
// These names start with the word 'timestamp' so as to assure
// that it acts like a 'namespace' for the these kind of files.
//
// It also helps in making sure that the persistent logger does not
// 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 Expand Up @@ -149,6 +155,12 @@ class GlacierBackend {
stat.xattr[GlacierBackend.XATTR_RESTORE_REQUEST_STAGED]) {
return false;
}

// If there are no associated blocks with the file then skip
// the migration.
if (stat.blocks === 0) return false;

return true;
}

/**
Expand Down
Loading

0 comments on commit 3afa670

Please sign in to comment.