當前位置: 首頁>>代碼示例>>Golang>>正文


Golang kv.NewVersion函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。