Example #1
0
func NewIDMapHAMT(w, t uint) (m *IDMapHAMT, err error) {
	h, err := gh.NewHAMT(w, t)
	if err == nil {
		m = &IDMapHAMT{h: h}
	}
	return
}
Example #2
0
// Insert N items into the HAMT, then find eacah J times.  This is a
// SINGLE-THREADED benchmark.
//
func doBenchmark(w, t uint, J, N uint, cpuProfFile *os.File) {
	// build an array of N random-ish K-byte rawKeys
	K := uint(16)
	// t0 := time.Now()
	rawKeys, bKeys := makeSomeUniqueKeys(N, K)
	//t1 := time.Now()
	//deltaT := t1.Sub(t0)
	//fmt.Printf("setup time for %d %d-byte rawKeys: %v\n", N, K, deltaT)

	pprof.StartCPUProfile(cpuProfFile)
	// XXX we ignore any possible errors
	m, _ := gh.NewHAMT(w, t)

	for i := uint(0); i < N; i++ {
		_ = m.Insert(bKeys[i], &rawKeys[i])
	}

	// verify several times that the rawKeys are present in the map
	for j := uint(0); j < J; j++ {
		for i := uint(0); i < N; i++ {
			value, err := m.Find(bKeys[i])
			// DEBUG
			if err != nil {
				fmt.Printf("error finding key %d\n", i, err.Error())
			}
			if value == nil {
				fmt.Printf("cannot find key %d\n", i)
			}
			// END
			//val := value.(*[]byte)	// NOT USED
			_ = value

		} // GEEP
	}
}
Example #3
0
func NewRegCluster(name string, id *xi.NodeID, attrs uint64,
	maxSize, epCount uint32) (rc *RegCluster, err error) {

	var m ha.HAMT

	if name == "" {
		name = "xlCluster"
	}
	nameMap := make(map[string]*ClientInfo)
	if epCount < 1 {
		err = ClusterMembersMustHaveEndPoint
	}
	if err == nil && maxSize < 1 {
		//err = ClusterMustHaveTwo
		err = ClusterMustHaveMember
	} else {
		t := uint(xm.NextExp2_32(maxSize))
		m, err = ha.NewHAMT(DEFAULT_W, t)
	}
	if err == nil {
		rc = &RegCluster{
			Attrs:         attrs,
			Name:          name,
			ID:            id.Value(),
			epCount:       epCount,
			maxSize:       maxSize,
			MembersByName: nameMap,
			MembersByID:   m,
		}
	}
	return
}
Example #4
0
// Insert N items into the HAMT, then find each J times.  This is
// a very crude test!
//
// (a) inserts should be done with a write lock (doesn't matter now
//     because insertions are single-threaded
// (b) finds should be done with a read lock
// (c) inserts and finds should be overlapped
//
func doBenchmark(w, t uint, J, N uint) (deltaT time.Duration) {
	// build an array of N random-ish K-byte rawKeys
	K := uint(16)
	rawKeys, bKeys := makeSomeUniqueKeys(N, K)

	// set up HAMT, ignoring any errors
	m, _ := gh.NewHAMT(w, t)
	done := make([]chan bool, J)
	for i := uint(0); i < J; i++ {
		done[i] = make(chan bool)
	}

	t0 := time.Now()
	for i := uint(0); i < N; i++ {
		_ = m.Insert(bKeys[i], &rawKeys[i])
	}

	// Verify several times that the rawKeys are present in the map.
	for j := uint(0); j < J; j++ {
		go func(j uint) {
			for i := uint(0); i < N; i++ {
				value, err := m.Find(bKeys[i])
				// DEBUG
				if err != nil {
					fmt.Printf("error finding key %d\n", i, err.Error())
				}
				if value == nil {
					fmt.Printf("cannot find key %d\n", i)
				}
				// END
				//val := value.(*[]byte)	// NOT USED
				_ = value
			}
			done[j] <- true
		}(j)
	}
	for j := uint(0); j < J; j++ {
		<-done[j]
	}
	t1 := time.Now()
	deltaT = t1.Sub(t0)
	return
}
Example #5
0
func NewRegistry(clusters []*RegCluster,
	rn *RegNode,
	opt *RegOptions) (
	reg *Registry, err error) {

	var (
		idFilter      xf.BloomSHAI
		m             ha.HAMT
		serverVersion xu.DecimalVersion
	)
	serverVersion, err = xu.ParseDecimalVersion(VERSION)
	if err == nil && rn == nil {
		err = NilRegNode
	}
	if err == nil {
		if opt.BackingFile == "" {
			idFilter, err = xf.NewBloomSHA(opt.M, opt.K)
		} else {
			idFilter, err = xf.NewMappedBloomSHA(opt.M, opt.K, opt.BackingFile)
		}
		if err == nil {
			// HAMT root table size is 2^opt.T
			m, err = ha.NewHAMT(DEFAULT_W, opt.T)
		}
	}
	if err == nil {
		logger := opt.Logger
		if logger == nil {
			logger = log.New(os.Stderr, "", log.Ldate|log.Ltime)
		}
		testing := opt.Testing
		// DEBUG
		if testing {
			logger.Printf("testing and globalEndPoint = %s\n", opt.GlobalEndPoint)
		}
		// END
		reg = &Registry{
			idFilter:       idFilter,
			Clusters:       clusters,
			GlobalEndPoint: opt.GlobalEndPoint, // written to regCred
			ClustersByName: make(map[string]*RegCluster),
			ClustersByID:   m,

			Logger:  logger,
			RegNode: *rn,
		}
		if clusters != nil {
			// XXX need to populate the indexes here
		}
		myLFS := rn.GetLFS()
		if myLFS != "" {
			var ep []xt.EndPointI
			// list of endpoints for regCred
			//for i := 0; i < rn.SizeEndPoints(); i++ {
			//	ep = append(ep, rn.GetEndPoint(i))
			//}
			// XXX err should never be nil here
			if err == nil {
				ep = append(ep, opt.GlobalEndPoint)
				regCred := &RegCred{
					Name:        rn.GetName(),
					ID:          rn.GetNodeID(),
					CommsPubKey: rn.GetCommsPublicKey(),
					SigPubKey:   rn.GetSigPublicKey(),
					EndPoints:   ep,
					Version:     serverVersion,
				}
				serialized := regCred.String() // shd have terminating CRLF
				logger.Print(serialized)
				pathToFile := filepath.Join(myLFS, "regCred.dat")
				err = ioutil.WriteFile(pathToFile, []byte(serialized), 0644)
			}
		}
	}
	if err == nil {
		// registry's own ID added to Bloom filter
		regID := rn.GetNodeID()
		// DEBUG
		reg.Logger.Printf("\ninserting registry ID %x\n", regID.Value())
		// END
		err = reg.InsertID(regID)
	}
	return
}