-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: local wal perform different with remote wal (#39967)
issue: #38399 Signed-off-by: chyezh <[email protected]>
- Loading branch information
Showing
5 changed files
with
137 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
internal/streamingnode/client/handler/registry/is_local.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package registry | ||
|
||
var ( | ||
_ isLocal = localWAL{} | ||
_ isLocal = localScanner{} | ||
) | ||
|
||
// localTrait is used to make isLocal can only be implemented by current package. | ||
type localTrait struct{} | ||
|
||
// isLocal is a hint interface for local wal. | ||
type isLocal interface { | ||
isLocal() localTrait | ||
} | ||
|
||
// IsLocal checks if the component is local. | ||
func IsLocal(component any) bool { | ||
_, ok := component.(isLocal) | ||
return ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
internal/streamingnode/client/handler/registry/wal_manager_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package registry | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
|
||
"github.com/milvus-io/milvus-proto/go-api/v2/msgpb" | ||
"github.com/milvus-io/milvus/internal/mocks/streamingnode/server/mock_wal" | ||
"github.com/milvus-io/milvus/internal/streamingnode/server/wal" | ||
"github.com/milvus-io/milvus/pkg/streaming/util/message" | ||
"github.com/milvus-io/milvus/pkg/streaming/util/types" | ||
"github.com/milvus-io/milvus/pkg/util/paramtable" | ||
"github.com/milvus-io/milvus/pkg/util/typeutil" | ||
) | ||
|
||
type mockWALManager struct { | ||
t *testing.T | ||
} | ||
|
||
func (m *mockWALManager) GetAvailableWAL(channel types.PChannelInfo) (wal.WAL, error) { | ||
l := mock_wal.NewMockWAL(m.t) | ||
l.EXPECT().Append(mock.Anything, mock.Anything).Return(&types.AppendResult{}, nil) | ||
l.EXPECT().AppendAsync(mock.Anything, mock.Anything, mock.Anything).Return() | ||
l.EXPECT().Read(mock.Anything, mock.Anything).Return(mock_wal.NewMockScanner(m.t), nil) | ||
return l, nil | ||
} | ||
|
||
func TestGetLocalAvailableWAL(t *testing.T) { | ||
paramtable.Init() | ||
paramtable.SetLocalComponentEnabled(typeutil.StreamingNodeRole) | ||
|
||
manager := &mockWALManager{t: t} | ||
RegisterLocalWALManager(manager) | ||
|
||
walInstance, err := GetLocalAvailableWAL(types.PChannelInfo{}) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, walInstance) | ||
assert.True(t, IsLocal(walInstance)) | ||
|
||
msg, _ := message.NewTimeTickMessageBuilderV1(). | ||
WithAllVChannel(). | ||
WithHeader(&message.TimeTickMessageHeader{}). | ||
WithBody(&msgpb.TimeTickMsg{}). | ||
BuildMutable() | ||
walInstance.Append(context.Background(), msg) | ||
walInstance.AppendAsync(context.Background(), msg, func(ar *wal.AppendResult, err error) {}) | ||
|
||
s, err := walInstance.Read(context.Background(), wal.ReadOption{}) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, walInstance) | ||
assert.True(t, IsLocal(s)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters