-
Notifications
You must be signed in to change notification settings - Fork 0
/
rraft.pyi
3431 lines (3089 loc) · 116 KB
/
rraft.pyi
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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Type hints for Native Rust Extension
"""
from abc import ABCMeta, abstractmethod
from typing import Any, Callable, Final, Optional
NO_LIMIT: Final[Any]
"""
A number to represent that there is no limit.
"""
CAMPAIGN_ELECTION: Final[Any]
"""
CAMPAIGN_ELECTION represents a normal (time-based) election (the second phase
of the election when Config.pre_vote is true).
"""
CAMPAIGN_PRE_ELECTION: Final[Any]
"""
CAMPAIGN_PRE_ELECTION represents the first phase of a normal election when
Config.pre_vote is true.
"""
CAMPAIGN_TRANSFER: Final[Any]
"""
CAMPAIGN_TRANSFER represents the type of leader transfer.
"""
INVALID_ID: Final[Any]
"""
A constant represents invalid id of raft.
"""
INVALID_INDEX: Final[Any]
"""
A constant represents invalid index of raft log.
"""
def majority(total: int) -> int:
"""
Get the majority number of given nodes count.
"""
def default_logger() -> "Logger":
"""
The default logger we fall back to when passed `None` in external_bindings facing constructors.
Currently, this is a `log` adaptor behind a `Once` to ensure there is no clobbering.
"""
def vote_resp_msg_type(t: "MessageType") -> "MessageType":
"""
Maps vote and pre_vote message types to their correspond responses.
"""
class __DICT_SERIALIZABLE(metaclass=ABCMeta):
@abstractmethod
def to_dict(self) -> dict[str, Any]: ...
class __Cloneable(metaclass=ABCMeta):
@abstractmethod
def clone(self) -> Any: ...
class __Encoder:
def encode(self) -> bytes:
""" """
class __Decoder:
@staticmethod
def decode(v: bytes) -> Any:
""" """
def set_snapshot_data_deserializer(cb: Callable[[bytes], str | bytes]) -> None:
""" """
def set_message_context_deserializer(cb: Callable[[bytes], str | bytes]) -> None:
""" """
def set_confchange_context_deserializer(cb: Callable[[bytes], str | bytes]) -> None:
""" """
def set_confchangev2_context_deserializer(cb: Callable[[bytes], str | bytes]) -> None:
""" """
def set_entry_data_deserializer(cb: Callable[[bytes], str | bytes]) -> None:
""" """
def set_entry_context_deserializer(cb: Callable[[bytes], str | bytes]) -> None:
""" """
class OverflowStrategy:
""" """
Block: Final[Any]
"""
The caller is blocked until there's enough space.
"""
Drop: Final[Any]
"""
The message gets dropped silently.
"""
DropAndReport: Final[Any]
"""
The message gets dropped and a message with number of dropped is produced once there's
space.
This is the default.
Note that the message with number of dropped messages takes one slot in the channel as
well.
"""
class SnapshotStatus:
"""The status of the snapshot."""
Finish: Final[Any]
"""
Represents that the snapshot is finished being created.
"""
Failure: Final[Any]
"""
Indicates that the snapshot failed to build or is not ready.
"""
class ProgressState:
"""The state of the progress."""
Probe: Final[Any]
"""
Whether it's probing.
"""
Replicate: Final[Any]
"""
Whether it's replicating.
"""
Snapshot: Final[Any]
"""
Whether it's a snapshot.
"""
class StateRole:
"""The role of the node."""
Candidate: Final[Any]
"""
The node could become a leader.
"""
Follower: Final[Any]
"""
The node is a follower of the leader.
"""
Leader: Final[Any]
"""
The node is a leader.
"""
PreCandidate: Final[Any]
"""
The node could become a candidate, if `prevote` is enabled.
"""
class ReadOnlyOption:
"""Determines the relative safety of and consistency of read only requests."""
Safe: Final[Any]
"""
Safe guarantees the linearizability of the read only request by
communicating with the quorum. It is the default and suggested option.
"""
LeaseBased: Final[Any]
"""
LeaseBased ensures linearizability of the read only request by
relying on the leader lease. It can be affected by clock drift.
If the clock drift is unbounded, leader might keep the lease longer than it
should (clock can move backward/pause without any bound). ReadIndex is not safe
in that case.
"""
class MessageType:
""" """
MsgHup: Final[Any]
MsgBeat: Final[Any]
MsgPropose: Final[Any]
MsgAppend: Final[Any]
MsgAppendResponse: Final[Any]
MsgRequestVote: Final[Any]
MsgRequestVoteResponse: Final[Any]
MsgSnapshot: Final[Any]
MsgHeartbeat: Final[Any]
MsgHeartbeatResponse: Final[Any]
MsgUnreachable: Final[Any]
MsgSnapStatus: Final[Any]
MsgCheckQuorum: Final[Any]
MsgTransferLeader: Final[Any]
MsgTimeoutNow: Final[Any]
MsgReadIndex: Final[Any]
MsgReadIndexResp: Final[Any]
MsgRequestPreVote: Final[Any]
MsgRequestPreVoteResponse: Final[Any]
@staticmethod
def from_int(v: int) -> "MessageType": ...
def __int__(self) -> int: ...
class ConfChangeTransition:
""" """
Auto: Final[Any]
"""
Automatically use the simple protocol if possible, otherwise fall back
to ConfChangeType::Implicit. Most applications will want to use this.
"""
Implicit: Final[Any]
"""
Use joint consensus unconditionally, and transition out of them
automatically (by proposing a zero configuration change).
This option is suitable for applications that want to minimize the time
spent in the joint configuration and do not store the joint configuration
in the state machine (outside of InitialState).
"""
Explicit: Final[Any]
"""
Use joint consensus and remain in the joint configuration until the
application proposes a no-op configuration change. This is suitable for
applications that want to explicitly control the transitions, for example
to use a custom payload (via the Context field).
"""
@staticmethod
def from_int(v: int) -> "ConfChangeTransition": ...
def __int__(self) -> int: ...
class ConfChangeType:
""" """
AddNode: Final[Any]
AddLearnerNode: Final[Any]
RemoveNode: Final[Any]
@staticmethod
def from_int(v: int) -> "ConfChangeType": ...
def __int__(self) -> int: ...
class EntryType:
""" """
EntryConfChange: Final[Any]
EntryConfChangeV2: Final[Any]
EntryNormal: Final[Any]
@staticmethod
def from_int(v: int) -> "EntryType": ...
def __int__(self) -> int: ...
class __API_Logger:
def info(self, s: str) -> None:
"""
Log info level record
See `slog_log` for documentation.
"""
def debug(self, s: str) -> None:
"""
Log debug level record
See `slog_debug` for documentation.
"""
def trace(self, s: str) -> None:
"""
Log trace level record
See `slog_trace` for documentation.
"""
def crit(self, s: str) -> None:
"""
Log crit level record
See `slog_crit` for documentation.
"""
def error(self, s: str) -> None:
"""
Log error level record
See `slog_error` for documentation.
"""
class Logger(__API_Logger):
""" """
def __init__(
self, chan_size: int, overflow_strategy: "OverflowStrategy"
) -> None: ...
@staticmethod
def new_file_logger(
log_path: str, chan_size: int, rotate_size: int, rotate_keep: int
): ...
def make_ref(self) -> "LoggerRef": ...
class LoggerRef(__API_Logger):
""" """
class __API_RaftState(__Cloneable):
def clone(self) -> "RaftState": ...
def initialized(self) -> bool:
"""
Indicates the `RaftState` is initialized or not.
"""
def get_conf_state(self) -> "ConfStateRef":
"""
`conf_state`: Records the current node IDs like `[1, 2, 3]` in the cluster. Every Raft node must have a
unique ID in the cluster;
"""
def set_conf_state(self, cs: "ConfState" | "ConfStateRef") -> None:
"""
`conf_state`: Records the current node IDs like `[1, 2, 3]` in the cluster. Every Raft node must have a
unique ID in the cluster;
"""
def get_hard_state(self) -> "HardStateRef":
"""
`hard_state`: Contains the last meta information including commit index, the vote leader, and the vote term.
"""
def set_hard_state(self, hs: "HardState" | "HardStateRef") -> None:
"""
`hard_state`: Contains the last meta information including commit index, the vote leader, and the vote term.
"""
class RaftState(__API_RaftState):
"""
Holds both the hard state (commit index, vote leader, term) and the configuration state
(Current node IDs)
"""
def __init__(self) -> None: ...
def make_ref(self) -> "RaftStateRef": ...
@staticmethod
def default() -> "RaftState": ...
class RaftStateRef(__API_RaftState):
"""
Reference type of :class:`RaftState`.
"""
class __API_MemStorageCore:
def append(self, ents: list["Entry"] | list["EntryRef"]) -> None:
"""
Append the new entries to storage.
# Panics
Panics if `ents` contains compacted entries, or there's a gap between `ents` and the last
received entry in the storage.
"""
def apply_snapshot(self, snapshot: "Snapshot" | "SnapshotRef") -> None:
"""
Overwrites the contents of this Storage object with those of the given snapshot.
# Panics
Panics if the snapshot index is less than the storage's first index.
"""
def compact(self, compact_index: int) -> None:
"""
Discards all log entries prior to compact_index.
It is the application's responsibility to not attempt to compact an index
greater than RaftLog.applied.
# Panics
Panics if `compact_index` is higher than `Storage::last_index(&self) + 1`.
"""
def commit_to(self, index: int) -> None:
"""
Commit to an index.
# Panics
Panics if there is no such entry in raft logs.
"""
def commit_to_and_set_conf_states(
self, idx: int, cs: Optional["ConfState"] | Optional["ConfStateRef"]
) -> None:
"""
Commit to `idx` and set configuration to the given states. Only used for tests.
"""
def set_conf_state(self, cs: "ConfState" | "ConfStateRef") -> None:
"""
Saves the current conf state.
"""
def hard_state(self) -> "HardStateRef":
"""
Get the hard state.
"""
def set_hardstate(self, hs: "HardState" | "HardStateRef") -> None:
"""
Saves the current HardState.
"""
def trigger_snap_unavailable(self) -> None:
"""
Trigger a SnapshotTemporarilyUnavailable error.
"""
def trigger_log_unavailable(self, v: bool) -> None:
"""
Set a LogTemporarilyUnavailable error.
"""
def take_get_entries_context(self) -> Optional["GetEntriesContext"]:
"""
Take get entries context.
"""
class MemStorageCore(__API_MemStorageCore):
"""
The Memory Storage Core instance holds the actual state of the storage struct. To access this
value, use the `rl` and `wl` functions on the main MemStorage implementation.
"""
def make_ref(self) -> "MemStorageCoreRef": ...
@staticmethod
def default() -> "MemStorageCore": ...
class MemStorageCoreRef(__API_MemStorageCore):
"""
Reference type of :class:`MemStorage`.
"""
class __API_Storage(__Cloneable):
def clone(self) -> Any: ...
def initialize_with_conf_state(
self, conf_state: "ConfState" | "ConfStateRef"
) -> None:
"""
Initialize a `MemStorage` with a given `Config`.
You should use the same input to initialize all nodes.
"""
def initial_state(self) -> RaftState:
"""
`initial_state` is called when Raft is initialized. This interface will return a `RaftState`
which contains `HardState` and `ConfState`.
`RaftState` could be initialized or not. If it's initialized it means the `Storage` is
created with a configuration, and its last index and term should be greater than 0.
"""
def entries(
self,
low: int,
high: int,
context: "GetEntriesContextRef",
max_size: Optional[int],
) -> list["Entry"]:
"""
Returns a slice of log entries in the range `[low, high)`.
max_size limits the total size of the log entries returned if not `None`, however
the slice of entries returned will always have length at least 1 if entries are
found in the range.
Entries are supported to be fetched asynchronously depending on the context. Async is optional.
Storage should check context.can_async() first and decide whether to fetch entries asynchronously
based on its own implementation. If the entries are fetched asynchronously, storage should return
LogTemporarilyUnavailable, and application needs to call `on_entries_fetched(context)` to trigger
re-fetch of the entries after the storage finishes fetching the entries.
# Panics
Panics if `high` is higher than `Storage::last_index(&self) + 1`.
"""
def term(self, idx: int) -> int:
"""
Returns the term of entry idx, which must be in the range
[first_index()-1, last_index()]. The term of the entry before
first_index is retained for matching purpose even though the
rest of that entry may not be available.
"""
def first_index(self) -> int:
"""
Returns the index of the first log entry that is possible available via entries, which will
always equal to `truncated index` plus 1.
New created (but not initialized) `Storage` can be considered as truncated at 0 so that 1
will be returned in this case.
"""
def last_index(self) -> int:
"""
The index of the last entry replicated in the `Storage`.
"""
def snapshot(self, request_index: int, to: int) -> "Snapshot":
"""
Returns the most recent snapshot.
If snapshot is temporarily unavailable, it should return SnapshotTemporarilyUnavailable,
so raft state machine could know that Storage needs some time to prepare
snapshot and call snapshot later.
A snapshot's index must not less than the `request_index`.
`to` indicates which peer is requesting the snapshot.
"""
class MemStorage(__API_Storage):
"""
`MemStorage` is a thread-safe but incomplete implementation of `Storage`, mainly for tests.
A real `Storage` should save both raft logs and applied data. However `MemStorage` only
contains raft logs. So you can call `MemStorage::append` to persist new received unstable raft
logs and then access them with `Storage` APIs. The only exception is `Storage::snapshot`. There
is no data in `Snapshot` returned by `MemStorage::snapshot` because applied data is not stored
in `MemStorage`.
"""
def __init__(self) -> None: ...
def make_ref(self) -> "MemStorageRef": ...
def clone(self) -> "MemStorage": ...
@staticmethod
def default() -> "MemStorage": ...
@staticmethod
def new_with_conf_state(
conf_state: "ConfState" | "ConfStateRef",
) -> "MemStorage":
"""
Create a new `MemStorage` with a given `Config`. The given `Config` will be used to
initialize the storage.
You should use the same input to initialize all nodes.
"""
def wl(self) -> "MemStorageCoreRef":
"""
Opens up a write lock on the storage and returns guard handle. Use this
with functions that take a mutable reference to self.
"""
def rl(self) -> "MemStorageCoreRef":
"""
Opens up a read lock on the storage and returns a guard handle. Use this
with functions that don't require mutation.
"""
class MemStorageRef(__API_Storage):
"""
Reference type of :class:`MemStorage`.
"""
def clone(self) -> "MemStorage": ...
def wl(self) -> "MemStorageCoreRef":
"""
Opens up a write lock on the storage and returns guard handle. Use this
with functions that take a mutable reference to self.
"""
def rl(self) -> "MemStorageCoreRef":
"""
Opens up a read lock on the storage and returns a guard handle. Use this
with functions that don't require mutation.
"""
class Storage(__API_Storage):
"""
Storage saves all the information about the current Raft implementation, including Raft Log,
commit index, the leader to vote for, etc.
If any Storage method returns an error, the raft instance will
become inoperable and refuse to participate in elections; the
application is responsible for cleanup and recovery in this case.
"""
def __init__(self, storage: Any) -> None: ...
def make_ref(self) -> "StorageRef": ...
def clone(self) -> "Storage": ...
@staticmethod
def default() -> "Storage": ...
@staticmethod
def new_with_conf_state(
conf_state: "ConfState" | "ConfStateRef",
) -> "Storage":
""" """
def wl(self) -> Any:
"""
Opens up a write lock on the storage and returns guard handle. Use this
with functions that take a mutable reference to self.
"""
def rl(self) -> Any:
"""
Opens up a read lock on the storage and returns a guard handle. Use this
with functions that don't require mutation.
"""
class StorageRef(__API_Storage):
"""
Reference type of :class:`Storage`.
"""
def clone(self) -> "Storage": ...
def wl(self) -> Any:
"""
Opens up a write lock on the storage and returns guard handle. Use this
with functions that take a mutable reference to self.
"""
def rl(self) -> Any:
"""
Opens up a read lock on the storage and returns a guard handle. Use this
with functions that don't require mutation.
"""
class __API_Ready:
def hs(self) -> Optional["HardStateRef"]:
"""
The current state of a Node to be saved to stable storage.
HardState will be None state if there is no update.
"""
def ss(self) -> Optional["SoftStateRef"]:
"""
The current volatile state of a Node.
SoftState will be None if there is no update.
It is not required to consume or store SoftState.
"""
def must_sync(self) -> bool:
"""
MustSync is false if and only if
1. no HardState or only its commit is different from before
2. no Entries and Snapshot
If it's false, an asynchronous write of HardState is permissible before calling
[`RawNode::on_persist_ready`] or [`RawNode::advance`] or its families.
"""
def number(self) -> int:
"""
The number of current Ready.
It is used for identifying the different Ready and ReadyRecord.
"""
def snapshot(self) -> "SnapshotRef":
"""
Snapshot specifies the snapshot to be saved to stable storage.
"""
def committed_entries(self) -> list["EntryRef"]:
"""
CommittedEntries specifies entries to be committed to a
store/state-machine. These have previously been committed to stable
store.
"""
def take_committed_entries(self) -> list["Entry"]:
"""
Take the CommitEntries.
"""
def entries(self) -> list["EntryRef"]:
"""
Entries specifies entries to be saved to stable storage.
"""
def take_entries(self) -> list["Entry"]:
"""
Take the Entries.
"""
def messages(self) -> list["MessageRef"]:
"""
Messages specifies outbound messages to be sent.
If it contains a MsgSnap message, the application MUST report back to raft
when the snapshot has been received or has failed by calling ReportSnapshot.
"""
def take_messages(self) -> list["Message"]:
"""
Take the Messages.
"""
def persisted_messages(self) -> list["MessageRef"]:
"""
Persisted Messages specifies outbound messages to be sent AFTER the HardState,
Entries and Snapshot are persisted to stable storage.
"""
def take_persisted_messages(self) -> list["Message"]:
"""
Take the Persisted Messages.
"""
def read_states(self) -> list["ReadStateRef"]:
"""
ReadStates specifies the state for read only query.
"""
def take_read_states(self) -> list["ReadState"]:
"""
ReadStates specifies the state for read only query.
"""
class Ready(__API_Ready):
"""
Ready encapsulates the entries and messages that are ready to read,
be saved to stable storage, committed or sent to other peers.
"""
def make_ref(self) -> "ReadyRef": ...
@staticmethod
def default() -> "Ready": ...
class ReadyRef(__API_Ready):
"""
Reference type of :class:`Ready`.
"""
class __API_RawNode:
def advance_apply(self) -> None:
"""
Advance apply to the index of the last committed entries given before.
"""
def advance_apply_to(self, applied: int) -> None:
"""
Advance apply to the passed index.
"""
def advance(self, rd: "ReadyRef") -> "LightReady":
"""
Advances the ready after fully processing it.
Fully processing a ready requires to persist snapshot, entries and hard states, apply all
committed entries, send all messages.
Returns the LightReady that contains commit index, committed entries and messages. [`LightReady`]
contains updates that only valid after persisting last ready. It should also be fully processed.
Then [`Self::advance_apply`] or [`Self::advance_apply_to`] should be used later to update applying
progress.
"""
def advance_append(self, rd: "ReadyRef") -> "LightReady":
"""
Advances the ready without applying committed entries. [`Self::advance_apply`] or
[`Self::advance_apply_to`] should be used later to update applying progress.
Returns the LightReady that contains commit index, committed entries and messages.
Since Ready must be persisted in order, calling this function implicitly means
all ready collected before have been persisted.
"""
def advance_append_async(self, rd: "ReadyRef") -> None:
"""
Same as [`Self::advance_append`] except that it allows to only store the updates in cache.
[`Self::on_persist_ready`] should be used later to update the persisting progress.
Raft works on an assumption persisted updates should not be lost, which usually requires expensive
operations like `fsync`. `advance_append_async` allows you to control the rate of such operations and
get a reasonable batch size. However, it's still required that the updates can be read by raft from the
`Storage` trait before calling `advance_append_async`.
"""
def has_ready(self) -> bool:
"""
HasReady called when RawNode user need to check if any Ready pending.
"""
def tick(self) -> bool:
"""
Tick advances the internal logical clock by a single tick.
Returns true to indicate that there will probably be some readiness which
needs to be handled.
"""
def set_batch_append(self, batch_append: bool) -> None:
"""
Set whether to batch append msg at runtime.
"""
def set_priority(self, priority: int) -> None:
"""
Sets priority of node.
"""
def report_snapshot(self, id: int, status: "SnapshotStatus") -> None:
"""
ReportSnapshot reports the status of the sent snapshot.
"""
def report_unreachable(self, id: int) -> None:
"""
ReportUnreachable reports the given node is not reachable for the last send.
"""
def transfer_leader(self, transferee: int) -> None:
"""
TransferLeader tries to transfer leadership to the given transferee.
"""
def snap(self) -> Optional["SnapshotRef"]:
"""
Grabs the snapshot from the raft if available.
"""
def step(self, msg: "Message" | "MessageRef") -> None:
"""
Step advances the state machine using the given message.
"""
def skip_bcast_commit(self, skip: bool) -> None:
"""
Set whether skip broadcast empty commit messages at runtime.
"""
def campaign(self) -> None:
"""
Campaign causes this RawNode to transition to candidate state.
"""
def propose(self, context: bytes, data: bytes) -> None:
"""
Propose proposes data be appended to the raft log.
"""
def propose_conf_change(
self, context: bytes, cc: "ConfChange" | "ConfChangeRef"
) -> None:
"""
ProposeConfChange proposes a config change.
If the node enters joint state with `auto_leave` set to true, it's
caller's responsibility to propose an empty conf change again to force
leaving joint state.
"""
def propose_conf_change_v2(
self, context: bytes, cc: "ConfChangeV2" | "ConfChangeV2Ref"
) -> None:
"""
ProposeConfChange proposes a config change.
If the node enters joint state with `auto_leave` set to true, it's
caller's responsibility to propose an empty conf change again to force
leaving joint state.
"""
def apply_conf_change(self, cc: "ConfChange" | "ConfChangeRef") -> "ConfState":
"""
Applies a config change to the local node. The app must call this when it
applies a configuration change, except when it decides to reject the
configuration change, in which case no call must take place.
"""
def apply_conf_change_v2(
self, cc: "ConfChangeV2" | "ConfChangeV2Ref"
) -> "ConfState":
"""
Applies a config change to the local node. The app must call this when it
applies a configuration change, except when it decides to reject the
configuration change, in which case no call must take place.
"""
def ping(self) -> None:
"""
Broadcast heartbeats to all the followers.
If it's not leader, nothing will happen.
"""
def on_persist_ready(self, number: int) -> None:
"""
Notifies that the ready of this number has been persisted.
Since Ready must be persisted in order, calling this function implicitly means
all readies with numbers smaller than this one have been persisted.
[`Self::has_ready`] and [`Self::ready`] should be called later to handle further
updates that become valid after ready being persisted.
"""
def read_index(self, rctx: bytes) -> None:
"""
ReadIndex requests a read state. The read state will be set in ready.
Read State has a read index. Once the application advances further than the read
index, any linearizable read requests issued before the read request can be
processed safely. The read state will have the same rctx attached.
"""
def ready(self) -> Ready:
"""
Returns the outstanding work that the application needs to handle.
This includes appending and applying entries or a snapshot, updating the HardState,
and sending messages. The returned `Ready` *MUST* be handled and subsequently
passed back via `advance` or its families. Before that, *DO NOT* call any function like
`step`, `propose`, `campaign` to change internal state.
[`Self::has_ready`] should be called first to check if it's necessary to handle the ready.
"""
def request_snapshot(self) -> "Ready":
"""
Request a snapshot from a leader.
The snapshot's index must be greater or equal to the request_index (last_index) or
the leader's term must be greater than the request term (last_index's term).
"""
def on_entries_fetched(self) -> None:
"""
A callback when entries are fetched asynchronously.
The context should provide the context passed from Storage.entires().
See more in the comment of Storage.entires().
# Panics
Panics if passed with the context of context.can_async() == false
"""
class InMemoryRawNode(__API_RawNode):
"""
RawNode is a thread-unsafe Node.
The methods of this struct correspond to the methods of Node and are described
more fully there.
"""
def __init__(
self,
cfg: "Config" | "ConfigRef",
store: "MemStorage" | "MemStorageRef",
logger: "Logger" | "LoggerRef",
) -> None: ...
def make_ref(self) -> "InMemoryRawNodeRef": ...
def get_raft(self) -> "InMemoryRaftRef":
""" """
def store(self) -> "MemStorageRef":
"""Returns the store as a mutable reference."""
class InMemoryRawNodeRef(__API_RawNode):
"""
Reference type of :class:`InMemoryRawNode`.
"""
def get_raft(self) -> "InMemoryRaftRef":
""" """
def store(self) -> "MemStorageRef":
"""Returns the store as a mutable reference."""
# def status(self) -> InMemoryStatus:
# """
# Status returns the current status of the given group.
# """
class RawNode(__API_RawNode):
"""
RawNode is a thread-unsafe Node.
The methods of this struct correspond to the methods of Node and are described
more fully there.
"""
def __init__(
self,
cfg: "Config" | "ConfigRef",
store: "Storage" | "StorageRef",
logger: "Logger" | "LoggerRef",
) -> None: ...
def make_ref(self) -> "RawNodeRef": ...
def get_raft(self) -> "RaftRef":
""" """
def store(self) -> "StorageRef":
"""Returns the store as a mutable reference."""
# def status(self) -> Status:
# """
# Status returns the current status of the given group.
# """
class RawNodeRef(__API_RawNode):
"""
Reference type of :class:`RawNode`.
"""
def get_raft(self) -> "RaftRef":
""" """
def store(self) -> "StorageRef":
"""Returns the store as a mutable reference."""
# def status(self) -> InMemoryStatus:
# """
# Status returns the current status of the given group.
# """
class __API_Peer:
def get_id(self) -> int:
"""
`id`: The ID of the peer.
"""
def set_id(self, id: int) -> None:
"""
`id`: The ID of the peer.
"""
def get_context(self) -> bytes:
"""
`context`: If there is context associated with the peer (like connection information), it can be
serialized and stored here.
"""
def set_context(self, context: bytes) -> None:
"""
`context`: If there is context associated with the peer (like connection information), it can be
serialized and stored here.
"""
# * No place for use.
# class Peer(__API_Peer):
# """
# Represents a Peer node in the cluster.
# """
# def __init__(self) -> None: ...
# def make_ref(self) -> "PeerRef": ...
# class PeerRef(__API_Peer):
# """
# Reference type of :class:`Peer`.
# """
class __API_LightReady:
def commit_index(self) -> Optional[int]:
"""
The current commit index.
It will be None state if there is no update.
It is not required to save it to stable storage.
"""
def committed_entries(self) -> list["EntryRef"]:
"""
CommittedEntries specifies entries to be committed to a
store/state-machine. These have previously been committed to stable
store.
"""
def take_committed_entries(self) -> list["Entry"]:
"""
Take the CommitEntries.
"""
def messages(self) -> list["MessageRef"]:
"""
Messages specifies outbound messages to be sent.
"""
def take_messages(self) -> list["Message"]:
"""