github.com/matrixorigin/matrixone@v1.2.0/pkg/clusterservice/types.go (about) 1 // Copyright 2023 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 clusterservice 16 17 import ( 18 "context" 19 20 logpb "github.com/matrixorigin/matrixone/pkg/pb/logservice" 21 "github.com/matrixorigin/matrixone/pkg/pb/metadata" 22 ) 23 24 // Op compare op 25 type Op int 26 27 var ( 28 // EQ == 29 EQ = Op(1) 30 31 // EQ_Globbing means the labels are equal, also support globbing(*) 32 // to match key/value from request. 33 EQ_Globbing = Op(2) 34 35 // Contain means the requested labels are contained in the CN labels. 36 Contain = Op(3) 37 ) 38 39 // Selector is used to choose a service from MOCluster 40 type Selector struct { 41 byServiceID bool 42 serviceID string 43 44 byLabel bool 45 labels map[string]string 46 labelOp Op 47 48 // all is ture means that we only want all the CN services to do 49 // the filter. Otherwise, only the ones whose work state is working 50 // would do the filter. This is only used for CN. Its default value 51 // is false. 52 all bool 53 } 54 55 // MOCluster is used to get the meta and status information of the MO cluster. 56 // 57 // TODO(fagongzi): In the future, all cluster-related information should be obtained 58 // from this interface, such as the distribution of table data on cn and other 59 // statistical information. 60 type MOCluster interface { 61 // GetCNService get services by selector, and the applyFunc used to save the 62 // cn service that matches the selector's conditions. 63 // 64 // Since the query result may be a Slice, to avoid memory allocation overhead, 65 // we use apply to notify the caller of a Service that satisfies the condition. 66 GetCNService(selector Selector, apply func(metadata.CNService) bool) 67 // GetTNService get services by selector, and the applyFunc used to save the 68 // tn service that matches the selector's conditions. 69 // 70 // Since the query result may be a Slice, to avoid memory allocation overhead, 71 // we use apply to notify the caller of a Service that satisfies the condition. 72 GetTNService(selector Selector, apply func(metadata.TNService) bool) 73 // GetAllTNServices get all tn services 74 GetAllTNServices() []metadata.TNService 75 // GetCNServiceWithoutWorkingState get services by selector, and the applyFunc used to save the 76 // cn service that matches the selector's conditions. 77 // 78 // Since the query result may be a Slice, to avoid memory allocation overhead, 79 // we use apply to notify the caller of a Service that satisfies the condition. 80 GetCNServiceWithoutWorkingState(selector Selector, apply func(metadata.CNService) bool) 81 // ForceRefresh when other modules use the cluster information and find out that 82 // the current cache information is out of date, you can force the cache to be 83 // refreshed. 84 ForceRefresh(sync bool) 85 // Close close the cluster 86 Close() 87 // DebugUpdateCNLabel updates the labels on specified CN. It is only used in mo_ctl 88 // internally for debug purpose. 89 DebugUpdateCNLabel(uuid string, kvs map[string][]string) error 90 DebugUpdateCNWorkState(uuid string, state int) error 91 92 // RemoveCN removes the specified CN from the cluster 93 RemoveCN(id string) 94 // AddCN adds the specified CN to the cluster 95 AddCN(metadata.CNService) 96 } 97 98 type ClusterClient interface { 99 GetClusterDetails(ctx context.Context) (logpb.ClusterDetails, error) 100 } 101 102 type labelSupportedClient interface { 103 ClusterClient 104 UpdateCNLabel(ctx context.Context, label logpb.CNStoreLabel) error 105 UpdateCNWorkState(ctx context.Context, state logpb.CNWorkState) error 106 }