Skip to content

Commit

Permalink
refactor: Apply code review suggestions
Browse files Browse the repository at this point in the history
Changes:
- rename old write algorithm to inode based write algorithm and new
write algorithm to chunk based write algorithm.
- update help message of sfsuseinodebasedwritealgorithm option. It was
made also to be explicitly 0|1. Update doc entry accordignly.
- change safs_* functions occurrences for the safs::* equivalent ones.
- rename gWaveTimeout to gWriteWaveTimeout.
- change the throws in write_data_truncate for regular returns. Old
code was using POSIX error codes sometimes and other times SaunaFS
ancestors error codes: the POSIX errors were normally returned and the
other ones were "thrown" up. Current codebase uses for this specific
case only SaunaFS error codes.
- Log the truncateend failures.
  • Loading branch information
dmga44 committed Dec 3, 2024
1 parent 3b89a90 commit 77c447c
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 85 deletions.
15 changes: 8 additions & 7 deletions doc/sfsmount.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,14 @@ Equivalent to *--nostdopts* (*-n*) option for use in fstab.
*-o nonempty*::
Equivalent to *--nonempty* option for use in fstab.

*-o sfsuseoldwritealgorithm*::
Use legacy write algorithm. Though new algorithm is faster in most cases, old
algorithm may prove useful in some scenarios.

*-o sfsignoreflush*'0|1'::
Advanced: use with caution. Ignore flush usual behavior by replying SUCCESS to it
immediately. Targets fast creation of small files, but may cause data loss
*-o sfsuseinodebasedwritealgorithm=*'0|1'::
Use inode based write algorithm when set to 1. Use chunk based write algorithm
when set to 0. Though chunk based algorithm is faster in most cases, inode
based algorithm may prove useful in some scenarios (default: 0).

*-o sfsignoreflush=*'0|1'::
Advanced: use with caution. Ignore flush usual behavior by replying SUCCESS to
it immediately. Targets fast creation of small files, but may cause data loss
during crashes when allegedly flushed data is still being processed (default: 0).

*-o sfsdirectio=*'0|1'::
Expand Down
3 changes: 2 additions & 1 deletion src/mount/fuse/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ static int mainloop(struct fuse_args *args, struct fuse_cmdline_opts *fuse_opts,
params.acl_cache_size = gMountOptions.aclcachesize;
params.debug_mode = gMountOptions.debug;
params.direct_io = gMountOptions.directio;
params.use_old_write_algorithm = gMountOptions.useoldwritealgorithm;
params.use_inode_based_write_algorithm =
gMountOptions.useinodebasedwritealgorithm;
params.ignore_flush = gMountOptions.ignoreflush;

if (!gMountOptions.meta) {
Expand Down
7 changes: 5 additions & 2 deletions src/mount/fuse/mount_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct fuse_opt gSfsOptsStage2[] = {
SFS_OPT("bandwidthoveruse=%lf", bandwidthoveruse, 1),
SFS_OPT("sfsdirentrycachesize=%u", direntrycachesize, 0),
SFS_OPT("nostdmountoptions", nostdmountoptions, 1),
SFS_OPT("sfsuseoldwritealgorithm", useoldwritealgorithm, 1),
SFS_OPT("sfsuseinodebasedwritealgorithm=%d", useinodebasedwritealgorithm, 0),
SFS_OPT("sfsignoreflush=%d", ignoreflush, 0),

SFS_OPT("enablefilelocks=%u", filelocks, 0),
Expand Down Expand Up @@ -172,7 +172,9 @@ void usage(const char *progname) {
" -o sfswriteworkers=N define number of write workers (default: %u)\n"
" -o sfswritewindowsize=N define write window size (in blocks) for "
"each chunk (default: %u)\n"
" -o sfsuseoldwritealgorithm use legacy write algorithm.\n"
" -o sfsuseinodebasedwritealgorithm=0|1 use inode based write algorithm when "
"set to 1. Use chunk based write algorithm when set to 0 "
"(default: %d)\n"
" -o sfsignoreflush=0|1 Advanced: use with caution. Ignore flush usual "
"behavior by replying SUCCESS to it immediately. Targets fast "
"creation of small files, but may cause data loss during crashes "
Expand Down Expand Up @@ -255,6 +257,7 @@ void usage(const char *progname) {
SaunaClient::FsInitParams::kDefaultCachePerInodePercentage,
SaunaClient::FsInitParams::kDefaultWriteWorkers,
SaunaClient::FsInitParams::kDefaultWriteWindowSize,
SaunaClient::FsInitParams::kDefaultUseInodeBasedWriteAlgorithm,
SaunaClient::FsInitParams::kDefaultIgnoreFlush,
SaunaClient::FsInitParams::kDefaultUseRwLock,
SaunaClient::FsInitParams::kDefaultMkdirCopySgid,
Expand Down
4 changes: 2 additions & 2 deletions src/mount/fuse/mount_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct sfsopts_ {
double bandwidthoveruse;
int nonemptymount;
bool directio;
int useoldwritealgorithm;
int useinodebasedwritealgorithm;
int ignoreflush;

sfsopts_()
Expand Down Expand Up @@ -174,7 +174,7 @@ struct sfsopts_ {
bandwidthoveruse(SaunaClient::FsInitParams::kDefaultBandwidthOveruse),
nonemptymount(SaunaClient::FsInitParams::kDefaultNonEmptyMounts),
directio(SaunaClient::FsInitParams::kDirectIO),
useoldwritealgorithm(SaunaClient::FsInitParams::kDefaultUseOldWriteAlgorithm),
useinodebasedwritealgorithm(SaunaClient::FsInitParams::kDefaultUseInodeBasedWriteAlgorithm),
ignoreflush(SaunaClient::FsInitParams::kDefaultIgnoreFlush)
{ }
};
Expand Down
2 changes: 1 addition & 1 deletion src/mount/sauna_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3497,7 +3497,7 @@ void fs_init(FsInitParams &params) {
params.prefetch_xor_stripes,
std::max(params.bandwidth_overuse, 1.));

gUseOldWriteAlgorithm = params.use_old_write_algorithm;
gUseInodeBasedWriteAlgorithm = params.use_inode_based_write_algorithm;
write_data_init(
params.write_cache_size, params.io_retries, params.write_workers,
params.write_window_size, params.chunkserver_write_timeout_ms,
Expand Down
8 changes: 4 additions & 4 deletions src/mount/sauna_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct FsInitParams {
static constexpr float kDefaultBandwidthOveruse = 1.0;
static constexpr unsigned kDefaultChunkserverWriteTo = 5000;
static constexpr bool kDefaultIgnoreFlush = false;
static constexpr bool kDefaultUseOldWriteAlgorithm = false;
static constexpr bool kDefaultUseInodeBasedWriteAlgorithm = false;
static constexpr unsigned kDefaultWriteCacheSize = 128;
#ifdef _WIN32
static constexpr unsigned kDefaultWriteWaveTo = 10;
Expand Down Expand Up @@ -152,7 +152,7 @@ struct FsInitParams {
#ifdef _WIN32
mounting_uid(USE_LOCAL_ID), mounting_gid(USE_LOCAL_ID),
#endif
use_old_write_algorithm(kDefaultUseOldWriteAlgorithm),
use_inode_based_write_algorithm(kDefaultUseInodeBasedWriteAlgorithm),
ignore_flush(kDefaultIgnoreFlush), verbose(kDefaultVerbose), direct_io(kDirectIO) {
}

Expand Down Expand Up @@ -187,7 +187,7 @@ struct FsInitParams {
#ifdef _WIN32
mounting_uid(USE_LOCAL_ID), mounting_gid(USE_LOCAL_ID),
#endif
use_old_write_algorithm(kDefaultUseOldWriteAlgorithm),
use_inode_based_write_algorithm(kDefaultUseInodeBasedWriteAlgorithm),
ignore_flush(kDefaultIgnoreFlush), verbose(kDefaultVerbose), direct_io(kDirectIO) {
}

Expand Down Expand Up @@ -241,7 +241,7 @@ struct FsInitParams {
std::unordered_set<uint32_t> allowed_users;
#endif

bool use_old_write_algorithm;
bool use_inode_based_write_algorithm;
bool ignore_flush;
bool verbose;
bool direct_io;
Expand Down
Loading

0 comments on commit 77c447c

Please sign in to comment.