Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvserver/rangefeed: wip #132882

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft

Commits on Oct 17, 2024

  1. kvserver/rangefeed: remove context from kvpb.RangeFeedEventSink

    Previously, `node.MuxRangefeed` created a child context for each rangefeed
    request, storing it in the stream interface to allow the node level to be able
    to shut down registration goroutines. This patch simplifies the approach by
    passing the stream context directly to `p.Register`, eliminating the need to
    store context in `streamSink` or return context via the interface. So this patch
    also removes context from `kvpb.RangeFeedEventSink`.
    
    Epic: none
    Release note: none
    wenyihu6 committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    3189832 View commit details
    Browse the repository at this point in the history
  2. kvserver/rangefeed: move helper functions to registry_helpers_test

    This patch moves helper functions to registry_helpers_test.
    
    Part of: cockroachdb#129814
    Release note: none
    wenyihu6 committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    ebc7d4a View commit details
    Browse the repository at this point in the history
  3. kvserver/rangefeed: refactor registry_helpers_test to facilitate futu…

    …re tests
    
    This patch refactors helper functions in registry_helpers_test.
    
    Part of: cockroachdb#129814
    Release note: none
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/registry_test.go
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/registry_test_helper.go
    wenyihu6 committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    20836cc View commit details
    Browse the repository at this point in the history
  4. kvserver/rangefeed: process unregister requests asyncronously

    After the output loop completes, 2 cleanup steps are performed:
    
    1) The registration is removed from the processors registry
    2) The process is potentially stopped and removed from the replica.
    
    Before this change, both of these happened syncronously after the
    output loop finished.
    
    With this change, step (1) happens asyncronously. To facilitate this,
    an overflow mechanism is provided. This overflow mechanism potentially
    allocates. Note that we expect that the number of requests is
    relatively small and should be O(rangefeeds_on_range) so hopefully
    this mechanism won't be used often.
    
    Step (2) is now handled by the processor itself. After processing an
    unregister request, if the set of registrations falls to zero, we
    enqueue a Stop event for ourselves. Then, when processing the Stop, we
    unregister ourselves from the replica.
    
    Note that this may look like a small semantics change since the
    previous unregister callback called Stop() which processes all events.
    However, note that a Stopped event is processed after all other
    events, so any events in the queue at the point of processing the
    unregistration that enqueued the stop will be processed.
    
    The motivation for this change is to eventually allow cleanup step (1)
    to be run as part of registration.disconnect(), which needs to be
    non-blocking. This is desired for a future change in which there is
    not a dedicated goroutine to perform this cleanup.
    
    Epic: none
    Release note: None
    stevendanna authored and wenyihu6 committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    3de8f21 View commit details
    Browse the repository at this point in the history
  5. kvserver/rangefeed: add unbuffered registration

    This patch adds unbufferedRegistration.
    
    UnbufferedRegistration is like BufferedRangefeed but uses BufferedStream to
    buffer live raft updates instead of a using buf channel and having a
    dedicated per-range per-registration goroutine to volley events to underlying
    grpc stream. Instead, there is only one BufferedStream for each incoming
    node.MuxRangefeed rpc call. BufferedStream is responsible for buffering and
    sending its updates to the underlying grpc stream in a dedicated goroutine
    O(node).
    
    Note that BufferedStreamSender is still left unimplemented. This commit doesn't
    add any tests for it yet. More tests will be added in future commits of this PR.
    
    Part of: cockroachdb#129814
    Release note: none
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/scheduled_processor.go
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/scheduled_processor.go
    wenyihu6 committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    216c173 View commit details
    Browse the repository at this point in the history
  6. kvserver/rangefeed: add event queue

    This patch adds a new data structure eventQueue which is like a queue but uses a
    fixed size for the chunked linked list. Each chunk has a fixed size of 4096
    elements. This implementation uses sync.Pool to reduce the number of
    allocations.
    
    pushBack, popFront, len run in constant time. removeAll runs in linear time with
    respect to the number of elements in the queue. This structure is not safe for
    concurrent use.
    
    This is for future commits to include the queue in the BufferedSender to buffer
    events at the node level.
    
    Part of: cockroachdb#129813
    Release note: none
    wenyihu6 committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    16dccc2 View commit details
    Browse the repository at this point in the history

Commits on Oct 18, 2024

  1. kvserver/rangefeed: add node level buffered sender

    This patch is the last step for reducing long-running O(ranges) goroutines in
    kvserver/rangefeed. It changes the BufferedSender to use a queue to buffer
    events before forwarding them to underlying grpc stream.
    
    Closed: cockroachdb#129813
    Release note: A new cluster setting
    `kv.rangefeed.buffered_stream_sender.enabled` can now be used to allow rangefeed
    to use buffered sender for all rangefeed feeds instead of buffering events
    separately per client per range.
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/buffered_sender.go
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/buffered_sender.go
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/buffered_sender.go
    wenyihu6 committed Oct 18, 2024
    Configuration menu
    Copy the full SHA
    df35095 View commit details
    Browse the repository at this point in the history
  2. kvserver/rangefeed: add newRetryErrBufferCapacityExceeded

    This patch refactors the error for kvpb.RangeFeedRetryError_REASON_SLOW_CONSUMER
    into newRetryErrBufferCapacityExceeded.
    
    Part of: cockroachdb#126560
    Release note: none
    wenyihu6 committed Oct 18, 2024
    Configuration menu
    Copy the full SHA
    c02c9cb View commit details
    Browse the repository at this point in the history
  3. kvserver/rangefeed: add capacity to node level buffered sender

    This patch adds capacity to node level buffered sender which will shut down all
    registrations if the node level buffer had overflowed.
    
    Part of: cockroachdb#129813
    Release note: none
    
    TODO: add a larger test at the kvclient side to make sure error returned here is treated as a restart signal
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/buffered_sender.go
    #	pkg/kv/kvserver/rangefeed/buffered_sender_test.go
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/buffered_sender_test.go
    wenyihu6 committed Oct 18, 2024
    Configuration menu
    Copy the full SHA
    ee1adf8 View commit details
    Browse the repository at this point in the history
  4. to be squashed separated out for easier code review

    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/registry_test_helper.go
    wenyihu6 committed Oct 18, 2024
    Configuration menu
    Copy the full SHA
    e6811af View commit details
    Browse the repository at this point in the history
  5. to be squashed separated out for easier code review

    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/processor_test.go
    #	pkg/kv/kvserver/rangefeed/registry_helpers_test.go
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/processor_helpers_test.go
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/processor_test.go
    wenyihu6 committed Oct 18, 2024
    Configuration menu
    Copy the full SHA
    7e78d97 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    a806b9f View commit details
    Browse the repository at this point in the history
  7. kvserver/rangefeed: add unbuffered registration tests

    This patch adds more test cases for unbufferedRegistration.
    
    Closed: cockroachdb#126560
    Release note: none
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/registry_test.go
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/registry_test.go
    wenyihu6 committed Oct 18, 2024
    Configuration menu
    Copy the full SHA
    ef430f2 View commit details
    Browse the repository at this point in the history
  8. to be squashed separated out for easier code reviews

    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/buffered_sender_test.go
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/buffered_sender_test.go
    #	pkg/kv/kvserver/rangefeed/unbuffered_registration_test.go
    
    # Conflicts:
    #	pkg/kv/kvserver/rangefeed/buffered_sender_test.go
    wenyihu6 committed Oct 18, 2024
    Configuration menu
    Copy the full SHA
    e17bbda View commit details
    Browse the repository at this point in the history
  9. more

    wenyihu6 committed Oct 18, 2024
    Configuration menu
    Copy the full SHA
    7fc4d84 View commit details
    Browse the repository at this point in the history