Skip to content

Commit

Permalink
Merge pull request #211 from Pchelolo/tid
Browse files Browse the repository at this point in the history
Remove implicit _TID adding
  • Loading branch information
eevans committed Jul 19, 2017
2 parents eaf0db5 + c65650c commit d2689f6
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 38 deletions.
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,10 @@ class RBCassandra {
return this.store.getTableSchema(domain, req.params.table)
.then((res) => ({
status: 200,
headers: { etag: res.tid.toString() },
body: res.schema
}))
.catch((e) => ({
status: 500,

body: {
type: 'schema_query_error',
title: 'Internal error querying table schema in Cassandra storage backend',
Expand Down
17 changes: 2 additions & 15 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const P = require('bluebird');
const cass = require('cassandra-driver');
const TimeUuid = cass.types.TimeUuid;
const extend = require('extend');
const dbu = require('./dbutils');
const cassID = dbu.cassID;
Expand Down Expand Up @@ -68,11 +67,9 @@ class DB {
attributes: {
key: 'string',
value: 'json',
tid: 'timeuuid'
},
index: [
{ attribute: 'key', type: 'hash' },
{ attribute: 'tid', type: 'range', order: 'desc' }
{ attribute: 'key', type: 'hash' }
]
});
this.infoSchemaInfo = dbu.makeSchemaInfo(this.infoSchema, true);
Expand Down Expand Up @@ -304,16 +301,6 @@ class DB {
if (!req.schema) {
throw new Error('Table not found!');
}
const schema = req.schema;
const query = req.query;

const tid = query.attributes[schema.tid];
if (!tid) {
query.attributes[schema.tid] = TimeUuid.now();
} else if (tid.constructor === String) {
query.attributes[schema.tid] = TimeUuid.fromString(query.attributes[schema.tid]);
}

const queryOptions = { consistency: req.consistency, prepare: true };
const queryInfo = dbu.buildPutQuery(req);

Expand Down Expand Up @@ -645,7 +632,7 @@ class DB {
});
}
const item = response.items[0];
return { tid: item.tid, schema: JSON.parse(item.value) };
return { schema: JSON.parse(item.value) };
});
}

Expand Down
21 changes: 0 additions & 21 deletions lib/dbutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ dbu.cassTTL = function cassTTL(name) {
return `_ttl_${name}`;
};

dbu.tidNanoTime = (tid) => {
const datePrecision = tid.getDatePrecision();
return datePrecision.date.getTime() + datePrecision.ticks / 1000;
};

// Hash a key into a valid Cassandra key name
dbu.hashKey = function hashKey(key) {
return new crypto.Hash('sha1')
Expand Down Expand Up @@ -336,11 +331,6 @@ dbu.makeSchemaInfo = function makeSchemaInfo(schema, isMetaCF) {
// Then add some private properties
psi.versioned = false;

// Check if the last index entry is a timeuuid, which we take to mean that
// this table is versioned
const lastElem = schema.index[schema.index.length - 1];
const lastKey = lastElem.attribute;

// Extract attributes that need conversion in the read or write path
psi.conversions = {};
Object.keys(psi.attributes).forEach((att) => {
Expand All @@ -364,17 +354,6 @@ dbu.makeSchemaInfo = function makeSchemaInfo(schema, isMetaCF) {
psi.index.unshift({ attribute: '_domain', type: 'hash' });
}

if (lastKey && lastElem.type === 'range'
&& lastElem.order === 'desc'
&& schema.attributes[lastKey] === 'timeuuid') {
psi.tid = lastKey;
} else {
// Add a hidden _tid timeuuid attribute
psi.attributes._tid = 'timeuuid';
psi.index.push({ attribute: '_tid', type: 'range', order: 'desc' });
psi.tid = '_tid';
}

// Create summary data on the primary data index
psi.iKeys = dbu.indexKeys(psi.index);
psi.iKeyMap = {};
Expand Down

0 comments on commit d2689f6

Please sign in to comment.