Skip to content

Commit 0f2ad5e

Browse files
authored
Merge pull request #150 from apkar/remove-explicit-tr
Remove explicit transactions
2 parents 1214a6f + f51d00f commit 0f2ad5e

14 files changed

+88
-764
lines changed

docs/architecture.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ FoundationDB.
4545

4646
As the application sees the instance pool through load balancer, reconnection
4747
to the same IP could go to different instance. This makes it hard to depend on
48-
any server state. In this setup, the Document Layer transactions do not provide
49-
correct consistency guarantees. Transactions should not be used in this model.
48+
any server state.
5049

5150
**Note:** Cursors work properly as cursor requests come with an ID, which is used
5251
to fail the request that went to wrong server.

docs/data-modeling.md

Lines changed: 1 addition & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,7 @@ transactions, see [transactions](transactions.md).
1313
The Document Layer implements a subset of the MongoDB® API (v 3.0.0)
1414
with a few [known differences](known-differences.md). As a result,
1515
most of the data modeling techniques used with MongoDB® are
16-
applicable to the Document Layer as well. However, the Document
17-
Layer adds transactions in a way that differs from the way transactions
18-
were added to the MongoDB® v 4.0 API, which means that client code
19-
written to use multi-document transactions may need to be modified
20-
to work with the Document Layer.
21-
22-
Transactions are a tool for concurrency control that allows multiple
23-
clients to read and write data with strong guarantees about how the
24-
clients can affect each other. Transactions provide new capabilities for
25-
data modeling because they can operate on multiple documents with full
26-
[ACID](https://en.wikipedia.org/wiki/ACID_(computer_science)) guarantees.
27-
28-
Note that regardless of whether or not the user specifies an explicit
29-
transaction, all Document Layer operations must occur within the context
30-
of some transaction of the underlying FoundationDB Key-Value Store. If
31-
the user does not supply one explicitly, then the Document Layer will
32-
create one transaction per operation. This means that there is very
33-
little overhead for using a multi-document transaction compared to a
34-
single-document operation. As a result, the Document Layer is very
35-
amenable to data models that require such transactions.
16+
applicable to the Document Layer as well.
3617

3718
## Embedding data
3819

@@ -144,88 +125,3 @@ to) a given task as follows:
144125
def find_members(db, task_id):
145126
return db.tasks.find_one({'_id': ObjectId(task_id)}, {'members': 1})
146127
```
147-
148-
## Transactions for multi-document operations
149-
150-
The `find_members` function is a simple example that reads from only a
151-
*single* document. In order to change a task assignment, you'll need to
152-
update *two* documents, one for the person and one for the task. The
153-
Document Layer's transactions make it easy to perform multi-document
154-
operations in an atomic and isolated manner.
155-
156-
Here are a few examples using the [@transactional](transactions.md#retry-loops)
157-
decorator with PyMongo. You can add a new member to a task as follows:
158-
159-
```python
160-
@transactional
161-
def add_member(db, person_id, task_id):
162-
db.persons.update({u'_id': ObjectId(person_id)},
163-
{'$addToSet': {u'tasks': ObjectId(task_id)}})
164-
db.tasks.update({u'_id': ObjectId(task_id)},
165-
{'$addToSet': {u'members': ObjectId(person_id)}})
166-
```
167-
168-
The `@transactional` decorator implements a retry loop, which may, on
169-
occasion, execute the transaction more than once. You should therefore
170-
check that this transactional function is [idempotent](transactions.md#idempotence),
171-
producing the same result if executed multiple times as if executed once.
172-
173-
In this case, the idempotence of `add_member()` is guaranteed by the
174-
`$addToSet` operator, which never adds more than a single copy of an
175-
element to an array. It would therefore be a bug to use the `$push`
176-
operator in this function instead of `$addToSet`, as `$push` may add
177-
redundant copies of an element.
178-
179-
Removing a member from a task is similar:
180-
181-
```python
182-
@transactional
183-
def remove_member(db, person_id, task_id):
184-
db.persons.update({u'_id': ObjectId(person_id)},
185-
{'$pullAll': {u'tasks': [ObjectId(task_id)]}})
186-
db.tasks.update({u'_id': ObjectId(task_id)},
187-
{'$pullAll': {u'members': [ObjectId(person_id)]}})
188-
```
189-
190-
Here, idempotence is guaranteed because an element can only be removed
191-
from an array once. `$pullAll` will simply have no effect on a
192-
subsequent execution.
193-
194-
Finally, you can wholesale reassign a task by removing and adding lists
195-
of persons, all in a single transaction:
196-
197-
```python
198-
@transactional
199-
def reassign_task(db, task_id, old_person_ids, new_person_ids):
200-
201-
# get lists of the object ids
202-
remove_objects = map(ObjectId, old_person_ids)
203-
add_objects = map(ObjectId, new_person_ids)
204-
205-
# remove task from old persons
206-
db.persons.update({u'_id': {'$in': remove_objects}},
207-
{'$pullAll': {u'tasks': [ObjectId(task_id)]}},
208-
multi=True)
209-
210-
# add task to new persons
211-
db.persons.update({u'_id': {'$in': add_objects}},
212-
{'$addToSet': {u'tasks': ObjectId(task_id)}},
213-
multi=True)
214-
215-
# remove old persons from task
216-
db.tasks.update({u'_id': ObjectId(task_id)},
217-
{'$pullAll': {u'members': remove_objects}})
218-
219-
# add new persons to task
220-
db.tasks.update({u'_id': ObjectId(task_id)},
221-
{'$addToSet': {u'members': add_objects}})
222-
```
223-
224-
This transactional function is idempotent for the same reasons as
225-
`add_member()` and `remove_member()`.
226-
227-
In summary, all data modeling techniques available in MongoDB® remain
228-
available in the Document Layer. However, transactions provide a new
229-
capability by coordinating operations across multiple documents with
230-
guarantees of atomicity and isolation. This capability makes the use of
231-
references between documents much safer.

docs/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Welcome to the documentation for the FoundationDB Document Layer.
88

99
FoundationDB Document Layer is a stateless microserver that exposes a document-oriented database API. The Document Layer speaks the MongoDB® wire protocol, allowing the use of the MongoDB® API via existing MongoDB® client bindings. All persistent data are stored in the FoundationDB Key-Value Store.
1010

11-
The Document Layer implements a subset of the MongoDB® API (v 3.0.0) with some [differences](known-differences.md). This subset is mainly focused on CRUD operations, indexes and transactions. The Document Layer works with all the latest official MongoDB® drivers.
11+
The Document Layer implements a subset of the MongoDB® API (v 3.0.0) with some [differences](known-differences.md). This subset is mainly focused on CRUD operations and indexes. The Document Layer works with all the latest official MongoDB® drivers.
1212

1313
NOTE: [mongo-go-driver](https://github.com/mongodb/mongo-go-driver) assumes server is atleast 3.2. If you use it against Document Layer it fails on `find` commands. This should be fixed with [#11](https://github.com/FoundationDB/fdb-document-layer/issues/11).
1414

@@ -25,7 +25,6 @@ Layer and how to develop applications on top of it.
2525
* [Getting started on Linux](getting-started-linux.md)
2626
* [Architecture](architecture.md)
2727
* [Developer Guide](developer-guide.md)
28-
* [Transactions](transactions.md)
2928
* [Data Modeling](data-modeling.md)
3029
* [Known Differences](known-differences.md)
3130
* [Configuration](configuration.md)

docs/known-differences.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ future release, we expect this limit to become configurable.
6666

6767
## Unimplemented features
6868

69-
Document Layer's feature set is focused on CRUD operations, indexes and
70-
transactions. Some of the important features missing are listed here.
69+
Document Layer's feature set is focused on CRUD operations and indexes. Some of the important features missing are listed here.
7170

7271
#### Aggregation framework
7372
The Document Layer does not implement the MongoDB® aggregation

0 commit comments

Comments
 (0)