sapling/eden/fs/inodes/FileHandle.h
Chad Austin 0c8f577cd8 close FileInode file handle when there are no open file handles
Summary:
In some workloads we're seeing folks run out of file descriptors.
We forgot that we'd taken out the code that closes the underlying fds.
This diff takes a run at adding a simple counter of the open file handle
objects that is incremented when they are constructed and decremented
when they are destroyed.

When the count falls to zero we release the file handle.

Note that we unconditionally open files when we first load the inodes
from the overlay.  I tried to defer that open attempt and it broke
the timestamp overlay test.  I think we can revisit that aspect in
a follow on diff; for now we should be more resilient to transiently
opened files from things like ripgrep or similar.

Reviewed By: simpkins

Differential Revision: D6097090

fbshipit-source-id: 9a48220002e760fb1ffb8d7e2a68fa7036558b78
2017-11-21 09:21:29 -08:00

45 lines
1.3 KiB
C++

/*
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#pragma once
#include "eden/fs/fuse/FileHandle.h"
#include "eden/fs/inodes/InodePtr.h"
namespace facebook {
namespace eden {
class Blob;
class FileInode;
class LocalStore;
class FileHandle : public fusell::FileHandle {
public:
explicit FileHandle(FileInodePtr inode);
~FileHandle() override;
fuse_ino_t getInodeNumber() override;
folly::Future<fusell::Dispatcher::Attr> getattr() override;
folly::Future<fusell::Dispatcher::Attr> setattr(
const struct stat& attr,
int to_set) override;
bool preserveCache() const override;
bool isSeekable() const override;
folly::Future<fusell::BufVec> read(size_t size, off_t off) override;
folly::Future<size_t> write(fusell::BufVec&& buf, off_t off) override;
folly::Future<size_t> write(folly::StringPiece data, off_t off) override;
folly::Future<folly::Unit> flush(uint64_t lock_owner) override;
folly::Future<folly::Unit> fsync(bool datasync) override;
private:
FileInodePtr inode_;
};
} // namespace eden
} // namespace facebook