Skip to content

Commit f9bc9ef

Browse files
committed
feat: trigger controller wait eventbus ready
Signed-off-by: xdlbdy <[email protected]>
1 parent 4ec5540 commit f9bc9ef

File tree

9 files changed

+108
-68
lines changed

9 files changed

+108
-68
lines changed

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ require (
119119
go.uber.org/multierr v1.7.0 // indirect
120120
go.uber.org/zap v1.17.0 // indirect
121121
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
122-
golang.org/x/net v0.4.0 // indirect
123-
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
122+
golang.org/x/net v0.8.0 // indirect
123+
golang.org/x/oauth2 v0.6.0 // indirect
124124
golang.org/x/sync v0.1.0 // indirect
125-
golang.org/x/sys v0.3.0 // indirect
126-
golang.org/x/text v0.5.0 // indirect
125+
golang.org/x/sys v0.6.0 // indirect
126+
golang.org/x/text v0.8.0 // indirect
127127
google.golang.org/appengine v1.6.7 // indirect
128128
)
129129

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,8 @@ golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qx
534534
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
535535
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
536536
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
537-
golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
538-
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
537+
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
538+
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
539539
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
540540
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
541541
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -544,8 +544,8 @@ golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4Iltr
544544
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
545545
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
546546
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
547-
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 h1:nt+Q6cXKz4MosCSpnbMtqiQ8Oz0pxTef2B4Vca2lvfk=
548-
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg=
547+
golang.org/x/oauth2 v0.6.0 h1:Lh8GPgSKBfWSwFvtuWOfeI3aAAnbXTSutYxJiOJFgIw=
548+
golang.org/x/oauth2 v0.6.0/go.mod h1:ycmewcwgD4Rpr3eZJLSB4Kyyljb3qDh40vJ8STE5HKw=
549549
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
550550
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
551551
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -607,8 +607,8 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
607607
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
608608
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
609609
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
610-
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
611-
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
610+
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
611+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
612612
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
613613
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
614614
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -619,8 +619,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
619619
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
620620
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
621621
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
622-
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
623-
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
622+
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
623+
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
624624
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
625625
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
626626
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

internal/controller/trigger/controller.go

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package trigger
1616

1717
import (
1818
"context"
19-
stdErr "errors"
19+
stderr "errors"
2020
"fmt"
2121
"io"
2222
"os"
@@ -52,14 +52,15 @@ var _ ctrlpb.TriggerControllerServer = &controller{}
5252

5353
const (
5454
defaultGcSubscriptionInterval = time.Second * 10
55+
waitEventbusReadyTime = time.Minute * 3
56+
waitEventbusCheckPeriod = time.Second * 2
5557
)
5658

5759
func NewController(config Config, mem member.Member) *controller {
5860
ctrl := &controller{
5961
config: config,
6062
member: mem,
6163
needCleanSubscription: map[vanus.ID]string{},
62-
state: primitive.ServerStateCreated,
6364
cl: cluster.NewClusterController(config.ControllerAddr, insecure.NewCredentials()),
6465
ebClient: eb.Connect(config.ControllerAddr),
6566
}
@@ -81,17 +82,13 @@ type controller struct {
8182
isLeader bool
8283
ctx context.Context
8384
stopFunc context.CancelFunc
84-
state primitive.ServerState
8585
cl cluster.Cluster
8686
ebClient eb.Client
8787
}
8888

8989
func (ctrl *controller) SetDeadLetterEventOffset(
9090
ctx context.Context, request *ctrlpb.SetDeadLetterEventOffsetRequest,
9191
) (*emptypb.Empty, error) {
92-
if ctrl.state != primitive.ServerStateRunning {
93-
return nil, errors.ErrServerNotStart
94-
}
9592
subID := vanus.ID(request.SubscriptionId)
9693
err := ctrl.subscriptionManager.SaveDeadLetterOffset(ctx, subID, request.GetOffset())
9794
if err != nil {
@@ -103,9 +100,6 @@ func (ctrl *controller) SetDeadLetterEventOffset(
103100
func (ctrl *controller) GetDeadLetterEventOffset(
104101
ctx context.Context, request *ctrlpb.GetDeadLetterEventOffsetRequest,
105102
) (*ctrlpb.GetDeadLetterEventOffsetResponse, error) {
106-
if ctrl.state != primitive.ServerStateRunning {
107-
return nil, errors.ErrServerNotStart
108-
}
109103
subID := vanus.ID(request.SubscriptionId)
110104
offset, err := ctrl.subscriptionManager.GetDeadLetterOffset(ctx, subID)
111105
if err != nil {
@@ -117,9 +111,6 @@ func (ctrl *controller) GetDeadLetterEventOffset(
117111
func (ctrl *controller) CommitOffset(
118112
ctx context.Context, request *ctrlpb.CommitOffsetRequest,
119113
) (*ctrlpb.CommitOffsetResponse, error) {
120-
if ctrl.state != primitive.ServerStateRunning {
121-
return nil, errors.ErrServerNotStart
122-
}
123114
resp := new(ctrlpb.CommitOffsetResponse)
124115
for _, subInfo := range request.SubscriptionInfo {
125116
if len(subInfo.Offsets) == 0 {
@@ -142,9 +133,6 @@ func (ctrl *controller) CommitOffset(
142133
func (ctrl *controller) ResetOffsetToTimestamp(
143134
ctx context.Context, request *ctrlpb.ResetOffsetToTimestampRequest,
144135
) (*ctrlpb.ResetOffsetToTimestampResponse, error) {
145-
if ctrl.state != primitive.ServerStateRunning {
146-
return nil, errors.ErrServerNotStart
147-
}
148136
if request.Timestamp == 0 {
149137
return nil, errors.ErrInvalidRequest.WithMessage("timestamp is invalid")
150138
}
@@ -169,9 +157,6 @@ func (ctrl *controller) ResetOffsetToTimestamp(
169157
func (ctrl *controller) CreateSubscription(
170158
ctx context.Context, request *ctrlpb.CreateSubscriptionRequest,
171159
) (*metapb.Subscription, error) {
172-
if ctrl.state != primitive.ServerStateRunning {
173-
return nil, errors.ErrServerNotStart
174-
}
175160
err := validation.ValidateSubscriptionRequest(ctx, request.Subscription)
176161
if err != nil {
177162
log.Info(ctx, "create subscription validate fail", map[string]interface{}{
@@ -180,6 +165,14 @@ func (ctrl *controller) CreateSubscription(
180165
return nil, err
181166
}
182167
sub := convert.FromPbSubscriptionRequest(request.Subscription)
168+
_, err = ctrl.cl.NamespaceService().GetNamespace(ctx, sub.NamespaceID.Uint64())
169+
if err != nil {
170+
return nil, err
171+
}
172+
_, err = ctrl.cl.EventbusService().GetEventbus(ctx, sub.EventbusID.Uint64())
173+
if err != nil {
174+
return nil, err
175+
}
183176
sub.ID, err = vanus.NewID()
184177
sub.CreatedAt = time.Now()
185178
sub.UpdatedAt = time.Now()
@@ -205,9 +198,6 @@ func (ctrl *controller) CreateSubscription(
205198
func (ctrl *controller) UpdateSubscription(
206199
ctx context.Context, request *ctrlpb.UpdateSubscriptionRequest,
207200
) (*metapb.Subscription, error) {
208-
if ctrl.state != primitive.ServerStateRunning {
209-
return nil, errors.ErrServerNotStart
210-
}
211201
subID := vanus.ID(request.Id)
212202
sub := ctrl.subscriptionManager.GetSubscription(ctx, subID)
213203
if sub == nil {
@@ -248,9 +238,6 @@ func (ctrl *controller) UpdateSubscription(
248238
func (ctrl *controller) DeleteSubscription(
249239
ctx context.Context, request *ctrlpb.DeleteSubscriptionRequest,
250240
) (*emptypb.Empty, error) {
251-
if ctrl.state != primitive.ServerStateRunning {
252-
return nil, errors.ErrServerNotStart
253-
}
254241
subID := vanus.ID(request.Id)
255242
sub := ctrl.subscriptionManager.GetSubscription(ctx, subID)
256243
if sub != nil {
@@ -274,9 +261,6 @@ func (ctrl *controller) DeleteSubscription(
274261
func (ctrl *controller) DisableSubscription(
275262
ctx context.Context, request *ctrlpb.DisableSubscriptionRequest,
276263
) (*emptypb.Empty, error) {
277-
if ctrl.state != primitive.ServerStateRunning {
278-
return nil, errors.ErrServerNotStart
279-
}
280264
subID := vanus.ID(request.Id)
281265
sub := ctrl.subscriptionManager.GetSubscription(ctx, subID)
282266
if sub == nil {
@@ -307,9 +291,6 @@ func (ctrl *controller) DisableSubscription(
307291
func (ctrl *controller) ResumeSubscription(
308292
ctx context.Context, request *ctrlpb.ResumeSubscriptionRequest,
309293
) (*emptypb.Empty, error) {
310-
if ctrl.state != primitive.ServerStateRunning {
311-
return nil, errors.ErrServerNotStart
312-
}
313294
subID := vanus.ID(request.Id)
314295
sub := ctrl.subscriptionManager.GetSubscription(ctx, subID)
315296
if sub == nil {
@@ -331,9 +312,6 @@ func (ctrl *controller) ResumeSubscription(
331312
func (ctrl *controller) GetSubscription(
332313
ctx context.Context, request *ctrlpb.GetSubscriptionRequest,
333314
) (*metapb.Subscription, error) {
334-
if ctrl.state != primitive.ServerStateRunning {
335-
return nil, errors.ErrServerNotStart
336-
}
337315
sub := ctrl.subscriptionManager.GetSubscription(ctx, vanus.ID(request.Id))
338316
if sub == nil {
339317
return nil, errors.ErrResourceNotFound.WithMessage("subscription not exist")
@@ -360,7 +338,7 @@ func (ctrl *controller) TriggerWorkerHeartbeat(
360338
}
361339
req, err := heartbeat.Recv()
362340
if err != nil {
363-
if !stdErr.Is(err, io.EOF) {
341+
if !stderr.Is(err, io.EOF) {
364342
log.Warning(ctx, "heartbeat recv error", map[string]interface{}{
365343
log.KeyError: err,
366344
})
@@ -578,7 +556,6 @@ func (ctrl *controller) membershipChangedProcessor(
578556
ctrl.subscriptionManager.Start()
579557
ctrl.scheduler.Run()
580558
go ctrl.gcSubscriptions(ctx)
581-
ctrl.state = primitive.ServerStateRunning
582559
ctrl.isLeader = true
583560
case member.EventBecomeFollower:
584561
if !ctrl.isLeader {
@@ -597,13 +574,11 @@ func (ctrl *controller) membershipChangedProcessor(
597574

598575
func (ctrl *controller) stop(_ context.Context) error {
599576
ctrl.member.ResignIfLeader()
600-
ctrl.state = primitive.ServerStateStopping
601577
ctrl.stopFunc()
602578
ctrl.scheduler.Stop()
603579
ctrl.workerManager.Stop()
604580
ctrl.subscriptionManager.Stop()
605581
ctrl.storage.Close()
606-
ctrl.state = primitive.ServerStateStopped
607582
return nil
608583
}
609584

@@ -641,14 +616,48 @@ func (ctrl *controller) initTriggerSystemEventbus() {
641616
go func() {
642617
ctx := context.Background()
643618
log.Info(ctx, "trigger controller is ready to check system eventbus", nil)
619+
if err := ctrl.cl.WaitForControllerReady(false); err != nil {
620+
log.Error(ctx, "trigger controller check system eventbus, "+
621+
"but Vanus cluster hasn't ready, exit", map[string]interface{}{
622+
log.KeyError: err,
623+
})
624+
os.Exit(-1)
625+
}
626+
ready := util.WaitReady(func() bool {
627+
exist, err := ctrl.cl.EventbusService().IsSystemEventbusExistByName(ctx, primitive.TimerEventbusName)
628+
if err != nil {
629+
log.Error(ctx, "check TimerEventbus exist has error", map[string]interface{}{
630+
log.KeyError: err,
631+
})
632+
return false
633+
}
634+
return exist
635+
}, waitEventbusReadyTime, waitEventbusCheckPeriod)
636+
if !ready {
637+
log.Error(ctx, "check TimerEventbus timeout no exist, will exist", nil)
638+
os.Exit(-1)
639+
}
640+
641+
// wait TimerEventbus
642+
exist, err := ctrl.cl.EventbusService().IsSystemEventbusExistByName(ctx, primitive.RetryEventbusName)
643+
if err != nil {
644+
log.Error(ctx, "failed to check RetryEventbus exist, exit", map[string]interface{}{
645+
log.KeyError: err,
646+
})
647+
os.Exit(-1)
648+
}
649+
if exist {
650+
log.Info(ctx, "trigger controller check RetryEventbus exist", nil)
651+
return
652+
}
653+
log.Info(ctx, "trigger controller check RetryEventbus no exist, will create", nil)
644654
if err := ctrl.cl.WaitForControllerReady(true); err != nil {
645655
log.Error(ctx, "trigger controller try to create system eventbus, "+
646656
"but Vanus cluster hasn't ready, exit", map[string]interface{}{
647657
log.KeyError: err,
648658
})
649659
os.Exit(-1)
650660
}
651-
652661
if _, err := ctrl.cl.EventbusService().CreateSystemEventbusIfNotExist(ctx, primitive.RetryEventbusName,
653662
"System Eventbus For Trigger Service"); err != nil {
654663
log.Error(ctx, "failed to create RetryEventbus, exit", map[string]interface{}{

internal/controller/trigger/controller_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ func TestController_CommitOffset(t *testing.T) {
4747
ctrl.subscriptionManager = subManager
4848

4949
subID := vanus.NewTestID()
50-
ctrl.state = primitive.ServerStateRunning
5150
request := &ctrlpb.CommitOffsetRequest{
5251
ForceCommit: true,
5352
SubscriptionInfo: []*metapb.SubscriptionInfo{{
@@ -87,7 +86,6 @@ func TestController_ResetOffsetToTimestamp(t *testing.T) {
8786
ctrl.subscriptionManager = subManager
8887

8988
subID := vanus.NewTestID()
90-
ctrl.state = primitive.ServerStateRunning
9189
Convey("reset offset subscription not exist", func() {
9290
subManager.EXPECT().GetSubscription(gomock.Any(), gomock.Eq(subID)).AnyTimes().Return(nil)
9391
_, err := ctrl.ResetOffsetToTimestamp(ctx, &ctrlpb.ResetOffsetToTimestampRequest{
@@ -124,7 +122,6 @@ func TestController_CreateSubscription(t *testing.T) {
124122
ctrl.subscriptionManager = subManager
125123
ctrl.scheduler = worker.NewSubscriptionScheduler(ctrl.workerManager, ctrl.subscriptionManager)
126124

127-
ctrl.state = primitive.ServerStateRunning
128125
Convey("create subscription", func() {
129126
subManager.EXPECT().GetSubscriptionByName(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil)
130127
subManager.EXPECT().AddSubscription(gomock.Any(), gomock.Any()).AnyTimes().Return(nil)
@@ -168,7 +165,6 @@ func TestController_UpdateSubscription(t *testing.T) {
168165
subID := vanus.NewTestID()
169166
eventbusID := vanus.NewTestID()
170167
namespaceID := vanus.NewTestID()
171-
ctrl.state = primitive.ServerStateRunning
172168
Convey("update subscription not exist", func() {
173169
subManager.EXPECT().GetSubscription(gomock.Any(), gomock.Eq(subID)).Return(nil)
174170
request := &ctrlpb.UpdateSubscriptionRequest{
@@ -387,7 +383,6 @@ func TestController_DeleteSubscription(t *testing.T) {
387383
request := &ctrlpb.DeleteSubscriptionRequest{
388384
Id: subID.Uint64(),
389385
}
390-
ctrl.state = primitive.ServerStateRunning
391386
Convey("delete subscription no exist", func() {
392387
subManager.EXPECT().GetSubscription(gomock.Any(), gomock.Eq(subID)).Return(nil)
393388
_, err := ctrl.DeleteSubscription(ctx, request)
@@ -447,7 +442,6 @@ func TestController_GetSubscription(t *testing.T) {
447442
request := &ctrlpb.GetSubscriptionRequest{
448443
Id: subID.Uint64(),
449444
}
450-
ctrl.state = primitive.ServerStateRunning
451445
Convey("get subscription no exist", func() {
452446
subManager.EXPECT().GetSubscription(gomock.Any(), gomock.Eq(subID)).Return(nil)
453447
_, err := ctrl.GetSubscription(ctx, request)

pkg/cluster/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type NamespaceService interface {
6262
}
6363

6464
type EventbusService interface {
65+
IsSystemEventbusExistByName(ctx context.Context, name string) (bool, error)
6566
CreateSystemEventbusIfNotExist(ctx context.Context, name string, desc string) (*metapb.Eventbus, error)
6667
Delete(ctx context.Context, id uint64) error
6768
GetSystemEventbusByName(ctx context.Context, name string) (*metapb.Eventbus, error)

pkg/cluster/eventbus.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"strings"
77
"sync"
88

9+
"google.golang.org/protobuf/types/known/wrapperspb"
10+
911
"github.com/vanus-labs/vanus/pkg/cluster/raw_client"
1012
"github.com/vanus-labs/vanus/pkg/errors"
1113
ctrlpb "github.com/vanus-labs/vanus/proto/pkg/controller"
1214
"github.com/vanus-labs/vanus/proto/pkg/meta"
13-
"google.golang.org/protobuf/types/known/wrapperspb"
1415
)
1516

1617
var (
@@ -75,15 +76,21 @@ func (es *eventbusService) GetEventbus(ctx context.Context, id uint64) (*meta.Ev
7576

7677
func (es *eventbusService) IsSystemEventbusExistByName(ctx context.Context, name string) (bool, error) {
7778
ebPb, err := es.GetSystemEventbusByName(ctx, name)
78-
return ebPb != nil, err
79+
if err != nil {
80+
if !errors.Is(err, errors.ErrResourceNotFound) {
81+
return false, nil
82+
}
83+
return false, err
84+
}
85+
return ebPb != nil, nil
7986
}
8087

8188
func (es *eventbusService) CreateSystemEventbusIfNotExist(ctx context.Context, name string, desc string) (*meta.Eventbus, error) {
8289
if !strings.HasPrefix(name, systemEventbusPrefix) {
8390
return nil, errors.New("invalid system eventbus name")
8491
}
8592
exist, err := es.IsSystemEventbusExistByName(ctx, name)
86-
if err != nil && !errors.Is(err, errors.ErrResourceNotFound) {
93+
if err != nil {
8794
return nil, err
8895
}
8996

0 commit comments

Comments
 (0)