forked from pingcap/br
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Little-Wallace <bupt2013211450@gmail.com>
- Loading branch information
1 parent
18edf13
commit 4341adc
Showing
4 changed files
with
179 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package kv | ||
|
||
import ( | ||
"github.com/pingcap/br/pkg/lightning/metric" | ||
"github.com/pingcap/parser/model" | ||
"github.com/pingcap/tidb/kv" | ||
"github.com/pingcap/tidb/table" | ||
"github.com/pingcap/tidb/table/tables" | ||
"github.com/pingcap/tidb/tablecodec" | ||
"github.com/pingcap/tidb/types" | ||
) | ||
|
||
type TableKVDecoder struct { | ||
tbl table.Table | ||
se *session | ||
recordCache []types.Datum | ||
genCols []genCol | ||
// auto random bits value for this chunk | ||
autoRandomHeaderBits int64 | ||
} | ||
|
||
func (t *TableKVDecoder) DecodeHandleFromTable(key []byte) (kv.Handle, error) { | ||
return tablecodec.DecodeRowKey(key) | ||
} | ||
|
||
func (t *TableKVDecoder) EncodeHandleKey(h kv.Handle) kv.Key { | ||
return tablecodec.EncodeRowKeyWithHandle(t.tbl.Meta().ID, h) | ||
} | ||
|
||
func (t *TableKVDecoder) DecodeHandleFromIndex(indexInfo *model.IndexInfo, key []byte, value []byte) (kv.Handle, error) { | ||
cols := tables.BuildRowcodecColInfoForIndexColumns(indexInfo, t.tbl.Meta()) | ||
return tablecodec.DecodeIndexHandle(key, value, len(cols)) | ||
} | ||
|
||
// DecodeRawRowData decodes raw row data into a datum slice and a (columnID:columnValue) map. | ||
func (t *TableKVDecoder) DecodeRawRowData(h kv.Handle, value []byte) ([]types.Datum, map[int64]types.Datum, error) { | ||
return tables.DecodeRawRowData(t.se, t.tbl.Meta(), h, t.tbl.Cols(), value) | ||
} | ||
|
||
func NewTableKVDecoder(tbl table.Table, options *SessionOptions) (*TableKVDecoder, error) { | ||
metric.KvEncoderCounter.WithLabelValues("open").Inc() | ||
se := newSession(options) | ||
cols := tbl.Cols() | ||
// Set CommonAddRecordCtx to session to reuse the slices and BufStore in AddRecord | ||
recordCtx := tables.NewCommonAddRecordCtx(len(cols)) | ||
tables.SetAddRecordCtx(se, recordCtx) | ||
|
||
return &TableKVDecoder{ | ||
tbl: tbl, | ||
se: se, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters