2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// 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).
|
2013-10-16 23:59:46 +02:00
|
|
|
//
|
2011-03-18 23:37:00 +01:00
|
|
|
// 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
|
|
|
|
|
2013-10-05 07:32:05 +02:00
|
|
|
#pragma once
|
2011-03-18 23:37:00 +01:00
|
|
|
#include <stdint.h>
|
2014-07-02 18:54:20 +02:00
|
|
|
#include <unordered_map>
|
2011-03-18 23:37:00 +01:00
|
|
|
#include <string>
|
2014-07-02 18:54:20 +02:00
|
|
|
#include <vector>
|
2015-01-09 21:57:11 +01:00
|
|
|
|
2017-04-06 04:02:00 +02:00
|
|
|
#include "options/db_options.h"
|
2015-01-09 21:57:11 +01:00
|
|
|
#include "port/port.h"
|
|
|
|
#include "rocksdb/options.h"
|
2013-08-23 17:38:13 +02:00
|
|
|
#include "rocksdb/slice.h"
|
|
|
|
#include "rocksdb/status.h"
|
2013-10-24 08:39:23 +02:00
|
|
|
#include "rocksdb/transaction_log.h"
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
namespace rocksdb {
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
class Env;
|
2014-05-06 23:51:33 +02:00
|
|
|
class Directory;
|
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
2015-07-18 01:16:11 +02:00
|
|
|
class WritableFileWriter;
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
enum FileType {
|
|
|
|
kLogFile,
|
|
|
|
kDBLockFile,
|
|
|
|
kTableFile,
|
|
|
|
kDescriptorFile,
|
|
|
|
kCurrentFile,
|
|
|
|
kTempFile,
|
2012-12-17 20:26:59 +01:00
|
|
|
kInfoLogFile, // Either the current one, or an old one
|
2013-10-18 23:50:54 +02:00
|
|
|
kMetaDatabase,
|
2015-11-11 07:58:01 +01:00
|
|
|
kIdentityFile,
|
2017-04-18 21:00:36 +02:00
|
|
|
kOptionsFile,
|
|
|
|
kBlobFile
|
2011-03-18 23:37:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2017-04-18 21:00:36 +02:00
|
|
|
extern std::string BlobFileName(const std::string& bdirname, uint64_t number);
|
|
|
|
|
2018-08-31 20:59:49 +02:00
|
|
|
extern std::string BlobFileName(const std::string& dbname,
|
|
|
|
const std::string& blob_dir, uint64_t number);
|
|
|
|
|
2012-12-08 01:30:22 +01:00
|
|
|
static const std::string ARCHIVAL_DIR = "archive";
|
|
|
|
|
|
|
|
extern std::string ArchivalDirectory(const std::string& dbname);
|
|
|
|
|
2012-11-30 02:28:37 +01:00
|
|
|
// 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);
|
|
|
|
|
2014-07-02 18:54:20 +02:00
|
|
|
extern std::string MakeTableFileName(const std::string& name, uint64_t number);
|
|
|
|
|
2015-10-07 02:46:22 +02:00
|
|
|
// 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
2014-11-07 23:45:18 +01:00
|
|
|
// the reverse function of MakeTableFileName
|
|
|
|
// TODO(yhchiang): could merge this function with ParseFileName()
|
|
|
|
extern uint64_t TableFileNameToNumber(const std::string& name);
|
|
|
|
|
2011-03-18 23:37:00 +01:00
|
|
|
// Return the name of the sstable with the specified number
|
|
|
|
// in the db named by "dbname". The result will be prefixed with
|
|
|
|
// "dbname".
|
2014-07-15 00:34:30 +02:00
|
|
|
extern std::string TableFileName(const std::vector<DbPath>& db_paths,
|
2014-07-02 18:54:20 +02:00
|
|
|
uint64_t number, uint32_t path_id);
|
|
|
|
|
2014-08-13 20:57:40 +02:00
|
|
|
// Sufficient buffer size for FormatFileNumber.
|
2015-07-02 01:13:49 +02:00
|
|
|
const size_t kFormatFileNumberBufSize = 38;
|
2014-08-13 20:57:40 +02:00
|
|
|
|
|
|
|
extern void FormatFileNumber(uint64_t number, uint32_t path_id, char* out_buf,
|
|
|
|
size_t out_buf_size);
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2014-08-14 19:05:16 +02:00
|
|
|
// 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();
|
|
|
|
};
|
|
|
|
|
2011-03-18 23:37:00 +01:00
|
|
|
// Return the name of the info log file for "dbname".
|
2012-09-06 02:44:13 +02:00
|
|
|
extern std::string InfoLogFileName(const std::string& dbname,
|
2015-09-23 21:22:44 +02:00
|
|
|
const std::string& db_path = "",
|
|
|
|
const std::string& log_dir = "");
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
// Return the name of the old info log file for "dbname".
|
2012-09-06 02:44:13 +02:00
|
|
|
extern std::string OldInfoLogFileName(const std::string& dbname, uint64_t ts,
|
2015-09-23 21:22:44 +02:00
|
|
|
const std::string& db_path = "",
|
|
|
|
const std::string& log_dir = "");
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2015-11-11 07:58:01 +01:00
|
|
|
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);
|
|
|
|
|
2012-12-17 20:26:59 +01:00
|
|
|
// 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);
|
|
|
|
|
2013-10-18 23:50:54 +02:00
|
|
|
// 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);
|
|
|
|
|
2013-10-05 07:32:05 +02:00
|
|
|
// If filename is a rocksdb file, store the type of the file in *type.
|
2011-04-21 00:48:11 +02:00
|
|
|
// The number encoded in the filename is stored in *number. If the
|
|
|
|
// filename was successfully parsed, returns true. Else return false.
|
2014-08-14 19:05:16 +02:00
|
|
|
// 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,
|
2013-10-24 08:39:23 +02:00
|
|
|
WalFileType* log_type = nullptr);
|
2014-08-14 19:05:16 +02:00
|
|
|
// 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);
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
// Make the CURRENT file point to the descriptor file with the
|
|
|
|
// specified number.
|
|
|
|
extern Status SetCurrentFile(Env* env, const std::string& dbname,
|
2014-05-06 23:51:33 +02:00
|
|
|
uint64_t descriptor_number,
|
|
|
|
Directory* directory_to_fsync);
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2013-10-18 23:50:54 +02:00
|
|
|
// Make the IDENTITY file for the db
|
|
|
|
extern Status SetIdentityFile(Env* env, const std::string& dbname);
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2015-01-22 20:43:38 +01:00
|
|
|
// Sync manifest file `file`.
|
2016-09-24 01:34:04 +02:00
|
|
|
extern Status SyncManifest(Env* env, const ImmutableDBOptions* db_options,
|
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
2015-07-18 01:16:11 +02:00
|
|
|
WritableFileWriter* file);
|
2015-01-22 20:43:38 +01:00
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
} // namespace rocksdb
|