forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kvserver/rangefeed: move perRangeEventSink to rangefeed pacakge
Previously, perRangeEventSink was defined in pkg/server/node.go. This patch relocates it to the rangefeed package to facilitate future commits testing within the rangefeed package itself. Part of: cockroachdb#126560 Release note: none
- Loading branch information
Showing
4 changed files
with
80 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package rangefeed | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/kv/kvpb" | ||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
) | ||
|
||
// Stream is an object capable of transmitting RangeFeedEvents from a server | ||
// rangefeed to a client. | ||
type Stream interface { | ||
kvpb.RangeFeedEventSink | ||
// Disconnect disconnects the stream with the provided error. Note that this | ||
// function can be called by the processor worker while holding raftMu, so it | ||
// is important that this function doesn't block IO or try acquiring locks | ||
// that could lead to deadlocks. | ||
Disconnect(err *kvpb.Error) | ||
} | ||
|
||
// PerRangeEventSink is an implementation of Stream which annotates each | ||
// response with rangeID and streamID. It is used by MuxRangeFeed. | ||
type PerRangeEventSink struct { | ||
ctx context.Context | ||
rangeID roachpb.RangeID | ||
streamID int64 | ||
wrapped *StreamMuxer | ||
} | ||
|
||
func NewPerRangeEventSink( | ||
ctx context.Context, rangeID roachpb.RangeID, streamID int64, wrapped *StreamMuxer, | ||
) *PerRangeEventSink { | ||
return &PerRangeEventSink{ | ||
ctx: ctx, | ||
rangeID: rangeID, | ||
streamID: streamID, | ||
wrapped: wrapped, | ||
} | ||
} | ||
|
||
var _ kvpb.RangeFeedEventSink = (*PerRangeEventSink)(nil) | ||
var _ Stream = (*PerRangeEventSink)(nil) | ||
|
||
func (s *PerRangeEventSink) Context() context.Context { | ||
return s.ctx | ||
} | ||
|
||
// SendIsThreadSafe is a no-op declaration method. It is a contract that the | ||
// Send method is thread-safe. Note that Send wraps StreamMuxer which declares | ||
// its Send method to be thread-safe. | ||
func (s *PerRangeEventSink) SendIsThreadSafe() {} | ||
|
||
func (s *PerRangeEventSink) Send(event *kvpb.RangeFeedEvent) error { | ||
response := &kvpb.MuxRangeFeedEvent{ | ||
RangeFeedEvent: *event, | ||
RangeID: s.rangeID, | ||
StreamID: s.streamID, | ||
} | ||
return s.wrapped.Send(response) | ||
} | ||
|
||
// Disconnect implements the Stream interface. It requests the StreamMuxer to | ||
// detach the stream. The StreamMuxer is then responsible for handling the | ||
// actual disconnection and additional cleanup. Note that Caller should not rely | ||
// on immediate disconnection as cleanup takes place async. | ||
func (s *PerRangeEventSink) Disconnect(err *kvpb.Error) { | ||
s.wrapped.DisconnectStreamWithError(s.streamID, s.rangeID, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters