Skip to content

Commit e8d0cd8

Browse files
committed
wip
1 parent bed635a commit e8d0cd8

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

pages/client-libraries/python.mdx

+10-1
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ With sessions, you can run:
545545
##### Managed transactions
546546

547547
To create a managed transaction, use `Session.execute_read()` procedure for read queries and `Session.execute_write()` procedure for write queries.
548+
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.
549+
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.
550+
548551

549552
```python
550553
def match_user(tx, name):
@@ -581,6 +584,10 @@ To maintain multiple concurrent transactions, use [multiple concurrent sessions]
581584
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.
582585
Explicit transactions offer the possibility of explicitly controlling the end of a transaction with `Transaction.commit()`, `Transaction.rollback()` or `Transaction.close()` methods.
583586

587+
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.
588+
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.
589+
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.
590+
584591
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**.
585592

586593
The following example shows how to explicitly control the transaction of changing account balances based on a token transfer:
@@ -610,7 +617,7 @@ def create_users(client, sender, receiver):
610617

611618

612619
def transfer_tokens(client, sender_id, receiver_id, num_of_tokens):
613-
with client.session(database="memgraph") as session:
620+
with client.session(database="memgraph", default_access_mode="w") as session:
614621
tx = session.begin_transaction()
615622

616623
try:
@@ -675,6 +682,8 @@ In the above example, if John's account balance is changed to a number less than
675682

676683
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.
677684
With implicit transactions, you don't have the same control of transaction as with explicit transactions, so they are mostly used for quick prototyping.
685+
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.
686+
Access mode is automatically determined when executing single queries through implicit transactions.
678687

679688
To run an implicit transaction, use the `Session.run()` method:
680689

pages/help-center/errors/transactions.mdx

+25-4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ While some client drivers may handle serialization errors by retrying transactio
9999
developers should not rely solely on this mechanism. Always include comprehensive error handling
100100
in your application to address cases where the error persists beyond the retry logic.
101101

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.
102121

103122
## Transaction timeout
104123

@@ -119,15 +138,17 @@ Here are the [instructions](/configuration/configuration-settings#using-flags-an
119138

120139
Here are the storage access error messages you might encounter:
121140

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.**
123142
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.**
124144

125145
### Understanding storage access timeout
126146

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:
128148

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.
131152

132153
These timeouts prevent worker starvation and database blocking that could occur if queries were to wait indefinitely for storage access.
133154

0 commit comments

Comments
 (0)