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

Prevent configuring first_seq on mirrors #4345

Merged
merged 2 commits into from Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions server/errors.json
Expand Up @@ -299,6 +299,16 @@
"url": "",
"deprecates": ""
},
{
"constant": "JSMirrorWithFirstSeqErr",
"code": 400,
"error_code": 10143,
"description": "stream mirrors can not have first sequence configured",
"comment": "",
"help": "",
"url": "",
"deprecates": ""
},
{
"constant": "JSNotEnabledErr",
"code": 503,
Expand Down
14 changes: 14 additions & 0 deletions server/jetstream_errors_generated.go
Expand Up @@ -230,6 +230,9 @@ const (
// JSMirrorMaxMessageSizeTooBigErr stream mirror must have max message size >= source
JSMirrorMaxMessageSizeTooBigErr ErrorIdentifier = 10030

// JSMirrorWithFirstSeqErr stream mirrors can not have first sequence configured
JSMirrorWithFirstSeqErr ErrorIdentifier = 10143

// JSMirrorWithSourcesErr stream mirrors can not also contain other sources
JSMirrorWithSourcesErr ErrorIdentifier = 10031

Expand Down Expand Up @@ -506,6 +509,7 @@ var (
JSMirrorConsumerSetupFailedErrF: {Code: 500, ErrCode: 10029, Description: "{err}"},
JSMirrorInvalidStreamName: {Code: 400, ErrCode: 10142, Description: "mirrored stream name is invalid"},
JSMirrorMaxMessageSizeTooBigErr: {Code: 400, ErrCode: 10030, Description: "stream mirror must have max message size >= source"},
JSMirrorWithFirstSeqErr: {Code: 400, ErrCode: 10143, Description: "stream mirrors can not have first sequence configured"},
JSMirrorWithSourcesErr: {Code: 400, ErrCode: 10031, Description: "stream mirrors can not also contain other sources"},
JSMirrorWithStartSeqAndTimeErr: {Code: 400, ErrCode: 10032, Description: "stream mirrors can not have both start seq and start time configured"},
JSMirrorWithSubjectFiltersErr: {Code: 400, ErrCode: 10033, Description: "stream mirrors can not contain filtered subjects"},
Expand Down Expand Up @@ -1413,6 +1417,16 @@ func NewJSMirrorMaxMessageSizeTooBigError(opts ...ErrorOption) *ApiError {
return ApiErrors[JSMirrorMaxMessageSizeTooBigErr]
}

// NewJSMirrorWithFirstSeqError creates a new JSMirrorWithFirstSeqErr error: "stream mirrors can not have first sequence configured"
func NewJSMirrorWithFirstSeqError(opts ...ErrorOption) *ApiError {
eopts := parseOpts(opts)
if ae, ok := eopts.err.(*ApiError); ok {
return ae
}

return ApiErrors[JSMirrorWithFirstSeqErr]
}

// NewJSMirrorWithSourcesError creates a new JSMirrorWithSourcesErr error: "stream mirrors can not also contain other sources"
func NewJSMirrorWithSourcesError(opts ...ErrorOption) *ApiError {
eopts := parseOpts(opts)
Expand Down
16 changes: 16 additions & 0 deletions server/jetstream_test.go
Expand Up @@ -18134,6 +18134,22 @@ func TestJetStreamMirrorUpdatesNotSupported(t *testing.T) {
require_Error(t, err, NewJSStreamMirrorNotUpdatableError())
}

func TestJetStreamMirrorFirstSeqNotSupported(t *testing.T) {
s := RunBasicJetStreamServer(t)
defer s.Shutdown()

_, err := s.gacc.addStream(&StreamConfig{Name: "SOURCE"})
require_NoError(t, err)

cfg := &StreamConfig{
Name: "M",
Mirror: &StreamSource{Name: "SOURCE"},
FirstSeq: 123,
}
_, err = s.gacc.addStream(cfg)
require_Error(t, err, NewJSMirrorWithFirstSeqError())
}

func TestJetStreamDirectGetBySubject(t *testing.T) {
conf := createConfFile(t, []byte(`
listen: 127.0.0.1:-1
Expand Down
3 changes: 3 additions & 0 deletions server/stream.go
Expand Up @@ -1159,6 +1159,9 @@ func (s *Server) checkStreamCfg(config *StreamConfig, acc *Account) (StreamConfi

// Do some pre-checking for mirror config to avoid cycles in clustered mode.
if cfg.Mirror != nil {
if cfg.FirstSeq > 0 {
return StreamConfig{}, NewJSMirrorWithFirstSeqError()
}
if len(cfg.Subjects) > 0 {
return StreamConfig{}, NewJSMirrorWithSubjectsError()

Expand Down