mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-25 22:44:05 +00:00
05e8854085
Summary: This diff introduces a new Merge operation into rocksdb. The purpose of this review is mostly getting feedback from the team (everyone please) on the design. Please focus on the four files under include/leveldb/, as they spell the client visible interface change. include/leveldb/db.h include/leveldb/merge_operator.h include/leveldb/options.h include/leveldb/write_batch.h Please go over local/my_test.cc carefully, as it is a concerete use case. Please also review the impelmentation files to see if the straw man implementation makes sense. Note that, the diff does pass all make check and truly supports forward iterator over db and a version of Get that's based on iterator. Future work: - Integration with compaction - A raw Get implementation I am working on a wiki that explains the design and implementation choices, but coding comes just naturally and I think it might be a good idea to share the code earlier. The code is heavily commented. Test Plan: run all local tests Reviewers: dhruba, heyongqiang Reviewed By: dhruba CC: leveldb, zshao, sheki, emayanke, MarkCallaghan Differential Revision: https://reviews.facebook.net/D9651
97 lines
2.7 KiB
C++
97 lines
2.7 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_UTILITIES_TTL_DB_TTL_H_
|
|
#define LEVELDB_UTILITIES_TTL_DB_TTL_H_
|
|
|
|
#include "include/leveldb/db.h"
|
|
#include "db/db_impl.h"
|
|
|
|
namespace leveldb {
|
|
|
|
class DBWithTTL : public DB {
|
|
public:
|
|
DBWithTTL(const int32_t ttl,
|
|
const Options& options,
|
|
const std::string& dbname,
|
|
Status& st);
|
|
|
|
virtual ~DBWithTTL();
|
|
|
|
virtual Status Put(const WriteOptions& o,
|
|
const Slice& key,
|
|
const Slice& val);
|
|
|
|
virtual Status Get(const ReadOptions& options,
|
|
const Slice& key,
|
|
std::string* value);
|
|
|
|
virtual Status Delete(const WriteOptions& wopts, const Slice& key);
|
|
|
|
virtual Status Merge(const WriteOptions& options,
|
|
const Slice& key,
|
|
const Slice& value);
|
|
|
|
|
|
virtual Status Write(const WriteOptions& opts, WriteBatch* updates);
|
|
|
|
virtual Iterator* NewIterator(const ReadOptions& opts);
|
|
|
|
virtual const Snapshot* GetSnapshot();
|
|
|
|
virtual void ReleaseSnapshot(const Snapshot* snapshot);
|
|
|
|
virtual bool GetProperty(const Slice& property, std::string* value);
|
|
|
|
virtual void GetApproximateSizes(const Range* r, int n, uint64_t* sizes);
|
|
|
|
virtual void CompactRange(const Slice* begin, const Slice* end);
|
|
|
|
virtual int NumberLevels();
|
|
|
|
virtual int MaxMemCompactionLevel();
|
|
|
|
virtual int Level0StopWriteTrigger();
|
|
|
|
virtual Status Flush(const FlushOptions& fopts);
|
|
|
|
virtual Status DisableFileDeletions();
|
|
|
|
virtual Status EnableFileDeletions();
|
|
|
|
virtual Status GetLiveFiles(std::vector<std::string>& vec, uint64_t* mfs);
|
|
|
|
virtual SequenceNumber GetLatestSequenceNumber();
|
|
|
|
virtual Status GetUpdatesSince(SequenceNumber seq_number,
|
|
unique_ptr<TransactionLogIterator>* iter);
|
|
|
|
// Simulate a db crash, no elegant closing of database.
|
|
void TEST_Destroy_DBWithTtl();
|
|
|
|
static bool DeleteByTS(void* args,
|
|
int level,
|
|
const Slice& key,
|
|
const Slice& old_val,
|
|
std::string* new_val,
|
|
bool* value_changed);
|
|
|
|
static bool IsStale(const Slice& value, int32_t ttl);
|
|
|
|
static Status AppendTS(const Slice& val, std::string& val_with_ts);
|
|
|
|
static Status StripTS(std::string* str);
|
|
|
|
static Status GetCurrentTime(int32_t& curtime);
|
|
|
|
static const int32_t kTSLength = sizeof(int32_t); // size of timestamp
|
|
|
|
private:
|
|
DB* db_;
|
|
int32_t ttl_;
|
|
};
|
|
|
|
}
|
|
#endif // LEVELDB_UTILITIES_TTL_DB_TTL_H_
|