github.com/matrixorigin/matrixone@v1.2.0/pkg/hakeeper/operator/status.go (about)

     1  // Copyright 2020 PingCAP, Inc.
     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  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  // Portions of this file are additionally subject to the following
    15  // copyright.
    16  //
    17  // Copyright (C) 2021 Matrix Origin.
    18  //
    19  // Simplified the behavior and the interface of the status.
    20  
    21  package operator
    22  
    23  // OpStatus represents the status of an Operator.
    24  type OpStatus = uint32
    25  
    26  // Status list
    27  const (
    28  	// Status list
    29  
    30  	// STARTED and not finished. Next status: { SUCCESS, CANCELED, EXPIRED}.
    31  	STARTED OpStatus = iota
    32  
    33  	// Followings are end status, i.e. no next status.
    34  
    35  	// SUCCESS Finished successfully
    36  	SUCCESS
    37  
    38  	// CANCELED due to some reason
    39  	CANCELED
    40  
    41  	// EXPIRED waiting for too long
    42  	EXPIRED
    43  
    44  	// Status list end
    45  	statusCount    // Total count of status
    46  	firstEndStatus = SUCCESS
    47  )
    48  
    49  type transition [statusCount][statusCount]bool
    50  
    51  // Valid status transition
    52  var validTrans = transition{
    53  	STARTED: {
    54  		SUCCESS:  true,
    55  		CANCELED: true,
    56  		EXPIRED:  true,
    57  	},
    58  	SUCCESS:  {},
    59  	CANCELED: {},
    60  	EXPIRED:  {},
    61  }
    62  
    63  var statusString = [statusCount]string{
    64  	STARTED:  "Started",
    65  	SUCCESS:  "Success",
    66  	CANCELED: "Canceled",
    67  
    68  	EXPIRED: "Expired",
    69  }
    70  
    71  // IsEndStatus checks whether s is an end status.
    72  func IsEndStatus(s OpStatus) bool {
    73  	return firstEndStatus <= s && s < statusCount
    74  }
    75  
    76  // OpStatusToString converts Status to string.
    77  func OpStatusToString(s OpStatus) string {
    78  	if s < statusCount {
    79  		return statusString[s]
    80  	}
    81  	return "Unknown"
    82  }