forked from hachikuji/kafka-specification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AsyncIsr.tla
168 lines (144 loc) · 5.15 KB
/
AsyncIsr.tla
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
78
79
80
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
(*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*)
------------------------------ MODULE AsyncIsr ------------------------------
EXTENDS Integers, Util
CONSTANTS
Replicas,
Leader,
MaxOffset
ASSUME
/\ MaxOffset > 0
/\ Leader \in Replicas
VARIABLES
controllerState,
leaderState,
requests,
updates
Offsets == 0 .. MaxOffset
Nil == -1
LeaderState == [
isr: SUBSET Replicas,
version: Nat,
pendingIsr: SUBSET Replicas,
pendingVersion: Nat,
offsets: [Replicas -> Nat]
]
ControllerState == [
isr: SUBSET Replicas,
version: Nat
]
Message == [
isr: SUBSET Replicas,
version: Nat
]
HighWatermark ==
LET potentialIsr == leaderState.isr \union leaderState.pendingIsr
IN Min({leaderState.offsets[replica]: replica \in potentialIsr})
TypeOk ==
/\ controllerState \in ControllerState
/\ leaderState \in LeaderState
/\ requests \subseteq Message
/\ updates \subseteq Message
ControllerWriteIsr(isr, version) ==
/\ version = controllerState.version + 1
/\ controllerState' = [isr |-> isr, version |-> version]
ControllerShrinkIsr == \E replica \in Replicas:
/\ replica # Leader
/\ replica \in controllerState.isr
/\ LET version == controllerState.version + 1
isr == controllerState.isr \ {replica}
IN /\ ControllerWriteIsr(isr, version)
/\ updates' = updates \union {[isr |-> isr, version |-> version]}
/\ UNCHANGED <<leaderState, requests>>
ControllerHandleRequest == \E message \in requests:
/\ message.version = controllerState.version
/\ LET version == controllerState.version + 1
IN /\ ControllerWriteIsr(message.isr, version)
/\ updates' = updates \union {[isr |-> message.isr, version |-> version]}
/\ UNCHANGED <<leaderState, requests>>
LeaderRequestShrinkIsr == \E replica \in leaderState.isr:
/\ replica # Leader
/\ LET isr == leaderState.isr \ {replica}
version == leaderState.version
IN /\ requests' = requests \union {[
isr |-> isr,
version |-> version
]}
/\ leaderState' = [leaderState EXCEPT
!.pendingIsr = @ \union isr,
!.pendingVersion = version
]
/\ UNCHANGED <<controllerState, updates>>
LeaderRequestExpandIsr == \E replica \in Replicas:
/\ replica \notin leaderState.isr
/\ leaderState.offsets[replica] \geq HighWatermark
/\ LET isr == leaderState.isr \union {replica}
version == leaderState.version
IN /\ requests' = requests \union {[
isr |-> isr,
version |-> version
]}
/\ leaderState' = [leaderState EXCEPT
!.pendingIsr = @ \union isr,
!.pendingVersion = version
]
/\ UNCHANGED <<controllerState, updates>>
LeaderWrite ==
/\ leaderState' = [leaderState EXCEPT !.offsets[Leader] = @ + 1]
/\ UNCHANGED <<controllerState, requests, updates>>
LeaderHandleUpdate == \E update \in updates:
/\ update.version > leaderState.version
/\ leaderState' = [leaderState EXCEPT
!.isr = update.isr,
!.version = update.version,
!.pendingIsr = {},
!.pendingVersion = Nil
]
/\ UNCHANGED <<controllerState, requests, updates>>
FollowerReplicate == \E replica \in Replicas:
/\ replica # Leader
/\ leaderState.offsets[replica] < leaderState.offsets[Leader]
/\ leaderState' = [leaderState EXCEPT !.offsets[replica] = @ + 1]
/\ UNCHANGED <<controllerState, requests, updates>>
Init ==
/\ controllerState = [
isr |-> Replicas,
version |-> 0
]
/\ leaderState = [
isr |-> Replicas,
version |-> 0,
pendingIsr |-> {},
pendingVersion |-> Nil,
offsets |-> [replica \in Replicas |-> 0]
]
/\ requests = {}
/\ updates = {}
Next ==
\/ ControllerShrinkIsr
\/ ControllerHandleRequest
\/ LeaderRequestShrinkIsr
\/ LeaderRequestExpandIsr
\/ LeaderWrite
\/ LeaderHandleUpdate
\/ FollowerReplicate
ValidHighWatermark == \A replica \in controllerState.isr:
leaderState.offsets[replica] \geq HighWatermark
=============================================================================
\* Modification History
\* Last modified Mon Jul 01 19:50:44 PDT 2019 by jason
\* Created Fri Jun 28 23:42:14 PDT 2019 by jason