scratch.md 5.4 KB
Newer Older
H
more  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
```plantuml
    @startuml create_table
    skinparam sequenceMessageAlign center
    skinparam responseMessageBelowArrow true

    participant APP as app
    box "dnode1"
        participant RPC as rpc
        participant VNODE as vnode
        participant SYNC as sync
    end box

    box "dnode2"
        participant SYNC as sync2
        participant VNODE as vnode2
    end box

    box "dnode3"
        participant SYNC as sync3
        participant VNODE as vnode3
    end box

    ' APP send request to dnode and RPC in dnode recv the request
    app ->rpc: create table req

    ' RPC call vnodeProcessReq() function to process the request
    rpc -> vnode: vnodeProcessReq
    note right
    callback function 
    run in RPC module 
    threads. The function
    only puts the request
    to a vnode queue.
    end note

    ' VNODE call vnodeProcessReqs() function to integrate requests and process as a whole
    vnode -> vnode: vnodeProcessReqs()
    note right
    integrate reqs and 
    process as a whole
    end note


    ' sync the request to other nodes
    vnode -> sync: syncProcessReqs()

    ' make request persistent
    ' sync -->vnode: walWrite()\n(callback function)

    ' replicate requests to other DNODES
    sync -> sync2: replication req
    sync -> sync3: replication req
    sync2 -> vnode2: walWrite()\n(callback function)
    sync2 --> sync: replication rsp\n(confirm)
    sync3 -> vnode3: walWrite()\n(callback function)

    sync3 --> sync: replication rsp\n(confirm)

    ' send apply request
    sync -> sync2: apply req
    sync -> sync3: apply req

    ' vnode apply
    sync2 -> vnode2: vnodeApplyReqs()
    sync3 -> vnode3: vnodeApplyReqs()

    ' call apply request
    sync --> vnode: vnodeApplyReqs()\n(callback function)

    ' send response
    vnode --> rpc: rpcSendRsp()

    ' dnode send response to APP
    rpc --> app: create table rsp
    @enduml
```

H
more  
Hongze Cheng 已提交
78
## Leader处理强一致写入请求
H
more  
Hongze Cheng 已提交
79
```plantuml
H
more  
Hongze Cheng 已提交
80
    @startuml leader_process_stict_consistency
H
more  
Hongze Cheng 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    box "dnode1"
        participant CRPC as crpc
        participant VNODE as vnode
        participant SYNC as sync
    end box

    -> crpc: create table/submit req

    ' In CRPC threads
    group #pink "In CRPC threads"
        crpc -> vnode:vnodeProcessReq()
        note right
            A callback function
            run by CRPC thread
            to put the request
            to a vnode queue
        end note
    end

    ' In VNODE worker threads
    group #lightblue "In VNODE worker threads"
        vnode -> vnode: vnodeProcessReqs()
        note right
            VNODE process requests
            accumulated in a 
            vnode write queue and
            process the batch reqs
            as a whole
        end note

        vnode -> sync: syncProcessReqs()

        sync -> : replication req1
        sync -> : replication req2
    end

    group #red "SYNC threads"
        sync <- : replication rsp1
        sync <- : replication rsp2
        sync -> vnode: notify apply
H
more  
Hongze Cheng 已提交
121 122
        sync -> : apply rsp1
        sync -> : apply rsp2
H
more  
Hongze Cheng 已提交
123 124 125 126 127 128 129 130 131 132 133 134
    end

    group #lightblue "In VNODE worker threads"
        vnode -> vnode: vnodeApplyReqs()
        vnode -> crpc:
    end

    <- crpc: create table/submit rsp

    @enduml
```

H
more  
Hongze Cheng 已提交
135
## Follower处理强一致写入请求
H
more  
Hongze Cheng 已提交
136
```plantuml
H
more  
Hongze Cheng 已提交
137
    @startuml follower_process_strict_consistency
H
more  
Hongze Cheng 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
    participant SYNC as sync
    participant VNODE as vnode

    group #pink "SYNC threads"
        -> sync: replication req

        sync -> sync: syncProcessReqs()
        note right
            In the replication
            only data is
            persisted and response
            is sent back
        end note

        <- sync: replication rsp
H
more  
Hongze Cheng 已提交
153 154 155 156 157 158 159 160

        -> sync: apply req

        sync -> vnode: notify apply
    end

    group #lightblue "VNODE worker threads"
        vnode -> vnode: vnodeApplyReqs()
H
more  
Hongze Cheng 已提交
161 162 163 164 165
    end

    @enduml
```

H
more  
Hongze Cheng 已提交
166
## Leader处理最终一致写入请求
H
more  
Hongze Cheng 已提交
167
```plantuml
H
more  
Hongze Cheng 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
    @startuml leader_process_eventual_consistency
    box "dnode1"
        participant CRPC as crpc
        participant VNODE as vnode
        participant SYNC as sync
    end box

    -> crpc: create table/submit req

    ' In CRPC threads
    group #pink "In CRPC threads"
        crpc -> vnode:vnodeProcessReq()
        note right
            A callback function
            run by CRPC thread
            to put the request
            to a vnode queue
        end note
    end

    ' In VNODE worker threads
    group #lightblue "In VNODE worker threads"
        vnode -> vnode: vnodeProcessReqs()
        note right
            VNODE process requests
            accumulated in a 
            vnode write queue and
            process the batch reqs
            as a whole
        end note

        vnode -> sync: syncProcessReqs()

        sync -> : replication req1
        sync -> : replication req2

        sync -> vnode: notify apply
    end


    group #lightblue "In VNODE worker threads"
        vnode -> vnode: vnodeApplyReqs()
        vnode -> crpc:
    end

    <- crpc: create table/submit rsp

    @enduml
```

## Follower处理最终一致写入请求
```plantuml
    @startuml follower_process_eventual_consistency
H
more  
Hongze Cheng 已提交
221 222 223 224 225 226
    participant SYNC as sync
    participant VNODE as vnode

    group #pink "SYNC threads"
        -> sync: replication rsp

H
more  
Hongze Cheng 已提交
227 228
        sync -> sync: syncProcessReqs()

H
more  
Hongze Cheng 已提交
229 230 231 232 233 234 235 236
        sync -> vnode: notify VNODE \nthread to process\n the reqs
    end

    group #lightblue "VNODE worker threads"
        vnode -> vnode: vnodeApplyReqs()
    end
    @enduml
```