Skip to content

Commit 65fba4b

Browse files
author
Ankit Gupta
committed
Merge branch 'master' of https://github.com/facebook/rocksdb
2 parents 0e4e4db + 91ef2ea commit 65fba4b

21 files changed

+372
-316
lines changed

db/c.cc

+14
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,20 @@ rocksdb_t* rocksdb_open(
330330
return result;
331331
}
332332

333+
rocksdb_t* rocksdb_open_for_read_only(
334+
const rocksdb_options_t* options,
335+
const char* name,
336+
unsigned char error_if_log_file_exist,
337+
char** errptr) {
338+
DB* db;
339+
if (SaveError(errptr, DB::OpenForReadOnly(options->rep, std::string(name), &db, error_if_log_file_exist))) {
340+
return nullptr;
341+
}
342+
rocksdb_t* result = new rocksdb_t;
343+
result->rep = db;
344+
return result;
345+
}
346+
333347
void rocksdb_close(rocksdb_t* db) {
334348
delete db->rep;
335349
delete db;

db/db_test.cc

-4
Original file line numberDiff line numberDiff line change
@@ -5555,9 +5555,6 @@ TEST(DBTest, TransactionLogIteratorMoveOverZeroFiles) {
55555555
} while (ChangeCompactOptions());
55565556
}
55575557

5558-
// TODO(kailiu) disable the in non-linux platforms to temporarily solve
5559-
// // the unit test failure.
5560-
#ifdef OS_LINUX
55615558
TEST(DBTest, TransactionLogIteratorStallAtLastRecord) {
55625559
do {
55635560
Options options = OptionsForLogIterTest();
@@ -5575,7 +5572,6 @@ TEST(DBTest, TransactionLogIteratorStallAtLastRecord) {
55755572
ASSERT_TRUE(iter->Valid());
55765573
} while (ChangeCompactOptions());
55775574
}
5578-
#endif
55795575

55805576
TEST(DBTest, TransactionLogIteratorJustEmptyFile) {
55815577
do {

db/merge_test.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "db/write_batch_internal.h"
1818
#include "utilities/merge_operators.h"
1919
#include "util/testharness.h"
20-
#include "utilities/utility_db.h"
20+
#include "utilities/db_ttl.h"
2121

2222
using namespace std;
2323
using namespace rocksdb;
@@ -80,7 +80,6 @@ std::shared_ptr<DB> OpenDb(const string& dbname, const bool ttl = false,
8080
const size_t max_successive_merges = 0,
8181
const uint32_t min_partial_merge_operands = 2) {
8282
DB* db;
83-
StackableDB* sdb;
8483
Options options;
8584
options.create_if_missing = true;
8685
options.merge_operator = std::make_shared<CountMergeOperator>();
@@ -90,8 +89,9 @@ std::shared_ptr<DB> OpenDb(const string& dbname, const bool ttl = false,
9089
DestroyDB(dbname, Options());
9190
if (ttl) {
9291
cout << "Opening database with TTL\n";
93-
s = UtilityDB::OpenTtlDB(options, dbname, &sdb);
94-
db = sdb;
92+
DBWithTTL* db_with_ttl;
93+
s = DBWithTTL::Open(options, dbname, &db_with_ttl);
94+
db = db_with_ttl;
9595
} else {
9696
s = DB::Open(options, dbname, &db);
9797
}

include/rocksdb/c.h

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ extern rocksdb_t* rocksdb_open(
8383
const char* name,
8484
char** errptr);
8585

86+
extern rocksdb_t* rocksdb_open_for_read_only(
87+
const rocksdb_options_t* options,
88+
const char* name,
89+
unsigned char error_if_log_file_exist,
90+
char** errptr);
91+
8692
extern void rocksdb_close(rocksdb_t* db);
8793

8894
extern void rocksdb_put(

include/utilities/db_ttl.h

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under the BSD-style license found in the
3+
// LICENSE file in the root directory of this source tree. An additional grant
4+
// of patent rights can be found in the PATENTS file in the same directory.
5+
6+
#pragma once
7+
#ifndef ROCKSDB_LITE
8+
9+
#include <string>
10+
#include <vector>
11+
12+
#include "utilities/stackable_db.h"
13+
#include "rocksdb/db.h"
14+
15+
namespace rocksdb {
16+
17+
// Database with TTL support.
18+
//
19+
// USE-CASES:
20+
// This API should be used to open the db when key-values inserted are
21+
// meant to be removed from the db in a non-strict 'ttl' amount of time
22+
// Therefore, this guarantees that key-values inserted will remain in the
23+
// db for >= ttl amount of time and the db will make efforts to remove the
24+
// key-values as soon as possible after ttl seconds of their insertion.
25+
//
26+
// BEHAVIOUR:
27+
// TTL is accepted in seconds
28+
// (int32_t)Timestamp(creation) is suffixed to values in Put internally
29+
// Expired TTL values deleted in compaction only:(Timestamp+ttl<time_now)
30+
// Get/Iterator may return expired entries(compaction not run on them yet)
31+
// Different TTL may be used during different Opens
32+
// Example: Open1 at t=0 with ttl=4 and insert k1,k2, close at t=2
33+
// Open2 at t=3 with ttl=5. Now k1,k2 should be deleted at t>=5
34+
// read_only=true opens in the usual read-only mode. Compactions will not be
35+
// triggered(neither manual nor automatic), so no expired entries removed
36+
//
37+
// CONSTRAINTS:
38+
// Not specifying/passing or non-positive TTL behaves like TTL = infinity
39+
//
40+
// !!!WARNING!!!:
41+
// Calling DB::Open directly to re-open a db created by this API will get
42+
// corrupt values(timestamp suffixed) and no ttl effect will be there
43+
// during the second Open, so use this API consistently to open the db
44+
// Be careful when passing ttl with a small positive value because the
45+
// whole database may be deleted in a small amount of time
46+
47+
class DBWithTTL : public StackableDB {
48+
public:
49+
virtual Status CreateColumnFamilyWithTtl(
50+
const ColumnFamilyOptions& options, const std::string& column_family_name,
51+
ColumnFamilyHandle** handle, int ttl) = 0;
52+
53+
static Status Open(const Options& options, const std::string& dbname,
54+
DBWithTTL** dbptr, int32_t ttl = 0,
55+
bool read_only = false);
56+
57+
static Status Open(const DBOptions& db_options, const std::string& dbname,
58+
const std::vector<ColumnFamilyDescriptor>& column_families,
59+
std::vector<ColumnFamilyHandle*>* handles,
60+
DBWithTTL** dbptr, std::vector<int32_t> ttls,
61+
bool read_only = false);
62+
63+
protected:
64+
explicit DBWithTTL(DB* db) : StackableDB(db) {}
65+
};
66+
67+
} // namespace rocksdb
68+
#endif // ROCKSDB_LITE

include/utilities/stackable_db.h

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ class StackableDB : public DB {
2121
return db_;
2222
}
2323

24+
virtual Status CreateColumnFamily(const ColumnFamilyOptions& options,
25+
const std::string& column_family_name,
26+
ColumnFamilyHandle** handle) {
27+
return db_->CreateColumnFamily(options, column_family_name, handle);
28+
}
29+
30+
virtual Status DropColumnFamily(ColumnFamilyHandle* column_family) {
31+
return db_->DropColumnFamily(column_family);
32+
}
33+
2434
using DB::Put;
2535
virtual Status Put(const WriteOptions& options,
2636
ColumnFamilyHandle* column_family, const Slice& key,

include/utilities/utility_db.h

+11-44
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,22 @@
88
#include <string>
99

1010
#include "utilities/stackable_db.h"
11+
#include "utilities/db_ttl.h"
1112
#include "rocksdb/db.h"
1213

1314
namespace rocksdb {
1415

15-
// This class contains APIs to open rocksdb with specific support eg. TTL
16+
// Please don't use this class. It's deprecated
1617
class UtilityDB {
17-
18-
public:
19-
// Open the database with TTL support.
20-
//
21-
// USE-CASES:
22-
// This API should be used to open the db when key-values inserted are
23-
// meant to be removed from the db in a non-strict 'ttl' amount of time
24-
// Therefore, this guarantees that key-values inserted will remain in the
25-
// db for >= ttl amount of time and the db will make efforts to remove the
26-
// key-values as soon as possible after ttl seconds of their insertion.
27-
//
28-
// BEHAVIOUR:
29-
// TTL is accepted in seconds
30-
// (int32_t)Timestamp(creation) is suffixed to values in Put internally
31-
// Expired TTL values deleted in compaction only:(Timestamp+ttl<time_now)
32-
// Get/Iterator may return expired entries(compaction not run on them yet)
33-
// Different TTL may be used during different Opens
34-
// Example: Open1 at t=0 with ttl=4 and insert k1,k2, close at t=2
35-
// Open2 at t=3 with ttl=5. Now k1,k2 should be deleted at t>=5
36-
// read_only=true opens in the usual read-only mode. Compactions will not be
37-
// triggered(neither manual nor automatic), so no expired entries removed
38-
//
39-
// CONSTRAINTS:
40-
// Not specifying/passing or non-positive TTL behaves like TTL = infinity
41-
//
42-
// !!!WARNING!!!:
43-
// Calling DB::Open directly to re-open a db created by this API will get
44-
// corrupt values(timestamp suffixed) and no ttl effect will be there
45-
// during the second Open, so use this API consistently to open the db
46-
// Be careful when passing ttl with a small positive value because the
47-
// whole database may be deleted in a small amount of time
48-
static Status OpenTtlDB(const Options& options,
49-
const std::string& name,
50-
StackableDB** dbptr,
51-
int32_t ttl = 0,
52-
bool read_only = false);
53-
54-
// OpenTtlDB with column family support
55-
static Status OpenTtlDB(
56-
const DBOptions& db_options, const std::string& name,
57-
const std::vector<ColumnFamilyDescriptor>& column_families,
58-
std::vector<ColumnFamilyHandle*>* handles, StackableDB** dbptr,
59-
std::vector<int32_t> ttls, bool read_only = false);
18+
public:
19+
// This function is here only for backwards compatibility. Please use the
20+
// functions defined in DBWithTTl (utilities/db_ttl.h)
21+
// (deprecated)
22+
__attribute__((deprecated)) static Status OpenTtlDB(const Options& options,
23+
const std::string& name,
24+
StackableDB** dbptr,
25+
int32_t ttl = 0,
26+
bool read_only = false);
6027
};
6128

6229
} // namespace rocksdb

java/jdb_bench.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
java -Djava.library.path=.:../ -cp "rocksdbjni.jar:.:./*" org.rocksdb.benchmark.DbBenchmark $@
1+
java -server -d64 -XX:NewSize=4m -XX:+AggressiveOpts -Djava.library.path=.:../ -cp "rocksdbjni.jar:.:./*" org.rocksdb.benchmark.DbBenchmark $@

java/org/rocksdb/ReadOptions.java

-28
Original file line numberDiff line numberDiff line change
@@ -93,34 +93,6 @@ public ReadOptions setFillCache(boolean fillCache) {
9393
private native void setFillCache(
9494
long handle, boolean fillCache);
9595

96-
/**
97-
* If this option is set and memtable implementation allows, Seek
98-
* might only return keys with the same prefix as the seek-key
99-
* Default: false
100-
*
101-
* @return true if prefix-seek is enabled.
102-
*/
103-
public boolean prefixSeek() {
104-
assert(isInitialized());
105-
return prefixSeek(nativeHandle_);
106-
}
107-
private native boolean prefixSeek(long handle);
108-
109-
/**
110-
* If this option is set and memtable implementation allows, Seek
111-
* might only return keys with the same prefix as the seek-key
112-
*
113-
* @param prefixSeek if true, then prefix-seek will be enabled.
114-
* @return the reference to the current ReadOptions.
115-
*/
116-
public ReadOptions setPrefixSeek(boolean prefixSeek) {
117-
assert(isInitialized());
118-
setPrefixSeek(nativeHandle_, prefixSeek);
119-
return this;
120-
}
121-
private native void setPrefixSeek(
122-
long handle, boolean prefixSeek);
123-
12496
/**
12597
* Specify to create a tailing iterator -- a special iterator that has a
12698
* view of the complete database (i.e. it can also be used to read newly

0 commit comments

Comments
 (0)