@@ -42,6 +42,7 @@ align="right">
42
42
* [ Implementation details] ( #implementation-details )
43
43
* [ Queue drivers] ( #queue-drivers )
44
44
* [ Driver API] ( #driver-api )
45
+ * [ Queue and replication] ( #queue-and-replication )
45
46
46
47
# Queue types
47
48
@@ -753,3 +754,65 @@ seconds. If queue does not support `ttr`, error will be thrown. Returns the task
753
754
must be called only by the user who created this tube (has space ownership) OR
754
755
under a ` setuid ` function. Read more about ` setuid ` functions
755
756
[ 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