Skip to content

Commit 27d9b8d

Browse files
committed
readme: add queue and replication description
1 parent 08882b6 commit 27d9b8d

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ align="right">
4242
* [Implementation details](#implementation-details)
4343
* [Queue drivers](#queue-drivers)
4444
* [Driver API](#driver-api)
45+
* [Queue and replication](#queue-and-replication)
4546

4647
# Queue types
4748

@@ -753,3 +754,65 @@ seconds. If queue does not support `ttr`, error will be thrown. Returns the task
753754
must be called only by the user who created this tube (has space ownership) OR
754755
under a `setuid` function. Read more about `setuid` functions
755756
[here](http://tarantool.org/doc/book/box/authentication.html?highlight=function#functions-and-the-func-space).
757+
758+
# Queue and replication
759+
760+
Queue can be used in a master-replica scheme:
761+
762+
There are five states for queue:
763+
* INIT
764+
* STARTUP
765+
* RUNNING
766+
* ENDING
767+
* WAITING
768+
769+
When the tarantool is launched for the first time,
770+
the state of the queue is always `INIT` until `box.info.ro` is false.
771+
772+
States switching scheme:
773+
```mermaid
774+
stateDiagram-v2
775+
direction LR
776+
w: Waiting
777+
note right of w
778+
monitor rw status
779+
end note
780+
s: Startup
781+
note left of s
782+
wait for maximum
783+
upstream lag * 2
784+
release all tasks
785+
start driver
786+
end note
787+
Init --> s
788+
r: Running
789+
note right of r
790+
queue is ready
791+
end note
792+
e: Ending
793+
note left of e
794+
stop driver
795+
end note
796+
w --> s: ro -> rw
797+
s --> r
798+
r --> e: rw -> ro
799+
e --> w
800+
```
801+
802+
Current queue state can be shown by using `queue.state()` method.
803+
804+
In the `STARTUP` state, the queue is waiting for possible data synchronization
805+
with other cluster members by the time of the largest upstream lag multiplied
806+
by two. After that, all taken tasks are released, except for tasks with
807+
session uuid matching inactive sessions uuids. This makes possible to take
808+
a task, switch roles on the cluster, and release the task within the timeout
809+
specified by the `queue.cfg({ttr = N})` parameter. Note: all clients that `take()`
810+
and do not `ack()/release()` tasks must be disconnected before changing the role.
811+
And the last step in the `STARTUP` state is starting tube driver using new
812+
method called `start()`.
813+
814+
In the `RUNNING` state, the queue is working as usually. The `ENDING` state calls
815+
`stop()` method. in the `WAITING` state, the queue listens for a change in the
816+
read_only flag.
817+
818+
All states except `INIT` is controlled by new fiber called `queue_state_fiber`.

0 commit comments

Comments
 (0)