Ejemplo n.º 1
0
//
// Get the set of nodes for all the given buckets
//
func (p *ProjectorClientEnvImpl) GetNodeListForBuckets(buckets []string) (map[string]string, error) {

	logging.Debugf("ProjectorCLientEnvImpl::getNodeListForBuckets(): start")

	nodes := make(map[string]string)

	for _, bucket := range buckets {

		bucketRef, err := couchbase.GetBucket(COUCHBASE_INTERNAL_BUCKET_URL, DEFAULT_POOL_NAME, bucket)
		if err != nil {
			return nil, err
		}

		if err := bucketRef.Refresh(); err != nil {
			return nil, err
		}

		for _, node := range bucketRef.NodeAddresses() {
			// TODO: This may not work for cluster_run when all processes are run in the same node.  Need to check.
			logging.Debugf("ProjectorCLientEnvImpl::getNodeListForBuckets(): node=%v for bucket %v", node, bucket)
			nodes[node] = node
		}
	}

	return nodes, nil
}
Ejemplo n.º 2
0
//
// Get the set of nodes for all the given timestamps
//
func (p *ProjectorClientEnvImpl) GetNodeListForTimestamps(timestamps []*common.TsVbuuid) (map[string][]*protobuf.TsVbuuid, error) {

	logging.Debugf("ProjectorCLientEnvImpl::getNodeListForTimestamps(): start")

	nodes := make(map[string][]*protobuf.TsVbuuid)

	for _, ts := range timestamps {

		bucketRef, err := couchbase.GetBucket(COUCHBASE_INTERNAL_BUCKET_URL, DEFAULT_POOL_NAME, ts.Bucket)
		if err != nil {
			return nil, err
		}

		if err := bucketRef.Refresh(); err != nil {
			return nil, err
		}

		vbmap, err := bucketRef.GetVBmap(nil)
		if err != nil {
			return nil, err
		}

		for i, seqno := range ts.Seqnos {
			if seqno != 0 {
				found := false
				for kvaddr, vbnos := range vbmap {
					for _, vbno := range vbnos {
						if vbno == uint16(i) {
							newTs := p.findTimestamp(nodes, kvaddr, ts.Bucket)
							newTs.Append(uint16(i), ts.Seqnos[i], ts.Vbuuids[i],
								ts.Snapshots[i][0], ts.Snapshots[i][1])
							found = true
							break
						}
					}

					if found {
						break
					}
				}

				if !found {
					return nil, NewError2(ERROR_STREAM_INCONSISTENT_VBMAP, STREAM)
				}
			}
		}
	}

	return nodes, nil
}
Ejemplo n.º 3
0
//
// Filter the timestamp based on vb list on a certain node
//
func (p *ProjectorClientEnvImpl) FilterTimestampsForNode(timestamps []*protobuf.TsVbuuid,
	node string) ([]*protobuf.TsVbuuid, error) {

	logging.Debugf("ProjectorClientEnvImpl.FilterTimestampsForNode(): start")

	var newTimestamps []*protobuf.TsVbuuid = nil

	for _, ts := range timestamps {

		bucketRef, err := couchbase.GetBucket(COUCHBASE_INTERNAL_BUCKET_URL, DEFAULT_POOL_NAME, ts.GetBucket())
		if err != nil {
			return nil, err
		}

		if err := bucketRef.Refresh(); err != nil {
			return nil, err
		}

		vbmap, err := bucketRef.GetVBmap(nil)
		if err != nil {
			return nil, err
		}

		newTs := protobuf.NewTsVbuuid(DEFAULT_POOL_NAME, ts.GetBucket(), NUM_VB)

		for kvaddr, vbnos := range vbmap {
			if kvaddr == node {
				for _, vbno := range vbnos {
					seqno, vbuuid, sStart, sEnd, err := ts.Get(vbno)
					// If cannot get the seqno from this vbno (err != nil), then skip.
					// Otherwise, add to the new timestamp.
					if err == nil {
						newTs.Append(uint16(vbno), seqno, vbuuid, sStart, sEnd)
					}
				}
			}
		}

		if !newTs.IsEmpty() {
			newTimestamps = append(newTimestamps, newTs)
		}
	}

	return newTimestamps, nil
}