github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/petri/petrictx.go (about)

     1  // Copyright 2020 WHTCORPS INC, 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  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package petri
    15  
    16  import (
    17  	"github.com/whtcorpsinc/BerolinaSQL/perceptron"
    18  	"github.com/whtcorpsinc/milevadb/stochastikctx"
    19  )
    20  
    21  // petriKeyType is a dummy type to avoid naming defCauslision in context.
    22  type petriKeyType int
    23  
    24  // String defines a Stringer function for debugging and pretty printing.
    25  func (k petriKeyType) String() string {
    26  	return "petri"
    27  }
    28  
    29  const petriKey petriKeyType = 0
    30  
    31  // BindPetri binds petri to context.
    32  func BindPetri(ctx stochastikctx.Context, petri *Petri) {
    33  	ctx.SetValue(petriKey, petri)
    34  }
    35  
    36  // GetPetri gets petri from context.
    37  func GetPetri(ctx stochastikctx.Context) *Petri {
    38  	v, ok := ctx.Value(petriKey).(*Petri)
    39  	if !ok {
    40  		return nil
    41  	}
    42  	return v
    43  }
    44  
    45  // CanRuntimePruneTbl indicates whether tbl support runtime prune.
    46  func CanRuntimePruneTbl(ctx stochastikctx.Context, tbl *perceptron.BlockInfo) bool {
    47  	if tbl.Partition == nil {
    48  		return false
    49  	}
    50  	return GetPetri(ctx).StatsHandle().CanRuntimePrune(tbl.ID, tbl.Partition.Definitions[0].ID)
    51  }
    52  
    53  // CanRuntimePrune indicates whether tbl support runtime prune for causet and first partition id.
    54  func CanRuntimePrune(ctx stochastikctx.Context, tid, p0Id int64) bool {
    55  	return GetPetri(ctx).StatsHandle().CanRuntimePrune(tid, p0Id)
    56  }