Skip to content

Commit

Permalink
Fix shard close panic
Browse files Browse the repository at this point in the history
  • Loading branch information
xichen2020 committed Jan 28, 2019
1 parent 96f95f6 commit 701f137
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion storage/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ func (s *dbShard) Close() error {
s.unflushed = nil
active := s.active
s.active = nil
s.sealedByMaxTimeAsc = nil
byMaxTimeAsc := s.sealedByMaxTimeAsc
s.sealedByMaxTimeAsc = nil
s.Unlock()

active.Close()
Expand Down
17 changes: 15 additions & 2 deletions storage/shard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/golang/mock/gomock"
)

func TestRemoveFlushDoneSegmentsAllFlushed(t *testing.T) {
func TestShardRemoveFlushDoneSegmentsAllFlushed(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand All @@ -38,7 +38,7 @@ func TestRemoveFlushDoneSegmentsAllFlushed(t *testing.T) {
require.Equal(t, "segment4", s.unflushed[1].ID())
}

func TestRemoveFlushDoneSegmentsPartialFlushed(t *testing.T) {
func TestShardRemoveFlushDoneSegmentsPartialFlushed(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand All @@ -65,6 +65,19 @@ func TestRemoveFlushDoneSegmentsPartialFlushed(t *testing.T) {
require.Equal(t, "segment4", s.unflushed[2].ID())
}

func TestShardClose(t *testing.T) {
shard := newDatabaseShard([]byte("testNamespace"), 0, NewOptions(), NewNamespaceOptions())

// Closing once should result in no error.
require.NoError(t, shard.Close())
require.True(t, shard.closed)
require.Nil(t, shard.active)
require.Nil(t, shard.sealedByMaxTimeAsc)

// Closing twice should result in an error.
require.Equal(t, errShardAlreadyClosed, shard.Close())
}

// NB(xichen): Ugly, hand-written mocks for immutable segments because
// mockgen doesn't support generating mocks for interfaces that
// embed unexported interfaces.
Expand Down

0 comments on commit 701f137

Please sign in to comment.