jiacai2050 commented on code in PR #1483: URL: https://github.com/apache/incubator-horaedb/pull/1483#discussion_r1527732025
########## horaemeta/server/coordinator/inspector/node_inspector.go: ########## @@ -0,0 +1,147 @@ +/* + * 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 inspector + +import ( + "context" + "sync" + "time" + + "github.com/apache/incubator-horaedb-meta/pkg/coderr" + "github.com/apache/incubator-horaedb-meta/pkg/log" + "github.com/apache/incubator-horaedb-meta/server/cluster/metadata" + "github.com/apache/incubator-horaedb-meta/server/storage" + "go.uber.org/zap" +) + +var ErrStartAgain = coderr.NewCodeError(coderr.Internal, "try to start again") +var ErrStopNotStart = coderr.NewCodeError(coderr.Internal, "try to stop a not-started inspector") + +const defaultInspectInterval = time.Second * 5 + +// NodeInspector will inspect node status and remove expired data. +type NodeInspector struct { + logger *zap.Logger + clusterMetadata ClusterMetaDataManipulator + interval time.Duration + + starter sync.Once + // After `Start` is called, the following fields will be initialized + stopCtx context.Context + bgJobCancel context.CancelFunc +} + +// ClusterMetaDataManipulator provides the snapshot for NodeInspector to check and utilities of drop expired shard nodes. +type ClusterMetaDataManipulator interface { + GetClusterSnapshot() metadata.Snapshot + DropShardNode(context.Context, []storage.ShardNode) error +} + +func NewNodeInspectorWithInterval(logger *zap.Logger, clusterMetadata ClusterMetaDataManipulator, inspectInterval time.Duration) *NodeInspector { + return &NodeInspector{ + logger: logger, + clusterMetadata: clusterMetadata, + interval: inspectInterval, + starter: sync.Once{}, + stopCtx: nil, + bgJobCancel: nil, + } +} + +func NewNodeInspector(logger *zap.Logger, clusterMetadata ClusterMetaDataManipulator) *NodeInspector { + return NewNodeInspectorWithInterval(logger, clusterMetadata, defaultInspectInterval) +} + +func (i *NodeInspector) Start(ctx context.Context) error { Review Comment: It's weird to use `i` here, `i`, `j` are usually used for temp variables. how about `ni`? -- 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]
