本文整理匯總了Golang中github.com/dgraph-io/dgraph/x.AssertTruef函數的典型用法代碼示例。如果您正苦於以下問題:Golang AssertTruef函數的具體用法?Golang AssertTruef怎麽用?Golang AssertTruef使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AssertTruef函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: processSnapshot
func (n *node) processSnapshot(s raftpb.Snapshot) {
lead := n.raft.Status().Lead
if lead == 0 {
return
}
addr := n.peers.Get(lead)
x.AssertTruef(addr != "", "Should have the leader address: %v", lead)
pool := pools().get(addr)
x.AssertTruef(pool != nil, "Leader: %d pool should not be nil", lead)
_, err := populateShard(context.TODO(), pool, 0)
x.Checkf(err, "processSnapshot")
}
示例2: intersects
// returns true if the geometry represented by uid/attr intersects the given loop or point
func (q QueryData) intersects(g types.Geo) bool {
x.AssertTruef(q.pt != nil || q.loop != nil, "At least a point or loop should be defined.")
switch v := g.T.(type) {
case *geom.Point:
p := pointFromPoint(v)
if q.pt != nil {
// Points only intersect if they are the same. (We allow for small rounding errors)
return q.pt.ApproxEqual(p)
}
// else loop is not nil
return q.loop.ContainsPoint(p)
case *geom.Polygon:
l, err := loopFromPolygon(v)
if err != nil {
return false
}
if q.pt != nil {
return l.ContainsPoint(*q.pt)
}
// else loop is not nil
return Intersects(l, q.loop)
default:
// A type that we don't know how to handle.
return false
}
}
示例3: FilterUids
// FilterUids filters the uids based on the corresponding values and QueryData.
func FilterUids(uids *task.List, values []*task.Value, q *QueryData) *task.List {
x.AssertTruef(len(values) == len(uids.Uids), "lengths not matching")
rv := &task.List{}
for i := 0; i < len(values); i++ {
valBytes := values[i].Val
if bytes.Equal(valBytes, nil) {
continue
}
vType := values[i].ValType
if types.TypeID(vType) != types.GeoID {
continue
}
var g types.Geo
if err := g.UnmarshalBinary(valBytes); err != nil {
continue
}
if !q.MatchesFilter(g) {
continue
}
// we matched the geo filter, add the uid to the list
rv.Uids = append(rv.Uids, uids.Uids[i])
}
return rv
}
示例4: Store
func (p *proposals) Store(pid uint32, ch chan error) {
p.Lock()
defer p.Unlock()
_, has := p.ids[pid]
x.AssertTruef(!has, "Same proposal is being stored again.")
p.ids[pid] = ch
}
示例5: ServeTask
// ServeTask is used to respond to a query.
func (w *grpcWorker) ServeTask(ctx context.Context, q *task.Query) (*task.Result, error) {
if ctx.Err() != nil {
return &emptyResult, ctx.Err()
}
gid := group.BelongsTo(q.Attr)
x.Trace(ctx, "Attribute: %q NumUids: %v groupId: %v ServeTask", q.Attr, len(q.Uids), gid)
var reply *task.Result
x.AssertTruef(groups().ServesGroup(gid),
"attr: %q groupId: %v Request sent to wrong server.", q.Attr, gid)
c := make(chan error, 1)
go func() {
var err error
reply, err = processTask(q)
c <- err
}()
select {
case <-ctx.Done():
return reply, ctx.Err()
case err := <-c:
return reply, err
}
}
示例6: Sort
// Sort is used to sort given UID matrix.
func (w *grpcWorker) Sort(ctx context.Context, s *task.Sort) (*task.SortResult, error) {
if ctx.Err() != nil {
return &emptySortResult, ctx.Err()
}
gid := group.BelongsTo(s.Attr)
//x.Trace(ctx, "Attribute: %q NumUids: %v groupId: %v Sort", q.Attr(), q.UidsLength(), gid)
var reply *task.SortResult
x.AssertTruef(groups().ServesGroup(gid),
"attr: %q groupId: %v Request sent to wrong server.", s.Attr, gid)
c := make(chan error, 1)
go func() {
var err error
reply, err = processSort(s)
c <- err
}()
select {
case <-ctx.Done():
return &emptySortResult, ctx.Err()
case err := <-c:
return reply, err
}
}
示例7: addIndexMutation
func addIndexMutation(ctx context.Context, attr, token string,
tokensTable *TokensTable, edge *task.DirectedEdge, del bool) {
key := x.IndexKey(attr, token)
plist, decr := GetOrCreate(key)
defer decr()
x.AssertTruef(plist != nil, "plist is nil [%s] %d %s",
token, edge.ValueId, edge.Attr)
if del {
_, err := plist.AddMutation(ctx, edge, Del)
if err != nil {
x.TraceError(ctx, x.Wrapf(err,
"Error deleting %s for attr %s entity %d: %v",
token, edge.Attr, edge.Entity))
}
indexLog.Printf("DEL [%s] [%d] OldTerm [%s]",
edge.Attr, edge.Entity, token)
} else {
_, err := plist.AddMutation(ctx, edge, Set)
if err != nil {
x.TraceError(ctx, x.Wrapf(err,
"Error adding %s for attr %s entity %d: %v",
token, edge.Attr, edge.Entity))
}
indexLog.Printf("SET [%s] [%d] NewTerm [%s]",
edge.Attr, edge.Entity, token)
tokensTable.Add(token)
}
}
示例8: decr
func (l *List) decr() {
val := atomic.AddInt32(&l.refcount, -1)
x.AssertTruef(val >= 0, "List reference should never be less than zero: %v", val)
if val > 0 {
return
}
listPool.Put(l)
}
示例9: getTokens
func getTokens(funcArgs []string) ([]string, error) {
x.AssertTruef(len(funcArgs) > 1, "Invalid function")
if len(funcArgs) != 2 {
return nil, x.Errorf("Function requires 2 arguments, but got %d",
len(funcArgs))
}
return getStringTokens(funcArgs[1])
}
示例10: parsePeer
func parsePeer(peer string) (uint64, string) {
x.AssertTrue(len(peer) > 0)
kv := strings.SplitN(peer, ":", 2)
x.AssertTruef(len(kv) == 2, "Invalid peer format: %v", peer)
pid, err := strconv.ParseUint(kv[0], 10, 64)
x.Checkf(err, "Invalid peer id: %v", kv[0])
// TODO: Validate the url kv[1]
return pid, kv[1]
}
示例11: parentCoverTokens
func parentCoverTokens(parents s2.CellUnion, cover s2.CellUnion) []string {
// We index parents and cover using different prefix, that makes it more
// performant at query time to only look up parents/cover depending on what
// kind of query it is.
tokens := make([]string, 0, len(parents)+len(cover))
tokens = appendTokens(tokens, parents, parentPrefix)
tokens = appendTokens(tokens, cover, coverPrefix)
x.AssertTruef(len(tokens) == len(parents)+len(cover), "%d %d %d",
len(tokens), len(parents), len(cover))
return tokens
}
示例12: newPosting
func newPosting(t *task.DirectedEdge, op uint32) *types.Posting {
x.AssertTruef(bytes.Equal(t.Value, nil) || t.ValueId == math.MaxUint64,
"This should have been set by the caller.")
return &types.Posting{
Uid: t.ValueId,
Value: t.Value,
ValType: uint32(t.ValueType),
Label: t.Label,
Op: op,
}
}
示例13: send
func (n *node) send(m raftpb.Message) {
x.AssertTruef(n.id != m.To, "Seding message to itself")
data, err := m.Marshal()
x.Check(err)
if m.Type != raftpb.MsgHeartbeat && m.Type != raftpb.MsgHeartbeatResp {
fmt.Printf("\t\tSENDING: %v %v-->%v\n", m.Type, m.From, m.To)
}
select {
case n.messages <- sendmsg{to: m.To, data: data}:
// pass
default:
log.Fatalf("Unable to push messages to channel in send")
}
}
示例14: newNode
func (g *groupi) newNode(groupId uint32, nodeId uint64, publicAddr string) *node {
g.Lock()
defer g.Unlock()
if g.local == nil {
g.local = make(map[uint32]*node)
}
node := newNode(groupId, nodeId, publicAddr)
if _, has := g.local[groupId]; has {
x.AssertTruef(false, "Didn't expect a node in RAFT group mapping: %v", groupId)
}
g.local[groupId] = node
return node
}
示例15: processSort
// processSort does either a coarse or a fine sort.
func processSort(ts *task.Sort) (*task.SortResult, error) {
attr := ts.Attr
x.AssertTruef(ts.Count > 0,
("We do not yet support negative or infinite count with sorting: %s %d. " +
"Try flipping order and return first few elements instead."),
attr, ts.Count)
n := len(ts.UidMatrix)
out := make([]intersectedList, n)
for i := 0; i < n; i++ {
// offsets[i] is the offset for i-th posting list. It gets decremented as we
// iterate over buckets.
out[i].offset = int(ts.Offset)
out[i].ulist = &task.List{Uids: []uint64{}}
}
// Iterate over every bucket in TokensTable.
t := posting.GetTokensTable(attr)
var token string
if ts.Desc {
token = t.GetLast()
} else {
token = t.GetFirst()
}
BUCKETS:
for len(token) > 0 {
err := intersectBucket(ts, attr, token, out)
switch err {
case errDone:
break BUCKETS
case errContinue:
// Continue iterating over tokens.
default:
return &emptySortResult, err
}
if ts.Desc {
token = t.GetPrev(token)
} else {
token = t.GetNext(token)
}
}
r := new(task.SortResult)
for _, il := range out {
r.UidMatrix = append(r.UidMatrix, il.ulist)
}
return r, nil
}