github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/jobmaster/dm/metadata/metadata.go (about) 1 // Copyright 2022 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 package metadata 15 16 import ( 17 "context" 18 19 "github.com/coreos/go-semver/semver" 20 metaModel "github.com/pingcap/tiflow/engine/pkg/meta/model" 21 "go.uber.org/zap" 22 ) 23 24 // MetaData is the metadata of dm. 25 type MetaData struct { 26 clusterInfoStore *ClusterInfoStore 27 jobStore *JobStore 28 unitStateStore *UnitStateStore 29 } 30 31 // NewMetaData creates a new MetaData instance 32 func NewMetaData(kvClient metaModel.KVClient, pLogger *zap.Logger) *MetaData { 33 return &MetaData{ 34 clusterInfoStore: NewClusterInfoStore(kvClient), 35 jobStore: NewJobStore(kvClient, pLogger), 36 unitStateStore: NewUnitStateStore(kvClient), 37 } 38 } 39 40 // ClusterInfoStore returns internal infoStore 41 func (m *MetaData) ClusterInfoStore() *ClusterInfoStore { 42 return m.clusterInfoStore 43 } 44 45 // JobStore returns internal jobStore 46 func (m *MetaData) JobStore() *JobStore { 47 return m.jobStore 48 } 49 50 // UnitStateStore returns internal unitStateStore 51 func (m *MetaData) UnitStateStore() *UnitStateStore { 52 return m.unitStateStore 53 } 54 55 // Upgrade upgrades metadata. 56 func (m *MetaData) Upgrade(ctx context.Context, fromVer semver.Version) error { 57 // call infoStore.Upgrade/ddlStore.Upgrade if needed. 58 return m.jobStore.Upgrade(ctx, fromVer) 59 }