Permalink
Browse files

Make thrift remove use microsecond timestamps.

Like insert, remove now uses microsecond precision timestamps
by default (you can still pass in a Date object).
  • Loading branch information...
1 parent 536dee3 commit a4f2942ed4b78e7eb234936aa6a827bed1bff10a Muir Manders committed Oct 23, 2013
Showing with 49 additions and 3 deletions.
  1. +12 −3 lib/column_family.js
  2. +37 −0 test/thrift.js
View
@@ -3,7 +3,8 @@ var util = require('util'),
Column = require('./column'),
CounterColumn = require('./counter_column'),
Row = require('./row'),
- ttype = require('./cassandra/cassandra_types');
+ ttype = require('./cassandra/cassandra_types'),
+ microtime = require('microtime');
/**
* NO-Operation for deault callbacks
@@ -283,10 +284,18 @@ ColumnFamily.prototype.remove = function() {
var self = this;
var marshalledKey = this.keyMarshaller.serialize(args.key).toString('binary'),
path = columnPath(self, args.column, args.subcolumn),
- timestamp = args.options.timestamp || new Date(),
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);
};
/**
View
@@ -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) {
var key = [ 'åbcd', new Helenus.UUID('e491d6ac-b124-4795-9ab3-c8a0cf92615c') ],
col = [12345678912345, new Date(1326400762701)];

0 comments on commit a4f2942

Please sign in to comment.