github.com/matrixorigin/matrixone@v1.2.0/pkg/util/status/logtail_client.go (about)

     1  // Copyright 2021 -2024 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //	http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package status
    16  
    17  import (
    18  	"fmt"
    19  	"github.com/matrixorigin/matrixone/pkg/pb/timestamp"
    20  	"time"
    21  
    22  	"github.com/matrixorigin/matrixone/pkg/vm/engine/disttae"
    23  )
    24  
    25  type SubTableID struct {
    26  	DatabaseID uint64 `json:"database_id"`
    27  	TableID    uint64 `json:"table_id"`
    28  }
    29  
    30  type SubTableStatus struct {
    31  	IsDeleting bool      `json:"is_deleting"`
    32  	LatestTime time.Time `json:"latest_time"`
    33  }
    34  
    35  type LogtailStatus struct {
    36  	LatestTS         timestamp.Timestamp       `json:"latest_ts"`
    37  	SubscribedTables map[string]SubTableStatus `json:"subscribed_tables"`
    38  }
    39  
    40  func (s *LogtailStatus) fill(c *disttae.PushClient) {
    41  	if c == nil {
    42  		return
    43  	}
    44  	st := c.GetState()
    45  	s.SubscribedTables = make(map[string]SubTableStatus, len(st.SubTables))
    46  	for id, status := range st.SubTables {
    47  		tid := fmt.Sprintf("%d-%d", id.DatabaseID, id.TableID)
    48  		s.SubscribedTables[tid] = SubTableStatus{
    49  			IsDeleting: status.IsDeleting,
    50  			LatestTime: status.LatestTime,
    51  		}
    52  	}
    53  	s.LatestTS = st.LatestTS
    54  }