You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/client-libraries/python.mdx
+14-1
Original file line number
Diff line number
Diff line change
@@ -452,6 +452,10 @@ In v2.10, Memgraph added the [multi-tenant support](/database-management/multi-t
452
452
453
453
The `execute_query()` procedure automatically creates a transaction that can include multiple Cypher statements as a single query. If the transaction fails, the procedure will automatically rerun it.
454
454
455
+
As of Memgraph version 3.2, queries are categorized as read or write and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
456
+
While it is possible to define the read/write mode using `execute_query` it is recommended to use `execute_read` or `execute_write` instead.
457
+
If `execute_query` must be used, it is possible to use the `routing_` variable to define the transaction's read/write type.
458
+
455
459
Bolt protocol specifies additional [metadata](/database-management/query-metadata) that can be sent along with the requested results. Metadata can be divided into two groups: query statistics and notifications.
456
460
The query statistics metadata provides query counters that indicate the changes that the **write query** triggered on the server.
457
461
@@ -545,6 +549,9 @@ With sessions, you can run:
545
549
##### Managed transactions
546
550
547
551
To create a managed transaction, use `Session.execute_read()` procedure for read queries and `Session.execute_write()` procedure for write queries.
552
+
As of Memgraph version 3.2, queries are categorized as read or write and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
553
+
An exception will be thrown if the user tries to execute a write query inside a read transaction. See [transaction accessor misalignment](/fundamentals/transactions#transaction-accessor-misalignment) for more details.
554
+
548
555
549
556
```python
550
557
defmatch_user(tx, name):
@@ -581,6 +588,10 @@ To maintain multiple concurrent transactions, use [multiple concurrent sessions]
581
588
With explicit transactions, you can get **complete control over transactions**. To begin a transaction, run `Session.begin_transaction()` procedure and to run a transaction, use `Transaction.run()` procedure.
582
589
Explicit transactions offer the possibility of explicitly controlling the end of a transaction with `Transaction.commit()`, `Transaction.rollback()` or `Transaction.close()` methods.
583
590
591
+
As of Memgraph version 3.2, queries are categorized as read or write and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
592
+
Explicit transactions can cover a number of individual queries, but storage access is given at the start. For best performance, the user needs to declare whether the transaction should use read or write access.
593
+
This can be done by setting the session's `default_access_mode` to `"r"` or `"w"`. This will in turn set the access mode of a transaction created via the `begin_transaction` function. Note that `execute_read` and `execute_write` will override the session's default access.
594
+
584
595
Use explicit transaction if you need to **distribute Cypher execution across multiple functions for the same transaction** or if you need to **run multiple queries within a single transactions without automatic retries**.
585
596
586
597
The following example shows how to explicitly control the transaction of changing account balances based on a token transfer:
with client.session(database="memgraph") as session:
624
+
with client.session(database="memgraph", default_access_mode="w") as session:
614
625
tx = session.begin_transaction()
615
626
616
627
try:
@@ -675,6 +686,8 @@ In the above example, if John's account balance is changed to a number less than
675
686
676
687
Implicit or auto-commit transactions are the simplest way to run a Cypher query since they won't be automatically retried as with `execute_query()` procedure or managed transactions.
677
688
With implicit transactions, you don't have the same control of transaction as with explicit transactions, so they are mostly used for quick prototyping.
689
+
As of Memgraph version 3.2, queries are categorized as read or write and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
690
+
Access mode is automatically determined when executing single queries through implicit transactions.
678
691
679
692
To run an implicit transaction, use the `Session.run()` method:
Copy file name to clipboardExpand all lines: pages/help-center/errors/transactions.mdx
+25-4
Original file line number
Diff line number
Diff line change
@@ -99,6 +99,25 @@ While some client drivers may handle serialization errors by retrying transactio
99
99
developers should not rely solely on this mechanism. Always include comprehensive error handling
100
100
in your application to address cases where the error persists beyond the retry logic.
101
101
102
+
## Transaction accessor misalignment
103
+
104
+
### Error message
105
+
106
+
1.**Accessor type {} and query type {} are misaligned!**
107
+
108
+
### Handling transaction timeout
109
+
110
+
Transactions in Memgraph must acquire the appropriate type of storage access at the start of their execution. This access can be one of the following types:
111
+
112
+
-**Shared access**: Allows multiple queries to run in parallel, marked as either read or write.
113
+
-**Read-only access**: Permits multiple read queries to run in parallel but forbids any write operations or queries requiring unique access.
114
+
-**Unique access**: Grants exclusive access to a single query, preventing any other type of access during its execution.
115
+
116
+
While single queries can be parsed and the correct type of storage access can be determined automatically by Memgraph, this is not the case for explicit (managed) transactions.
117
+
In managed transactions, the database cannot infer the required access type in advance because the transaction's operations are not know at the beginning.
118
+
This can lead to storage access misalignment if the requested access type does not match the operations being performed.
119
+
120
+
See appropriate driver's documentation for more information on how to define transaction's type.
102
121
103
122
## Transaction timeout
104
123
@@ -119,15 +138,17 @@ Here are the [instructions](/configuration/configuration-settings#using-flags-an
119
138
120
139
Here are the storage access error messages you might encounter:
121
140
122
-
1.**Cannot access storage, unique access query is running. Try again later.**
141
+
1.**Cannot get shared access storage. Try stopping other queries that are running in parallel.**
123
142
2.**Cannot get unique access to the storage. Try stopping other queries that are running in parallel.**
143
+
3.**Cannot get read only access to the storage. Try stopping other queries that are running in parallel.**
124
144
125
145
### Understanding storage access timeout
126
146
127
-
Storage access timeouts occur during query preparation when the query execution engine cannot get the required type of access to the storage. There are two types of storage access:
147
+
Storage access timeouts occur during query preparation when the query execution engine cannot get the required type of access to the storage. There are three types of storage access:
128
148
129
-
-**Shared access**: Multiple queries can have shared access at the same time, but shared access cannot be granted while a query with unique access is running.
130
-
-**Unique access**: Only one query can have unique access at a time, and no other query can have any type of access during that period.
149
+
-**Shared access**: Multiple queries can have shared access at the same time. These queries are marked with a read or write type, allowing Memgraph to efficiently execute multiple operations in parallel without conflicts.
150
+
-**Unique access**: Only one query can have unique access at a time, and no other access type can be granted during that period.
151
+
-**Read-only access**: Queries with read-only access allow other read queries to run in parallel but forbid any write operations or unique access queries.
131
152
132
153
These timeouts prevent worker starvation and database blocking that could occur if queries were to wait indefinitely for storage access.
0 commit comments