sapling/eden/fs/prjfs/PrjfsDispatcher.h
Xavier Deguillard 87ef50135e prjfs: make readdir more asynchronous
Summary:
The makeImmediateFuture is merely a glorified try/catch, and thus the entirety
of the readdir callback would run immediately, and would block on every size
sequentially. This is inefficient and may cause files to be fetched one at a time.

By reworking the inner logic, we can collect all the sizes beforehand prior to
servicing the callback, allowing for sizes to be fetched concurrently, and for
completing the callback asynchronously.

Reviewed By: chadaustin

Differential Revision: D31782916

fbshipit-source-id: d6315347492e969ffa79037dc2a4f275f4b95a8d
2021-11-05 12:55:58 -07:00

125 lines
2.9 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#pragma once
#include "folly/portability/Windows.h"
#include <ProjectedFSLib.h> // @manual
#include "eden/fs/prjfs/Enumerator.h"
#include "eden/fs/utils/Guid.h"
#include "eden/fs/utils/PathFuncs.h"
namespace facebook::eden {
class ObjectFetchContext;
class EdenStats;
template <class T>
class ImmediateFuture;
struct InodeMetadata {
// To ensure that the OS has a record of the canonical file name, and not
// just whatever case was used to lookup the file, we capture the
// relative path here.
RelativePath path;
size_t size;
bool isDir;
};
struct LookupResult {
InodeMetadata meta;
folly::Function<void()> incFsRefcount;
};
class PrjfsDispatcher {
public:
virtual ~PrjfsDispatcher();
explicit PrjfsDispatcher(EdenStats* stats);
EdenStats* getStats() const;
/**
* Open a directory
*/
virtual ImmediateFuture<std::vector<PrjfsDirEntry>> opendir(
RelativePath path,
ObjectFetchContext& context) = 0;
/**
* Lookup the specified file and get its attributes.
*/
virtual ImmediateFuture<std::optional<LookupResult>> lookup(
RelativePath path,
ObjectFetchContext& context) = 0;
/**
* Test if a file with the given name exist
*/
virtual ImmediateFuture<bool> access(
RelativePath path,
ObjectFetchContext& context) = 0;
/**
* Read the file with the given name
*
* Returns the entire content of the file at path.
*
* In the future, this will return only what's in between offset and
* offset+length.
*/
virtual ImmediateFuture<std::string> read(
RelativePath path,
ObjectFetchContext& context) = 0;
/**
* Notification sent when a file was created
*/
virtual ImmediateFuture<folly::Unit> fileCreated(
RelativePath path,
ObjectFetchContext& context) = 0;
/**
* Notification sent when a directory was created
*/
virtual ImmediateFuture<folly::Unit> dirCreated(
RelativePath path,
ObjectFetchContext& context) = 0;
/**
* Notification sent when a file has been modified
*/
virtual ImmediateFuture<folly::Unit> fileModified(
RelativePath relPath,
ObjectFetchContext& context) = 0;
/**
* Notification sent when a file is renamed
*/
virtual ImmediateFuture<folly::Unit> fileRenamed(
RelativePath oldPath,
RelativePath newPath,
ObjectFetchContext& context) = 0;
/**
* Notification sent when a file was removed
*/
virtual ImmediateFuture<folly::Unit> fileDeleted(
RelativePath relPath,
ObjectFetchContext& context) = 0;
/**
* Notification sent when a directory was removed
*/
virtual ImmediateFuture<folly::Unit> dirDeleted(
RelativePath relPath,
ObjectFetchContext& context) = 0;
private:
EdenStats* stats_{nullptr};
};
} // namespace facebook::eden