mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-25 22:44:05 +00:00
12f1137355
Summary: Introduces and uses a SystemClock class to RocksDB. This class contains the time-related functions of an Env and these functions can be redirected from the Env to the SystemClock. Many of the places that used an Env (Timer, PerfStepTimer, RepeatableThread, RateLimiter, WriteController) for time-related functions have been changed to use SystemClock instead. There are likely more places that can be changed, but this is a start to show what can/should be done. Over time it would be nice to migrate most (if not all) of the uses of the time functions from the Env to the SystemClock. There are several Env classes that implement these functions. Most of these have not been converted yet to SystemClock implementations; that will come in a subsequent PR. It would be good to unify many of the Mock Timer implementations, so that they behave similarly and be tested similarly (some override Sleep, some use a MockSleep, etc). Additionally, this change will allow new methods to be introduced to the SystemClock (like https://github.com/facebook/rocksdb/issues/7101 WaitFor) in a consistent manner across a smaller number of classes. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7858 Reviewed By: pdillinger Differential Revision: D26006406 Pulled By: mrambacher fbshipit-source-id: ed10a8abbdab7ff2e23d69d85bd25b3e7e899e90
68 lines
1.7 KiB
C++
68 lines
1.7 KiB
C++
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
//
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
//
|
|
// Logger implementation that can be shared by all environments
|
|
// where enough posix functionality is available.
|
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <windows.h>
|
|
|
|
#include <atomic>
|
|
#include <memory>
|
|
|
|
#include "rocksdb/env.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
class SystemClock;
|
|
|
|
namespace port {
|
|
|
|
class WinLogger : public ROCKSDB_NAMESPACE::Logger {
|
|
public:
|
|
WinLogger(uint64_t (*gettid)(), const std::shared_ptr<SystemClock>& clock,
|
|
HANDLE file,
|
|
const InfoLogLevel log_level = InfoLogLevel::ERROR_LEVEL);
|
|
|
|
virtual ~WinLogger();
|
|
|
|
WinLogger(const WinLogger&) = delete;
|
|
|
|
WinLogger& operator=(const WinLogger&) = delete;
|
|
|
|
void Flush() override;
|
|
|
|
using ROCKSDB_NAMESPACE::Logger::Logv;
|
|
void Logv(const char* format, va_list ap) override;
|
|
|
|
size_t GetLogFileSize() const override;
|
|
|
|
void DebugWriter(const char* str, int len);
|
|
|
|
protected:
|
|
|
|
Status CloseImpl() override;
|
|
|
|
private:
|
|
HANDLE file_;
|
|
uint64_t (*gettid_)(); // Return the thread id for the current thread
|
|
std::atomic_size_t log_size_;
|
|
std::atomic_uint_fast64_t last_flush_micros_;
|
|
std::shared_ptr<SystemClock> clock_;
|
|
bool flush_pending_;
|
|
|
|
Status CloseInternal();
|
|
|
|
const static uint64_t flush_every_seconds_ = 5;
|
|
};
|
|
}
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|