Fine0830 commented on code in PR #918: URL: https://github.com/apache/skywalking-banyandb/pull/918#discussion_r2660252298
########## fodc/agent/internal/proxy/conn_manager.go: ########## @@ -0,0 +1,428 @@ +// Licensed to 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. Apache Software Foundation (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 proxy provides connection management for the FODC Proxy client. +package proxy + +import ( + "context" + "fmt" + "sync" + "time" + + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + + "github.com/apache/skywalking-banyandb/pkg/logger" +) + +const ( + connManagerMaxRetryInterval = 30 * time.Second +) + +// ConnEventType represents the type of connection event. +type ConnEventType int + +// Possible connection event types. +const ( + ConnEventConnect ConnEventType = iota + ConnEventReconnect + ConnEventDisconnect +) + +// ConnEvent represents a connection event sent to the manager. +type ConnEvent struct { + ResultCh chan<- ConnResult + Context context.Context + Type ConnEventType + Immediate bool // If true, skip backoff and retry immediately +} + +// ConnResult represents the result of a connection operation. +type ConnResult struct { + Conn *grpc.ClientConn + Error error +} + +// ConnState represents the state of the connection. +type ConnState int + +const ( + // ConnStateDisconnected indicates the connection is disconnected. + ConnStateDisconnected ConnState = iota + // ConnStateConnecting indicates a connection attempt is in progress. + ConnStateConnecting + // ConnStateConnected indicates the connection is established. + ConnStateConnected + // ConnStateReconnecting indicates a reconnection attempt is in progress. + ConnStateReconnecting +) + +// ConnManager manages connection lifecycle using a single goroutine. +type ConnManager struct { + logger *logger.Logger + eventCh chan ConnEvent + stopCh chan struct{} + doneCh chan struct{} // Signals when run() goroutine has exited + currentConn *grpc.ClientConn + proxyAddr string + reconnectInterval time.Duration Review Comment: It's a initial value for exponential backoff. -- 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]
