robocanic commented on code in PR #1366: URL: https://github.com/apache/dubbo-admin/pull/1366#discussion_r2636888133
########## pkg/core/lock/const.go: ########## Review Comment: Suggestion: There is already a constant directory in pkg/common/constants, move this file to that directory ########## pkg/core/lock/errors.go: ########## Review Comment: Suggestion: There is a standard biz error defined in pkg/common/bizerror, add a new error code and use bizerror instead. ########## pkg/core/lock/component.go: ########## @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package lock + +import ( + "context" + "gorm.io/gorm" + "math" + "time" + + "github.com/pkg/errors" + + "github.com/apache/dubbo-admin/pkg/core/logger" + "github.com/apache/dubbo-admin/pkg/core/runtime" +) + +const ( + // DistributedLockComponent is the component type for distributed lock + DistributedLockComponent runtime.ComponentType = "distributed lock" +) + +// Component implements the runtime.Component interface for distributed lock +type Component struct { + lock Lock +} + +// NewComponent creates a new distributed lock component +func NewComponent() *Component { + return &Component{} +} + +// Type returns the component type +func (c *Component) Type() runtime.ComponentType { + return DistributedLockComponent +} + +// Order indicates the initialization order +// Lock should be initialized after Store (Order math.MaxInt - 1) +// Higher order values are initialized first, so we use math.MaxInt - 2 +func (c *Component) Order() int { + return math.MaxInt - 2 // After Store, before other services +} + +// Init initializes the distributed lock component +func (c *Component) Init(ctx runtime.BuilderContext) error { + // Get the store component to access database connection + storeComp, err := ctx.GetActivatedComponent(runtime.ResourceStore) + if err != nil { + return err + } + + // Try to extract database connection from store component + // We use GetDB() interface to avoid circular dependency with dbcommon package + type DBProvider interface { + GetDB() *gorm.DB + } + + storeWithDB, ok := storeComp.(DBProvider) Review Comment: Suggestion: gorm.DB is just a kind of implemention of Lock, would be better put the gormDB into the implemention -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
