forked from eurosys2024ladon/ladon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skippingsegment.go
82 lines (68 loc) · 2.12 KB
/
skippingsegment.go
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
// Copyright 2022 IBM Corp. All Rights Reserved.
//
// Licensed 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.
package manager
import "github.com/hyperledger-labs/ladon/request"
// Represents a segment with a non-contiguous ordered range of sequence numbers.
// Each sequence number has a fixed distance form the previous sequence number.
type SkippingSegment struct {
segID int
snDistance int32
seqNos []int32
leaders []int32
followers []int32
snOffset int32 // the first sequence number of the segment
snLength int32
startsAfter int32
buckets *request.BucketGroup
batchSize int
}
// Initializes the sequence numbers of the segment
// It expects as an argument the order of the segment in case
func (s *SkippingSegment) initSNs() {
s.seqNos = make([]int32, 0, s.snLength)
for i := int32(0); i < s.snLength; i++ {
s.seqNos = append(s.seqNos, s.snOffset+i*s.snDistance)
}
}
func (s *SkippingSegment) SegID() int {
return s.segID
}
func (s *SkippingSegment) Leaders() []int32 {
return s.leaders
}
func (s *SkippingSegment) Followers() []int32 {
return s.followers
}
// Generates the list of sequence numbers based on offset and length.
func (s *SkippingSegment) SNs() []int32 {
return s.seqNos
}
func (s *SkippingSegment) FirstSN() int32 {
return s.snOffset
}
func (s *SkippingSegment) LastSN() int32 {
return s.SNs()[s.snLength-1]
}
func (s *SkippingSegment) Len() int32 {
return s.snLength
}
func (s *SkippingSegment) StartsAfter() int32 {
return s.startsAfter
}
func (s *SkippingSegment) Buckets() *request.BucketGroup {
return s.buckets
}
func (s *SkippingSegment) BatchSize() int {
return s.batchSize
}