Permalink
Browse files

Get Seek working again.

Next step turn iterator code into async.
  • Loading branch information...
1 parent 63ac116 commit 773f83372c8fb73fca74dc5e89d5d0f32d966167 @my8bird my8bird committed Sep 7, 2011
Showing with 18 additions and 77 deletions.
  1. +4 −0 README.markdown
  2. +5 −7 demo/iterator.coffee
  3. +0 −61 demo/iterator.js
  4. +1 −1 package.json
  5. +6 −7 src/Iterator.cc
  6. +2 −1 src/Iterator.h
View
@@ -8,6 +8,10 @@ While implementing nStore, I realized there are a couple things that V8 and node
Since LevelDB provides good primitives like MVCC and binary support (It was designed to back IndexDB in the Chrome browser), then it can be used as a base to implement things like CouchDB.
+## TODO
+
+ 1. Trun Iterator code to be async
+
## Status
This project is still under heavy development in my free-time. It was started by a long night where I couldn't sleep. I am not a C++ coder and am learning as I go.
View
@@ -38,12 +38,13 @@ d.addCallback () ->
iterator.seekToFirst()
-
while iterator.valid()
key = iterator.key().toString('utf8')
if lastKey && lastKey > key
console.log('found sorting error')
+ else
+ console.log(key)
lastKey = key
readCount++
@@ -53,21 +54,18 @@ d.addCallback () ->
console.log('read sequential ' + readCount + ' db contents in ' + (Date.now() - start) + 'ms')
d.addCallback () ->
- console.log "Seek is broken"
- return
- console.log '1'
+ console.log 'Start Seek test'
iterator = db.newIterator({})
- console.log '2'
for i in [0 .. 100]
testUUID = uuid()
- iterator.seek(new Buffer(testUUID))
+ iterator.seek("" + testUUID)
console.log('looking for first key after: ' + testUUID)
# if we found something the report
if (iterator.valid())
- console.log('FOUND: ' + iterator.key())
+ console.log('FOUND: ' + iterator.key().toString('utf-8'))
d.addCallback () ->
View
@@ -1,61 +0,0 @@
-var DB = require('../build/default/leveldb.node').DB,
- uuid = require('node-uuid'),
- start = Date.now(),
- entryCount = 1000000,
- lastKey,
- readCount = 0,
- ii;
-
-console.log("Creating test database");
-var path = "/tmp/iterator.db";
-var db = new DB();
-db.open({create_if_missing: true}, path);
-
-console.log('!! creating ' + entryCount + ' random key entries');
-for (ii = 0; ii < entryCount; ii++) {
- var id = uuid();
-
- db.put({}, new Buffer(id), new Buffer(JSON.stringify({
- id: id,
- name: 'Bob',
- age: 33
- })));
-} // for
-
-console.log('created in ' + (Date.now() - start) + 'ms');
-console.log('!! iterating db in key order');
-
-// reset the start counter
-start = Date.now();
-
-// iterate over the test database
-var iterator = db.newIterator({});
-
-for (iterator.seekToFirst(); iterator.valid(); iterator.next()) {
- var key = iterator.key().toString('utf8');
-
- if (lastKey && lastKey > key) {
- console.log('found sorting error');
- } // if
-
- lastKey = key;
- readCount++;
-} // for
-
-console.log('read sequential ' + readCount + ' db contents in ' + (Date.now() - start) + 'ms');
-
-// do some random seeking
-for (ii = 0; ii < 100; ii++) {
- var testUUID = uuid();
- iterator.seek(new Buffer(testUUID));
-
- console.log('looking for first key after: ' + testUUID);
-
- // if we found something the report
- if (iterator.valid()) {
- console.log('FOUND: ' + iterator.key());
- } // if
-} // for
-
-db.close();
-DB.destroyDB(path, {});
View
@@ -3,7 +3,7 @@
"tags": ["database", "cache"],
"description": "Bindings for using LevelDB through node.",
"homepage": "https://github.com/my8bird/node-leveldb",
- "version": "0.3.0",
+ "version": "0.3.5",
"author": {
"name": "Nathan Landis",
"email": "my8bird@gmail.com"},
View
@@ -1,5 +1,6 @@
#include "Iterator.h"
#include "helpers.h"
+#include "iostream"
using namespace node_leveldb;
@@ -76,13 +77,10 @@ Handle<Value> Iterator::SeekToLast(const Arguments& args) {
Handle<Value> Iterator::Seek(const Arguments& args) {
HandleScope scope;
- // Check args
- if (!(args.Length() == 2 && Buffer::HasInstance(args[1]))) {
- return ThrowException(Exception::TypeError(String::New("Invalid arguments: Expected (Buffer)")));
- } // if
-
- //leveldb::Slice key = JsToSlice(args[0], &self->strings);
- //ObjectWrap::Unwrap<Iterator>(args.This())->it->Seek(key);
+ std::vector<std::string> strings;
+
+ leveldb::Slice key = JsToSlice(args[0], &strings);
+ ObjectWrap::Unwrap<Iterator>(args.This())->it->Seek(key);
return Undefined();
}
@@ -118,3 +116,4 @@ Handle<Value> Iterator::status(const Arguments& args) {
return processStatus(status);
}
+
View
@@ -37,4 +37,5 @@ class Iterator : ObjectWrap {
} // node_leveldb
-#endif ITERATOR_H_
+#endif
+

0 comments on commit 773f833

Please sign in to comment.