github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/lorry/engines/interface.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 4 This file is part of KubeBlocks project 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package engines 21 22 import ( 23 "context" 24 25 "github.com/go-logr/logr" 26 27 "github.com/1aal/kubeblocks/pkg/lorry/dcs" 28 "github.com/1aal/kubeblocks/pkg/lorry/engines/models" 29 ) 30 31 type DBManager interface { 32 IsRunning() bool 33 34 IsDBStartupReady() bool 35 36 // Functions related to cluster initialization. 37 InitializeCluster(context.Context, *dcs.Cluster) error 38 IsClusterInitialized(context.Context, *dcs.Cluster) (bool, error) 39 // IsCurrentMemberInCluster checks if current member is configured in cluster for consensus. 40 // it will always return true for replicationset. 41 IsCurrentMemberInCluster(context.Context, *dcs.Cluster) bool 42 43 // IsClusterHealthy is only for consensus cluster healthy check. 44 // For Replication cluster IsClusterHealthy will always return true, 45 // and its cluster's healthy is equal to leader member's healthy. 46 IsClusterHealthy(context.Context, *dcs.Cluster) bool 47 48 // Member healthy check 49 // IsMemberHealthy focuses on the database's read and write capabilities. 50 IsMemberHealthy(context.Context, *dcs.Cluster, *dcs.Member) bool 51 IsCurrentMemberHealthy(context.Context, *dcs.Cluster) bool 52 // IsMemberLagging focuses on the latency between the leader and standby 53 IsMemberLagging(context.Context, *dcs.Cluster, *dcs.Member) (bool, int64) 54 GetLag(context.Context, *dcs.Cluster) (int64, error) 55 56 // GetDBState will get most required database kernel states of current member in one HA loop to Avoiding duplicate queries and conserve I/O. 57 // We believe that the states of database kernel remains unchanged within a single HA loop. 58 GetDBState(context.Context, *dcs.Cluster) *dcs.DBState 59 60 // HasOtherHealthyLeader is applicable only to consensus cluster, 61 // where the db's internal role services as the source of truth. 62 // for replicationset cluster, HasOtherHealthyLeader will always be nil. 63 HasOtherHealthyLeader(context.Context, *dcs.Cluster) *dcs.Member 64 HasOtherHealthyMembers(context.Context, *dcs.Cluster, string) []*dcs.Member 65 66 // Functions related to replica member relationship. 67 IsLeader(context.Context, *dcs.Cluster) (bool, error) 68 IsLeaderMember(context.Context, *dcs.Cluster, *dcs.Member) (bool, error) 69 IsFirstMember() bool 70 GetReplicaRole(context.Context, *dcs.Cluster) (string, error) 71 72 JoinCurrentMemberToCluster(context.Context, *dcs.Cluster) error 73 LeaveMemberFromCluster(context.Context, *dcs.Cluster, string) error 74 75 // IsPromoted is applicable only to consensus cluster, which is used to 76 // check if DB has complete switchover. 77 // for replicationset cluster, it will always be true. 78 IsPromoted(context.Context) bool 79 // Functions related to HA 80 // The functions should be idempotent, indicating that if they have been executed in one ha cycle, 81 // any subsequent calls during that cycle will have no effect. 82 Promote(context.Context, *dcs.Cluster) error 83 Demote(context.Context) error 84 Follow(context.Context, *dcs.Cluster) error 85 Recover(context.Context) error 86 87 // Start and Stop just send signal to lorryctl 88 Start(context.Context, *dcs.Cluster) error 89 Stop() error 90 91 // GetHealthiestMember(*dcs.Cluster, string) *dcs.Member 92 // IsHealthiestMember(*dcs.Cluster) bool 93 94 GetCurrentMemberName() string 95 GetMemberAddrs(context.Context, *dcs.Cluster) []string 96 97 // Functions related to account manage 98 IsRootCreated(context.Context) (bool, error) 99 CreateRoot(context.Context) error 100 101 // Readonly lock for disk full 102 Lock(context.Context, string) error 103 Unlock(context.Context) error 104 105 // sql query 106 Exec(context.Context, string) (int64, error) 107 Query(context.Context, string) ([]byte, error) 108 109 // user management 110 ListUsers(context.Context) ([]models.UserInfo, error) 111 ListSystemAccounts(context.Context) ([]models.UserInfo, error) 112 CreateUser(context.Context, string, string) error 113 DeleteUser(context.Context, string) error 114 DescribeUser(context.Context, string) (*models.UserInfo, error) 115 GrantUserRole(context.Context, string, string) error 116 RevokeUserRole(context.Context, string, string) error 117 118 GetPort() (int, error) 119 120 MoveData(context.Context, *dcs.Cluster) error 121 122 GetLogger() logr.Logger 123 124 ShutDownWithWait() 125 }