Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit a4f2942ed4b78e7eb234936aa6a827bed1bff10a 1 parent 536dee3
Muir Manders muirmanders authored
Showing with 49 additions and 3 deletions.
  1. +12 −3 lib/column_family.js
  2. +37 −0 test/thrift.js
15 lib/column_family.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);
};
/**
37 test/thrift.js
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)];
Please sign in to comment.
Something went wrong with that request. Please try again.