Skip to content
This repository has been archived by the owner on Feb 22, 2019. It is now read-only.

Commit

Permalink
Make thrift remove use microsecond timestamps.
Browse files Browse the repository at this point in the history
Like insert, remove now uses microsecond precision timestamps
by default (you can still pass in a Date object).
  • Loading branch information
Muir Manders committed Oct 23, 2013
1 parent 536dee3 commit a4f2942
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/column_family.js
Expand Up @@ -3,7 +3,8 @@ var util = require('util'),
Column = require('./column'), Column = require('./column'),
CounterColumn = require('./counter_column'), CounterColumn = require('./counter_column'),
Row = require('./row'), Row = require('./row'),
ttype = require('./cassandra/cassandra_types'); ttype = require('./cassandra/cassandra_types'),
microtime = require('microtime');


/** /**
* NO-Operation for deault callbacks * NO-Operation for deault callbacks
Expand Down Expand Up @@ -283,10 +284,18 @@ ColumnFamily.prototype.remove = function() {
var self = this; var self = this;
var marshalledKey = this.keyMarshaller.serialize(args.key).toString('binary'), var marshalledKey = this.keyMarshaller.serialize(args.key).toString('binary'),
path = columnPath(self, args.column, args.subcolumn), path = columnPath(self, args.column, args.subcolumn),
timestamp = args.options.timestamp || new Date(),
consistency = args.options.consistency || args.options.consistencyLevel || DEFAULT_WRITE_CONSISTENCY; consistency = args.options.consistency || args.options.consistencyLevel || DEFAULT_WRITE_CONSISTENCY;


this.connection.execute('remove', marshalledKey, path, timestamp * 1000, consistency, args.callback); var timestamp;
if (args.options.timestamp == null) {
timestamp = microtime.now();
} else if (args.options.timestamp instanceof Date) {
timestamp = args.options.timestamp.getTime() * 1000;
} else {
timestamp = args.options.timestamp;
}

this.connection.execute('remove', marshalledKey, path, timestamp, consistency, args.callback);
}; };


/** /**
Expand Down
37 changes: 37 additions & 0 deletions test/thrift.js
Expand Up @@ -699,6 +699,43 @@ module.exports = {
}); });
}, },


'test standard cf remove default microsecond timestamp':function(test, assert) {
//try to tease out same-ms collision with 50 attempts
var finished = 0, ok = true;
var callback = function() {
finished++;
if (finished % 2 == 0) {
cf_standard.get(config.standard_row_key, function(err, row){
assert.ifError(err);

ok = ok && (row.count === 3);

if (finished == 100) {
assert.ok(ok);
assert.ifError(err);
test.finish();
} else {
setTimeout(try_race, 0);
}
});
}
};

var try_race = function() {
cf_standard.insert(config.standard_row_key, {"one": "a"}, function(err, results){
assert.ifError(err);
callback();
});

cf_standard.remove(config.standard_row_key, "one", function(err, results){
assert.ifError(err);
callback();
});
};

try_race();
},

'test composite cf remove column':function(test, assert) { 'test composite cf remove column':function(test, assert) {
var key = [ 'åbcd', new Helenus.UUID('e491d6ac-b124-4795-9ab3-c8a0cf92615c') ], var key = [ 'åbcd', new Helenus.UUID('e491d6ac-b124-4795-9ab3-c8a0cf92615c') ],
col = [12345678912345, new Date(1326400762701)]; col = [12345678912345, new Date(1326400762701)];
Expand Down

0 comments on commit a4f2942

Please sign in to comment.