Skip to content

Commit 53cc93b

Browse files
committed
work on database internals section
1 parent ef5c6ca commit 53cc93b

File tree

10 files changed

+349
-567
lines changed

10 files changed

+349
-567
lines changed

modules/ROOT/content-nav.adoc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@
154154
** xref:performance/gc-tuning.adoc[]
155155
** xref:performance/bolt-thread-pool-configuration.adoc[]
156156
** xref:performance/linux-file-system-tuning.adoc[]
157-
** xref:performance/locks-deadlocks.adoc[]
158157
** xref:performance/disks-ram-and-other-tips.adoc[]
159158
** xref:performance/statistics-execution-plans.adoc[]
160159
** xref:performance/space-reuse.adoc[]
@@ -166,8 +165,6 @@
166165
*** xref:monitoring/metrics/enable.adoc[]
167166
*** xref:monitoring/metrics/expose.adoc[]
168167
*** xref:monitoring/metrics/reference.adoc[]
169-
** xref:monitoring/query-management.adoc[]
170-
** xref:monitoring/transaction-management.adoc[]
171168
** xref:monitoring/connection-management.adoc[]
172169
** xref:monitoring/background-jobs.adoc[]
173170
// ** xref:monitoring/cluster/index.adoc[]

modules/ROOT/pages/database-internals/index.adoc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
= Database internals
1+
= Database internals and transactional behavior
22
:description: Database internals and transactional behavior
33

4+
To maintain data integrity and ensure reliable transactional behavior, Neo4j DBMS supports transactions with full ACID properties, and it uses a write-ahead transaction log to ensure durability.
45

5-
To fully maintain data integrity and ensure good transactional behavior, Neo4j DBMS supports the **ACID** properties:
6+
* **Atomicity** -- If a part of a transaction fails, the database state is left unchanged.
7+
* **Consistency** -- Every transaction leaves the database in a consistent state.
8+
* **Isolation** -- During a transaction, modified data cannot be accessed by other operations.
9+
* **Durability** -- The DBMS can always recover the results of a committed transaction.
610
7-
* **A**tomicity -- If a part of a transaction fails, the database state is left unchanged.
8-
* **C**onsistency -- Every transaction leaves the database in a consistent state.
9-
* **I**solation -- During a transaction, modified data cannot be accessed by other operations.
10-
* **D**urability -- The DBMS can always recover the results of a committed transaction.
11-
12-
Specifically for Neo4j, the following transactional behavior is important to understand:
11+
Neo4j DBMS supports the following transactional behavior:
1312

1413
* All database operations that access the graph, indexes, or schema must be performed in a transaction.
15-
* The default isolation level is _read-committed isolation level_.
14+
* The default isolation level is _read-committed_ isolation level.
15+
* Write locks are acquired automatically at the node and relationship levels.
16+
However, you can also manually acquire write locks if you want to achieve a higher level of isolation -- _serialization_ isolation level.
1617
* Data retrieved by traversals is not protected from modification by other transactions.
1718
* Non-repeatable reads may occur (i.e., only write locks are acquired and held until the end of the transaction).
18-
* One can manually acquire write locks on nodes and relationships to achieve a higher level of isolation -- _serialization isolation level_.
19-
* Locks are acquired at the Node and Relationship levels.
2019
* Deadlock detection is built into the core transaction management.
2120
22-
The following sections describe the transactional behavior and how to control it.
21+
The following sections describe the transactional behavior in detail and how to control it:
2322

2423
* xref:database-internals/transaction-management.adoc[]
2524
* xref:database-internals/locks-deadlocks.adoc[]

modules/ROOT/pages/database-internals/locks-deadlocks.adoc

Lines changed: 246 additions & 188 deletions
Large diffs are not rendered by default.

modules/ROOT/pages/database-internals/transaction-logs.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ Other possible ways to configure the log retention policy are:
6565
====
6666
This option is not recommended due to the effectively unbounded storage usage.
6767
Old transaction logs cannot be safely archived or removed by external jobs since safe log pruning requires knowledge about the most recent successful checkpoint.
68-
For more information, see <<checkpointing>>.
68+
For more information, see xref:database-internals/checkpointing.adoc[Checkpointing and log pruning].
6969
====
7070

7171
* `db.tx_log.rotation.retention_policy=false|keep_none` -- keep only the most recent non-empty log.
7272
+
7373
Log pruning is called only after checkpoint completion to ensure at least one checkpoint and points to a valid place in the transaction log data.
7474
In reality, this means that all transaction logs created between checkpoints are kept for some time, and only after a checkpoint, the pruning strategy removes them.
75-
For more details on how to speed up checkpointing, see <<transaction-logging-log-pruning>>.
75+
For more details on how to speed up checkpointing, see xref:database-internals/checkpointing.adoc#transaction-logging-log-pruning[Configure log pruning].
7676
To force a checkpoint, run the procedure xref:reference/procedures.adoc#procedure_db_checkpoint[`CALL db.checkpoint()`].
7777
+
7878
[NOTE]
Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
[[transaction-management]]
22
= Transaction management
33

4-
[[transactions-interaction]]
5-
== Interaction cycle
4+
== Transactions
65

7-
There are database operations that must be performed in a transaction to ensure the ACID properties.
8-
Specifically, operations that access the graph, indexes, or schema are such operations.
6+
Database operations that access the graph, indexes, or schema are performed in a transaction to ensure the ACID properties.
97
Transactions are single-threaded, confined, and independent.
108
Multiple transactions can be started in a single thread and they are independent of each other.
119

@@ -15,17 +13,8 @@ The interaction cycle of working with transactions follows the steps:
1513
. Perform database operations.
1614
. Commit or roll back the transaction.
1715

18-
[NOTE]
19-
====
20-
It is crucial to finish each transaction.
21-
The locks or memory acquired by a transaction are only released upon completion.
22-
====
23-
24-
The idiomatic use of transactions in Neo4j is to use a `try-with-resources` statement and declare `transaction` as one of the resources.
25-
Then start the transaction and try to perform graph operations.
26-
The last operation in the `try` block should commit or roll back the transaction, depending on the business logic.
27-
In this scenario, `try-with-resources` is used as a guard against unexpected exceptions and as an additional safety mechanism to ensure that the transaction gets closed no matter what happens inside the statement block.
28-
All non-committed transactions will be rolled back as part of resource cleanup at the end of the statement.
16+
It is crucial to finish each transaction because the xref:/database-internals/locks-deadlocks.adoc#_locks[locks] or memory acquired by a transaction are only released upon completion.
17+
All non-committed transactions are rolled back as part of resource cleanup at the end of the statement.
2918
No resource cleanup is required for a transaction that is explicitly committed or rolled back, and the transaction closure is an empty operation.
3019

3120
[NOTE]
@@ -34,13 +23,90 @@ All modifications performed in a transaction are kept in memory.
3423
This means that very large updates must be split into several transactions to avoid running out of memory.
3524
====
3625

26+
== Configure transactional behavior
27+
28+
The transaction settings help you manage the transactions in your database, for example, the transaction timeout, the maximum number of concurrently running transactions, how much time to allow Neo4j to wait for running transactions to complete before allowing initiated database shutdown to continue, and so on.
29+
For all available settings, see xref:/configuration/configuration-settings.adoc#_transaction_settings[Transaction settings].
30+
31+
=== Configure the maximum number of concurrently running transactions
32+
33+
By default, Neo4j can run a maximum of 1000 concurrent transactions.
34+
To change this value, use the xref:configuration/configuration-settings.adoc#config_db.transaction.concurrent.maximum[`db.transaction.concurrent.maximum`] setting.
35+
If set to `0`, the limit is disabled.
36+
37+
[[transaction-management-transaction-timeout]]
38+
=== Configure transaction timeout
39+
40+
It is recommended to configure Neo4j to terminate transactions whose execution time has exceeded the configured timeout.
41+
42+
* Set `xref:configuration/configuration-settings.adoc#config_db.transaction.timeout[db.transaction.timeout]` to some positive time interval value (e.g.,`10s`) denoting the default transaction timeout.
43+
Setting `db.transaction.timeout` to `0` -- which is the default value -- disables the feature.
44+
45+
* You can also set this dynamically on each primary server using the procedure `dbms.setConfigValue('db.transaction.timeout','10s')`.
46+
47+
.Configure transaction timeout
48+
====
49+
Set the timeout to ten seconds.
50+
[source, parameters]
51+
----
52+
db.transaction.timeout=10s
53+
----
54+
====
55+
56+
Configuring transaction timeout does not affect transactions executed with custom timeouts (e.g., via the Java API or Neo4j Drivers), as the custom timeout overrides the value set for `db.transaction.timeout`.
57+
Note that the timeout value can only be overridden to a value that is smaller than that configured by `db.transaction.timeout`.
58+
The _transaction timeout_ feature is also known as the _transaction guard_.
59+
60+
61+
== Manage transactions
62+
63+
Transactions can be managed using the Cypher commands `SHOW TRANSACTIONS` and `TERMINATE TRANSACTIONS`.
64+
The `TERMINATE TRANSACTIONS` command can be combined with multiple `SHOW TRANSACTIONS` and `TERMINATE TRANSACTIONS` commands in the same query.
65+
66+
For more information, see link:{neo4j-docs-base-uri}/cypher-manual/{page-version}/clauses/transaction-clauses/[Cypher manual -> Transaction commands].
67+
68+
// [[transaction-management-list-transactions]]
69+
// === List all running transactions
70+
71+
// To list all running transactions on the current server, use the `SHOW TRANSACTIONS` command.
72+
73+
// [NOTE]
74+
// ====
75+
// The command `SHOW TRANSACTIONS` returns only the default output.
76+
// For a full output use `SHOW TRANSACTIONS YIELD *`.
77+
78+
// For more information on this command, such as syntax, output fields, filtering, and examples, see the link:{neo4j-docs-base-uri}/cypher-manual/{page-version}/clauses/transaction-clauses#query-listing-transactions[Cypher manual -> `SHOW TRANSACTIONS` command].
79+
// ====
80+
81+
// A user with the link:{neo4j-docs-base-uri}/cypher-manual/{page-version}/administration/access-control/database-administration#access-control-database-administration-transaction[`SHOW TRANSACTION` privilege] can view the currently executing transactions per the privilege grants.
82+
83+
// All users may view all of their own currently executing transactions.
84+
85+
// === Terminata a transaction
86+
87+
// To terminate a transaction, use the `TERMINATE TRANSACTIONS` command.
88+
89+
// [[query-management-terminate-queries]]
90+
// == Terminate queries
91+
92+
// Queries are terminated by terminating the transaction on which they are running. This is done using the `TERMINATE TRANSACTIONS transactionIds` command.
93+
// The `transactionIds` can be found using the link:{neo4j-docs-base-uri}/cypher-manual/{page-version}/clauses/transaction-clauses#query-listing-transactions[`SHOW TRANSACTIONS` command].
94+
95+
// The link:{neo4j-docs-base-uri}/cypher-manual/{page-version}/administration/access-control/database-administration#access-control-database-administration-transaction[`TERMINATE TRANSACTION` privilege] determines what transactions can be terminated.
96+
// However, the xref:authentication-authorization/terminology.adoc#term-current-user[current user] can always terminate all of their own transactions.
97+
98+
// *Syntax:*
99+
100+
// `TERMINATE TRANSACTIONS transactionIds`
37101

38-
[[transactions-isolation]]
39-
== Isolation levels
102+
// *Argument:*
40103

41-
Transactions in Neo4j use a _read-committed isolation level_, which means they see data as soon as it has been committed but cannot see data in other transactions that have not yet been committed.
42-
This type of isolation is weaker than serialization but offers significant performance advantages while being sufficient for the overwhelming majority of cases.
104+
// [options="header"]
105+
// |===
106+
// | Name | Type | Description
107+
// | `transactionIds` | Comma-separated strings | The IDs of all the transactions to be terminated.
108+
// | `transactionIds` | Single string parameter | The ID of the transaction to be terminated.
109+
// | `transactionIds` | List parameter | The IDs of all the transactions to be terminated.
110+
// |===
43111

44-
In addition, the Neo4j Java API enables explicit locking of nodes and relationships.
45-
Using locks allows simulating the effects of higher levels of isolation by obtaining and releasing locks explicitly.
46-
For example, if a write lock is taken on a common node or relationship, then all transactions are serialized on that lock -- giving the effect of a _serialization isolation level_.
112+
// For more information on the command, see the link:{neo4j-docs-base-uri}/cypher-manual/{page-version}/clauses/transaction-clauses#query-terminate-transactions[Cypher manual -> `TERMINATE TRANSACTIONS` command].

modules/ROOT/pages/monitoring/index.adoc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[[monitoring]]
22
= Monitoring
3-
:description: This chapter describes the tools that are available for monitoring Neo4j.
3+
:description: This chapter describes the tools that are available for monitoring Neo4j.
44

55
Neo4j provides mechanisms for continuous analysis through the output of metrics as well as the inspection and management of currently-executing queries.
66

@@ -18,14 +18,6 @@ This chapter describes the following:
1818
** xref:monitoring/metrics/enable.adoc[Enable metrics logging]
1919
** xref:monitoring/metrics/expose.adoc[Connect monitoring tools]
2020
** xref:monitoring/metrics/reference.adoc[Metrics reference]
21-
* xref:monitoring/query-management.adoc[Manage queries]
22-
** xref:monitoring/query-management.adoc#query-management-list-queries[List all running queries]
23-
** xref:monitoring/query-management.adoc#query-management-list-active-locks[List all active locks for a query]
24-
** xref:monitoring/query-management.adoc#query-management-terminate-queries[Terminate queries]
25-
* xref:monitoring/transaction-management.adoc[Manage transactions]
26-
** xref:monitoring/transaction-management.adoc#transaction-management-transaction-timeout[Configure transaction timeout]
27-
** xref:monitoring/transaction-management.adoc#transaction-management-lock-acquisition-timeout[Configure lock acquisition timeout]
28-
** xref:monitoring/transaction-management.adoc#transaction-management-list-transactions[List all running transactions]
2921
* xref:monitoring/connection-management.adoc[Manage connections]
3022
** xref:monitoring/connection-management.adoc#connection-management-list-connections[List all network connections]
3123
** xref:monitoring/connection-management.adoc#connection-management-terminate-multiple-connections[Terminate multiple network connections]

modules/ROOT/pages/monitoring/query-management.adoc

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)