Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rethinkdb reconnection #21

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

molnarzs
Copy link

For an uws issue, the rethinkdb instance in our cluster assigned to a deepstream instance sometimes crases. In such case, the deepstream instance cannot recover: it logs the lost connection then game over.

In this PR I have added some configurable reconnection logic (see the readme). If you don't specify the new config parameters, then deepstream should behave as before, however, when you do it, and the plugin is able to recognize the lost rethinkdb connection, then it will try to reconnect, then re-execute the failed operation.

Which means that the deepstream instance gets another, working rethinkdb instance from the cluster and completes the operation. Otherwise, it stays in the failed status as before.

@molnarzs molnarzs changed the title retinkdb reconnection rethinkdb reconnection Jul 18, 2018
this._splitChar = options.splitChar || null
this._tableMatch = this._splitChar ?
new RegExp('^(\\w+)' + this._escapeRegExp(this._splitChar)) :
null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.
Too many errors. (21% scanned).

this._defaultTable = options.defaultTable || 'deepstream_records'
this._splitChar = options.splitChar || null
this._tableMatch = this._splitChar ?
new RegExp('^(\\w+)' + this._escapeRegExp(this._splitChar)) :

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed double and single quotes.

this._reconnectCount = this._connection.reconnectCount
this._tableManager = new TableManager(this._connection)
this._defaultTable = options.defaultTable || 'deepstream_records'
this._splitChar = options.splitChar || null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

this._connection = new Connection(options, this._onConnection.bind(this))
this._reconnectCount = this._connection.reconnectCount
this._tableManager = new TableManager(this._connection)
this._defaultTable = options.defaultTable || 'deepstream_records'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed double and single quotes.
Missing semicolon.

this._options = options
this._connection = new Connection(options, this._onConnection.bind(this))
this._reconnectCount = this._connection.reconnectCount
this._tableManager = new TableManager(this._connection)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

*/
constructor(options) {
super()
this.isReady = false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

* @constructor
*/
constructor(options) {
super()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

*
* database specifies which database to use. Defaults to 'deepstream'
* defaultTable specifies which table records will be stored in that don't specify a table. Defaults to deepstream_records
* splitChar specifies a character that separates the record's id from the table it should be stored in. defaults to null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

* Please note the three additional, optional keys:
*
* database specifies which database to use. Defaults to 'deepstream'
* defaultTable specifies which table records will be stored in that don't specify a table. Defaults to deepstream_records

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

* for instance will create a user table and store it in it. This will allow for more sophisticated queries as
* well as speed up read operations since there are less entries to look through
*
* @param {Object} options rethinkdb driver options. See rethinkdb.com/api/javascript/#connect

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

@@ -29,7 +29,7 @@ describe( 'it distributes records between multiple tables', () => {
})

it( 'deletes dsTestA', ( done ) => {
conn = cacheConnector._connection.get()
conn = cacheConnector._connection.connection

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

@@ -53,7 +53,7 @@ describe( 'Is able to insert a larger number of values in quick succession', ()
})

it( 'deletes dsTestA', ( done ) => {
const conn = storageConnector._connection.get()
const conn = storageConnector._connection.connection

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Missing semicolon.

setTimeout(() => cacheConnector.get('someValue', (error, value) => {
expect(error).to.equal(null)
expect(value).to.deep.equal(data)
done()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.
Too many errors. (27% scanned).

expect(error.msg).to.equal("Connection is closed.")
setTimeout(() => cacheConnector.get('someValue', (error, value) => {
expect(error).to.equal(null)
expect(value).to.deep.equal(data)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

}).then(cacheConnector.get('someValue', (error) => {
expect(error.msg).to.equal("Connection is closed.")
setTimeout(() => cacheConnector.get('someValue', (error, value) => {
expect(error).to.equal(null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

setTimeout(() => cacheConnector.set('someValue', data, (error) => {
expect(error).to.equal(null)
done()
}), 1500)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

expect(error.msg).to.equal("Connection is closed.")
setTimeout(() => cacheConnector.set('someValue', data, (error) => {
expect(error).to.equal(null)
done()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

}).then(cacheConnector.set('someValue', data, (error) => {
expect(error.msg).to.equal("Connection is closed.")
setTimeout(() => cacheConnector.set('someValue', data, (error) => {
expect(error).to.equal(null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

noreplyWait: true
}).then(cacheConnector.set('someValue', data, (error) => {
expect(error.msg).to.equal("Connection is closed.")
setTimeout(() => cacheConnector.set('someValue', data, (error) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

cacheConnector._connection._connection.close({
noreplyWait: true
}).then(cacheConnector.set('someValue', data, (error) => {
expect(error.msg).to.equal("Connection is closed.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed double and single quotes.
Missing semicolon.

@yasserf yasserf force-pushed the master branch 2 times, most recently from 10d57d3 to e6ad910 Compare April 12, 2020 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants