Skip to content

Commit

Permalink
feat: Add sfsuseoldwritealgorithm option
Browse files Browse the repository at this point in the history
This commit also contains the changes to make this feature possible:
- align the write related structures to make them the same for both
algorithms.
- take old write algorithm code and put it into the writedata.cc file.
- wire the option as usual.
  • Loading branch information
dmga44 committed Oct 22, 2024
1 parent 837a1b4 commit a864651
Show file tree
Hide file tree
Showing 10 changed files with 1,089 additions and 21 deletions.
4 changes: 4 additions & 0 deletions doc/sfsmount.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ 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*::
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
Expand Down
21 changes: 10 additions & 11 deletions src/mount/chunk_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,11 @@ bool ChunkWriter::Operation::isFullStripe(uint32_t stripeSize) const {
return (journalPositions.size() == elementsInStripe);
}

ChunkWriter::ChunkWriter(uint32_t chunkIndex,
ChunkserverStats &chunkserverStats,
ChunkWriter::ChunkWriter(ChunkserverStats &chunkserverStats,
ChunkConnector &connector, int dataChainFd)
: chunkserverStats_(chunkserverStats),
connector_(connector),
dataChainFd_(dataChainFd),
chunkIndex_(chunkIndex) {
}
: chunkserverStats_(chunkserverStats),
connector_(connector),
dataChainFd_(dataChainFd) {}

ChunkWriter::~ChunkWriter() {
try {
Expand Down Expand Up @@ -458,7 +455,8 @@ void ChunkWriter::fillNotExisting(Operation &operation, int first_block,
// Fills not existing blocks with zeroes
for (int index = beyond_start; index < beyond_start + blocks_number;
++index) {
WriteCacheBlock block(chunkIndex_, index, WriteCacheBlock::kReadBlock);
WriteCacheBlock block(locator_->chunkIndex(), index,
WriteCacheBlock::kReadBlock);
memset(block.data(), 0, SFSBLOCKSIZE);
block.from = block_from;
block.to = block_to;
Expand Down Expand Up @@ -573,8 +571,8 @@ void ChunkWriter::startOperation(Operation operation) {
continue;
}

operation.parityBuffers.push_back(
WriteCacheBlock(chunkIndex_, 0, WriteCacheBlock::kParityBlock));
operation.parityBuffers.push_back(WriteCacheBlock(
locator_->chunkIndex(), 0, WriteCacheBlock::kParityBlock));
WriteCacheBlock &block = operation.parityBuffers.back();
parity_blocks.push_back(&block);
blocks_to_write.push_back(&block);
Expand Down Expand Up @@ -660,7 +658,8 @@ void ChunkWriter::readBlocks(int block_index, int size, int block_from, int bloc
for (int index = block_index; index < block_index + size; ++index) {
assert(index < SFSBLOCKSINCHUNK);

WriteCacheBlock block(chunkIndex_, index, WriteCacheBlock::kReadBlock);
WriteCacheBlock block(locator_->chunkIndex(), index,
WriteCacheBlock::kReadBlock);
memcpy(block.data(), buffer.data() + offset, SFSBLOCKSIZE);
block.from = block_from;
block.to = block_to;
Expand Down
6 changes: 2 additions & 4 deletions src/mount/chunk_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ class ChunkWriter {
/**
* Constructor
*
* \param chunkIndex - index of the chunk within the inode the ChunkWriter will be writing.
* \param stats - database which will be updated by the object when accessing servers
* \param connector - object that will be used to create connection with chunkservers
* to write to them and read from them
* \param dataChainFd - end of pipe; if anything is written to it, ChunkWriter will break its
* poll call and look for some new data in write cache for the currently written chunk
*/
ChunkWriter(uint32_t chunkIndex, ChunkserverStats &stats,
ChunkConnector &connector, int dataChainFd);
ChunkWriter(ChunkserverStats &stats, ChunkConnector &connector,
int dataChainFd);
ChunkWriter(const ChunkWriter&) = delete;
~ChunkWriter();
ChunkWriter& operator=(const ChunkWriter&) = delete;
Expand Down Expand Up @@ -183,7 +182,6 @@ class ChunkWriter {
int combinedStripeSize_ = 0;
int dataChainFd_;
int chunkSizeInBlocks_;
uint32_t chunkIndex_;

std::map<int, std::unique_ptr<WriteExecutor>> executors_;
std::list<WriteCacheBlock> journal_;
Expand Down
1 change: 1 addition & 0 deletions src/mount/fuse/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ 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.ignore_flush = gMountOptions.ignoreflush;

if (!gMountOptions.meta) {
Expand Down
2 changes: 2 additions & 0 deletions src/mount/fuse/mount_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +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("sfsignoreflush", ignoreflush, 1),

SFS_OPT("enablefilelocks=%u", filelocks, 0),
Expand Down Expand Up @@ -171,6 +172,7 @@ 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 sfsignoreflush 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.\n"
Expand Down
2 changes: 2 additions & 0 deletions src/mount/fuse/mount_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ struct sfsopts_ {
double bandwidthoveruse;
int nonemptymount;
bool directio;
int useoldwritealgorithm;
int ignoreflush;

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

gUseOldWriteAlgorithm = params.use_old_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
4 changes: 4 additions & 0 deletions src/mount/sauna_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +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 unsigned kDefaultWriteCacheSize = 128;
#ifdef _WIN32
static constexpr unsigned kDefaultWriteWaveTo = 10;
Expand Down Expand Up @@ -151,6 +152,7 @@ struct FsInitParams {
#ifdef _WIN32
mounting_uid(USE_LOCAL_ID), mounting_gid(USE_LOCAL_ID),
#endif
use_old_write_algorithm(kDefaultUseOldWriteAlgorithm),
ignore_flush(kDefaultIgnoreFlush), verbose(kDefaultVerbose), direct_io(kDirectIO) {
}

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

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

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

0 comments on commit a864651

Please sign in to comment.