本文整理匯總了Golang中github.com/pingcap/tidb/kv.Transaction.LockKeys方法的典型用法代碼示例。如果您正苦於以下問題:Golang Transaction.LockKeys方法的具體用法?Golang Transaction.LockKeys怎麽用?Golang Transaction.LockKeys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/kv.Transaction
的用法示例。
在下文中一共展示了Transaction.LockKeys方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: backfillIndexInTxn
// 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
}
示例2: writeSchemaInfo
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)
}
示例3: GenID
// 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)
}
示例4: verifySchemaMetaVersion
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)
}