mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
1cf24c15b5
Summary: Add new fields to EdenConfig to control log rotation settings, and update edenfs_monitor to set up the log rotation strategy using these settings. Reviewed By: chadaustin Differential Revision: D20427271 fbshipit-source-id: 9960bdb6f4d077a4e21fb4a6209aa02ab21ad653
67 lines
1.4 KiB
C++
67 lines
1.4 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 <condition_variable>
|
|
#include <deque>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <thread>
|
|
|
|
#include <folly/File.h>
|
|
#include <folly/Synchronized.h>
|
|
|
|
#include "eden/fs/utils/PathFuncs.h"
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
class LogRotationStrategy;
|
|
|
|
class LogFile {
|
|
public:
|
|
LogFile(
|
|
const AbsolutePath& path,
|
|
size_t maxSize,
|
|
std::unique_ptr<LogRotationStrategy> rotationStrategy);
|
|
~LogFile();
|
|
|
|
/**
|
|
* Write data to the log file.
|
|
*
|
|
* If the full buffer was successfully written 0 is returned.
|
|
* Returns an errno value on failure.
|
|
*/
|
|
int write(const void* buffer, size_t size);
|
|
|
|
int fd() const {
|
|
return log_.fd();
|
|
}
|
|
|
|
private:
|
|
using RotateQueue = std::deque<std::optional<AbsolutePath>>;
|
|
|
|
void rotate();
|
|
folly::File mainThreadRotation();
|
|
void triggerBackgroundRotation(std::optional<AbsolutePath>&& path);
|
|
void runRotateThread();
|
|
|
|
AbsolutePath const path_;
|
|
folly::File log_;
|
|
size_t logSize_{0};
|
|
size_t maxLogSize_{100 * 1024 * 1024};
|
|
std::unique_ptr<LogRotationStrategy> const rotationStrategy_;
|
|
|
|
std::condition_variable rotationCV_;
|
|
folly::Synchronized<RotateQueue, std::mutex> rotationQueue_;
|
|
std::thread rotationThread_;
|
|
};
|
|
|
|
} // namespace eden
|
|
} // namespace facebook
|