|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// File names used by DB code
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "options/db_options.h"
|
|
|
|
#include "port/port.h"
|
|
|
|
#include "rocksdb/file_system.h"
|
|
|
|
#include "rocksdb/options.h"
|
|
|
|
#include "rocksdb/slice.h"
|
|
|
|
#include "rocksdb/status.h"
|
|
|
|
#include "rocksdb/transaction_log.h"
|
|
|
|
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
|
|
|
|
class Env;
|
|
|
|
class Directory;
|
|
|
|
class SystemClock;
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
9 years ago
|
|
|
class WritableFileWriter;
|
|
|
|
|
|
|
|
#ifdef OS_WIN
|
|
|
|
const char kFilePathSeparator = '\\';
|
|
|
|
#else
|
|
|
|
const char kFilePathSeparator = '/';
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Return the name of the log file with the specified number
|
|
|
|
// in the db named by "dbname". The result will be prefixed with
|
|
|
|
// "dbname".
|
|
|
|
extern std::string LogFileName(const std::string& dbname, uint64_t number);
|
|
|
|
|
|
|
|
extern std::string LogFileName(uint64_t number);
|
|
|
|
|
|
|
|
extern std::string BlobFileName(uint64_t number);
|
|
|
|
|
|
|
|
extern std::string BlobFileName(const std::string& bdirname, uint64_t number);
|
|
|
|
|
|
|
|
extern std::string BlobFileName(const std::string& dbname,
|
|
|
|
const std::string& blob_dir, uint64_t number);
|
|
|
|
|
|
|
|
static const std::string ARCHIVAL_DIR = "archive";
|
|
|
|
|
|
|
|
extern std::string ArchivalDirectory(const std::string& dbname);
|
|
|
|
|
|
|
|
// Return the name of the archived log file with the specified number
|
|
|
|
// in the db named by "dbname". The result will be prefixed with "dbname".
|
|
|
|
extern std::string ArchivedLogFileName(const std::string& dbname,
|
|
|
|
uint64_t num);
|
|
|
|
|
|
|
|
extern std::string MakeTableFileName(const std::string& name, uint64_t number);
|
|
|
|
|
|
|
|
extern std::string MakeTableFileName(uint64_t number);
|
|
|
|
|
|
|
|
// Return the name of sstable with LevelDB suffix
|
|
|
|
// created from RocksDB sstable suffixed name
|
|
|
|
extern std::string Rocks2LevelTableFileName(const std::string& fullname);
|
|
|
|
|
CompactFiles, EventListener and GetDatabaseMetaData
Summary:
This diff adds three sets of APIs to RocksDB.
= GetColumnFamilyMetaData =
* This APIs allow users to obtain the current state of a RocksDB instance on one column family.
* See GetColumnFamilyMetaData in include/rocksdb/db.h
= EventListener =
* A virtual class that allows users to implement a set of
call-back functions which will be called when specific
events of a RocksDB instance happens.
* To register EventListener, simply insert an EventListener to ColumnFamilyOptions::listeners
= CompactFiles =
* CompactFiles API inputs a set of file numbers and an output level, and RocksDB
will try to compact those files into the specified level.
= Example =
* Example code can be found in example/compact_files_example.cc, which implements
a simple external compactor using EventListener, GetColumnFamilyMetaData, and
CompactFiles API.
Test Plan:
listener_test
compactor_test
example/compact_files_example
export ROCKSDB_TESTS=CompactFiles
db_test
export ROCKSDB_TESTS=MetaData
db_test
Reviewers: ljin, igor, rven, sdong
Reviewed By: sdong
Subscribers: MarkCallaghan, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D24705
10 years ago
|
|
|
// the reverse function of MakeTableFileName
|
|
|
|
// TODO(yhchiang): could merge this function with ParseFileName()
|
|
|
|
extern uint64_t TableFileNameToNumber(const std::string& name);
|
|
|
|
|
|
|
|
// Return the name of the sstable with the specified number
|
|
|
|
// in the db named by "dbname". The result will be prefixed with
|
|
|
|
// "dbname".
|
|
|
|
extern std::string TableFileName(const std::vector<DbPath>& db_paths,
|
|
|
|
uint64_t number, uint32_t path_id);
|
|
|
|
|
|
|
|
// Sufficient buffer size for FormatFileNumber.
|
|
|
|
const size_t kFormatFileNumberBufSize = 38;
|
|
|
|
|
|
|
|
extern void FormatFileNumber(uint64_t number, uint32_t path_id, char* out_buf,
|
|
|
|
size_t out_buf_size);
|
|
|
|
|
|
|
|
// Return the name of the descriptor file for the db named by
|
|
|
|
// "dbname" and the specified incarnation number. The result will be
|
|
|
|
// prefixed with "dbname".
|
|
|
|
extern std::string DescriptorFileName(const std::string& dbname,
|
|
|
|
uint64_t number);
|
|
|
|
|
|
|
|
// Return the name of the current file. This file contains the name
|
|
|
|
// of the current manifest file. The result will be prefixed with
|
|
|
|
// "dbname".
|
|
|
|
extern std::string CurrentFileName(const std::string& dbname);
|
|
|
|
|
|
|
|
// Return the name of the lock file for the db named by
|
|
|
|
// "dbname". The result will be prefixed with "dbname".
|
|
|
|
extern std::string LockFileName(const std::string& dbname);
|
|
|
|
|
|
|
|
// Return the name of a temporary file owned by the db named "dbname".
|
|
|
|
// The result will be prefixed with "dbname".
|
|
|
|
extern std::string TempFileName(const std::string& dbname, uint64_t number);
|
|
|
|
|
|
|
|
// A helper structure for prefix of info log names.
|
|
|
|
struct InfoLogPrefix {
|
|
|
|
char buf[260];
|
|
|
|
Slice prefix;
|
|
|
|
// Prefix with DB absolute path encoded
|
|
|
|
explicit InfoLogPrefix(bool has_log_dir, const std::string& db_absolute_path);
|
|
|
|
// Default Prefix
|
|
|
|
explicit InfoLogPrefix();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Return the name of the info log file for "dbname".
|
|
|
|
extern std::string InfoLogFileName(const std::string& dbname,
|
|
|
|
const std::string& db_path = "",
|
|
|
|
const std::string& log_dir = "");
|
|
|
|
|
|
|
|
// Return the name of the old info log file for "dbname".
|
|
|
|
extern std::string OldInfoLogFileName(const std::string& dbname, uint64_t ts,
|
|
|
|
const std::string& db_path = "",
|
|
|
|
const std::string& log_dir = "");
|
|
|
|
|
|
|
|
static const std::string kOptionsFileNamePrefix = "OPTIONS-";
|
|
|
|
static const std::string kTempFileNameSuffix = "dbtmp";
|
|
|
|
|
|
|
|
// Return a options file name given the "dbname" and file number.
|
|
|
|
// Format: OPTIONS-[number].dbtmp
|
|
|
|
extern std::string OptionsFileName(const std::string& dbname,
|
|
|
|
uint64_t file_num);
|
|
|
|
|
|
|
|
// Return a temp options file name given the "dbname" and file number.
|
|
|
|
// Format: OPTIONS-[number]
|
|
|
|
extern std::string TempOptionsFileName(const std::string& dbname,
|
|
|
|
uint64_t file_num);
|
|
|
|
|
|
|
|
// Return the name to use for a metadatabase. The result will be prefixed with
|
|
|
|
// "dbname".
|
|
|
|
extern std::string MetaDatabaseName(const std::string& dbname,
|
|
|
|
uint64_t number);
|
|
|
|
|
|
|
|
// Return the name of the Identity file which stores a unique number for the db
|
|
|
|
// that will get regenerated if the db loses all its data and is recreated fresh
|
|
|
|
// either from a backup-image or empty
|
|
|
|
extern std::string IdentityFileName(const std::string& dbname);
|
|
|
|
|
|
|
|
// If filename is a rocksdb file, store the type of the file in *type.
|
|
|
|
// The number encoded in the filename is stored in *number. If the
|
|
|
|
// filename was successfully parsed, returns true. Else return false.
|
|
|
|
// info_log_name_prefix is the path of info logs.
|
|
|
|
extern bool ParseFileName(const std::string& filename, uint64_t* number,
|
|
|
|
const Slice& info_log_name_prefix, FileType* type,
|
|
|
|
WalFileType* log_type = nullptr);
|
|
|
|
// Same as previous function, but skip info log files.
|
|
|
|
extern bool ParseFileName(const std::string& filename, uint64_t* number,
|
|
|
|
FileType* type, WalFileType* log_type = nullptr);
|
|
|
|
|
|
|
|
// Make the CURRENT file point to the descriptor file with the
|
|
|
|
// specified number.
|
Pass IOStatus to write path and set retryable IO Error as hard error in BG jobs (#6487)
Summary:
In the current code base, we use Status to get and store the returned status from the call. Specifically, for IO related functions, the current Status cannot reflect the IO Error details such as error scope, error retryable attribute, and others. With the implementation of https://github.com/facebook/rocksdb/issues/5761, we have the new Wrapper for IO, which returns IOStatus instead of Status. However, the IOStatus is purged at the lower level of write path and transferred to Status.
The first job of this PR is to pass the IOStatus to the write path (flush, WAL write, and Compaction). The second job is to identify the Retryable IO Error as HardError, and set the bg_error_ as HardError. In this case, the DB Instance becomes read only. User is informed of the Status and need to take actions to deal with it (e.g., call db->Resume()).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6487
Test Plan: Added the testing case to error_handler_fs_test. Pass make asan_check
Reviewed By: anand1976
Differential Revision: D20685017
Pulled By: zhichao-cao
fbshipit-source-id: ff85f042896243abcd6ef37877834e26f36b6eb0
5 years ago
|
|
|
extern IOStatus SetCurrentFile(FileSystem* fs, const std::string& dbname,
|
|
|
|
uint64_t descriptor_number,
|
|
|
|
FSDirectory* directory_to_fsync);
|
|
|
|
|
|
|
|
// Make the IDENTITY file for the db
|
|
|
|
extern Status SetIdentityFile(Env* env, const std::string& dbname,
|
|
|
|
const std::string& db_id = {});
|
|
|
|
|
|
|
|
// Sync manifest file `file`.
|
|
|
|
extern IOStatus SyncManifest(const std::shared_ptr<SystemClock>& clock,
|
|
|
|
const ImmutableDBOptions* db_options,
|
Pass IOStatus to write path and set retryable IO Error as hard error in BG jobs (#6487)
Summary:
In the current code base, we use Status to get and store the returned status from the call. Specifically, for IO related functions, the current Status cannot reflect the IO Error details such as error scope, error retryable attribute, and others. With the implementation of https://github.com/facebook/rocksdb/issues/5761, we have the new Wrapper for IO, which returns IOStatus instead of Status. However, the IOStatus is purged at the lower level of write path and transferred to Status.
The first job of this PR is to pass the IOStatus to the write path (flush, WAL write, and Compaction). The second job is to identify the Retryable IO Error as HardError, and set the bg_error_ as HardError. In this case, the DB Instance becomes read only. User is informed of the Status and need to take actions to deal with it (e.g., call db->Resume()).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6487
Test Plan: Added the testing case to error_handler_fs_test. Pass make asan_check
Reviewed By: anand1976
Differential Revision: D20685017
Pulled By: zhichao-cao
fbshipit-source-id: ff85f042896243abcd6ef37877834e26f36b6eb0
5 years ago
|
|
|
WritableFileWriter* file);
|
|
|
|
|
|
|
|
// Return list of file names of info logs in `file_names`.
|
|
|
|
// The list only contains file name. The parent directory name is stored
|
|
|
|
// in `parent_dir`.
|
|
|
|
// `db_log_dir` should be the one as in options.db_log_dir
|
|
|
|
extern Status GetInfoLogFiles(const std::shared_ptr<FileSystem>& fs,
|
|
|
|
const std::string& db_log_dir,
|
|
|
|
const std::string& dbname,
|
|
|
|
std::string* parent_dir,
|
|
|
|
std::vector<std::string>* file_names);
|
|
|
|
|
|
|
|
extern std::string NormalizePath(const std::string& path);
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|