Skip to content

Commit 9fab63b

Browse files
committed
span: redefine Frontier in terms of ReadOnlyFrontier
The `ReadOnlyFrontier` interface is a strict subset of `Frontier` and to reduce duplicate code, this commit redefines `Frontier` in terms of `ReadOnlyFrontier`. Release note: None
1 parent 3fa36dc commit 9fab63b

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

pkg/util/span/frontier.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,14 @@ import (
2727
// Frontier is not safe for concurrent modification, but MakeConcurrentFrontier
2828
// can be used to make thread safe frontier.
2929
type Frontier interface {
30+
ReadOnlyFrontier
31+
3032
// AddSpansAt adds the provided spans to the frontier at the provided timestamp.
3133
// If the span overlaps any spans already tracked by the frontier, the tree is adjusted
3234
// to hold union of the span and the overlaps, with all entries assigned startAt starting
3335
// timestamp.
3436
AddSpansAt(startAt hlc.Timestamp, spans ...roachpb.Span) error
3537

36-
// Frontier returns the minimum timestamp being tracked.
37-
Frontier() hlc.Timestamp
38-
39-
// PeekFrontierSpan returns one of the spans at the Frontier.
40-
PeekFrontierSpan() roachpb.Span
41-
4238
// Forward advances the timestamp for a span. Any part of the span that doesn't
4339
// overlap the tracked span set will be ignored. True is returned if the
4440
// frontier advanced as a result.
@@ -49,6 +45,16 @@ type Frontier interface {
4945
// letting a frontier be GCed is safe in that it won't cause a memory leak,
5046
// but it will prevent frontier nodes from being efficiently re-used.
5147
Release()
48+
}
49+
50+
// ReadOnlyFrontier is a subset of Frontier with only the methods
51+
// that are read-only.
52+
type ReadOnlyFrontier interface {
53+
// Frontier returns the minimum timestamp being tracked.
54+
Frontier() hlc.Timestamp
55+
56+
// PeekFrontierSpan returns one of the spans at the Frontier.
57+
PeekFrontierSpan() roachpb.Span
5258

5359
// Entries returns an iterator over the entries in the frontier.
5460
// Updates to the frontier are restricted until iteration is stopped.

pkg/util/span/multi_frontier.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,6 @@ func (f *MultiFrontier[P]) String() string {
241241
return buf.String()
242242
}
243243

244-
// ReadOnlyFrontier is a subset of Frontier with only the methods
245-
// that are read-only.
246-
type ReadOnlyFrontier interface {
247-
Frontier() hlc.Timestamp
248-
PeekFrontierSpan() roachpb.Span
249-
Entries() iter.Seq2[roachpb.Span, hlc.Timestamp]
250-
SpanEntries(span roachpb.Span) iter.Seq2[roachpb.Span, hlc.Timestamp]
251-
Len() int
252-
String() string
253-
}
254-
255-
var _ ReadOnlyFrontier = Frontier(nil)
256-
257244
// Frontiers returns an iterator over the sub-frontiers (with read-only access).
258245
func (f *MultiFrontier[P]) Frontiers() iter.Seq2[P, ReadOnlyFrontier] {
259246
return func(yield func(P, ReadOnlyFrontier) bool) {

0 commit comments

Comments
 (0)