Skip to content

Bolt V3 support & transaction configuration #403

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

Merged
merged 4 commits into from
Aug 30, 2018

Conversation

lutovich
Copy link
Contributor

Bolt V3 allows additional metadata to be attached to BEGIN and RUN messages. This makes it possible to expose a couple new features in the API.

Auto-commit transactions executed via Session#run() now support bookmarks. In previous protocol versions, there was no good place in the RUN message to attach bookmarks. Auto-commit transactions will now use bookmarks given in Driver#session(bookmarkOrBookmarks) function and participate in causal chaining within a session.

Transactions functions, auto-commit, and explicit transactions now accept a configuration object with transaction timeout and metadata. Example of a configuration object:

{
    timeout: 3000, // 3 seconds
    metadata: {key1: 42, key2: '42'}
}

where timeout is specified in milliseconds and metadata is an object containing valid Cypher types.

Transactions that execute longer than the configured timeout will be terminated by the database. This functionality allows limiting query/transaction execution time. Specified timeout overrides the default timeout configured in the database using dbms.transaction.timeout setting. Examples:

Specified transaction metadata will be attached to the executing transaction and visible in the output of dbms.listQueries and dbms.listTransactions procedures. It will also get logged to the query.log. This functionality makes it easier to tag transactions and is equivalent to dbms.setTXMetaData procedure.

Examples:

var driver = neo4j.driver(...);
var session = driver.session();

var txConfig = {
  timeout: 5000, // 5 seconds
  metadata: {
    type: 'My Query',
    application: 'My App #1',
    sequence_number: 42
  }
};

// transaction configuration for auto-commit transaction
session.run('RETURN $x', {x: 42}, txConfig)
       .then(...)
       .catch(...)

// transaction configuration for explicit transaction
var tx = session.beginTransaction(txConfig);
tx.run(...);

// transaction configuration for read transaction function
session.readTransaction(tx => tx.run('RETURN $x', {x: 42}), txConfig)
       .then(...)
       .catch(...)

// transaction configuration for write transaction function
session.writeTransaction(tx => tx.run('RETURN $x', {x: 42}), txConfig)
       .then(...)
       .catch(...)

Add protocol negotiation and messaging for Bolt V3. This commit does
not expose new features in the API. It only makes code use new
protocol version to execute existing operations.
Move it into a dedicated function instead of being part
of the `Transaction` constructor.
Bolt V3 allows additional metadata to be attached to BEGIN and RUN
messages. This makes it possible to expose a couple new features in
the API.

Auto-commit transactions executed via `Session#run()` now support
bookmarks. In previous protocol versions, there was no good place in
the RUN message to attach bookmarks. Auto-commit transactions will
now use bookmarks given in `Driver#session(bookmarkOrBookmarks)`
function and participate in causal chaining within a session.

Transactions functions, auto-commit, and explicit transactions now
accept a configuration object with transaction timeout and metadata.
Example of a configuration object:

```
{
    timeout: 3000, // 3 seconds
    metadata: {key1: 42, key2: '42'}
}
```

where timeout is specified in milliseconds and metadata is an object
containing valid Cypher types.

Transactions that execute longer than the configured timeout will be
terminated by the database. This functionality allows limiting
query/transaction execution time. Specified timeout overrides the
default timeout configured in the database using
`dbms.transaction.timeout` setting. Examples:

Specified transaction metadata will be attached to the executing
transaction and visible in the output of `dbms.listQueries` and
`dbms.listTransactions` procedures. It will also get logged to the
`query.log`. This functionality makes it easier to tag transactions
and is equivalent to `dbms.setTXMetaData` procedure.

Examples:

```
var driver = neo4j.driver(...);
var session = driver.session();

var txConfig = {
  timeout: 5000, // 5 seconds
  metadata: {
    type: 'My Query',
    application: 'My App neo4j#1',
    sequence_number: 42
  }
};

// transaction configuration for auto-commit transaction
session.run('RETURN $x', {x: 42}, txConfig)
       .then(...)
       .catch(...)

// transaction configuration for explicit transaction
var tx = session.beginTransaction(txConfig);
tx.run(...);

// transaction configuration for read transaction function
session.readTransaction(tx => tx.run('RETURN $x', {x: 42}), txConfig)
       .then(...)
       .catch(...)

// transaction configuration for write transaction function
session.writeTransaction(tx => tx.run('RETURN $x', {x: 42}), txConfig)
       .then(...)
       .catch(...)
```
@lutovich lutovich mentioned this pull request Aug 29, 2018
@zhenlineo zhenlineo merged commit 4a9af6d into neo4j:1.7 Aug 30, 2018
@lutovich lutovich deleted the 1.7-bolt-v3 branch August 30, 2018 11:32
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