Skip to content

Commit

Permalink
Merge pull request #242 from aerospike/f-error-in-doubt
Browse files Browse the repository at this point in the history
Improve AerospikeError & add new inDoubt flag
  • Loading branch information
jhecking committed Feb 2, 2018
2 parents 9f4cf8f + 0982f35 commit ae1ff31
Show file tree
Hide file tree
Showing 16 changed files with 450 additions and 211 deletions.
9 changes: 5 additions & 4 deletions lib/aerospike.js
@@ -1,5 +1,5 @@
// *****************************************************************************
// Copyright 2013-2017 Aerospike, Inc.
// Copyright 2013-2018 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,8 @@
'use strict'

const as = require('bindings')('aerospike.node')
const asEventLoop = require('./event_loop')
const AerospikeError = require('./error')
const EventLoop = require('./event_loop')
const utils = require('./utils')

/**
Expand Down Expand Up @@ -120,7 +121,7 @@ exports.status = require('./status')
*
* @summary {@link AerospikeError} class
*/
exports.AerospikeError = require('./error')
exports.AerospikeError = AerospikeError

/**
* The main interface of the Aerospike client. Through the Client class,
Expand Down Expand Up @@ -319,7 +320,7 @@ exports.indexType = as.indexType
// ========================================================================

exports.print = utils.print
exports.releaseEventLoop = asEventLoop.releaseEventLoop
exports.releaseEventLoop = EventLoop.releaseEventLoop

let Client = exports.Client

Expand Down
78 changes: 49 additions & 29 deletions lib/client.js
@@ -1,5 +1,5 @@
// *****************************************************************************
// Copyright 2013-2017 Aerospike, Inc.
// Copyright 2013-2018 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
Expand All @@ -22,17 +22,13 @@ const EventEmitter = require('events')

const as = require('bindings')('aerospike.node')
const AerospikeError = require('./error')
const BatchCommand = require('./commands/batch_command')
const Command = require('./commands/command')
const Commands = require('./commands')
const Config = require('./config')
const ExistsCommand = require('./commands/exists_command')
const EventLoop = require('./event_loop')
const IndexJob = require('./index_job')
const Query = require('./query')
const ReadRecordCommand = require('./commands/read_record_command')
const Scan = require('./scan')
const UdfJob = require('./udf_job')
const WriteRecordCommand = require('./commands/write_record_command')
const asEventLoop = require('./event_loop')
const operations = require('./operations')
const utils = require('./utils')

Expand Down Expand Up @@ -143,7 +139,31 @@ function Client (config) {
/** @private */
this.connected = false

/** @private */
/**
* @name Client#captureStackTraces
*
* @summary Set to <code>true</code> to enable capturing of debug stacktraces for
* every database command.
*
* @description The client will capture a stacktrace before each database
* command is executed, instead of capturing the stacktrace only when an
* error is raised. This generally results in much more useful stacktraces
* that include stackframes from the calling application issuing the database
* command.
*
* **Note:** Enabling this feature incurs a significant performance overhead for
* every database command. It is recommended to leave this feature disabled
* in production environments.
*
* By default, the client will set this flag to true, if the
* <code>AEROSPIKE_DEBUG_STACKTRACES</code> environment variable is set (to
* any value).
*
* @type {boolean}
* @default <code>true</code>, if
* <code>process.env.AEROSPIKE_DEBUG_STACKTRACES</code> is set;
* <code>false</code> otherwise.
*/
this.captureStackTraces = !!process.env.AEROSPIKE_DEBUG_STACKTRACES
}

Expand Down Expand Up @@ -235,7 +255,7 @@ Client.prototype.batchExists = function (keys, policy, callback) {
policy = null
}

let cmd = new BatchCommand(this, 'batchExists', [keys, policy], callback)
let cmd = new Commands.BatchExists(this, [keys, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -288,7 +308,7 @@ Client.prototype.batchGet = function (keys, policy, callback) {
policy = null
}

let cmd = new BatchCommand(this, 'batchGet', [keys, policy], callback)
let cmd = new Commands.BatchGet(this, [keys, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -343,7 +363,7 @@ Client.prototype.batchRead = function (records, policy, callback) {
policy = null
}

let cmd = new BatchCommand(this, 'batchRead', [records, policy], callback)
let cmd = new Commands.BatchRead(this, [records, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -398,7 +418,7 @@ Client.prototype.batchSelect = function (keys, bins, policy, callback) {
policy = null
}

let cmd = new BatchCommand(this, 'batchSelect', [keys, bins, policy], callback)
let cmd = new Commands.BatchSelect(this, [keys, bins, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -430,7 +450,7 @@ Client.prototype.close = function (releaseEventLoop) {
_connectedClients -= 1
}
if (releaseEventLoop && _connectedClients === 0) {
asEventLoop.releaseEventLoop()
EventLoop.releaseEventLoop()
}
}

Expand Down Expand Up @@ -481,7 +501,7 @@ Client.prototype.close = function (releaseEventLoop) {
* })
*/
Client.prototype.connect = function (callback) {
asEventLoop.registerASEventLoop()
EventLoop.registerASEventLoop()

let eventsCb = eventsCallback.bind(this)
this.as_client.setupEventCb(eventsCb)
Expand Down Expand Up @@ -627,7 +647,7 @@ Client.prototype.createIndex = function (options, policy, callback) {
policy
]

let cmd = new Command(this, 'indexCreate', args, callback)
let cmd = new Commands.IndexCreate(this, args, callback)
cmd.convertResult = () => new IndexJob(this, options.ns, options.index)
return cmd.execute()
}
Expand Down Expand Up @@ -825,7 +845,7 @@ Client.prototype.apply = function (key, udfArgs, policy, callback) {
policy = null
}

let cmd = new Command(this, 'applyAsync', [key, udfArgs, policy], callback)
let cmd = new Commands.Apply(this, [key, udfArgs, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -869,7 +889,7 @@ Client.prototype.exists = function exists (key, policy, callback) {
policy = null
}

let cmd = new ExistsCommand(this, 'existsAsync', [key, policy], callback)
let cmd = new Commands.Exists(this, [key, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -905,7 +925,7 @@ Client.prototype.get = function (key, policy, callback) {
policy = null
}

let cmd = new ReadRecordCommand(this, 'getAsync', [key, policy], callback)
let cmd = new Commands.Get(this, key, [policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -939,7 +959,7 @@ Client.prototype.indexRemove = function (namespace, index, policy, callback) {
policy = null
}

let cmd = new Command(this, 'indexRemove', [namespace, index, policy], callback)
let cmd = new Commands.IndexRemove(this, [namespace, index, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -985,7 +1005,7 @@ Client.prototype.info = function (request, host, policy, callback) {
host = utils.parseHostString(host)
}

let cmd = new Command(this, 'info', [request, host, policy], callback)
let cmd = new Commands.Info(this, [request, host, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -1027,7 +1047,7 @@ Client.prototype.infoAny = function (request, policy, callback) {
policy = null
}

let cmd = new Command(this, 'info', [request, null, policy], callback)
let cmd = new Commands.Info(this, [request, null, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -1072,7 +1092,7 @@ Client.prototype.infoAll = function (request, policy, callback) {
policy = null
}

let cmd = new Command(this, 'infoForeach', [request, policy], callback)
let cmd = new Commands.InfoForeach(this, [request, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -1145,7 +1165,7 @@ Client.prototype.operate = function (key, operations, metadata, policy, callback
metadata = null
}

let cmd = new ReadRecordCommand(this, 'operateAsync', [key, operations, metadata, policy], callback)
let cmd = new Commands.Operate(this, key, [operations, metadata, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -1288,7 +1308,7 @@ Client.prototype.put = function (key, bins, meta, policy, callback) {
policy = null
}

let cmd = new WriteRecordCommand(this, 'putAsync', [key, bins, meta, policy], callback)
let cmd = new Commands.Put(this, key, [bins, meta, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -1349,7 +1369,7 @@ Client.prototype.remove = function (key, policy, callback) {
policy = null
}

let cmd = new WriteRecordCommand(this, 'removeAsync', [key, policy], callback)
let cmd = new Commands.Remove(this, key, [policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -1406,7 +1426,7 @@ Client.prototype.select = function (key, bins, policy, callback) {
policy = null
}

let cmd = new ReadRecordCommand(this, 'selectAsync', [key, bins, policy], callback)
let cmd = new Commands.Select(this, key, [bins, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -1446,7 +1466,7 @@ Client.prototype.truncate = function (ns, set, beforeNanos, policy, callback) {
policy = null
}

let cmd = new Command(this, 'truncate', [ns, set, beforeNanos, policy], callback)
let cmd = new Commands.Truncate(this, [ns, set, beforeNanos, policy], callback)
return cmd.execute()
}

Expand Down Expand Up @@ -1506,7 +1526,7 @@ Client.prototype.udfRegister = function (udfPath, udfType, policy, callback) {
udfType = null
}

let cmd = new Command(this, 'udfRegister', [udfPath, udfType, policy], callback)
let cmd = new Commands.UdfRegister(this, [udfPath, udfType, policy], callback)
cmd.convertResult = () => {
let module = path.basename(udfPath)
return new UdfJob(this, module, UdfJob.REGISTER)
Expand Down Expand Up @@ -1559,7 +1579,7 @@ Client.prototype.udfRemove = function (udfModule, policy, callback) {
policy = null
}

let cmd = new Command(this, 'udfRemove', [udfModule, policy], callback)
let cmd = new Commands.UdfRemove(this, [udfModule, policy], callback)
cmd.convertResult = () => new UdfJob(this, udfModule, UdfJob.UNREGISTER)
return cmd.execute()
}
Expand Down
6 changes: 2 additions & 4 deletions lib/commands/batch_command.js
@@ -1,5 +1,5 @@
// *****************************************************************************
// Copyright 2013-2017 Aerospike, Inc.
// Copyright 2013-2018 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
Expand All @@ -26,7 +26,7 @@ class BatchResult {
}
}

class BatchCommand extends Command {
module.exports = asCommand => class BatchCommand extends Command(asCommand) {
convertResult (results) {
if (!results) return []

Expand All @@ -36,5 +36,3 @@ class BatchCommand extends Command {
})
}
}

module.exports = BatchCommand

0 comments on commit ae1ff31

Please sign in to comment.