// backfillIndexInTxn deals with a part of backfilling index data in a Transaction. // This part of the index data rows is defaultSmallBatchCnt. func (d *ddl) backfillIndexInTxn(t table.Table, kvIdx table.Index, handles []int64, txn kv.Transaction) (int64, error) { idxRecords, err := d.fetchRowColVals(txn, t, handles, kvIdx.Meta()) if err != nil { return 0, errors.Trace(err) } for _, idxRecord := range idxRecords { log.Debug("[ddl] backfill index...", idxRecord.handle) err = txn.LockKeys(idxRecord.key) if err != nil { return 0, errors.Trace(err) } // Create the index. handle, err := kvIdx.Create(txn, idxRecord.vals, idxRecord.handle) if err != nil { if terror.ErrorEqual(err, kv.ErrKeyExists) && idxRecord.handle == handle { // Index already exists, skip it. continue } return 0, errors.Trace(err) } } return idxRecords[len(idxRecords)-1].handle, 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) }
// GenID adds step to the value for key and returns the sum. func GenID(txn kv.Transaction, key []byte, step int) (int64, error) { if len(key) == 0 { return 0, errors.New("Invalid key") } err := txn.LockKeys(key) if err != nil { return 0, err } id, err := txn.Inc(key, int64(step)) if err != nil { return 0, errors.Trace(err) } return id, errors.Trace(err) }
func (d *ddl) verifySchemaMetaVersion(txn kv.Transaction, schemaMetaVersion int64) error { curVer, err := txn.GetInt64(meta.SchemaMetaVersionKey) if err != nil { return errors.Trace(err) } if curVer != schemaMetaVersion { return errors.Errorf("Schema changed, our version %d, but got %d", schemaMetaVersion, curVer) } // Increment version. _, err = txn.Inc(meta.SchemaMetaVersionKey, 1) if err != nil { return errors.Trace(err) } if err := txn.LockKeys(meta.SchemaMetaVersionKey); err != nil { return errors.Trace(err) } return errors.Trace(err) }