Skip to content

Commit 25c6b20

Browse files
committed
wip
1 parent bed635a commit 25c6b20

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-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 ... 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

+6-4
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,17 @@ Here are the [instructions](/configuration/configuration-settings#using-flags-an
119119

120120
Here are the storage access error messages you might encounter:
121121

122-
1. **Cannot access storage, unique access query is running. Try again later.**
122+
1. **Cannot get shared access storage. Try stopping other queries that are running in parallel.**
123123
2. **Cannot get unique access to the storage. Try stopping other queries that are running in parallel.**
124+
3. **Cannot get read only access to the storage. Try stopping other queries that are running in parallel.**
124125

125126
### Understanding storage access timeout
126127

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:
128+
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:
128129

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.
130+
- **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.
131+
- **Unique access**: Only one query can have unique access at a time, and no other access type can be granted during that period.
132+
- **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.
131133

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

0 commit comments

Comments
 (0)