当前位置: 首页>>代码示例>>Golang>>正文


Golang Subspace.Sub方法代码示例

本文整理汇总了Golang中github.com/FoundationDB/fdb-go/fdb/subspace.Subspace.Sub方法的典型用法代码示例。如果您正苦于以下问题:Golang Subspace.Sub方法的具体用法?Golang Subspace.Sub怎么用?Golang Subspace.Sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/FoundationDB/fdb-go/fdb/subspace.Subspace的用法示例。


在下文中一共展示了Subspace.Sub方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: newHCA

func newHCA(s subspace.Subspace) highContentionAllocator {
	var hca highContentionAllocator

	hca.counters = s.Sub(0)
	hca.recent = s.Sub(1)

	return hca
}
开发者ID:ptomasroos,项目名称:fdb-go,代码行数:8,代码来源:allocator.go

示例2: subdirNodes

func (dl directoryLayer) subdirNodes(tr fdb.Transaction, node subspace.Subspace) []subspace.Subspace {
	sd := node.Sub(_SUBDIRS)

	rr := tr.GetRange(sd, fdb.RangeOptions{})
	ri := rr.Iterator()

	var ret []subspace.Subspace

	for ri.Advance() {
		kv := ri.MustGet()

		ret = append(ret, dl.nodeWithPrefix(kv.Value))
	}

	return ret
}
开发者ID:ptomasroos,项目名称:fdb-go,代码行数:16,代码来源:directoryLayer.go

示例3: allocate

func (hca highContentionAllocator) allocate(tr fdb.Transaction, s subspace.Subspace) (subspace.Subspace, error) {
	rr := tr.Snapshot().GetRange(hca.counters, fdb.RangeOptions{Limit: 1, Reverse: true})
	kvs := rr.GetSliceOrPanic()

	var start, count int64

	if len(kvs) == 1 {
		t, e := hca.counters.Unpack(kvs[0].Key)
		if e != nil {
			return nil, e
		}
		start = t[0].(int64)

		e = binary.Read(bytes.NewBuffer(kvs[0].Value), binary.LittleEndian, &count)
		if e != nil {
			return nil, e
		}
	}

	window := windowSize(start)

	if (count+1)*2 >= window {
		// Advance the window
		tr.ClearRange(fdb.KeyRange{hca.counters, append(hca.counters.Sub(start).FDBKey(), 0x00)})
		start += window
		tr.ClearRange(fdb.KeyRange{hca.recent, hca.recent.Sub(start)})
		window = windowSize(start)
	}

	// Increment the allocation count for the current window
	tr.Add(hca.counters.Sub(start), oneBytes)

	for {
		// As of the snapshot being read from, the window is less than half
		// full, so this should be expected to take 2 tries.  Under high
		// contention (and when the window advances), there is an additional
		// subsequent risk of conflict for this transaction.
		candidate := rand.Int63n(window) + start
		key := hca.recent.Sub(candidate)
		if tr.Get(key).MustGet() == nil {
			tr.Set(key, []byte(""))
			return s.Sub(candidate), nil
		}
	}
}
开发者ID:ptomasroos,项目名称:fdb-go,代码行数:45,代码来源:allocator.go

示例4: subdirNames

func (dl directoryLayer) subdirNames(rtr fdb.ReadTransaction, node subspace.Subspace) ([]string, error) {
	sd := node.Sub(_SUBDIRS)

	rr := rtr.GetRange(sd, fdb.RangeOptions{})
	ri := rr.Iterator()

	var ret []string

	for ri.Advance() {
		kv := ri.MustGet()

		p, e := sd.Unpack(kv.Key)
		if e != nil {
			return nil, e
		}

		ret = append(ret, p[0].(string))
	}

	return ret, nil
}
开发者ID:ptomasroos,项目名称:fdb-go,代码行数:21,代码来源:directoryLayer.go

示例5: createOrOpen

func (dl directoryLayer) createOrOpen(rtr fdb.ReadTransaction, tr *fdb.Transaction, path []string, layer []byte, prefix []byte, allowCreate, allowOpen bool) (DirectorySubspace, error) {
	if e := dl.checkVersion(rtr, nil); e != nil {
		return nil, e
	}

	if prefix != nil && !dl.allowManualPrefixes {
		if len(dl.path) == 0 {
			return nil, errors.New("cannot specify a prefix unless manual prefixes are enabled")
		} else {
			return nil, errors.New("cannot specify a prefix in a partition")
		}
	}

	if len(path) == 0 {
		return nil, errors.New("the root directory cannot be opened")
	}

	existingNode := dl.find(rtr, path).prefetchMetadata(rtr)
	if existingNode.exists() {
		if existingNode.isInPartition(nil, false) {
			subpath := existingNode.getPartitionSubpath()
			enc, e := existingNode.getContents(dl, nil)
			if e != nil {
				return nil, e
			}
			return enc.(directoryPartition).createOrOpen(rtr, tr, subpath, layer, prefix, allowCreate, allowOpen)
		}

		if !allowOpen {
			return nil, errors.New("the directory already exists")
		}

		if layer != nil && bytes.Compare(existingNode._layer.MustGet(), layer) != 0 {
			return nil, errors.New("the directory was created with an incompatible layer")
		}

		return existingNode.getContents(dl, nil)
	}

	if !allowCreate {
		return nil, errors.New("the directory does not exist")
	}

	if e := dl.checkVersion(rtr, tr); e != nil {
		return nil, e
	}

	if prefix == nil {
		newss, e := dl.allocator.allocate(*tr, dl.contentSS)
		if e != nil {
			return nil, fmt.Errorf("unable to allocate new directory prefix (%s)", e.Error())
		}

		if !isRangeEmpty(rtr, newss) {
			return nil, fmt.Errorf("the database has keys stored at the prefix chosen by the automatic prefix allocator: %v", prefix)
		}

		prefix = newss.Bytes()

		pf, e := dl.isPrefixFree(rtr.Snapshot(), prefix)
		if e != nil {
			return nil, e
		}
		if !pf {
			return nil, errors.New("the directory layer has manually allocated prefixes that conflict with the automatic prefix allocator")
		}
	} else {
		pf, e := dl.isPrefixFree(rtr, prefix)
		if e != nil {
			return nil, e
		}
		if !pf {
			return nil, errors.New("the given prefix is already in use")
		}
	}

	var parentNode subspace.Subspace

	if len(path) > 1 {
		pd, e := dl.createOrOpen(rtr, tr, path[:len(path)-1], nil, nil, true, true)
		if e != nil {
			return nil, e
		}
		parentNode = dl.nodeWithPrefix(pd.Bytes())
	} else {
		parentNode = dl.rootNode
	}

	if parentNode == nil {
		return nil, errors.New("the parent directory does not exist")
	}

	node := dl.nodeWithPrefix(prefix)
	tr.Set(parentNode.Sub(_SUBDIRS, path[len(path)-1]), prefix)

	if layer == nil {
		layer = []byte{}
	}

	tr.Set(node.Sub([]byte("layer")), layer)
//.........这里部分代码省略.........
开发者ID:ptomasroos,项目名称:fdb-go,代码行数:101,代码来源:directoryLayer.go


注:本文中的github.com/FoundationDB/fdb-go/fdb/subspace.Subspace.Sub方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。