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

Change SubjectDeleteMarkerTTL stream config field to duration #6404

Merged
merged 1 commit into from
Jan 26, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5356,7 +5356,7 @@ func (fs *fileStore) subjectDeleteMarkerIfNeeded(sm *StoreMsg, reason string) fu
// we'll default to 15 minutes — by that time every possible condition
// should have cleared (i.e. ordered consumer timeout, client timeouts,
// route/gateway interruptions, even device/client restarts etc).
ttl, _ := parseMessageTTL(fs.cfg.SubjectDeleteMarkerTTL)
ttl := int64(fs.cfg.SubjectDeleteMarkerTTL.Seconds())
if ttl <= 0 {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions server/filestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8570,7 +8570,7 @@ func TestFileStoreSubjectDeleteMarkers(t *testing.T) {
StreamConfig{
Name: "zzz", Subjects: []string{"test"}, Storage: FileStorage,
MaxAge: time.Second, AllowMsgTTL: true,
SubjectDeleteMarkers: true, SubjectDeleteMarkerTTL: "1s",
SubjectDeleteMarkers: true, SubjectDeleteMarkerTTL: time.Second,
},
)
require_NoError(t, err)
Expand Down Expand Up @@ -8614,7 +8614,7 @@ func TestFileStoreSubjectDeleteMarkersOnRestart(t *testing.T) {
StreamConfig{
Name: "zzz", Subjects: []string{"test"}, Storage: FileStorage,
MaxAge: time.Second, AllowMsgTTL: true,
SubjectDeleteMarkers: true, SubjectDeleteMarkerTTL: "1s",
SubjectDeleteMarkers: true, SubjectDeleteMarkerTTL: time.Second,
},
)
require_NoError(t, err)
Expand All @@ -8637,7 +8637,7 @@ func TestFileStoreSubjectDeleteMarkersOnRestart(t *testing.T) {
StreamConfig{
Name: "zzz", Subjects: []string{"test"}, Storage: FileStorage,
MaxAge: time.Second, AllowMsgTTL: true,
SubjectDeleteMarkers: true, SubjectDeleteMarkerTTL: "1s",
SubjectDeleteMarkers: true, SubjectDeleteMarkerTTL: time.Second,
},
)
require_NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions server/jetstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24171,7 +24171,7 @@ func TestJetStreamStreamCreatePedanticMode(t *testing.T) {
Storage: FileStorage,
AllowMsgTTL: true,
SubjectDeleteMarkers: true,
SubjectDeleteMarkerTTL: "10m",
SubjectDeleteMarkerTTL: 10 * time.Minute,
},
Pedantic: true,
},
Expand Down Expand Up @@ -24218,7 +24218,7 @@ func TestJetStreamStreamCreatePedanticMode(t *testing.T) {
Storage: FileStorage,
AllowMsgTTL: true,
SubjectDeleteMarkers: true,
SubjectDeleteMarkerTTL: "11m",
SubjectDeleteMarkerTTL: 11 * time.Minute,
},
Pedantic: true,
},
Expand Down Expand Up @@ -25369,7 +25369,7 @@ func TestJetStreamSubjectDeleteMarkers(t *testing.T) {
MaxAge: time.Second,
AllowMsgTTL: true,
SubjectDeleteMarkers: true,
SubjectDeleteMarkerTTL: "1s",
SubjectDeleteMarkerTTL: time.Second,
})

sub, err := js.SubscribeSync("test")
Expand Down
2 changes: 1 addition & 1 deletion server/memstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ func (ms *memStore) subjectDeleteMarkerIfNeeded(sm *StoreMsg, reason string) fun
// we'll default to 15 minutes — by that time every possible condition
// should have cleared (i.e. ordered consumer timeout, client timeouts,
// route/gateway interruptions, even device/client restarts etc).
ttl, _ := parseMessageTTL(ms.cfg.SubjectDeleteMarkerTTL)
ttl := int64(ms.cfg.SubjectDeleteMarkerTTL.Seconds())
if ttl <= 0 {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion server/memstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ func TestMemStoreSubjectDeleteMarkers(t *testing.T) {
&StreamConfig{
Name: "zzz", Subjects: []string{"test"}, Storage: MemoryStorage,
MaxAge: time.Second, AllowMsgTTL: true,
SubjectDeleteMarkers: true, SubjectDeleteMarkerTTL: "1s",
SubjectDeleteMarkers: true, SubjectDeleteMarkerTTL: time.Second,
},
)
require_NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion server/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var (
)

// Default value for SubjectDeleteMarkerTTL if not specified.
const subjectDeleteMarkerDefaultTTL = "15m"
const subjectDeleteMarkerDefaultTTL = 15 * time.Minute

// StoreMsg is the stored message format for messages that are retained by the Store layer.
type StoreMsg struct {
Expand Down
14 changes: 5 additions & 9 deletions server/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type StreamConfig struct {

// SubjectDeleteMarkerTTL sets the TTL of delete marker messages left behind by
// SubjectDeleteMarkers.
SubjectDeleteMarkerTTL string `json:"subject_delete_marker_ttl,omitempty"`
SubjectDeleteMarkerTTL time.Duration `json:"subject_delete_marker_ttl,omitempty"`

// Metadata is additional metadata for the Stream.
Metadata map[string]string `json:"metadata,omitempty"`
Expand Down Expand Up @@ -1370,22 +1370,18 @@ func (s *Server) checkStreamCfg(config *StreamConfig, acc *Account, pedantic boo
if !cfg.AllowMsgTTL {
return StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf("subject marker delete cannot be set if message TTLs are disabled"))
}
if pedantic && cfg.SubjectDeleteMarkerTTL == _EMPTY_ {
if pedantic && cfg.SubjectDeleteMarkerTTL == 0 {
return StreamConfig{}, NewJSPedanticError(fmt.Errorf("pedantic mode: subject marker delete TTL can not be empty"))
}
if cfg.SubjectDeleteMarkerTTL != _EMPTY_ {
ttl, err := parseMessageTTL(cfg.SubjectDeleteMarkerTTL)
if err != nil {
return StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf("invalid subject marker delete TTL: %s", err.Error()))
}
if ttl < 1 {
if cfg.SubjectDeleteMarkerTTL != 0 {
if cfg.SubjectDeleteMarkerTTL < time.Second {
return StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf("subject marker delete TTL must be at least 1 second"))
}
} else {
cfg.SubjectDeleteMarkerTTL = subjectDeleteMarkerDefaultTTL
}
} else {
if cfg.SubjectDeleteMarkerTTL != _EMPTY_ {
if cfg.SubjectDeleteMarkerTTL != 0 {
return StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf("subject marker delete TTL requires subject delete markers to be enabled"))
}
}
Expand Down
Loading