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


Golang Backend.BatchTx方法代碼示例

本文整理匯總了Golang中github.com/coreos/etcd/mvcc/backend.Backend.BatchTx方法的典型用法代碼示例。如果您正苦於以下問題:Golang Backend.BatchTx方法的具體用法?Golang Backend.BatchTx怎麽用?Golang Backend.BatchTx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/coreos/etcd/mvcc/backend.Backend的用法示例。


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

示例1: removeFrom

func (l Lease) removeFrom(b backend.Backend) {
	key := int64ToBytes(int64(l.ID))

	b.BatchTx().Lock()
	b.BatchTx().UnsafeDelete(leaseBucketName, key)
	b.BatchTx().Unlock()
}
開發者ID:achanda,項目名稱:etcd,代碼行數:7,代碼來源:lessor.go

示例2: mustSaveClusterVersionToBackend

func mustSaveClusterVersionToBackend(be backend.Backend, ver *semver.Version) {
	ckey := backendClusterVersionKey()

	tx := be.BatchTx()
	tx.Lock()
	defer tx.Unlock()
	tx.UnsafePut(clusterBucketName, ckey, []byte(ver.String()))
}
開發者ID:CliffYuan,項目名稱:etcd,代碼行數:8,代碼來源:store.go

示例3: mustCreateBackendBuckets

func mustCreateBackendBuckets(be backend.Backend) {
	tx := be.BatchTx()
	tx.Lock()
	defer tx.Unlock()
	tx.UnsafeCreateBucket(membersBucketName)
	tx.UnsafeCreateBucket(membersRemovedBuckedName)
	tx.UnsafeCreateBucket(clusterBucketName)
}
開發者ID:CliffYuan,項目名稱:etcd,代碼行數:8,代碼來源:store.go

示例4: mustDeleteMemberFromBackend

func mustDeleteMemberFromBackend(be backend.Backend, id types.ID) {
	mkey := backendMemberKey(id)

	tx := be.BatchTx()
	tx.Lock()
	tx.UnsafeDelete(membersBucketName, mkey)
	tx.UnsafePut(membersRemovedBuckedName, mkey, []byte("removed"))
	tx.Unlock()
}
開發者ID:CliffYuan,項目名稱:etcd,代碼行數:9,代碼來源:store.go

示例5: mustSaveMemberToBackend

func mustSaveMemberToBackend(be backend.Backend, m *Member) {
	mkey := backendMemberKey(m.ID)
	mvalue, err := json.Marshal(m)
	if err != nil {
		plog.Panicf("marshal raftAttributes should never fail: %v", err)
	}

	tx := be.BatchTx()
	tx.Lock()
	tx.UnsafePut(membersBucketName, mkey, mvalue)
	tx.Unlock()
}
開發者ID:CliffYuan,項目名稱:etcd,代碼行數:12,代碼來源:store.go

示例6: persistTo

func (l Lease) persistTo(b backend.Backend) {
	key := int64ToBytes(int64(l.ID))

	lpb := leasepb.Lease{ID: int64(l.ID), TTL: int64(l.TTL)}
	val, err := lpb.Marshal()
	if err != nil {
		panic("failed to marshal lease proto item")
	}

	b.BatchTx().Lock()
	b.BatchTx().UnsafePut(leaseBucketName, key, val)
	b.BatchTx().Unlock()
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:13,代碼來源:lessor.go

示例7: WriteKV

func WriteKV(be backend.Backend, kv mvccpb.KeyValue) {
	ibytes := newRevBytes()
	revToBytes(revision{main: kv.ModRevision}, ibytes)

	d, err := kv.Marshal()
	if err != nil {
		plog.Fatalf("cannot marshal event: %v", err)
	}

	be.BatchTx().Lock()
	be.BatchTx().UnsafePut(keyBucketName, ibytes, d)
	be.BatchTx().Unlock()
}
開發者ID:CliffYuan,項目名稱:etcd,代碼行數:13,代碼來源:util.go

示例8: NewAuthStore

func NewAuthStore(be backend.Backend) *authStore {
	tx := be.BatchTx()
	tx.Lock()

	tx.UnsafeCreateBucket(authBucketName)
	tx.UnsafeCreateBucket(authUsersBucketName)
	tx.UnsafeCreateBucket(authRolesBucketName)

	tx.Unlock()
	be.ForceCommit()

	return &authStore{
		be: be,
	}
}
開發者ID:dnaeon,項目名稱:etcd,代碼行數:15,代碼來源:store.go

示例9: NewAuthStore

func NewAuthStore(be backend.Backend) *authStore {
	tx := be.BatchTx()
	tx.Lock()

	tx.UnsafeCreateBucket(authBucketName)
	tx.UnsafeCreateBucket(authUsersBucketName)
	tx.UnsafeCreateBucket(authRolesBucketName)

	tx.Unlock()
	be.ForceCommit()

	return &authStore{
		be:           be,
		simpleTokens: make(map[string]string),
	}
}
開發者ID:pulcy,項目名稱:j2,代碼行數:16,代碼來源:store.go

示例10: Recover

func (as *authStore) Recover(be backend.Backend) {
	enabled := false
	as.be = be
	tx := be.BatchTx()
	tx.Lock()
	_, vs := tx.UnsafeRange(authBucketName, enableFlagKey, nil, 0)
	if len(vs) == 1 {
		if bytes.Equal(vs[0], authEnabled) {
			enabled = true
		}
	}
	tx.Unlock()

	as.enabledMu.Lock()
	as.enabled = enabled
	as.enabledMu.Unlock()
}
開發者ID:pulcy,項目名稱:j2,代碼行數:17,代碼來源:store.go

示例11: Restore

func (s *store) Restore(b backend.Backend) error {
	s.mu.Lock()
	defer s.mu.Unlock()

	close(s.stopc)
	s.fifoSched.Stop()

	s.b = b
	s.kvindex = newTreeIndex()
	s.currentRev = revision{main: 1}
	s.compactMainRev = -1
	s.tx = b.BatchTx()
	s.txnID = -1
	s.fifoSched = schedule.NewFIFOScheduler()
	s.stopc = make(chan struct{})

	return s.restore()
}
開發者ID:XiangrongFan,項目名稱:etcd,代碼行數:18,代碼來源:kvstore.go

示例12: UpdateConsistentIndex

func UpdateConsistentIndex(be backend.Backend, index uint64) {
	tx := be.BatchTx()
	tx.Lock()
	defer tx.Unlock()

	var oldi uint64
	_, vs := tx.UnsafeRange(metaBucketName, consistentIndexKeyName, nil, 0)
	if len(vs) != 0 {
		oldi = binary.BigEndian.Uint64(vs[0])
	}

	if index <= oldi {
		return
	}

	bs := make([]byte, 8)
	binary.BigEndian.PutUint64(bs, index)
	tx.UnsafePut(metaBucketName, consistentIndexKeyName, bs)
}
開發者ID:CliffYuan,項目名稱:etcd,代碼行數:19,代碼來源:util.go

示例13: prepareBackend

func prepareBackend() backend.Backend {
	var be backend.Backend

	bch := make(chan struct{})
	dbpath := path.Join(migrateDatadir, "member", "snap", "db")
	go func() {
		defer close(bch)
		be = backend.New(dbpath, time.Second, 10000)

	}()
	select {
	case <-bch:
	case <-time.After(time.Second):
		fmt.Fprintf(os.Stderr, "waiting for etcd to close and release its lock on %q\n", dbpath)
		<-bch
	}

	tx := be.BatchTx()
	tx.Lock()
	tx.UnsafeCreateBucket([]byte("key"))
	tx.UnsafeCreateBucket([]byte("meta"))
	tx.Unlock()
	return be
}
開發者ID:gyuho,項目名稱:etcd,代碼行數:24,代碼來源:migrate_command.go


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