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.
Browse files
Browse the repository at this point in the history
…db#61397 61036: streamclient: add client for sinkless CREATE REPLICATION STREAM r=miretskiy,dt a=pbardea This commit adds support for a stream client that can connect to a cluster and start replicating changes that happen on that stream. This commit also reorganizes some testing helpers to be used between streamclient and streamproducer. Release justification: low impact (very experimental feature), high reward (makes cluster replication work end to end) Release note: None 61106: sql: disallow creation of interleaved partitioned indexes r=mgartner a=mgartner Previously, creating interleaved partitioned indexes panicked. This commit disallows their creation to prevent panicking. Fixes cockroachdb#60699 Release justification: This is a low risk change that prevents panics when attempting to create interleaved partitioned tables. Release note (bug fix): Creating interleaved partitioned indexes is now disallowed. Previously, the database would crash when trying to create one. 61347: execinfra: clean up ProcessorBase r=yuzefovich a=yuzefovich This commit removes redundant context argument from `trailingMetaCallback` in favor of just using `ProcessorBase.Ctx` when needed. This was already actually the case since the callback was always called with `ProcessorBase.Ctx`. We also had the wrong sequences of actions when collecting trailing metadata in inverted joiner, join reader, and zigzag joiner, where we first called `InternalClose` and then generated the metadata. That is wrong because `InternalClose` replaces the context used throughout the operation of a processor with the "original" context (the one passed into `StartInternal`). This is now fixed. Additionally, a few unnecessary method overwrites are removed and `ProcessorBase` now provides the default implementation of `ConsumerClosed` (which simply calls `InternalClose`). This commit also makes a slight adjustment to context management of the change aggregator. Release justification: low-risk cleanup. Release note: None 61397: server: remove unnecessary % escape r=stevendanna a=stevendanna As of 1982047 this log line is now formatted with Go's templating system, which doesn't require that % is escaped. Before: ``` I210303 09:56:17.459802 311 2@server/status/runtime.go:553 ⋮ [n1] 76 runtime stats: 106 MiB RSS, 261 goroutines (stacks: 5.0 MiB), 29 MiB/63 MiB Go alloc/total (heap fragmentation: 6.8 MiB, heap reserved: 11 MiB, heap released: 12 MiB), 7.6 MiB/13 MiB CGO alloc/total (0.6 CGO/sec), 1.8/1.2 %%(u/s)time, 0.0 %%gc (0x ), 17 KiB/22 KiB (r/w)net ``` After: ``` I210303 09:59:17.607021 59 2@server/status/runtime.go:553 ⋮ [n1] 71 runtime stats: 92 MiB RSS, 255 goroutines (stacks: 3.7 MiB), 27 MiB/48 MiB Go alloc/total (heap fragmentation: 4.8 MiB, heap reserved: 1.3 MiB, heap released: 27 MiB), 10 MiB/15 MiB CGO alloc/total (0.0 CGO/sec), 0.0/0.0 %(u/s)time, 0.0 %gc (0x), 30 KiB/34 KiB (r/w)net ``` Release justification: Negligible risk. Release note: None Co-authored-by: Paul Bardea <pbardea@gmail.com> Co-authored-by: Marcus Gartner <marcus@cockroachlabs.com> Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com> Co-authored-by: Steven Danna <danna@cockroachlabs.com>
- Loading branch information
Showing
53 changed files
with
951 additions
and
413 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
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
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
129 changes: 129 additions & 0 deletions
129
pkg/ccl/streamingccl/streamclient/cockroach_sinkless_replication_client.go
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,129 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package streamclient | ||
|
||
import ( | ||
"context" | ||
gosql "database/sql" | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/ccl/streamingccl" | ||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/util/hlc" | ||
"github.com/cockroachdb/cockroach/pkg/util/protoutil" | ||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
// sinklessReplicationClient creates and reads a stream from the source cluster. | ||
type sinklessReplicationClient struct{} | ||
|
||
var _ Client = &sinklessReplicationClient{} | ||
|
||
// GetTopology implements the Client interface. | ||
func (m *sinklessReplicationClient) GetTopology( | ||
sa streamingccl.StreamAddress, | ||
) (streamingccl.Topology, error) { | ||
// The core changefeed clients only have 1 partition, and it's located at the | ||
// stream address. | ||
return streamingccl.Topology{ | ||
Partitions: []streamingccl.PartitionAddress{streamingccl.PartitionAddress(sa)}, | ||
}, nil | ||
} | ||
|
||
// ConsumePartition implements the Client interface. | ||
func (m *sinklessReplicationClient) ConsumePartition( | ||
ctx context.Context, pa streamingccl.PartitionAddress, startTime hlc.Timestamp, | ||
) (chan streamingccl.Event, chan error, error) { | ||
pgURL, err := pa.URL() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
q := pgURL.Query() | ||
tenantToReplicate := q.Get(TenantID) | ||
if len(tenantToReplicate) == 0 { | ||
return nil, nil, errors.New("no tenant specified") | ||
} | ||
tenantID, err := strconv.Atoi(tenantToReplicate) | ||
if err != nil { | ||
return nil, nil, errors.Wrap(err, "parsing tenant") | ||
} | ||
|
||
streamTenantQuery := fmt.Sprintf( | ||
`CREATE REPLICATION STREAM FOR TENANT %d`, tenantID) | ||
if startTime.WallTime != 0 { | ||
streamTenantQuery = fmt.Sprintf( | ||
`CREATE REPLICATION STREAM FOR TENANT %d WITH cursor='%s'`, tenantID, startTime.AsOfSystemTime()) | ||
} | ||
|
||
db, err := gosql.Open("postgres", pgURL.String()) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
conn, err := db.Conn(ctx) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
_, err = conn.QueryContext(ctx, `SET enable_experimental_stream_replication = true`) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
rows, err := conn.QueryContext(ctx, streamTenantQuery) | ||
if err != nil { | ||
return nil, nil, errors.Wrap(err, "creating source replication stream") | ||
} | ||
|
||
eventCh := make(chan streamingccl.Event) | ||
errCh := make(chan error, 1) | ||
|
||
go func() { | ||
defer close(eventCh) | ||
defer close(errCh) | ||
defer db.Close() | ||
defer rows.Close() | ||
for rows.Next() { | ||
var ignoreTopic gosql.NullString | ||
var k, v []byte | ||
if err := rows.Scan(&ignoreTopic, &k, &v); err != nil { | ||
errCh <- err | ||
return | ||
} | ||
|
||
var event streamingccl.Event | ||
if len(k) == 0 { | ||
var resolved hlc.Timestamp | ||
if err := protoutil.Unmarshal(v, &resolved); err != nil { | ||
errCh <- err | ||
return | ||
} | ||
event = streamingccl.MakeCheckpointEvent(resolved) | ||
} else { | ||
var kv roachpb.KeyValue | ||
kv.Key = k | ||
if err := protoutil.Unmarshal(v, &kv.Value); err != nil { | ||
errCh <- err | ||
return | ||
} | ||
event = streamingccl.MakeKVEvent(kv) | ||
} | ||
|
||
select { | ||
case eventCh <- event: | ||
case <-ctx.Done(): | ||
errCh <- ctx.Err() | ||
return | ||
} | ||
} | ||
}() | ||
|
||
return eventCh, errCh, nil | ||
} |
Oops, something went wrong.