-
Notifications
You must be signed in to change notification settings - Fork 6
/
log_stream_selector.go
41 lines (32 loc) · 1.17 KB
/
log_stream_selector.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
package varlog
import (
"errors"
"github.com/kakao/varlog/pkg/types"
)
var (
errNoLogStream = errors.New("no such logstream")
)
// LogStreamSelector is the interface that wraps the Select method.
//
// Select selects a log stream, but if there is no log stream to choose it returns false.
// GetAll returns all log streams belonging to the topic specified by the argument topicID.
type LogStreamSelector interface {
Select(topicID types.TopicID) (types.LogStreamID, bool)
GetAll(topicID types.TopicID) []types.LogStreamID
}
// alsSelector implements LogStreamSelector. It uses allowlist to select an appendable log stream.
type alsSelector struct {
allowlist Allowlist
}
var _ LogStreamSelector = (*alsSelector)(nil)
func newAppendableLogStreamSelector(allowlist Allowlist) *alsSelector {
return &alsSelector{allowlist: allowlist}
}
// Select implements (LogStreamSelector).Select method.
func (als *alsSelector) Select(topicID types.TopicID) (types.LogStreamID, bool) {
return als.allowlist.Pick(topicID)
}
// GetAll implements (LogStreamSelector).GetAll method.
func (als *alsSelector) GetAll(topicID types.TopicID) []types.LogStreamID {
return als.allowlist.GetAll(topicID)
}