tidb rowindexcodec 源码

  • 2022-09-19
  • 浏览 (319)

tidb rowindexcodec 代码

文件路径:/tablecodec/rowindexcodec/rowindexcodec.go

// Copyright 2021 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package rowindexcodec

import (
	"bytes"
)

// KeyKind is a specific type of key, mainly used to distinguish row/index.
type KeyKind int

const (
	// KeyKindUnknown indicates that this key is unknown type.
	KeyKindUnknown KeyKind = iota
	// KeyKindRow means that this key belongs to row.
	KeyKindRow
	// KeyKindIndex means that this key belongs to index.
	KeyKindIndex
)

var (
	tablePrefix = []byte{'t'}
	rowPrefix   = []byte("_r")
	indexPrefix = []byte("_i")
)

// GetKeyKind returns the KeyKind that matches the key in the minimalist way.
func GetKeyKind(key []byte) KeyKind {
	// [ TABLE_PREFIX | TABLE_ID | ROW_PREFIX (INDEX_PREFIX) | ROW_ID (INDEX_ID) | ... ]   (name)
	// [      1       |    8     |            2              |         8         | ... ]   (byte)
	if len(key) < 11 {
		return KeyKindUnknown
	}
	if !bytes.HasPrefix(key, tablePrefix) {
		return KeyKindUnknown
	}
	key = key[9:]
	if bytes.HasPrefix(key, rowPrefix) {
		return KeyKindRow
	}
	if bytes.HasPrefix(key, indexPrefix) {
		return KeyKindIndex
	}
	return KeyKindUnknown
}

相关信息

tidb 源码目录

相关文章

tidb bind_cache 源码

tidb bind_record 源码

tidb handle 源码

tidb session_handle 源码

tidb stat 源码

tidb backup 源码

tidb cmd 源码

tidb debug 源码

tidb main 源码

tidb restore 源码

0  赞