本文整理汇总了Golang中github.com/pingcap/tidb/kv.NewVersion函数的典型用法代码示例。如果您正苦于以下问题:Golang NewVersion函数的具体用法?Golang NewVersion怎么用?Golang NewVersion使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewVersion函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CurrentVersion
func (s *tikvStore) CurrentVersion() (kv.Version, error) {
bo := NewBackoffer(tsoMaxBackoff, context.Background())
startTS, err := s.getTimestampWithRetry(bo)
if err != nil {
return kv.NewVersion(0), errors.Trace(err)
}
return kv.NewVersion(startTS), nil
}
开发者ID:pingcap,项目名称:tidb,代码行数:8,代码来源:kv.go
示例2: CurrentVersion
func (s *tikvStore) CurrentVersion() (kv.Version, error) {
startTS, err := s.getTimestampWithRetry()
if err != nil {
return kv.NewVersion(0), errors.Trace(err)
}
return kv.NewVersion(startTS), nil
}
开发者ID:yubobo,项目名称:tidb,代码行数:8,代码来源:kv.go
示例3: TestMvccSnapshotScan
func (t *testMvccSuite) TestMvccSnapshotScan(c *C) {
tx, _ := t.s.Begin()
err := tx.Set(encodeInt(1), []byte("new"))
c.Assert(err, IsNil)
err = tx.Commit()
c.Assert(err, IsNil)
v, err := tx.CommittedVersion()
c.Assert(err, IsNil)
snapshot, err := t.s.GetSnapshot(kv.MaxVersion)
defer snapshot.MvccRelease()
c.Assert(err, IsNil)
testKey := encodeTestDataKey(1)
// iter helper function
iterFunc := func(it kv.Iterator) bool {
found := false
for it.Valid() {
if string(it.Value()) == "new" {
found = true
}
it, err = it.Next()
c.Assert(err, IsNil)
}
return found
}
it := snapshot.NewMvccIterator(testKey, kv.MaxVersion)
found := iterFunc(it)
c.Assert(found, IsTrue)
it = snapshot.NewMvccIterator(testKey, kv.NewVersion(v.Ver-1))
found = iterFunc(it)
c.Assert(found, IsFalse)
}
开发者ID:botvs,项目名称:tidb,代码行数:35,代码来源:mvcc_test.go
示例4: TestSnapshotGet
func (t *testMvccSuite) TestSnapshotGet(c *C) {
tx, _ := t.s.Begin()
b, err := tx.Get(encodeInt(1))
c.Assert(err, IsNil)
tx.Commit()
// Modify
tx, _ = t.s.Begin()
err = tx.Set(encodeInt(1), []byte("new"))
c.Assert(err, IsNil)
err = tx.Commit()
c.Assert(err, IsNil)
v, err := tx.CommittedVersion()
c.Assert(err, IsNil)
testKey := encodeTestDataKey(1)
snapshot, err := t.s.GetSnapshot(kv.MaxVersion)
defer snapshot.MvccRelease()
b, err = snapshot.MvccGet(testKey, kv.MaxVersion)
c.Assert(err, IsNil)
c.Assert(string(b), Equals, "new")
// Get last version
b, err = snapshot.MvccGet(testKey, kv.NewVersion(v.Ver-1))
c.Assert(err, IsNil)
c.Assert(string(b), Equals, string(encodeInt(1)))
// Get version not exists
b, err = snapshot.MvccGet(testKey, kv.MinVersion)
c.Assert(err, NotNil)
}
开发者ID:botvs,项目名称:tidb,代码行数:31,代码来源:mvcc_test.go
示例5: loadInfoSchema
// loadInfoSchema loads infoschema at startTS into handle, usedSchemaVersion is the currently used
// infoschema version, if it is the same as the schema version at startTS, we don't need to reload again.
func (do *Domain) loadInfoSchema(handle *infoschema.Handle, usedSchemaVersion int64, startTS uint64) error {
snapshot, err := do.store.GetSnapshot(kv.NewVersion(startTS))
if err != nil {
return errors.Trace(err)
}
m := meta.NewSnapshotMeta(snapshot)
latestSchemaVersion, err := m.GetSchemaVersion()
if err != nil {
return errors.Trace(err)
}
if usedSchemaVersion != 0 && usedSchemaVersion == latestSchemaVersion {
log.Debugf("[ddl] schema version is still %d, no need reload", usedSchemaVersion)
return nil
}
ok, err := do.tryLoadSchemaDiffs(m, usedSchemaVersion, latestSchemaVersion)
if err != nil {
// We can fall back to full load, don't need to return the error.
log.Errorf("[ddl] failed to load schema diff %v", err)
}
if ok {
log.Infof("[ddl] diff load InfoSchema from version %d to %d", usedSchemaVersion, latestSchemaVersion)
return nil
}
schemas, err := do.getAllSchemasWithTablesFromMeta(m)
if err != nil {
return errors.Trace(err)
}
newISBuilder, err := infoschema.NewBuilder(handle).InitWithDBInfos(schemas, latestSchemaVersion)
if err != nil {
return errors.Trace(err)
}
log.Infof("[ddl] full load InfoSchema from version %d to %d", usedSchemaVersion, latestSchemaVersion)
return newISBuilder.Build()
}
开发者ID:jmptrader,项目名称:tidb,代码行数:37,代码来源:domain.go
示例6: newTiKVTxn
func newTiKVTxn(store *tikvStore) (*tikvTxn, error) {
startTS, err := store.getTimestampWithRetry()
if err != nil {
return nil, errors.Trace(err)
}
ver := kv.NewVersion(startTS)
return &tikvTxn{
us: kv.NewUnionStore(newTiKVSnapshot(store, ver)),
store: store,
startTS: startTS,
valid: true,
}, nil
}
开发者ID:anywhy,项目名称:tidb,代码行数:13,代码来源:txn.go
示例7: newTiKVTxn
func newTiKVTxn(store *tikvStore) (*tikvTxn, error) {
bo := NewBackoffer(tsoMaxBackoff, context.Background())
startTS, err := store.getTimestampWithRetry(bo)
if err != nil {
return nil, errors.Trace(err)
}
ver := kv.NewVersion(startTS)
return &tikvTxn{
us: kv.NewUnionStore(newTiKVSnapshot(store, ver)),
store: store,
startTS: startTS,
valid: true,
}, nil
}
开发者ID:pingcap,项目名称:tidb,代码行数:14,代码来源:txn.go
示例8: doCommit
func (txn *hbaseTxn) doCommit() error {
if err := txn.UnionStore.CheckLazyConditionPairs(); err != nil {
return errors.Trace(err)
}
err := txn.each(func(iter kv.Iterator) error {
var row, val []byte
row = make([]byte, len(iter.Key()))
if len(iter.Value()) == 0 { // Deleted marker
copy(row, iter.Key())
d := hbase.NewDelete(row)
d.AddStringColumn(hbaseColFamily, hbaseQualifier)
err := txn.txn.Delete(txn.storeName, d)
if err != nil {
return errors.Trace(err)
}
} else {
val = make([]byte, len(iter.Value()))
copy(row, iter.Key())
copy(val, iter.Value())
p := hbase.NewPut(row)
p.AddValue(hbaseColFamilyBytes, hbaseQualifierBytes, val)
txn.txn.Put(txn.storeName, p)
}
return nil
})
if err != nil {
return errors.Trace(err)
}
err = txn.txn.Commit()
if err != nil {
log.Error(err)
return errors.Trace(err)
}
txn.version = kv.NewVersion(txn.txn.GetCommitTS())
log.Debugf("commit successfully, txn.version:%d", txn.version.Ver)
return nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:41,代码来源:txn.go
示例9: loadInfoSchema
// loadInfoSchema loads infoschema at startTS into handle, usedSchemaVersion is the currently used
// infoschema version, if it is the same as the schema version at startTS, we don't need to reload again.
// It returns the latest schema version and an error.
func (do *Domain) loadInfoSchema(handle *infoschema.Handle, usedSchemaVersion int64, startTS uint64) (int64, error) {
snapshot, err := do.store.GetSnapshot(kv.NewVersion(startTS))
if err != nil {
return 0, errors.Trace(err)
}
m := meta.NewSnapshotMeta(snapshot)
latestSchemaVersion, err := m.GetSchemaVersion()
if err != nil {
return 0, errors.Trace(err)
}
if usedSchemaVersion != 0 && usedSchemaVersion == latestSchemaVersion {
return latestSchemaVersion, nil
}
startTime := time.Now()
ok, err := do.tryLoadSchemaDiffs(m, usedSchemaVersion, latestSchemaVersion)
if err != nil {
// We can fall back to full load, don't need to return the error.
log.Errorf("[ddl] failed to load schema diff err %v", err)
}
if ok {
log.Infof("[ddl] diff load InfoSchema from version %d to %d, in %v",
usedSchemaVersion, latestSchemaVersion, time.Since(startTime))
return latestSchemaVersion, nil
}
schemas, err := do.fetchAllSchemasWithTables(m)
if err != nil {
return 0, errors.Trace(err)
}
newISBuilder, err := infoschema.NewBuilder(handle).InitWithDBInfos(schemas, latestSchemaVersion)
if err != nil {
return 0, errors.Trace(err)
}
log.Infof("[ddl] full load InfoSchema from version %d to %d, in %v",
usedSchemaVersion, latestSchemaVersion, time.Since(startTime))
newISBuilder.Build()
return latestSchemaVersion, nil
}
开发者ID:pingcap,项目名称:tidb,代码行数:42,代码来源:domain.go
示例10: doCommit
func (txn *hbaseTxn) doCommit() error {
if err := txn.us.CheckLazyConditionPairs(); err != nil {
return errors.Trace(err)
}
err := txn.us.WalkBuffer(func(k kv.Key, v []byte) error {
row := append([]byte(nil), k...)
if len(v) == 0 { // Deleted marker
d := hbase.NewDelete(row)
d.AddStringColumn(hbaseColFamily, hbaseQualifier)
err := txn.txn.Delete(txn.storeName, d)
if err != nil {
return errors.Trace(err)
}
} else {
val := append([]byte(nil), v...)
p := hbase.NewPut(row)
p.AddValue(hbaseColFamilyBytes, hbaseQualifierBytes, val)
txn.txn.Put(txn.storeName, p)
}
return nil
})
if err != nil {
return errors.Trace(err)
}
err = txn.txn.Commit()
if err != nil {
log.Error(err)
return errors.Trace(err)
}
txn.version = kv.NewVersion(txn.txn.GetCommitTS())
log.Debugf("[kv] commit successfully, txn.version:%d", txn.version.Ver)
return nil
}
开发者ID:astaxie,项目名称:tidb,代码行数:37,代码来源:txn.go
注:本文中的github.com/pingcap/tidb/kv.NewVersion函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论