github.com/matrixorigin/matrixone@v1.2.0/pkg/bootstrap/versions/types.go (about)

     1  // Copyright 2024 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 versions
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/catalog"
    21  )
    22  
    23  var (
    24  	FrameworkInitSQLs = []string{
    25  		fmt.Sprintf(`create table %s.%s (
    26  			version             varchar(50) not null,
    27  		    version_offset      int unsigned default 0,
    28  			state               int,
    29  			create_at           timestamp not null,
    30  			update_at           timestamp not null,
    31  			primary key(version, version_offset)
    32  		)`, catalog.MO_CATALOG, catalog.MOVersionTable),
    33  
    34  		fmt.Sprintf(`create table %s.%s (
    35  			id                   bigint unsigned not null primary key auto_increment,
    36  			from_version         varchar(50) not null,
    37  			to_version           varchar(50) not null,
    38  			final_version        varchar(50) not null,
    39              final_version_offset int unsigned default 0,
    40  			state                int,
    41  			upgrade_cluster      int,
    42  			upgrade_tenant       int,
    43  			upgrade_order        int,
    44  			total_tenant         int,
    45  			ready_tenant         int,
    46  			create_at            timestamp not null,
    47  			update_at            timestamp not null
    48  		)`, catalog.MO_CATALOG, catalog.MOUpgradeTable),
    49  
    50  		fmt.Sprintf(`create table %s.%s (
    51  			id                  bigint unsigned not null primary key auto_increment,
    52  			upgrade_id		    bigint unsigned not null,
    53  			target_version      varchar(50) not null,
    54  			from_account_id     int not null,
    55  			to_account_id       int not null,
    56  			ready               int,
    57  			create_at           timestamp not null,
    58  			update_at           timestamp not null
    59  		)`, catalog.MO_CATALOG, catalog.MOUpgradeTenantTable),
    60  
    61  		"alter table `mo_account` add column `create_version` varchar(50) default '1.1.0' after suspended_time",
    62  	}
    63  )
    64  
    65  var (
    66  	No  = int32(0)
    67  	Yes = int32(1)
    68  )
    69  
    70  var (
    71  	StateCreated         = int32(0)
    72  	StateUpgradingTenant = int32(1)
    73  	StateReady           = int32(2)
    74  )
    75  
    76  type Version struct {
    77  	// Version version string, like 1.0.0
    78  	Version string
    79  	// State.
    80  	State int32
    81  	// MinUpgradeVersion the min version that can be directly upgraded to current version
    82  	MinUpgradeVersion string
    83  	// UpgradeCluster upgrade cluster or not.
    84  	UpgradeCluster int32
    85  	// UpgradeTenant tenant need upgrade. The upgrade framework is responsible for upgrading
    86  	// all tenants in parallel.
    87  	UpgradeTenant int32
    88  	// Tenant upgrade version upgrade Offset location
    89  	VersionOffset uint32
    90  }
    91  
    92  type VersionUpgrade struct {
    93  	// ID upgrade id
    94  	ID uint64
    95  	// FromVersion from version
    96  	FromVersion string
    97  	// ToVersion to version
    98  	ToVersion string
    99  	// FinalVersion upgrade final version
   100  	FinalVersion string
   101  	// FinalVersionOffset upgrade final version
   102  	FinalVersionOffset uint32
   103  	// State.
   104  	State int32
   105  	// UpgradeOrder upgrade order
   106  	UpgradeOrder int32
   107  	// UpgradeCluster upgrade cluster or not.
   108  	UpgradeCluster int32
   109  	// UpgradeTenant tenant need upgrade. The upgrade framework is responsible for upgrading
   110  	// all tenants in parallel.
   111  	UpgradeTenant int32
   112  	// TotalTenant total tenant need upgrade
   113  	TotalTenant int32
   114  	// ReadyTenant ready tenant count
   115  	ReadyTenant int32
   116  }
   117  
   118  func (v VersionUpgrade) String() string {
   119  	return fmt.Sprintf("%dth: %s -> %s (%v, %v, %d, %d), state %d",
   120  		v.UpgradeOrder,
   121  		v.FromVersion,
   122  		v.ToVersion,
   123  		v.UpgradeCluster == Yes,
   124  		v.UpgradeTenant == Yes,
   125  		v.TotalTenant,
   126  		v.ReadyTenant,
   127  		v.State)
   128  }