Exemplo n.º 1
0
// getPostingList tries to get posting list from l.pbuffer. If it is nil, then
// we query RocksDB. There is no need for lock acquisition here.
func (l *List) getPostingList(loop int) *types.PostingList {
	if loop >= 10 {
		x.Fatalf("This is over the 10th loop: %v", loop)
	}
	l.AssertRLock()
	// Wait for any previous commits to happen before retrieving posting list again.
	l.Wait()

	pb := atomic.LoadPointer(&l.pbuffer)
	plist := (*types.PostingList)(pb)

	if plist == nil {
		x.AssertTrue(l.pstore != nil)
		plist = new(types.PostingList)

		if slice, err := l.pstore.Get(l.key); err == nil && slice != nil {
			x.Checkf(plist.Unmarshal(slice.Data()), "Unable to Unmarshal PostingList from store")
			slice.Free()
		}
		if atomic.CompareAndSwapPointer(&l.pbuffer, pb, unsafe.Pointer(plist)) {
			return plist
		}
		// Someone else replaced the pointer in the meantime. Retry recursively.
		return l.getPostingList(loop + 1)
	}
	return plist
}
Exemplo n.º 2
0
// Less returns true if a is strictly less than b.
func (s Scalar) Less(a, b Value) bool {
	switch s.ID() {
	case DateID:
		return a.(*Date).Time.Before(b.(*Date).Time)
	case DateTimeID:
		return a.(*Time).Time.Before(b.(*Time).Time)
	case Int32ID:
		return *(a.(*Int32)) < *(b.(*Int32))
	case FloatID:
		return *(a.(*Float)) < *(b.(*Float))
	case StringID:
		return *(a.(*String)) < *(b.(*String))
	case BytesID:
		return bytes.Compare(*(a.(*Bytes)), *(b.(*Bytes))) < 0
	}
	x.Fatalf("Unexpected scalar: %v", s)
	return false
}
Exemplo n.º 3
0
// AssignUids is used to assign new uids by communicating with the leader of the RAFT group
// responsible for handing out uids.
func (w *grpcWorker) AssignUids(ctx context.Context, num *task.Num) (*task.List, error) {
	if ctx.Err() != nil {
		return &emptyUIDList, ctx.Err()
	}

	if !groups().ServesGroup(num.Group) {
		x.Fatalf("groupId: %v. GetOrAssign. We shouldn't be getting this req", num.Group)
	}

	reply := &emptyUIDList
	c := make(chan error, 1)
	go func() {
		var err error
		reply, err = assignUids(ctx, num)
		c <- err
	}()

	select {
	case <-ctx.Done():
		return reply, ctx.Err()
	case err := <-c:
		return reply, err
	}
}