]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Expose statistic for sequence number and implement setTickerCount
authorMayank Agarwal <amayank@fb.com>
Fri, 16 Aug 2013 05:06:26 +0000 (22:06 -0700)
committerMayank Agarwal <amayank@fb.com>
Fri, 16 Aug 2013 06:00:20 +0000 (23:00 -0700)
Summary: statistic for sequence number is needed by wormhole. setTickerCount is demanded for this statistic. I can't simply recordTick(max_sequence) when db recovers because the statistic iobject is owned by client and may/may not be reset during reopen. Eg. statistic is reset in mcrocksdb whereas it is not in db_stress. Therefore it is best to go with setTickerCount

Test Plan: ./db_stress ... --statistics=1 and observed expected sequence number

Reviewers: dhruba

CC: leveldb
Differential Revision: https://reviews.facebook.net/D12327

db/db_impl.cc
db/db_statistics.h
include/leveldb/statistics.h

index e72445183b72ea757866827ea655a6677c88b655..f2351037b9e6e9f36a4fe3e9c583e50f0e52e567 100644 (file)
@@ -643,6 +643,8 @@ Status DBImpl::Recover(VersionEdit* edit, MemTable* external_table,
       } else {
         last_flushed_sequence_ = versions_->LastSequence();
       }
+      SetTickerCount(options_.statistics, SEQUENCE_NUMBER,
+                     versions_->LastSequence());
     }
   }
 
@@ -2448,6 +2450,7 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
           // have succeeded in memtable but Status reports error for all writes.
           throw std::runtime_error("In memory WriteBatch corruption!");
         }
+        RecordTick(options_.statistics, SEQUENCE_NUMBER, my_batch_count);
         versions_->SetLastSequence(last_sequence);
         last_flushed_sequence_ = current_sequence;
       }
index 9f2d93ef28b342757a4b70d575317f3860b7bf59..725b7579811a1b45a1e625f2c8624d5439a16fd4 100644 (file)
@@ -30,6 +30,11 @@ class DBStatistics: public Statistics {
     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);
index e214c2befafad5f2b4ffeed7af68977053ec51ee..9a36ffccf5a56cf3e058dbdf2a873cf58e3222bd 100644 (file)
@@ -59,10 +59,10 @@ enum Tickers {
   NUMBER_MULTIGET_BYTES_READ = 20,
 
   NUMBER_FILTERED_DELETES = 21,
-
   NUMBER_MERGE_FAILURES = 22,
+  SEQUENCE_NUMBER = 23,
 
-  TICKER_ENUM_MAX = 23
+  TICKER_ENUM_MAX = 24
 };
 
 const std::vector<std::pair<Tickers, std::string>> TickersNameMap = {
@@ -88,7 +88,8 @@ const std::vector<std::pair<Tickers, std::string>> TickersNameMap = {
   { NUMBER_MULTIGET_KEYS_READ, "rocksdb.number.multiget.keys.read" },
   { NUMBER_MULTIGET_BYTES_READ, "rocksdb.number.multiget.bytes.read" },
   { NUMBER_FILTERED_DELETES, "rocksdb.number.deletes.filtered" },
-  { NUMBER_MERGE_FAILURES, "rocksdb.number.merge.failures" }
+  { NUMBER_MERGE_FAILURES, "rocksdb.number.merge.failures" },
+  { SEQUENCE_NUMBER, "rocksdb.sequence.number" }
 };
 
 /**
@@ -179,11 +180,11 @@ class Ticker {
  public:
   Ticker() : count_(0) { }
 
inline void recordTick() {
-    count_++;
 inline void setTickerCount(uint64_t count) {
+    count_ = count;
   }
 
-  inline void recordTick(int count) {
+  inline void recordTick(int count = 1) {
     count_ += count;
   }
 
@@ -201,6 +202,7 @@ class Statistics {
 
   virtual long getTickerCount(Tickers tickerType) = 0;
   virtual void recordTick(Tickers tickerType, uint64_t count = 0) = 0;
+  virtual void setTickerCount(Tickers tickerType, uint64_t count) = 0;
   virtual void measureTime(Histograms histogramType, uint64_t time) = 0;
 
   virtual void histogramData(Histograms type, HistogramData * const data) = 0;
@@ -221,6 +223,17 @@ inline void RecordTick(std::shared_ptr<Statistics> statistics,
     statistics->recordTick(ticker, count);
   }
 }
+
+inline void SetTickerCount(std::shared_ptr<Statistics> statistics,
+                           Tickers ticker,
+                           uint64_t count) {
+  assert(HistogramsNameMap.size() == HISTOGRAM_ENUM_MAX);
+  assert(TickersNameMap.size() == TICKER_ENUM_MAX);
+  if (statistics) {
+    statistics->setTickerCount(ticker, count);
+  }
+}
+
 }  // namespace leveldb
 
 #endif  // STORAGE_LEVELDB_INCLUDE_STATISTICS_H_