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


Golang datastore.DataStore類代碼示例

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


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

示例1: initializeAddressSpace

func (a *Allocator) initializeAddressSpace(as string, ds datastore.DataStore) error {
	scope := ""
	if ds != nil {
		scope = ds.Scope()
	}

	a.Lock()
	if currAS, ok := a.addrSpaces[as]; ok {
		if currAS.ds != nil {
			a.Unlock()
			return types.ForbiddenErrorf("a datastore is already configured for the address space %s", as)
		}
	}
	a.addrSpaces[as] = &addrSpace{
		subnets: map[SubnetKey]*PoolData{},
		id:      dsConfigKey + "/" + as,
		scope:   scope,
		ds:      ds,
		alloc:   a,
	}
	a.Unlock()

	a.checkConsistency(as)

	return nil
}
開發者ID:docker,項目名稱:docker,代碼行數:26,代碼來源:allocator.go

示例2: ensureKeys

func ensureKeys(key string, cs datastore.DataStore) error {
	exists, err := cs.KVStore().Exists(key)
	if err != nil {
		return err
	}
	if exists {
		return nil
	}
	return cs.KVStore().Put(key, []byte{}, nil)
}
開發者ID:natehefner,項目名稱:docker,代碼行數:10,代碼來源:store.go

示例3: getNetworksFromStore

func (c *controller) getNetworksFromStore(global bool) ([]*store.KVPair, error) {
	var cs datastore.DataStore
	c.Lock()
	if global {
		cs = c.globalStore
	} else {
		cs = c.localStore
	}
	c.Unlock()
	return cs.KVStore().List(datastore.Key(datastore.NetworkKeyPrefix))
}
開發者ID:c0b,項目名稱:libnetwork,代碼行數:11,代碼來源:store.go

示例4: initializeAddressSpace

func (a *Allocator) initializeAddressSpace(as string, ds datastore.DataStore) error {
	a.Lock()
	if _, ok := a.addrSpaces[as]; ok {
		a.Unlock()
		return types.ForbiddenErrorf("tried to add an axisting address space: %s", as)
	}
	a.addrSpaces[as] = &addrSpace{
		subnets: map[SubnetKey]*PoolData{},
		id:      dsConfigKey + "/" + as,
		scope:   ds.Scope(),
		ds:      ds,
		alloc:   a,
	}
	a.Unlock()

	a.checkConsistency(as)

	return nil
}
開發者ID:contiv,項目名稱:docker,代碼行數:19,代碼來源:allocator.go

示例5: set

// set/reset the bit
func (h *Handle) set(ordinal, start, end uint64, any bool, release bool) (uint64, error) {
	var (
		bitPos  uint64
		bytePos uint64
		ret     uint64
		err     error
	)

	for {
		var store datastore.DataStore
		h.Lock()
		store = h.store
		h.Unlock()
		if store != nil {
			if err := store.GetObject(datastore.Key(h.Key()...), h); err != nil && err != datastore.ErrKeyNotFound {
				return ret, err
			}
		}

		h.Lock()
		// Get position if available
		if release {
			bytePos, bitPos = ordinalToPos(ordinal)
		} else {
			if any {
				bytePos, bitPos, err = getFirstAvailable(h.head, start)
				ret = posToOrdinal(bytePos, bitPos)
				if end < ret {
					err = ErrNoBitAvailable
				}
			} else {
				bytePos, bitPos, err = checkIfAvailable(h.head, ordinal)
				ret = ordinal
			}
		}
		if err != nil {
			h.Unlock()
			return ret, err
		}

		// Create a private copy of h and work on it
		nh := h.getCopy()
		h.Unlock()

		nh.head = pushReservation(bytePos, bitPos, nh.head, release)
		if release {
			nh.unselected++
		} else {
			nh.unselected--
		}

		// Attempt to write private copy to store
		if err := nh.writeToStore(); err != nil {
			if _, ok := err.(types.RetryError); !ok {
				return ret, fmt.Errorf("internal failure while setting the bit: %v", err)
			}
			// Retry
			continue
		}

		// Previous atomic push was succesfull. Save private copy to local copy
		h.Lock()
		defer h.Unlock()
		h.unselected = nh.unselected
		h.head = nh.head
		h.dbExists = nh.dbExists
		h.dbIndex = nh.dbIndex
		return ret, nil
	}
}
開發者ID:CadeLaRen,項目名稱:docker-3,代碼行數:71,代碼來源:sequence.go


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