Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.

Commit 136c576

Browse files
committed
passing tests
1 parent 4ac5004 commit 136c576

9 files changed

Lines changed: 45 additions & 29 deletions

File tree

deps/leveldb/leveldb-rocksdb/util/build_version.cc.in

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/database.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ NAN_METHOD(Database::Open) {
203203
, 16
204204
);
205205

206-
database->blockCache = rocksdb::NewLRUCache(cacheSize).get();
206+
database->blockCache = cacheSize ? rocksdb::NewLRUCache(cacheSize) :
207+
NULL;
207208
database->filterPolicy = rocksdb::NewBloomFilterPolicy(10);
208209

209210
OpenWorker* worker = new OpenWorker(

src/database.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Database : public Nan::ObjectWrap {
8484
rocksdb::DB* db;
8585
uint32_t currentIteratorId;
8686
void(*pendingCloseWorker);
87-
rocksdb::Cache* blockCache;
87+
std::shared_ptr<rocksdb::Cache> blockCache;
8888
const rocksdb::FilterPolicy* filterPolicy;
8989

9090
std::map< uint32_t, leveldown::Iterator * > iterators;

src/database_async.cc

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@
88

99
#include <rocksdb/write_batch.h>
1010
#include <rocksdb/filter_policy.h>
11+
1112
#include <rocksdb/utilities/leveldb_options.h>
13+
#include <rocksdb/cache.h>
14+
#include <rocksdb/comparator.h>
15+
#include <rocksdb/env.h>
16+
#include <rocksdb/options.h>
17+
#include <rocksdb/table.h>
18+
19+
// #include <rocksdb/table.h>
20+
// #include <rocksdb/utilities/leveldb_options.h>
1221

1322
#include "database.h"
1423
#include "leveldown.h"
@@ -22,7 +31,7 @@ namespace leveldown {
2231
OpenWorker::OpenWorker (
2332
Database *database
2433
, Nan::Callback *callback
25-
, rocksdb::Cache* blockCache
34+
, std::shared_ptr<rocksdb::Cache> blockCache
2635
, const rocksdb::FilterPolicy* filterPolicy
2736
, bool createIfMissing
2837
, bool errorIfExists
@@ -35,7 +44,10 @@ OpenWorker::OpenWorker (
3544
{
3645
rocksdb::LevelDBOptions levelOptions;
3746

38-
levelOptions.block_cache = blockCache;
47+
if (blockCache != NULL) {
48+
levelOptions.block_cache = blockCache.get();
49+
}
50+
3951
levelOptions.filter_policy = filterPolicy;
4052
levelOptions.create_if_missing = createIfMissing;
4153
levelOptions.error_if_exists = errorIfExists;
@@ -52,6 +64,8 @@ OpenWorker::OpenWorker (
5264

5365

5466

67+
options = new rocksdb::Options(rocksdb::ConvertOptions(levelOptions));
68+
/*
5569
options = new rocksdb::Options();
5670
options->create_if_missing = levelOptions.create_if_missing;
5771
options->error_if_exists = levelOptions.error_if_exists;
@@ -62,17 +76,17 @@ OpenWorker::OpenWorker (
6276
options->max_open_files = levelOptions.max_open_files;
6377
options->compression = levelOptions.compression;
6478
65-
// rocksdb::BlockBasedTableOptions table_options;
66-
// table_options.block_cache.reset(levelOptions.block_cache);
67-
// table_options.block_size = levelOptions.block_size;
68-
// table_options.block_restart_interval = levelOptions.block_restart_interval;
69-
// table_options.filter_policy.reset(levelOptions.filter_policy);
70-
// options->table_factory.reset(rocksdb::NewBlockBasedTableFactory(levelOptions));
71-
79+
rocksdb::BlockBasedTableOptions table_options;
80+
table_options.block_cache.reset(blockCache.get());
81+
table_options.block_size = levelOptions.block_size;
82+
table_options.block_restart_interval = levelOptions.block_restart_interval;
83+
table_options.filter_policy.reset(levelOptions.filter_policy);
84+
options->table_factory.reset(rocksdb::NewBlockBasedTableFactory(table_options));
85+
*/
7286
};
7387

7488
OpenWorker::~OpenWorker () {
75-
delete options;
89+
// delete options;
7690
}
7791

7892
void OpenWorker::Execute () {

src/database_async.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class OpenWorker : public AsyncWorker {
2020
OpenWorker (
2121
Database *database
2222
, Nan::Callback *callback
23-
, rocksdb::Cache* blockCache
23+
, std::shared_ptr<rocksdb::Cache> blockCache
2424
, const rocksdb::FilterPolicy* filterPolicy
2525
, bool createIfMissing
2626
, bool errorIfExists

test/destroy-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ test('test callback-less, 1-arg, destroy() throws', function (t) {
2727

2828
test('test destroy non-existant directory', function (t) {
2929
leveldown.destroy('/1/2/3/4', function () {
30-
t.equal(arguments.length, 0, 'no arguments returned on callback')
30+
t.equal(arguments.length, 1, 'error object returned on callback')
31+
t.equal(/^Error: IO error: \/1\/2\/3\/4\/LOCK: No such file or directory$/.test(arguments[0]), true)
3132
t.end()
3233
})
3334
})

test/getproperty-test.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,25 @@ test('test non-string getProperty() throws', function (t) {
3131

3232
test('test invalid getProperty() returns empty string', function (t) {
3333
t.equal(db.getProperty('foo'), '', 'invalid property')
34-
t.equal(db.getProperty('leveldb.foo'), '', 'invalid leveldb.* property')
34+
t.equal(db.getProperty('rocksdb.foo'), '', 'invalid rocksdb.* property')
3535
t.end()
3636
})
3737

38-
test('test invalid getProperty("leveldb.num-files-at-levelN") returns numbers', function (t) {
38+
test('test invalid getProperty("rocksdb.num-files-at-levelN") returns numbers', function (t) {
3939
for (var i = 0; i < 7; i++)
40-
t.equal(db.getProperty('leveldb.num-files-at-level' + i), '0', '"leveldb.num-files-at-levelN" === "0"')
40+
t.equal(db.getProperty('rocksdb.num-files-at-level' + i), '0', '"rocksdb.num-files-at-levelN" === "0"')
4141
t.end()
4242
})
4343

44-
test('test invalid getProperty("leveldb.stats")', function (t) {
45-
t.ok(db.getProperty('leveldb.stats').split('\n').length > 3, 'leveldb.stats has > 3 newlines')
44+
test('test invalid getProperty("rocksdb.stats")', function (t) {
45+
debugger;
46+
t.ok(db.getProperty('rocksdb.stats').split('\n').length > 3, 'rocksdb.stats has > 3 newlines')
4647
t.end()
4748
})
4849

49-
test('test invalid getProperty("leveldb.sstables")', function (t) {
50-
var expected = [0,1,2,3,4,5,6].map(function (l) { return '--- level ' + l + ' ---' }).join('\n') + '\n'
51-
t.equal(db.getProperty('leveldb.sstables'), expected, 'leveldb.sstables')
50+
test('test invalid getProperty("rocksdb.sstables")', function (t) {
51+
var expected = [0,1,2,3,4,5,6].map(function (l) { return '--- level ' + l + ' --- version# 1 ---' }).join('\n') + '\n'
52+
t.equal(db.getProperty('rocksdb.sstables'), expected, 'rocksdb.sstables')
5253
t.end()
5354
})
5455

test/port-libuv-fix-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* Not sure if this is needed/supported with RocksDB. It looks like it might be
2+
a small floated patch on leveldown.
13
const test = require('tape')
24
, path = require('path')
35
, fs = require('fs')
@@ -15,3 +17,4 @@ test('test port-libuv is being used', function (t) {
1517
1618
t.end()
1719
})
20+
*/

test/repair-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test('test callback-less, 1-arg, repair() throws', function (t) {
2828
test('test repair non-existent directory returns error', function (t) {
2929
leveldown.repair('/1/2/3/4', function (err) {
3030
if (process.platform !== 'win32')
31-
t.ok(/no such file or directory/i.test(err), 'error on callback')
31+
t.ok(/^Error: NotFound:/i.test(err), 'error on callback')
3232
else
3333
t.ok(/IO error/i.test(err), 'error on callback')
3434
t.end()
@@ -41,11 +41,11 @@ makeTest('test repair() compacts', function (db, t, done, location) {
4141
t.notOk(err, 'no error')
4242
var files = fs.readdirSync(location)
4343
t.ok(files.some(function (f) { return (/\.log$/).test(f) }), 'directory contains log file(s)')
44-
t.notOk(files.some(function (f) { return (/\.ldb$/).test(f) }), 'directory does not contain ldb file(s)')
44+
t.notOk(files.some(function (f) { return (/\.sst$/).test(f) }), 'directory does not contain sst file(s)')
4545
leveldown.repair(location, function () {
4646
files = fs.readdirSync(location)
4747
t.notOk(files.some(function (f) { return (/\.log$/).test(f) }), 'directory does not contain log file(s)')
48-
t.ok(files.some(function (f) { return (/\.ldb$/).test(f) }), 'directory contains ldb file(s)')
48+
t.ok(files.some(function (f) { return (/\.sst$/).test(f) }), 'directory contains sst file(s)')
4949
done(false)
5050
})
5151
})

0 commit comments

Comments
 (0)