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

[FIXED] On failed snapshot restore make sure healthz is clean. #5549

Merged
merged 1 commit into from
Jun 17, 2024
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
38 changes: 36 additions & 2 deletions server/jetstream_cluster_3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4735,7 +4735,7 @@ func TestJetStreamClusterSnapshotAndRestoreWithHealthz(t *testing.T) {

rresp.Error = nil
json.Unmarshal(rmsg.Data, &rresp)
require_True(t, resp.Error == nil)
require_True(t, rresp.Error == nil)

checkHealth()

Expand All @@ -4757,7 +4757,7 @@ func TestJetStreamClusterSnapshotAndRestoreWithHealthz(t *testing.T) {
require_NoError(t, err)
rresp.Error = nil
json.Unmarshal(rmsg.Data, &rresp)
require_True(t, resp.Error == nil)
require_True(t, rresp.Error == nil)

si, err := js.StreamInfo("TEST")
require_NoError(t, err)
Expand All @@ -4770,6 +4770,40 @@ func TestJetStreamClusterSnapshotAndRestoreWithHealthz(t *testing.T) {
si, err = js.StreamInfo("TEST")
require_NoError(t, err)
require_True(t, si.State.Msgs == uint64(toSend))

// Now make sure if we try to restore to a single server that the artifact is cleaned up and the server returns ok for healthz.
s := RunBasicJetStreamServer(t)
defer s.Shutdown()

nc, _ = jsClientConnect(t, s)
defer nc.Close()

rmsg, err = nc.Request(fmt.Sprintf(JSApiStreamRestoreT, "TEST"), req, 5*time.Second)
require_NoError(t, err)

rresp.Error = nil
json.Unmarshal(rmsg.Data, &rresp)
require_True(t, rresp.Error == nil)

for i, r := 0, bytes.NewReader(snapshot); ; {
n, err := r.Read(chunk[:])
if err != nil {
break
}
_, err = nc.Request(rresp.DeliverSubject, chunk[:n], time.Second)
require_NoError(t, err)
i++
}
rmsg, err = nc.Request(rresp.DeliverSubject, nil, time.Second)
require_NoError(t, err)
rresp.Error = nil
json.Unmarshal(rmsg.Data, &rresp)

require_True(t, rresp.Error != nil)
require_Equal(t, rresp.ApiResponse.Error.ErrCode, 10074)

status := s.healthz(nil)
require_Equal(t, status.StatusCode, 200)
}

func TestJetStreamClusterBinaryStreamSnapshotCapability(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions server/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -6106,6 +6106,8 @@ func (a *Account) RestoreStream(ncfg *StreamConfig, r io.Reader) (*stream, error
}
mset, err := a.addStream(&cfg)
if err != nil {
// Make sure to clean up after ourselves here.
os.RemoveAll(ndir)
return nil, err
}
if !fcfg.Created.IsZero() {
Expand Down