Skip to content

Commit

Permalink
fix: sql scan error on remote bucket id when replication to 1.x (#23826)
Browse files Browse the repository at this point in the history
  • Loading branch information
DStrand1 authored Oct 19, 2022
1 parent 3ac7a10 commit 55b7d29
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
14 changes: 7 additions & 7 deletions replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ func (r *UpdateReplicationRequest) OK() error {
// ReplicationHTTPConfig contains all info needed by a client to make HTTP requests against the
// remote bucket targeted by a replication.
type ReplicationHTTPConfig struct {
RemoteURL string `db:"remote_url"`
RemoteToken string `db:"remote_api_token"`
RemoteOrgID platform.ID `db:"remote_org_id"`
AllowInsecureTLS bool `db:"allow_insecure_tls"`
RemoteBucketID platform.ID `db:"remote_bucket_id"`
RemoteBucketName string `db:"remote_bucket_name"`
DropNonRetryableData bool `db:"drop_non_retryable_data"`
RemoteURL string `db:"remote_url"`
RemoteToken string `db:"remote_api_token"`
RemoteOrgID platform.ID `db:"remote_org_id"`
AllowInsecureTLS bool `db:"allow_insecure_tls"`
RemoteBucketID *platform.ID `db:"remote_bucket_id"`
RemoteBucketName string `db:"remote_bucket_name"`
DropNonRetryableData bool `db:"drop_non_retryable_data"`
}
2 changes: 1 addition & 1 deletion replications/internal/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var (
RemoteToken: replication.RemoteID.String(),
RemoteOrgID: platform.ID(888888),
AllowInsecureTLS: true,
RemoteBucketID: *replication.RemoteBucketID,
RemoteBucketID: replication.RemoteBucketID,
}
newRemoteID = platform.ID(200)
newQueueSize = influxdb.MinReplicationMaxQueueSizeBytes
Expand Down
6 changes: 4 additions & 2 deletions replications/remotewrite/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,11 @@ func PostWrite(ctx context.Context, config *influxdb.ReplicationHTTPConfig, data
conf.HTTPClient.Timeout = timeout
client := api.NewAPIClient(conf).WriteApi

bucket := config.RemoteBucketID.String()
if config.RemoteBucketName != "" {
var bucket string
if config.RemoteBucketID == nil || config.RemoteBucketName != "" {
bucket = config.RemoteBucketName
} else {
bucket = config.RemoteBucketID.String()
}

req := client.PostWrite(ctx).
Expand Down
4 changes: 2 additions & 2 deletions replications/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (s *service) ValidateNewReplication(ctx context.Context, request influxdb.C
return errLocalBucketNotFound(request.LocalBucketID, err)
}

config := influxdb.ReplicationHTTPConfig{RemoteBucketID: request.RemoteBucketID}
config := influxdb.ReplicationHTTPConfig{RemoteBucketID: &request.RemoteBucketID}
if err := s.store.PopulateRemoteHTTPConfig(ctx, request.RemoteID, &config); err != nil {
return err
}
Expand Down Expand Up @@ -231,7 +231,7 @@ func (s *service) ValidateUpdatedReplication(ctx context.Context, id platform.ID
return err
}
if request.RemoteBucketID != nil {
baseConfig.RemoteBucketID = *request.RemoteBucketID
baseConfig.RemoteBucketID = request.RemoteBucketID
}

if request.RemoteID != nil {
Expand Down
4 changes: 2 additions & 2 deletions replications/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var (
RemoteToken: replication1.RemoteID.String(),
RemoteOrgID: platform.ID(888888),
AllowInsecureTLS: true,
RemoteBucketID: *replication1.RemoteBucketID,
RemoteBucketID: replication1.RemoteBucketID,
}
)

Expand Down Expand Up @@ -295,7 +295,7 @@ func TestValidateNewReplication(t *testing.T) {

mocks.bucketSvc.EXPECT().FindBucketByID(gomock.Any(), tt.req.LocalBucketID).Return(nil, tt.bucketErr)

testConfig := &influxdb.ReplicationHTTPConfig{RemoteBucketID: tt.req.RemoteBucketID}
testConfig := &influxdb.ReplicationHTTPConfig{RemoteBucketID: &tt.req.RemoteBucketID}
if tt.bucketErr == nil {
mocks.serviceStore.EXPECT().PopulateRemoteHTTPConfig(gomock.Any(), tt.req.RemoteID, testConfig).Return(tt.storeErr)
}
Expand Down

0 comments on commit 55b7d29

Please sign in to comment.