Skip to content

Conversation

@e673
Copy link
Collaborator

@e673 e673 commented Nov 26, 2025

#1751

Linux behavior

  1. All read/write requests are sequenced, newest requests should observe the effects of completed previous requests no matter of whether O_DIRECT flag is set or not.
  2. Flag O_DIRECT only instructs that the data cannot be read from or written to a cache:

Note: O_DIRECT flag is a non-POSIX feature so we should follow Linux behavior.

Current behavior in filestore

  • Direct read: ignore O_DIRECT flag and read from cache. The read data is consistent but this breaks rule 2.
  • Direct write: bypass cache. This breaks rule 1 as the data in the cache is not invalidated nor updated and subsequent reads may return wrong data.

Proposed behavior

Add new state for WriteDataEntryPendingDirect, indicating that the request has O_DIRECT flag and cannot become cached. These requests share the same pending queue with non-direct requests. Queue rules make processing direct and non-direct requests mutually exclusive:

  • PendingDirect requests wait until all cached requests are flushed, and then they go directly to the session;
  • Cached requests cannot be flushed until all direct requests are completed.
    Note: cache invalidation is not an acceptable option here as it may result in data corruption.

For ReadData requests — the same logic as for write requests:

  • Pending direct read requests cannot be executed while there are cached write requests;
  • Cached write requests cannot be flushed until all direct requests are completed.

Additional: presence of direct requests in the pending queue trigger Flush immediately for the node.

@e673 e673 requested a review from SvartMetal November 26, 2025 12:44

struct TReadRequest
: public TRequestBase<fuse_read_in, ui32, ui32>
: public TRequestBase<fuse_read_in, void, ui32>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Странно, но этот код вообще нигде не тестировался.
Операция FUSE_READ не возвращает число прочитанных байт, а сразу содержит буфер переменного размера.
https://github.com/libfuse/libfuse/blob/ab5033f5d1bd1630870dc725eb3eae6ef3ef4859/doc/libfuse-operations.txt#L115

@github-actions
Copy link
Contributor

Note

This is an automated comment that will be appended during run.

🟢 linux-x86_64-relwithdebinfo: all tests PASSED for commit 3c8a757.

TESTS PASSED ERRORS FAILED FAILED BUILD SKIPPED MUTED?
9623 9622 0 0 0 1 0

@e673 e673 marked this pull request as draft November 26, 2025 16:59

TFuture<NProto::TReadDataResponse> future;
if (WriteBackCache) {
if (useWriteBackCache) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldUseServerWriteBackCache or ShouldUseServerWriteBackCache(fi) in place


bootstrap.Service->ReadDataHandler = [&] (auto, auto) {
NProto::TReadDataResponse result;
*result.MutableBuffer() = TString("direct_data");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest to use as in other places "result.MutableBuffer()->assign", just for consistency


{
// write request without O_DIRECT should go to write-back cache
auto reqWrite = std::make_shared<TWriteRequest>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add counter to writedatahandler and check it explicitly in test?

reinterpret_cast<const char*>(reqRead->Out->Data()),
rspRead.GetValue());

UNIT_ASSERT_VALUES_EQUAL("cached_data", readData);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check counter in handler? blow as well

@e673 e673 changed the title issue-1751: Read requests with O_DIRECT should bypass write-back cache issue-1751: Make behavior for read/write requests with O_DIRECT consistent with Linux behavior for write-back cache Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants