memory manage statistics

Summary:
Earlier Statistics object was a raw pointer. This meant the user had to clear up
the Statistics object after creating the database. In most use cases the database is created in a function and the statistics pointer is out of scope. Hence the statistics object would never be deleted.
Now Using a shared_ptr to manage this.

Want this in before the next release.

Test Plan: make all check.

Reviewers: dhruba, emayanke

Reviewed By: emayanke

CC: leveldb

Differential Revision: https://reviews.facebook.net/D9735
This commit is contained in:
Abhishek Kona
2013-03-27 11:27:39 -07:00
parent ecd8db0200
commit 63f216ee0a
8 changed files with 15 additions and 23 deletions

View File

@@ -11,6 +11,7 @@
#include <vector>
#include <stdint.h>
#include "leveldb/slice.h"
#include "leveldb/statistics.h"
namespace leveldb {
@@ -20,7 +21,6 @@ class Env;
class FilterPolicy;
class Logger;
class Snapshot;
class Statistics;
using std::shared_ptr;
@@ -258,7 +258,7 @@ struct Options {
// If non-null, then we should collect metrics about database operations
// Statistics objects should not be shared between DB instances as
// it does not use any locks to prevent concurrent updates.
Statistics* statistics;
shared_ptr<Statistics> statistics;
// If true, then the contents of data files are not synced
// to stable storage. Their contents remain in the OS buffers till the

View File

@@ -124,10 +124,10 @@ class Statistics {
};
// Ease of Use functions
inline void RecordTick(Statistics* const statistics,
inline void RecordTick(std::shared_ptr<Statistics> statistics,
Tickers ticker,
uint64_t count = 1) {
if (statistics != nullptr) {
if (statistics) {
statistics->recordTick(ticker, count);
}
}