Skip to content

Commit

Permalink
Fix delete stream error when dir is not empty
Browse files Browse the repository at this point in the history
Fix an edge case when deleting a stream directory that has been
partially removed.

Fixes #297
  • Loading branch information
tylertreat committed Dec 15, 2020
1 parent d7f2b01 commit 739008e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions server/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package server
import (
"context"
"fmt"
"os"
"path/filepath"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -236,12 +238,18 @@ func TestDeleteStream(t *testing.T) {
err = client.CreateStream(context.Background(), "foo", "foo", lift.Partitions(3))
require.NoError(t, err)

_, err = os.Stat(filepath.Join(s1Config.DataDir, "streams", "foo"))
require.NoError(t, err)

stream := s1.metadata.GetStream("foo")
require.NotNil(t, stream)

err = client.DeleteStream(context.Background(), "foo")
require.NoError(t, err)

_, err = os.Stat(filepath.Join(s1Config.DataDir, "streams", "foo"))
require.True(t, os.IsNotExist(err))

stream = s1.metadata.GetStream("foo")
require.Nil(t, stream)

Expand Down
2 changes: 1 addition & 1 deletion server/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ func (m *metadataAPI) CloseAndDeleteStream(stream *stream) error {

// Remove the (now empty) stream data directory

This comment has been minimized.

Copy link
@annismckenzie

annismckenzie Dec 15, 2020

Contributor

Then this comment should be changed, right? It's not necessarily true anymore if we force the removal.

streamDataDir := filepath.Join(m.Server.config.DataDir, "streams", stream.GetName())
err = os.Remove(streamDataDir)
err = os.RemoveAll(streamDataDir)
if err != nil {
return errors.Wrap(err, "failed to delete stream data directory")
}
Expand Down

0 comments on commit 739008e

Please sign in to comment.