Esempio n. 1
0
// 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)
}
Esempio n. 2
0
File: ddl.go Progetto: H0bby/tidb
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)
}