Permalink
Browse files

replication redo under way

  • Loading branch information...
pgte committed Jan 21, 2011
1 parent e22e6a0 commit c9fb8b63302cf88ce2ea20cbd25f6c282903150c
View
1 TODO
@@ -1,4 +1,3 @@
-- Create a chainable .first() (which maps into .limit(1))
- Compact meta key_map on database startup.
- BUG: For some strange reason the last replication master temp file is not deleted.
- Allow master-master replication
@@ -1,4 +1,5 @@
var fs = require('fs'),
+ assert = require('assert'),
Alfred = require('../lib/alfred'),
RandomGenerator = require('../tools/random_generator');
@@ -47,34 +48,50 @@ module.exports.run = function(benchmark, next) {
var found = 0;
benchmark.end();
- benchmark.start('find $eq operator', FIND_COUNT);
- for (var j = 0; j < FIND_COUNT; j++) {
- db.users.find({age: {$eq : Math.floor(Math.random() * 100)}}).bulk(function(err) {
+ benchmark.start('finder with no get', FIND_COUNT);
+
+ for (var ii = 0; ii < FIND_COUNT; ii++) {
+ db.users.find({age: {$eq: RandomGenerator.createRandomString(90)}}).bulk(function(err, users) {
if (err) { throw err; }
-
- if (++found == FIND_COUNT) {
-
- found = 0;
-
+ found ++;
+ assert.equal(0, users.length);
+ if (found == FIND_COUNT) {
benchmark.end();
-
- benchmark.start('find $range operator', FIND_COUNT);
- for (var k = 0; k < FIND_COUNT; k++) {
- var new_age = Math.floor(Math.random() * 100)
- db.users.find({age: {$range : [new_age, new_age + 1]}}).bulk(function(err) {
- if (err) { throw err; }
- if (++found == FIND_COUNT) {
- benchmark.end();
- db.close(function(err) {
- if (err) { throw err; }
- next();
- });
- }
- });
- }
+ (function() {
+ var found = 0;
+ benchmark.start('find $eq operator', FIND_COUNT);
+ for (var j = 0; j < FIND_COUNT; j++) {
+ db.users.find({age: {$eq : Math.floor(Math.random() * 100)}}).bulk(function(err) {
+ if (err) { throw err; }
+
+ if (++found == FIND_COUNT) {
+
+ found = 0;
+
+ benchmark.end();
+
+ benchmark.start('find $range operator', FIND_COUNT);
+ for (var k = 0; k < FIND_COUNT; k++) {
+ var new_age = Math.floor(Math.random() * 100)
+ db.users.find({age: {$range : [new_age, new_age + 1]}}).bulk(function(err) {
+ if (err) { throw err; }
+ if (++found == FIND_COUNT) {
+ benchmark.end();
+ db.close(function(err) {
+ if (err) { throw err; }
+ next();
+ });
+ }
+ });
+ }
+ }
+ });
+ }
+ })();
}
});
}
+
}
});
}

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -101,6 +101,9 @@ p.note Everything here is experimental, and the API is no exception, so expect t
ul
li <b>limit</b>: integer > 0
+ h2 .first ()
+ p The same as <i>.limit(1)</i>.
+
h2 .offset (x)
p Ignore the first x objects
p
View
@@ -192,16 +192,20 @@ Finder.prototype.executeBulk = function(callback) {
}
var results = [];
var got = 0;
- keys.forEach(function(key, index) {
- self.key_map.getAtPos(key.p, key.l, function(err, key, value) {
- if (err) { callback(err); return; }
- results.push({key: key, value: value});
- got ++;
- if (got == keys.length) {
- callback(null, results);
- }
+ if (keys && keys.length > 0) {
+ keys.forEach(function(key, index) {
+ self.key_map.getAtPos(key.p, key.l, function(err, key, value) {
+ if (err) { callback(err); return; }
+ results.push({key: key, value: value});
+ got ++;
+ if (got == keys.length) {
+ callback(null, results);
+ }
+ });
});
- });
+ } else {
+ callback(null, []);
+ }
});
};
@@ -243,6 +247,10 @@ module.exports.create = function(key_map, query) {
finder.offset = offset;
};
+ chainable.first = function() {
+ finder.limit = 1;
+ };
+
chainable.bulk = function(callback) {
finder.executeBulk(callback);
return chainable;
Oops, something went wrong.

0 comments on commit c9fb8b6

Please sign in to comment.