2013-10-29 04:34:02 +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.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "rocksdb/options.h"
|
|
|
|
#include "rocksdb/table.h"
|
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
|
|
|
|
struct Options;
|
|
|
|
struct EnvOptions;
|
|
|
|
|
|
|
|
using std::unique_ptr;
|
|
|
|
class Status;
|
|
|
|
class RandomAccessFile;
|
|
|
|
class WritableFile;
|
|
|
|
class Table;
|
|
|
|
class TableBuilder;
|
|
|
|
|
|
|
|
// IndexedTable requires fixed length key, configured as a constructor
|
|
|
|
// parameter of the factory class. Output file format:
|
2013-12-20 18:35:24 +01:00
|
|
|
// +-------------+-----------------+
|
|
|
|
// | version | user_key_length |
|
|
|
|
// +------------++------------------------------+ <= key1 offset
|
|
|
|
// | [key_size] | key1 | value_size | |
|
|
|
|
// +------------+-------------+-------------+ |
|
2013-10-29 04:34:02 +01:00
|
|
|
// | value1 |
|
|
|
|
// | |
|
|
|
|
// +----------------------------------------+---+ <= key2 offset
|
2013-12-20 18:35:24 +01:00
|
|
|
// | [key_size] | key2 | value_size | |
|
|
|
|
// +------------+-------------+-------------+ |
|
2013-10-29 04:34:02 +01:00
|
|
|
// | value2 |
|
|
|
|
// | |
|
|
|
|
// | ...... |
|
|
|
|
// +-----------------+--------------------------+
|
2014-01-28 06:58:46 +01:00
|
|
|
// If user_key_length = kPlainTableVariableLength, it means the key is variable
|
|
|
|
// length, there will be an extra field for key size encoded before every key.
|
|
|
|
class PlainTableFactory : public TableFactory {
|
|
|
|
public:
|
|
|
|
~PlainTableFactory() {}
|
2013-12-20 18:35:24 +01:00
|
|
|
// user_key_size is the length of the user key. If it is set to be
|
2014-01-28 06:58:46 +01:00
|
|
|
// kPlainTableVariableLength, then it means variable length. Otherwise, all
|
|
|
|
// the keys need to have the fix length of this value. bloom_bits_per_key is
|
2013-11-22 08:33:45 +01:00
|
|
|
// number of bits used for bloom filer per key. hash_table_ratio is
|
2013-12-20 18:35:24 +01:00
|
|
|
// the desired utilization of the hash table used for prefix hashing.
|
2013-11-22 00:13:45 +01:00
|
|
|
// hash_table_ratio = number of prefixes / #buckets in the hash table
|
2014-01-28 06:58:46 +01:00
|
|
|
explicit PlainTableFactory(uint32_t user_key_len = kPlainTableVariableLength,
|
|
|
|
int bloom_bits_per_key = 0,
|
|
|
|
double hash_table_ratio = 0.75)
|
|
|
|
: user_key_len_(user_key_len),
|
|
|
|
bloom_bits_per_key_(bloom_bits_per_key),
|
|
|
|
hash_table_ratio_(hash_table_ratio) {}
|
|
|
|
const char* Name() const override { return "PlainTable"; }
|
|
|
|
Status NewTableReader(const Options& options, const EnvOptions& soptions,
|
2014-01-27 22:53:22 +01:00
|
|
|
const InternalKeyComparator& internal_comparator,
|
2014-01-28 06:58:46 +01:00
|
|
|
unique_ptr<RandomAccessFile>&& file, uint64_t file_size,
|
2013-10-29 04:34:02 +01:00
|
|
|
unique_ptr<TableReader>* table) const override;
|
2014-01-27 22:53:22 +01:00
|
|
|
TableBuilder* NewTableBuilder(const Options& options,
|
|
|
|
const InternalKeyComparator& icomparator,
|
|
|
|
WritableFile* file,
|
|
|
|
CompressionType compression_type) const
|
|
|
|
override;
|
2013-10-29 04:34:02 +01:00
|
|
|
|
2014-01-27 22:53:22 +01:00
|
|
|
static const char kValueTypeSeqId0 = 0xFF;
|
2013-12-20 18:35:24 +01:00
|
|
|
|
2014-01-28 06:58:46 +01:00
|
|
|
private:
|
2013-12-20 18:35:24 +01:00
|
|
|
uint32_t user_key_len_;
|
2014-01-28 06:58:46 +01:00
|
|
|
int bloom_bits_per_key_;
|
2013-11-22 00:13:45 +01:00
|
|
|
double hash_table_ratio_;
|
2013-10-29 04:34:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace rocksdb
|