Skip to content

Commit 4e8b01d

Browse files
committed
Merge branch 'fix-error'
2 parents 795b00b + fec3b51 commit 4e8b01d

File tree

5 files changed

+37
-40
lines changed

5 files changed

+37
-40
lines changed

lib/cube/server/event.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ exports.putter = function(db) {
6767
var floor = tiers[tier].floor;
6868
metrics.update({
6969
i: false,
70-
l: +tier,
71-
t: {
70+
"_id.l": +tier,
71+
"_id.t": {
7272
$gte: floor(times[0]),
7373
$lte: floor(times[1])
7474
}

lib/cube/server/metric.js

+28-31
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ var util = require("util"),
44
types = require("./types"),
55
reduces = require("./reduces");
66

7-
var metric_fields = {t: 1, g: 1, v: 1},
8-
metric_options = {sort: {t: 1}, batchSize: 1000},
9-
event_options = {sort: {t: 1}, batchSize: 1000},
10-
update_options = {upsert: true};
7+
var metric_fields = {v: 1},
8+
metric_options = {sort: {_id: 1}, batchSize: 1000},
9+
event_options = {sort: {t: 1}, batchSize: 1000};
1110

1211
// Query for metrics.
1312
// TODO use expression ids, and record how often expressions are queried?
@@ -68,9 +67,9 @@ exports.getter = function(db) {
6867
// Query for the desired metric in the cache.
6968
type.metrics.find({
7069
i: false,
71-
e: expression.source,
72-
l: tier.key,
73-
t: {
70+
"_id.e": expression.source,
71+
"_id.l": tier.key,
72+
"_id.t": {
7473
$gte: start,
7574
$lt: stop
7675
}
@@ -84,9 +83,9 @@ exports.getter = function(db) {
8483
cursor.each(function(error, row) {
8584
if (error) throw error;
8685
if (row) {
87-
callback(row.t, row.v, row.g);
88-
if (time < row.t) compute(time, row.t);
89-
time = tier.step(row.t);
86+
callback(row._id.t, row.v, row._id.g);
87+
if (time < row._id.t) compute(time, row._id.t);
88+
time = tier.step(row._id.t);
9089
} else {
9190
if (time < stop) compute(time, stop);
9291
}
@@ -203,31 +202,29 @@ exports.getter = function(db) {
203202

204203
function saveGroup(time, value, group) {
205204
callback(time, value, group);
206-
if (value) type.metrics.update({
207-
e: expression.source,
208-
l: tier.key,
209-
t: time,
210-
g: group
211-
}, {
212-
$set: {
213-
i: false,
214-
v: new Double(value)
215-
}
216-
}, update_options);
205+
if (value) type.metrics.save({
206+
_id: {
207+
e: expression.source,
208+
l: tier.key,
209+
t: time,
210+
g: group
211+
},
212+
i: false,
213+
v: new Double(value)
214+
});
217215
}
218216

219217
function save(time, value) {
220218
callback(time, value);
221-
if (value) type.metrics.update({
222-
e: expression.source,
223-
l: tier.key,
224-
t: time
225-
}, {
226-
$set: {
227-
i: false,
228-
v: new Double(value)
229-
}
230-
}, update_options);
219+
if (value) type.metrics.save({
220+
_id: {
221+
e: expression.source,
222+
l: tier.key,
223+
t: time
224+
},
225+
i: false,
226+
v: new Double(value)
227+
});
231228
}
232229
}
233230
}

lib/cube/server/server.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var util = require("util"),
77

88
// Don't crash on errors.
99
process.on("uncaughtException", function(error) {
10+
util.log("uncaught exception: " + error);
1011
util.log(error.stack);
1112
});
1213

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cube",
3-
"version": "0.0.15",
3+
"version": "0.1.0",
44
"description": "A system for time series visualization using MongoDB, Node and D3.",
55
"keywords": ["time series", "visualization"],
66
"homepage": "http://square.github.com/cube/",
@@ -9,7 +9,7 @@
99
"main": "./lib/cube",
1010
"dependencies": {
1111
"d3": "2.7.2",
12-
"mongodb": "0.9.7-1.3",
12+
"mongodb": "0.9.8-1",
1313
"pegjs": "0.6.2",
1414
"vows": "0.5.11",
1515
"websocket": "1.0.2",

schema/schema-create.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
db.createCollection("boards");
22

3-
["random", "stock", "collectd_df", "collectd_load", "collectd_interface", "collectd_memory"].forEach(function(type) {
3+
["random", "collectd_df", "collectd_load", "collectd_interface", "collectd_memory"].forEach(function(type) {
44
var event = type + "_events", metric = type + "_metrics";
55
db.createCollection(event);
66
db[event].ensureIndex({t: 1});
7-
db.createCollection(metric, {capped: true, size: 1e6, autoIndexId: false});
8-
db[metric].ensureIndex({e: 1, l: 1, t: 1, g: 1}, {unique: true});
9-
db[metric].ensureIndex({i: 1, e: 1, l: 1, t: 1});
10-
db[metric].ensureIndex({i: 1, l: 1, t: 1});
7+
db.createCollection(metric, {capped: true, size: 1e7, autoIndexId: true});
8+
db[metric].ensureIndex({"i": 1, "_id.e": 1, "_id.l": 1, "_id.t": 1});
9+
db[metric].ensureIndex({"i": 1, "_id.l": 1, "_id.t": 1});
1110
});

0 commit comments

Comments
 (0)