74781a0c49
Summary: This patch adds three new MemTableRep's: UnsortedRep, PrefixHashRep, and VectorRep. UnsortedRep stores keys in an std::unordered_map of std::sets. When an iterator is requested, it dumps the keys into an std::set and iterates over that. VectorRep stores keys in an std::vector. When an iterator is requested, it creates a copy of the vector and sorts it using std::sort. The iterator accesses that new vector. PrefixHashRep stores keys in an unordered_map mapping prefixes to ordered sets. I also added one API change. I added a function MemTableRep::MarkImmutable. This function is called when the rep is added to the immutable list. It doesn't do anything yet, but it seems like that could be useful. In particular, for the vectorrep, it means we could elide the extra copy and just sort in place. The only reason I haven't done that yet is because the use of the ArenaAllocator complicates things (I can elaborate on this if needed). Test Plan: make -j32 check ./db_stress --memtablerep=vector ./db_stress --memtablerep=unsorted ./db_stress --memtablerep=prefixhash --prefix_size=10 Reviewers: dhruba, haobo, emayanke Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D12117
65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
// 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.
|
|
|
|
#ifndef LEVELDB_STORAGE_DB_DB_STATISTICS_H_
|
|
#define LEVELDB_STORAGE_DB_DB_STATISTICS_H_
|
|
|
|
#include <cassert>
|
|
#include <stdlib.h>
|
|
#include <vector>
|
|
#include <memory>
|
|
|
|
#include "leveldb/statistics.h"
|
|
#include "util/histogram.h"
|
|
#include "port/port.h"
|
|
#include "util/mutexlock.h"
|
|
|
|
|
|
namespace leveldb {
|
|
|
|
class DBStatistics: public Statistics {
|
|
public:
|
|
DBStatistics() : allTickers_(TICKER_ENUM_MAX),
|
|
allHistograms_(HISTOGRAM_ENUM_MAX) { }
|
|
|
|
virtual ~DBStatistics() {}
|
|
|
|
virtual long getTickerCount(Tickers tickerType) {
|
|
assert(tickerType < TICKER_ENUM_MAX);
|
|
return allTickers_[tickerType].getCount();
|
|
}
|
|
|
|
virtual void setTickerCount(Tickers tickerType, uint64_t count) {
|
|
assert(tickerType < TICKER_ENUM_MAX);
|
|
allTickers_[tickerType].setTickerCount(count);
|
|
}
|
|
|
|
virtual void recordTick(Tickers tickerType, uint64_t count) {
|
|
assert(tickerType < TICKER_ENUM_MAX);
|
|
allTickers_[tickerType].recordTick(count);
|
|
}
|
|
|
|
virtual void measureTime(Histograms histogramType, uint64_t value) {
|
|
assert(histogramType < HISTOGRAM_ENUM_MAX);
|
|
allHistograms_[histogramType].Add(value);
|
|
}
|
|
|
|
virtual void histogramData(Histograms histogramType,
|
|
HistogramData * const data) {
|
|
assert(histogramType < HISTOGRAM_ENUM_MAX);
|
|
allHistograms_[histogramType].Data(data);
|
|
}
|
|
|
|
std::vector<Ticker> allTickers_;
|
|
std::vector<HistogramImpl> allHistograms_;
|
|
};
|
|
|
|
std::shared_ptr<Statistics> CreateDBStatistics() {
|
|
return std::make_shared<DBStatistics>();
|
|
}
|
|
|
|
} // namespace leveldb
|
|
|
|
#endif // LEVELDB_STORAGE_DB_DB_STATISTICS_H_
|