github.com/matrixorigin/matrixone@v0.7.0/pkg/hakeeper/checkers/cnservice/check.go (about)

     1  // Copyright 2022 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 cnservice
    16  
    17  import (
    18  	"github.com/matrixorigin/matrixone/pkg/hakeeper"
    19  	"github.com/matrixorigin/matrixone/pkg/hakeeper/operator"
    20  	pb "github.com/matrixorigin/matrixone/pkg/pb/logservice"
    21  )
    22  
    23  func Check(cfg hakeeper.Config, infos pb.CNState, user pb.TaskTableUser, currentTick uint64) (operators []*operator.Operator) {
    24  	if user.Username == "" {
    25  		return
    26  	}
    27  	working, expired := parseCNStores(cfg, infos, currentTick)
    28  	for _, store := range working {
    29  		if !infos.Stores[store].TaskServiceCreated {
    30  			operators = append(operators, operator.CreateTaskServiceOp("",
    31  				store, pb.CNService, user))
    32  		}
    33  	}
    34  	for _, store := range expired {
    35  		operators = append(operators, operator.CreateDeleteCNOp("", store))
    36  	}
    37  	return operators
    38  }
    39  
    40  // parseCNStores returns all expired stores' ids.
    41  func parseCNStores(cfg hakeeper.Config, infos pb.CNState, currentTick uint64) ([]string, []string) {
    42  	working := make([]string, 0)
    43  	expired := make([]string, 0)
    44  	for uuid, storeInfo := range infos.Stores {
    45  		if cfg.CNStoreExpired(storeInfo.Tick, currentTick) {
    46  			expired = append(expired, uuid)
    47  		} else {
    48  			working = append(working, uuid)
    49  		}
    50  	}
    51  
    52  	return working, expired
    53  }