github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/doltcore/sqle/system_variables.go (about)

     1  // Copyright 2021 Dolthub, 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  // 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 sqle
    16  
    17  import (
    18  	"math"
    19  
    20  	"github.com/dolthub/go-mysql-server/sql"
    21  	"github.com/dolthub/go-mysql-server/sql/types"
    22  	_ "github.com/dolthub/go-mysql-server/sql/variables"
    23  
    24  	"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
    25  )
    26  
    27  // TODO: get rid of me, use an integration point to define new sysvars
    28  func init() {
    29  	AddDoltSystemVariables()
    30  }
    31  
    32  func AddDoltSystemVariables() {
    33  	sql.SystemVariables.AddSystemVariables([]sql.SystemVariable{
    34  		&sql.MysqlSystemVariable{
    35  			Name:              dsess.DoltOverrideSchema,
    36  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Both),
    37  			Dynamic:           true,
    38  			SetVarHintApplies: false,
    39  			Type:              types.NewSystemStringType(dsess.DoltOverrideSchema),
    40  			Default:           "",
    41  		},
    42  		&sql.MysqlSystemVariable{
    43  			Name:              dsess.ReplicateToRemote,
    44  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Global),
    45  			Dynamic:           true,
    46  			SetVarHintApplies: false,
    47  			Type:              types.NewSystemStringType(dsess.ReplicateToRemote),
    48  			Default:           "",
    49  		},
    50  		&sql.MysqlSystemVariable{
    51  			Name:              dsess.ReplicationRemoteURLTemplate,
    52  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Global),
    53  			Dynamic:           true,
    54  			SetVarHintApplies: false,
    55  			Type:              types.NewSystemStringType(dsess.ReplicationRemoteURLTemplate),
    56  			Default:           "",
    57  		},
    58  		&sql.MysqlSystemVariable{
    59  			Name:              dsess.ReadReplicaRemote,
    60  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Global),
    61  			Dynamic:           true,
    62  			SetVarHintApplies: false,
    63  			Type:              types.NewSystemStringType(dsess.ReadReplicaRemote),
    64  			Default:           "",
    65  		},
    66  		&sql.MysqlSystemVariable{
    67  			Name:              dsess.ReadReplicaForcePull,
    68  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Global),
    69  			Dynamic:           true,
    70  			SetVarHintApplies: false,
    71  			Type:              types.NewSystemBoolType(dsess.ReadReplicaForcePull),
    72  			Default:           int8(1),
    73  		},
    74  		&sql.MysqlSystemVariable{
    75  			Name:              dsess.SkipReplicationErrors,
    76  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Global),
    77  			Dynamic:           true,
    78  			SetVarHintApplies: false,
    79  			Type:              types.NewSystemBoolType(dsess.SkipReplicationErrors),
    80  			Default:           int8(0),
    81  		},
    82  		&sql.MysqlSystemVariable{
    83  			Name:              dsess.ReplicateHeads,
    84  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Global),
    85  			Dynamic:           true,
    86  			SetVarHintApplies: false,
    87  			Type:              types.NewSystemStringType(dsess.ReplicateHeads),
    88  			Default:           "",
    89  		},
    90  		&sql.MysqlSystemVariable{
    91  			Name:              dsess.ReplicateAllHeads,
    92  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Global),
    93  			Dynamic:           true,
    94  			SetVarHintApplies: false,
    95  			Type:              types.NewSystemBoolType(dsess.ReplicateAllHeads),
    96  			Default:           int8(0),
    97  		},
    98  		&sql.MysqlSystemVariable{
    99  			Name:              dsess.AsyncReplication,
   100  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Global),
   101  			Dynamic:           true,
   102  			SetVarHintApplies: false,
   103  			Type:              types.NewSystemBoolType(dsess.AsyncReplication),
   104  			Default:           int8(0),
   105  		},
   106  		&sql.MysqlSystemVariable{ // If true, causes a Dolt commit to occur when you commit a transaction.
   107  			Name:              dsess.DoltCommitOnTransactionCommit,
   108  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Both),
   109  			Dynamic:           true,
   110  			SetVarHintApplies: false,
   111  			Type:              types.NewSystemBoolType(dsess.DoltCommitOnTransactionCommit),
   112  			Default:           int8(0),
   113  		},
   114  		&sql.MysqlSystemVariable{ // If set, use this message for automatic Dolt commits
   115  			Name:              dsess.DoltCommitOnTransactionCommitMessage,
   116  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Both),
   117  			Dynamic:           true,
   118  			SetVarHintApplies: false,
   119  			Type:              types.NewSystemStringType(dsess.DoltCommitOnTransactionCommitMessage),
   120  			Default:           nil,
   121  		},
   122  		&sql.MysqlSystemVariable{
   123  			Name:              dsess.TransactionsDisabledSysVar,
   124  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Session),
   125  			Dynamic:           true,
   126  			SetVarHintApplies: false,
   127  			Type:              types.NewSystemBoolType(dsess.TransactionsDisabledSysVar),
   128  			Default:           int8(0),
   129  		},
   130  		&sql.MysqlSystemVariable{ // If true, disables the conflict and constraint violation check when you commit a transaction.
   131  			Name:              dsess.ForceTransactionCommit,
   132  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Both),
   133  			Dynamic:           true,
   134  			SetVarHintApplies: false,
   135  			Type:              types.NewSystemBoolType(dsess.ForceTransactionCommit),
   136  			Default:           int8(0),
   137  		},
   138  		&sql.MysqlSystemVariable{
   139  			Name:              dsess.CurrentBatchModeKey,
   140  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Session),
   141  			Dynamic:           true,
   142  			SetVarHintApplies: false,
   143  			Type:              types.NewSystemIntType(dsess.CurrentBatchModeKey, -9223372036854775808, 9223372036854775807, false),
   144  			Default:           int64(0),
   145  		},
   146  		&sql.MysqlSystemVariable{ // If true, disables the conflict violation check when you commit a transaction.
   147  			Name:              dsess.AllowCommitConflicts,
   148  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Session),
   149  			Dynamic:           true,
   150  			SetVarHintApplies: false,
   151  			Type:              types.NewSystemBoolType(dsess.AllowCommitConflicts),
   152  			Default:           int8(0),
   153  		},
   154  		&sql.MysqlSystemVariable{
   155  			Name:              dsess.AwsCredsFile,
   156  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Session),
   157  			Dynamic:           false,
   158  			SetVarHintApplies: false,
   159  			Type:              types.NewSystemStringType(dsess.AwsCredsFile),
   160  			Default:           nil,
   161  		},
   162  		&sql.MysqlSystemVariable{
   163  			Name:              dsess.AwsCredsProfile,
   164  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Session),
   165  			Dynamic:           false,
   166  			SetVarHintApplies: false,
   167  			Type:              types.NewSystemStringType(dsess.AwsCredsProfile),
   168  			Default:           nil,
   169  		},
   170  		&sql.MysqlSystemVariable{
   171  			Name:              dsess.AwsCredsRegion,
   172  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Session),
   173  			Dynamic:           false,
   174  			SetVarHintApplies: false,
   175  			Type:              types.NewSystemStringType(dsess.AwsCredsRegion),
   176  			Default:           nil,
   177  		},
   178  		&sql.MysqlSystemVariable{
   179  			Name:              dsess.ShowBranchDatabases,
   180  			Scope:             sql.GetMysqlScope(sql.SystemVariableScope_Both),
   181  			Dynamic:           true,
   182  			SetVarHintApplies: false,
   183  			Type:              types.NewSystemBoolType(dsess.ShowBranchDatabases),
   184  			Default:           int8(0),
   185  		},
   186  		&sql.MysqlSystemVariable{
   187  			Name:    dsess.DoltClusterAckWritesTimeoutSecs,
   188  			Dynamic: true,
   189  			Scope:   sql.GetMysqlScope(sql.SystemVariableScope_Persist),
   190  			Type:    types.NewSystemIntType(dsess.DoltClusterAckWritesTimeoutSecs, 0, 60, false),
   191  			Default: int64(0),
   192  		},
   193  		&sql.MysqlSystemVariable{
   194  			Name:    dsess.ShowSystemTables,
   195  			Dynamic: true,
   196  			Scope:   sql.GetMysqlScope(sql.SystemVariableScope_Both),
   197  			Type:    types.NewSystemBoolType(dsess.ShowSystemTables),
   198  			Default: int8(0),
   199  		},
   200  		&sql.MysqlSystemVariable{
   201  			Name:    "dolt_dont_merge_json",
   202  			Dynamic: true,
   203  			Scope:   sql.GetMysqlScope(sql.SystemVariableScope_Both),
   204  			Type:    types.NewSystemBoolType("dolt_dont_merge_json"),
   205  			Default: int8(0),
   206  		},
   207  		&sql.MysqlSystemVariable{
   208  			Name:    dsess.DoltStatsAutoRefreshEnabled,
   209  			Dynamic: true,
   210  			Scope:   sql.GetMysqlScope(sql.SystemVariableScope_Global),
   211  			Type:    types.NewSystemBoolType(dsess.DoltStatsAutoRefreshEnabled),
   212  			Default: int8(0),
   213  		},
   214  		&sql.MysqlSystemVariable{
   215  			Name:    dsess.DoltStatsMemoryOnly,
   216  			Dynamic: true,
   217  			Scope:   sql.GetMysqlScope(sql.SystemVariableScope_Global),
   218  			Type:    types.NewSystemBoolType(dsess.DoltStatsMemoryOnly),
   219  			Default: int8(0),
   220  		},
   221  		&sql.MysqlSystemVariable{
   222  			Name:    dsess.DoltStatsAutoRefreshThreshold,
   223  			Dynamic: true,
   224  			Scope:   sql.GetMysqlScope(sql.SystemVariableScope_Global),
   225  			Type:    types.NewSystemDoubleType(dsess.DoltStatsAutoRefreshEnabled, 0, 10),
   226  			Default: float64(.5),
   227  		},
   228  		&sql.MysqlSystemVariable{
   229  			Name:    dsess.DoltStatsAutoRefreshInterval,
   230  			Dynamic: true,
   231  			Scope:   sql.GetMysqlScope(sql.SystemVariableScope_Global),
   232  			Type:    types.NewSystemIntType(dsess.DoltStatsAutoRefreshInterval, 0, math.MaxInt, false),
   233  			Default: 120,
   234  		},
   235  		&sql.MysqlSystemVariable{
   236  			Name:    dsess.DoltStatsBranches,
   237  			Dynamic: true,
   238  			Scope:   sql.GetMysqlScope(sql.SystemVariableScope_Global),
   239  			Type:    types.NewSystemStringType(dsess.DoltStatsBranches),
   240  			Default: "",
   241  		},
   242  	})
   243  }
   244  
   245  func ReadReplicaForcePull() bool {
   246  	_, forcePull, ok := sql.SystemVariables.GetGlobal(dsess.ReadReplicaForcePull)
   247  	if !ok {
   248  		panic("dolt system variables not loaded")
   249  	}
   250  	return forcePull == dsess.SysVarTrue
   251  }