Repository: pingcap/tidb
File: pkg/session/bootstrap.go (Go)

Code before:
        module varchar(128),
        name varchar(128),
        value varchar(128),
        updated_at datetime,
        status varchar(128),
        description text,
        primary key(module, name));`

	// CreateTiDBWorkloadValuesTable is a table to store workload-based learning values for tidb.
	CreateTiDBWorkloadValuesTable = `CREATE TABLE IF NOT EXISTS mysql.tidb_workload_values (
		id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
		version bigint(20) NOT NULL,
		category varchar(64) NOT NULL,
		type varchar(64) NOT NULL,
		table_id bigint(20) NOT NULL,
		value json NOT NULL,
		index idx_version_category_type (version, category, type),
		index idx_table_id (table_id));`
)

// bootstrap initiates system DB for a store.
func bootstrap(s sessionapi.Session) {
	startTime := time.Now()
	err := InitMDLVariableForBootstrap(s.GetStore())
	if err != nil {
		logutil.BgLogger().Fatal("[bootstrap] init metadata lock failed", zap.Error(err))
	}
	dom := domain.GetDomain(s)
	bootLogger := logutil.SampleLoggerFactory(30*time.Second, 1)()
	for {
		b, err := checkBootstrapped(s)
		if err != nil {
			logutil.BgLogger().Fatal("check bootstrap error",
				zap.Error(err))
		}
		// For rolling upgrade, we can't do upgrade only in the owner.
		if b {
			upgrade(s)
			logutil.BgLogger().Info("upgrade successful in bootstrap",
				zap.Duration("take time", time.Since(startTime)))
			return
		}
		// To reduce conflict when multiple TiDB-server start at the same time.
		// Actually only one server need to do the bootstrap. So we chose DDL owner to do this.
		if dom.DDL().OwnerManager().IsOwner() {
			doDDLWorks(s)
			doDMLWorks(s)
			runBootstrapSQLFile = true
			logutil.BgLogger().Info("bootstrap successful",
				zap.Duration("take time", time.Since(startTime)))
			return

Review comment (suggestion):
better use a structured way, like add a zap field `zap.String('category', "bootstrap"`, although i don't think we need it here, since we are inside `bootstrap.go`

Code after:
        module varchar(128),
        name varchar(128),
        value varchar(128),
        updated_at datetime,
        status varchar(128),
        description text,
        primary key(module, name));`

	// CreateTiDBWorkloadValuesTable is a table to store workload-based learning values for tidb.
	CreateTiDBWorkloadValuesTable = `CREATE TABLE IF NOT EXISTS mysql.tidb_workload_values (
		id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
		version bigint(20) NOT NULL,
		category varchar(64) NOT NULL,
		type varchar(64) NOT NULL,
		table_id bigint(20) NOT NULL,
		value json NOT NULL,
		index idx_version_category_type (version, category, type),
		index idx_table_id (table_id));`
)

// bootstrap initiates system DB for a store.
func bootstrap(s sessionapi.Session) {
	startTime := time.Now()
	err := InitMDLVariableForBootstrap(s.GetStore())
	if err != nil {
		logutil.BgLogger().Fatal("init metadata lock failed during bootstrap", zap.Error(err))
	}
	dom := domain.GetDomain(s)
	bootLogger := logutil.SampleLoggerFactory(30*time.Second, 1)()
	for {
		b, err := checkBootstrapped(s)
		if err != nil {
			logutil.BgLogger().Fatal("check bootstrap error",
				zap.Error(err))
		}
		// For rolling upgrade, we can't do upgrade only in the owner.
		if b {
			upgrade(s)
			logutil.BgLogger().Info("upgrade successful in bootstrap",
				zap.Duration("take time", time.Since(startTime)))
			return
		}
		// To reduce conflict when multiple TiDB-server start at the same time.
		// Actually only one server need to do the bootstrap. So we chose DDL owner to do this.
		if dom.DDL().OwnerManager().IsOwner() {
			doDDLWorks(s)
			doDMLWorks(s)
			runBootstrapSQLFile = true
			logutil.BgLogger().Info("bootstrap successful",
				zap.Duration("take time", time.Since(startTime)))
			return