Skip to content

Commit

Permalink
streamingccl: add GenerationEvent type
Browse files Browse the repository at this point in the history
Add `GenerationEvent` as a possible event type to be emitted over a cluster stream. When a `GenerationEvent` is emitted, we should be able to get its topology as well as the start time of the new generation.

Release note: None
  • Loading branch information
azhu-crl committed Jul 28, 2021
1 parent 82b32cf commit ff40d73
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/ccl/streamingccl/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const (
// CheckpointEvent indicates that GetResolved will be meaningful. The resolved
// timestamp indicates that all KVs have been emitted up to this timestamp.
CheckpointEvent
// GenerationEvent indicates that the stream should start ingesting with the
// updated topology.
GenerationEvent
)

// Event describes an event emitted by a cluster to cluster stream. Its Type
Expand Down Expand Up @@ -84,6 +87,26 @@ func (ce checkpointEvent) GetResolved() *hlc.Timestamp {
return &ce.resolvedTimestamp
}

// generationEvent indicates that the topology of the stream has changed.
type generationEvent struct{}

var _ Event = generationEvent{}

// Type implements the Event interface.
func (ge generationEvent) Type() EventType {
return GenerationEvent
}

// GetKV implements the Event interface.
func (ge generationEvent) GetKV() *roachpb.KeyValue {
return nil
}

// GetResolved implements the Event interface.
func (ge generationEvent) GetResolved() *hlc.Timestamp {
return nil
}

// MakeKVEvent creates an Event from a KV.
func MakeKVEvent(kv roachpb.KeyValue) Event {
return kvEvent{kv: kv}
Expand All @@ -93,3 +116,8 @@ func MakeKVEvent(kv roachpb.KeyValue) Event {
func MakeCheckpointEvent(resolvedTimestamp hlc.Timestamp) Event {
return checkpointEvent{resolvedTimestamp: resolvedTimestamp}
}

// MakeGenerationEvent creates an GenerationEvent.
func MakeGenerationEvent() Event {
return generationEvent{}
}
2 changes: 2 additions & 0 deletions pkg/ccl/streamingccl/streamclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func ExampleClient() {
fmt.Printf("%s->%s@%d\n", kv.Key.String(), string(kv.Value.RawBytes), kv.Value.Timestamp.WallTime)
case streamingccl.CheckpointEvent:
fmt.Printf("resolved %d\n", event.GetResolved().WallTime)
case streamingccl.GenerationEvent:
fmt.Printf("received generation event")
default:
panic(fmt.Sprintf("unexpected event type %v", event.Type()))
}
Expand Down

0 comments on commit ff40d73

Please sign in to comment.