|
| 1 | +// Copyright 2025 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 v3_0_1 |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "time" |
| 20 | + |
| 21 | + "github.com/matrixorigin/matrixone/pkg/bootstrap/versions" |
| 22 | + "github.com/matrixorigin/matrixone/pkg/catalog" |
| 23 | + "github.com/matrixorigin/matrixone/pkg/common/moerr" |
| 24 | + "github.com/matrixorigin/matrixone/pkg/util/executor" |
| 25 | + "go.uber.org/zap" |
| 26 | +) |
| 27 | + |
| 28 | +var ( |
| 29 | + Handler *versionHandle |
| 30 | +) |
| 31 | + |
| 32 | +func init() { |
| 33 | + Handler = &versionHandle{ |
| 34 | + metadata: versions.Version{ |
| 35 | + Version: "3.0.1", |
| 36 | + MinUpgradeVersion: "3.0.0", |
| 37 | + UpgradeCluster: versions.No, |
| 38 | + UpgradeTenant: versions.Yes, |
| 39 | + VersionOffset: uint32(len(tenantUpgEntries) + len(clusterUpgEntries)), |
| 40 | + }, |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +type versionHandle struct { |
| 45 | + metadata versions.Version |
| 46 | +} |
| 47 | + |
| 48 | +func (v *versionHandle) Metadata() versions.Version { |
| 49 | + return v.metadata |
| 50 | +} |
| 51 | + |
| 52 | +func (v *versionHandle) Prepare( |
| 53 | + ctx context.Context, |
| 54 | + txn executor.TxnExecutor, |
| 55 | + final bool) error { |
| 56 | + txn.Use(catalog.MO_CATALOG) |
| 57 | + return nil |
| 58 | +} |
| 59 | + |
| 60 | +func (v *versionHandle) HandleTenantUpgrade( |
| 61 | + ctx context.Context, |
| 62 | + tenantID int32, |
| 63 | + txn executor.TxnExecutor, |
| 64 | +) error { |
| 65 | + |
| 66 | + var ( |
| 67 | + err error |
| 68 | + goon bool |
| 69 | + ) |
| 70 | + |
| 71 | + for _, upgEntry := range tenantUpgEntries { |
| 72 | + goon = false |
| 73 | + |
| 74 | + start := time.Now() |
| 75 | + err = upgEntry.Upgrade(txn, uint32(tenantID)) |
| 76 | + |
| 77 | + duration := time.Since(start) |
| 78 | + |
| 79 | + if err == nil { |
| 80 | + goon = true |
| 81 | + getLogger(txn.Txn().TxnOptions().CN).Info("tenant upgrade", |
| 82 | + zap.String("cn", txn.Txn().TxnOptions().CN), |
| 83 | + zap.String("entry", upgEntry.String()), |
| 84 | + zap.Int32("tenantId", tenantID), |
| 85 | + zap.String("version", v.metadata.Version), |
| 86 | + zap.Duration("duration", duration), |
| 87 | + zap.Error(err), |
| 88 | + ) |
| 89 | + } else { |
| 90 | + getLogger(txn.Txn().TxnOptions().CN).Error("tenant upgrade", |
| 91 | + zap.String("cn", txn.Txn().TxnOptions().CN), |
| 92 | + zap.String("entry", upgEntry.String()), |
| 93 | + zap.Int32("tenantId", tenantID), |
| 94 | + zap.String("version", v.metadata.Version), |
| 95 | + zap.Duration("duration", duration), |
| 96 | + zap.Error(err), |
| 97 | + ) |
| 98 | + } |
| 99 | + |
| 100 | + if goon { |
| 101 | + continue |
| 102 | + } |
| 103 | + return err |
| 104 | + } |
| 105 | + |
| 106 | + return nil |
| 107 | +} |
| 108 | + |
| 109 | +func (v *versionHandle) HandleClusterUpgrade( |
| 110 | + ctx context.Context, |
| 111 | + txn executor.TxnExecutor, |
| 112 | +) error { |
| 113 | + // No cluster-level upgrades for v3.0.1 |
| 114 | + return nil |
| 115 | +} |
| 116 | + |
| 117 | +func (v *versionHandle) HandleCreateFrameworkDeps(txn executor.TxnExecutor) error { |
| 118 | + return moerr.NewInternalErrorNoCtxf("Only v1.2.0 can initialize upgrade framework, current version is:%s", Handler.metadata.Version) |
| 119 | +} |
0 commit comments