github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/lock.go (about)

     1  // Copyright 2022 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 tree
    16  
    17  // TableLockType is the type of the table lock.
    18  type TableLockType int32
    19  
    20  const (
    21  	// TableLockNone means this table lock is absent.
    22  	TableLockNone TableLockType = iota
    23  	// TableLockRead means the session with this lock can read the table (but not write it).
    24  	// Multiple sessions can acquire a READ lock for the table at the same time.
    25  	// Other sessions can read the table without explicitly acquiring a READ lock.
    26  	TableLockRead
    27  	// The locks are the same as READ except that they allow INSERT commands to be executed
    28  	TableLockReadLocal
    29  	// TableLockWrite means only the session with this lock has write/read permission.
    30  	// Only the session that holds the lock can access the table. No other session can access it until the lock is released.
    31  	TableLockWrite
    32  	// Low priority write locks
    33  	TableLockLowPriorityWrite
    34  )
    35  
    36  func (t TableLockType) String() string {
    37  	switch t {
    38  	case TableLockNone:
    39  		return "NONE"
    40  	case TableLockRead:
    41  		return "READ"
    42  	case TableLockReadLocal:
    43  		return "READ LOCAL"
    44  	case TableLockWrite:
    45  		return "WRITE"
    46  	case TableLockLowPriorityWrite:
    47  		return "LOW_PRIORITY WRITE"
    48  	}
    49  	return ""
    50  }
    51  
    52  type TableLock struct {
    53  	Table    TableName
    54  	LockType TableLockType
    55  }
    56  
    57  type LockTableStmt struct {
    58  	statementImpl
    59  	TableLocks []TableLock
    60  }
    61  
    62  func (node *LockTableStmt) Format(ctx *FmtCtx) {
    63  	ctx.WriteString("Lock Tables")
    64  	if node.TableLocks != nil {
    65  		prefix := " "
    66  		for _, a := range node.TableLocks {
    67  			ctx.WriteString(prefix)
    68  			a.Table.Format(ctx)
    69  			ctx.WriteString(" ")
    70  			ctx.WriteString(a.LockType.String())
    71  			prefix = ", "
    72  		}
    73  	}
    74  }
    75  
    76  func (node *LockTableStmt) GetStatementType() string { return "Lock Tables" }
    77  func (node *LockTableStmt) GetQueryType() string     { return QueryTypeOth }
    78  
    79  type UnLockTableStmt struct {
    80  	statementImpl
    81  }
    82  
    83  func (node *UnLockTableStmt) Format(ctx *FmtCtx) {
    84  	ctx.WriteString("UnLock Tables")
    85  }
    86  
    87  func (node *UnLockTableStmt) GetStatementType() string { return "UnLock Tables" }
    88  func (node *UnLockTableStmt) GetQueryType() string     { return QueryTypeOth }