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


Golang kv.Storage類代碼示例

本文整理匯總了Golang中github.com/pingcap/tidb/kv.Storage的典型用法代碼示例。如果您正苦於以下問題:Golang Storage類的具體用法?Golang Storage怎麽用?Golang Storage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Storage類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: isBoostrapped

func isBoostrapped(store kv.Storage) bool {
	// check in memory
	_, ok := storeBootstrapped[store.UUID()]
	if ok {
		return true
	}

	// check in kv store
	err := kv.RunInNewTxn(store, false, func(txn kv.Transaction) error {
		var err error
		t := meta.NewMeta(txn)
		ok, err = t.IsBootstrapped()
		return errors.Trace(err)
	})

	if err != nil {
		log.Fatalf("check bootstrapped err %v", err)
	}

	if ok {
		// here mean memory is not ok, but other server has already finished it
		storeBootstrapped[store.UUID()] = true
	}

	return ok
}
開發者ID:losas,項目名稱:tidb,代碼行數:26,代碼來源:session.go

示例2: CreateSession

// CreateSession creates a new session environment.
func CreateSession(store kv.Storage) (Session, error) {
	s := &session{
		values: make(map[fmt.Stringer]interface{}),
		store:  store,
		sid:    atomic.AddInt64(&sessionID, 1),
	}
	domain, err := domap.Get(store)
	if err != nil {
		return nil, err
	}
	sessionctx.BindDomain(s, domain)

	variable.BindSessionVars(s)
	variable.GetSessionVars(s).SetStatusFlag(mysql.ServerStatusAutocommit, true)
	sessionMu.Lock()
	defer sessionMu.Unlock()

	_, ok := storeBootstrapped[store.UUID()]
	if !ok {
		bootstrap(s)
		storeBootstrapped[store.UUID()] = true
	}
	// Add auth here
	return s, nil
}
開發者ID:kevinhuo88888,項目名稱:tidb,代碼行數:26,代碼來源:session.go

示例3: CreateSession

// CreateSession creates a new session environment.
func CreateSession(store kv.Storage) (Session, error) {
	s := &session{
		values: make(map[fmt.Stringer]interface{}),
		store:  store,
		sid:    atomic.AddInt64(&sessionID, 1),
	}
	domain, err := domap.Get(store)
	if err != nil {
		return nil, err
	}
	sessionctx.BindDomain(s, domain)

	variable.BindSessionVars(s)
	variable.GetSessionVars(s).SetStatusFlag(mysql.ServerStatusAutocommit, true)

	// session implements variable.GlobalVarAccessor. Bind it to ctx.
	variable.BindGlobalVarAccessor(s, s)

	// session implements autocommit.Checker. Bind it to ctx
	autocommit.BindAutocommitChecker(s, s)
	sessionMu.Lock()
	defer sessionMu.Unlock()

	_, ok := storeBootstrapped[store.UUID()]
	if !ok {
		s.initing = true
		bootstrap(s)
		s.initing = false
		storeBootstrapped[store.UUID()] = true
	}
	// TODO: Add auth here
	privChecker := &privileges.UserPrivileges{}
	privilege.BindPrivilegeChecker(s, privChecker)
	return s, nil
}
開發者ID:kkpapa,項目名稱:tidb,代碼行數:36,代碼來源:session.go

示例4: getStoreBootstrapVersion

func getStoreBootstrapVersion(store kv.Storage) int64 {
	// check in memory
	_, ok := storeBootstrapped[store.UUID()]
	if ok {
		return currentBootstrapVersion
	}

	var ver int64
	// check in kv store
	err := kv.RunInNewTxn(store, false, func(txn kv.Transaction) error {
		var err error
		t := meta.NewMeta(txn)
		ver, err = t.GetBootstrapVersion()
		return errors.Trace(err)
	})

	if err != nil {
		log.Fatalf("check bootstrapped err %v", err)
	}

	if ver > notBootstrapped {
		// here mean memory is not ok, but other server has already finished it
		storeBootstrapped[store.UUID()] = true
	}

	return ver
}
開發者ID:pingcap,項目名稱:tidb,代碼行數:27,代碼來源:session.go

示例5: Get

func (dm *domainMap) Get(store kv.Storage) (d *domain.Domain, err error) {
	key := store.UUID()
	dm.mu.Lock()
	defer dm.mu.Unlock()
	d = dm.domains[key]
	if d != nil {
		return
	}

	if SchemaLease <= minSchemaLease {
		SchemaLease = minSchemaLease
	}

	lease := SchemaLease
	// if storage is local storage, we may in test environment or
	// run server in single machine mode, so we don't need wait
	// 2 * lease time for DDL operation.
	if localstore.IsLocalStore(store) {
		lease = 0
	}
	d, err = domain.NewDomain(store, lease)
	if err != nil {
		return nil, errors.Trace(err)
	}
	dm.domains[key] = d
	return
}
開發者ID:hanjinze,項目名稱:tidb,代碼行數:27,代碼來源:tidb.go

示例6: NewGCWorker

// NewGCWorker creates a GCWorker instance.
func NewGCWorker(store kv.Storage) (*GCWorker, error) {
	session, err := tidb.CreateSession(store)
	if err != nil {
		return nil, errors.Trace(err)
	}
	ver, err := store.CurrentVersion()
	if err != nil {
		return nil, errors.Trace(err)
	}
	hostName, err := os.Hostname()
	if err != nil {
		hostName = "unknown"
	}
	worker := &GCWorker{
		uuid:        strconv.FormatUint(ver.Ver, 16),
		desc:        fmt.Sprintf("host:%s, pid:%d, start at %s", hostName, os.Getpid(), time.Now()),
		store:       store.(*tikvStore),
		session:     session,
		gcIsRunning: false,
		lastFinish:  time.Now(),
		quit:        make(chan struct{}),
		done:        make(chan error),
	}
	go worker.start()
	return worker, nil
}
開發者ID:pingcap,項目名稱:tidb,代碼行數:27,代碼來源:gc_worker.go

示例7: prepareTableData

func prepareTableData(store kv.Storage, tbl *simpleTableInfo, count int64, gen genValueFunc) error {
	txn, err := store.Begin()
	if err != nil {
		return errors.Trace(err)
	}
	for i := int64(1); i <= count; i++ {
		setRow(txn, i, tbl, gen)
	}
	return txn.Commit()
}
開發者ID:pingcap,項目名稱:tidb,代碼行數:10,代碼來源:xapi_test.go

示例8: ScanSnapshotTableRecord

// ScanSnapshotTableRecord scans the ver version of the table data in a limited number.
// It returns data and the next startHandle until it doesn't have data, then returns data is nil and
// the next startHandle is the handle which can't get data. If startHandle = 0 and limit = -1,
// it returns the table data of the whole.
func ScanSnapshotTableRecord(store kv.Storage, ver kv.Version, t table.Table, startHandle, limit int64) (
	[]*RecordData, int64, error) {
	snap, err := store.GetSnapshot(ver)
	if err != nil {
		return nil, 0, errors.Trace(err)
	}

	records, nextHandle, err := ScanTableRecord(snap, t, startHandle, limit)

	return records, nextHandle, errors.Trace(err)
}
開發者ID:XuHuaiyu,項目名稱:tidb,代碼行數:15,代碼來源:inspectkv.go

示例9: finishBoostrap

func finishBoostrap(store kv.Storage) {
	storeBootstrapped[store.UUID()] = true

	err := kv.RunInNewTxn(store, true, func(txn kv.Transaction) error {
		t := meta.NewMeta(txn)
		err := t.FinishBootstrap()
		return errors.Trace(err)
	})
	if err != nil {
		log.Fatalf("finish bootstrap err %v", err)
	}
}
開發者ID:losas,項目名稱:tidb,代碼行數:12,代碼來源:session.go

示例10: Get

func (dm *domainMap) Get(store kv.Storage) (d *domain.Domain, err error) {
	key := store.UUID()
	dm.mu.Lock()
	defer dm.mu.Unlock()
	d = dm.domains[key]
	if d != nil {
		return
	}
	d, err = domain.NewDomain(store)
	if err != nil {
		return nil, errors.Trace(err)
	}
	dm.domains[key] = d
	return
}
開發者ID:awesomeleo,項目名稱:tidb,代碼行數:15,代碼來源:tidb.go

示例11: Get

func (dm *domainMap) Get(store kv.Storage) (d *domain.Domain, err error) {
	key := store.UUID()
	dm.mu.Lock()
	defer dm.mu.Unlock()
	d = dm.domains[key]
	if d != nil {
		return
	}

	lease := time.Duration(0)
	if !localstore.IsLocalStore(store) {
		lease = schemaLease
	}
	d, err = domain.NewDomain(store, lease)
	if err != nil {
		return nil, errors.Trace(err)
	}
	dm.domains[key] = d
	return
}
開發者ID:astaxie,項目名稱:tidb,代碼行數:20,代碼來源:tidb.go

示例12: Get

func (dm *domainMap) Get(store kv.Storage) (d *domain.Domain, err error) {
	key := store.UUID()
	dm.mu.Lock()
	defer dm.mu.Unlock()
	d = dm.domains[key]
	if d != nil {
		return
	}

	lease := time.Duration(0)
	if !localstore.IsLocalStore(store) {
		lease = schemaLease
	}
	err = util.RunWithRetry(defaultMaxRetries, retryInterval, func() (retry bool, err1 error) {
		d, err1 = domain.NewDomain(store, lease)
		return true, errors.Trace(err1)
	})
	if err != nil {
		return nil, errors.Trace(err)
	}
	dm.domains[key] = d
	return
}
開發者ID:jmptrader,項目名稱:tidb,代碼行數:23,代碼來源:tidb.go

示例13: Delete

func (dm *domainMap) Delete(store kv.Storage) {
	dm.mu.Lock()
	delete(dm.domains, store.UUID())
	dm.mu.Unlock()
}
開發者ID:pingcap,項目名稱:tidb,代碼行數:5,代碼來源:tidb.go


注:本文中的github.com/pingcap/tidb/kv.Storage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。