Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

life of a transaction #278

Merged
merged 1 commit into from
Dec 27, 2022
Merged

life of a transaction #278

merged 1 commit into from
Dec 27, 2022

Conversation

romange
Copy link
Collaborator

@romange romange commented Sep 10, 2022

No description provided.

@romange romange self-assigned this Sep 10, 2022
@romange romange force-pushed the TrDoc branch 4 times, most recently from e07727f to 35a8dbc Compare September 12, 2022 17:50
odedponcz
odedponcz previously approved these changes Sep 13, 2022
docs/transaction.md Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
@@ -0,0 +1,261 @@
# Life of a transaction

This document describes how Dragonfly transactions provide atomicity and serializability for its multi-key and multi-command operations.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DragonflyDB transaction algorithm provide linearizability and serializability

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is atomicity of multi-key command, isnt it the same as Serializability?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the atomicity of a multi-key command is called strict serializability. See at the bottom example of serializable but not linearizable schedule.


Linearizability (also known as atomic consistency, strong consistency, immediate consistency) describes reads and writes on a single object (stores a single value). it doesn’t involve multiple objects. It doesn’t involve “transaction”, which groups multiple objects. It treats each operation as an atom, i.e. to take effect in a single time point, rather than a timespan.

Note that simple, single-key operations in Dragonfly are already linearizable. Indeed, in a shared-nothing architecture each shard-thread performs operations on its keys sequentially.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a shared nothing architecture each shard-thread performs operations on its keys sequentially, therefor single-key operations in DragonflyDB are already linearizable and serializability. The compexity...

Move this line to the top where you write whats in this doc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that also multi key operations ensure Linearizability in the shared nothing architecture. What we handle here is just Serializability

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, if we user1 applies "mset x a1 y b1" and user2 applies "mset x a2 y b2", user3 may read "x=a1, y=b2" (serializable) but also "x=a2, y=b1" - also serializable. Both are not linearizable because it should be either "a1 b1" or "a2 b2"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the definistion you added on serializable and linearizable

Linearizability (also known as atomic consistency, strong consistency, immediate consistency) describes reads and writes on a single object (stores a single value). it doesn’t involve multiple objects.
From what I understand here it has nothing to do with the multi key command

Database can executed transactions in parallel (and the operations in parallel). Serializability guarantees the result is the same with, as if the transactions were executed one by one. i.e. to behave like executed in a serial order.
From what I understand here this exactly answers the issue that we can not return "x=a2, y=b1"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review again this comment. You describe Linearizability (for single object) and not atomicity.
Above you write
"This document describes how Dragonfly transactions provide atomicity and serializability for its multi-key and multi-command operations."
here you describe Linearizability and below you write
The complexity rises when we need to provide strict-serializability (aka serializability and linearizability) for multiple keys.
The terms are confusing.
Its better if you use one term, stick with it and describe it. f.e if you want to decribe how Dragonfly transactions provide atomicity and serializability, than define atomicity and serializability. The Linearizability definition is redundant


### Linearizability

Linearizability (also known as atomic consistency, strong consistency, immediate consistency) describes reads and writes on a single object (stores a single value). it doesn’t involve multiple objects. It doesn’t involve “transaction”, which groups multiple objects. It treats each operation as an atom, i.e. to take effect in a single time point, rather than a timespan.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add - Linearizability is a recency guarantee. Once a writer sets new value, the value immediately takes effect. All readers immediately see the new value


## Transactions high level overview
Transactions in Dragonfly are orchestrated by an abstract entity, called coordinator.
In reality, a client connection instance takes on itself the role of a coordinator: it coordinates transactions every time it executes a redis or memcached command. The algorithm behind Dragonfly transactions is based on the [VLL paper](https://www.cs.umd.edu/~abadi/papers/vldbj-vll.pdf).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coordinator is handling a single command every time till it finishes right ?
I would not say executes a command because it mixes with the execute phase below, use another word.
What is to coordinate a transaction?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a client connection instance takes on itself the role of a coordinator.The transaction to 2 phases schedule and execution, which might consist of one or more steps. The coordinator is responsible to orchestrate this 2 phases and the steps inside.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewritten differently.


The flow consists of two different phases: *scheduling* a transaction, and *executing* it. The execution phase may consist of one or more hops, depending on the complexity of the operation we model.

*Note, that only the coordinator fiber is blocked. Its thread can still execute other fibers - like processing requests on other connections or handling operations for the shard it owns. This is the advantage of adopting fibers - they allow us to separate the execution context from OS threads.*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thread has multiple coordinator fibers ? Or just one coordinator fiber and one data shard?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a thread may contain many fibers. each connection is a fiber

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I read again the shared nothing doc.
A thread can contain few coordinators and only one data shard
In my head a thread was only one data shard and one coordinators, so maybe we can update the diagram I created

As shown in the snippet below, a shard thread may receive transactions in a different sequence, so a transaction with a smaller id can be added to the tx-queue after a transaction with a larger id. If the scheduling algorithm running on the data shard, can not reorder the last added transaction, it fails the scheduling request. In that case, the coordinator reverts the scheduling operation by removing the tx from the shards, and retries the whole hop again by allocating a new sequence number. In reality the fail-rate of a scheduling attempt is low and the retries are rare (subject to contention on the keys). Note, inconsistent reordering happens when two coordinators try to schedule multi-shard transactions concurrently:

```
C1: enqueue msg to Shard1 to schedule T1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C1: enqueue msg to Shard1 to schedule T1
C2: enqueue msg to Shard2 to schedule T2
C2: enqueue msg to Shard1 to schedule T2
C1: enqueue msg to Shard2 to schedule T1

docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved
docs/transaction.md Outdated Show resolved Hide resolved

## Blocking commands (BLPOP)

Redis has a rich api with around 200 commands. Few of those commands provide blocking semantics, which allow using Redis as publisher/subscriber broker.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this is to much reading for me to digest in one day.. but
Is this section related to how DragonflyDB transactions framework provide serializability for its multi-key and multi-command operations?

Copy link
Collaborator Author

@romange romange Nov 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I will move it to another document in subsequent Prs. No need to read past this point

adiholden
adiholden previously approved these changes Dec 26, 2022
Signed-off-by: Roman Gershman <roman@dragonflydb.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants