func lockRow(txn kv.Transaction, t table.Table, h int64) error { // Get row lock key lockKey := t.RecordKey(h, nil) // set row lock key to current txn err := txn.Set(lockKey, []byte(txn.String())) return errors.Trace(err) }
func setRow(txn kv.Transaction, handle int64, tbl *simpleTableInfo, gen genValueFunc) error { rowKey := tablecodec.EncodeRowKey(tbl.tID, codec.EncodeInt(nil, handle)) columnValues := gen(handle, tbl) value, err := tablecodec.EncodeRow(columnValues, tbl.cIDs) if err != nil { return errors.Trace(err) } err = txn.Set(rowKey, value) if err != nil { return errors.Trace(err) } for i, idxCol := range tbl.indices { idxVal := columnValues[idxCol] encoded, err := codec.EncodeKey(nil, idxVal, types.NewDatum(handle)) if err != nil { return errors.Trace(err) } idxKey := tablecodec.EncodeIndexSeekKey(tbl.tID, tbl.iIDs[i], encoded) err = txn.Set(idxKey, []byte{0}) if err != nil { return errors.Trace(err) } } return nil }
func insertData(c *C, txn kv.Transaction) { for i := startIndex; i < testCount; i++ { val := encodeInt(i * indexStep) err := txn.Set(val, val) c.Assert(err, IsNil) } }
func setColValue(c *C, txn kv.Transaction, key kv.Key, v types.Datum) { row := []types.Datum{v, {}} colIDs := []int64{2, 3} value, err := tablecodec.EncodeRow(row, colIDs) c.Assert(err, IsNil) err = txn.Set(key, value) c.Assert(err, IsNil) }
// SetColValue implements table.Table SetColValue interface. func (t *Table) SetColValue(txn kv.Transaction, key []byte, data interface{}) error { v, err := t.EncodeValue(data) if err != nil { return errors.Trace(err) } if err := txn.Set(key, v); err != nil { return errors.Trace(err) } return nil }
func (d *ddl) writeSchemaInfo(info *model.DBInfo, txn kv.Transaction) error { var b []byte b, err := json.Marshal(info) if err != nil { return errors.Trace(err) } key := []byte(meta.DBMetaKey(info.ID)) if err := txn.LockKeys(key); err != nil { return errors.Trace(err) } txn.Set(key, b) log.Warn("save schema", string(b)) return errors.Trace(err) }
// backfillColumnInTxn deals with a part of backfilling column data in a Transaction. // This part of the column data rows is defaultSmallBatchCnt. func (d *ddl) backfillColumnInTxn(t table.Table, colID int64, handles []int64, colMap map[int64]*types.FieldType, defaultVal types.Datum, txn kv.Transaction) (int64, error) { nextHandle := handles[0] for _, handle := range handles { log.Debug("[ddl] backfill column...", handle) rowKey := t.RecordKey(handle) rowVal, err := txn.Get(rowKey) if terror.ErrorEqual(err, kv.ErrNotExist) { // If row doesn't exist, skip it. continue } if err != nil { return 0, errors.Trace(err) } rowColumns, err := tablecodec.DecodeRow(rowVal, colMap) if err != nil { return 0, errors.Trace(err) } if _, ok := rowColumns[colID]; ok { // The column is already added by update or insert statement, skip it. continue } newColumnIDs := make([]int64, 0, len(rowColumns)+1) newRow := make([]types.Datum, 0, len(rowColumns)+1) for colID, val := range rowColumns { newColumnIDs = append(newColumnIDs, colID) newRow = append(newRow, val) } newColumnIDs = append(newColumnIDs, colID) newRow = append(newRow, defaultVal) newRowVal, err := tablecodec.EncodeRow(newRow, newColumnIDs) if err != nil { return 0, errors.Trace(err) } err = txn.Set(rowKey, newRowVal) if err != nil { return 0, errors.Trace(err) } } return nextHandle, nil }