示例#1
0
文件: manager.go 项目: postfix/skizze
/*
CreateDomain ...
*/
func (m *ManagerStruct) CreateDomain(domainID string, domainType string, capacity uint64) error {

	// Check if domain with ID already exists
	if info, ok := m.info[domainID]; ok {
		errStr := fmt.Sprintf("Domain %s of type %s already exists", domainID, info.Type)
		return errors.New(errStr)
	}

	if len([]byte(domainID)) > config.MaxKeySize {
		return errors.New("Invalid length of domain ID: " + strconv.Itoa(len(domainID)) + ". Max length allowed: " + strconv.Itoa(config.MaxKeySize))
	}
	if domainType == "" {
		logger.Error.Println("DomainType is mandatory and must be set!")
		return errors.New("No domain type was given!")
	}
	info := &abstract.Info{ID: domainID,
		Type:     domainType,
		Capacity: capacity,
		State:    make(map[string]uint64)}
	var domain abstract.Counter
	var err error
	switch domainType {
	case abstract.Cardinality:
		domain, err = hllpp.NewDomain(info)
	case abstract.PurgableCardinality:
		domain, err = cuckoofilter.NewDomain(info)
	case abstract.TopK:
		domain, err = topk.NewDomain(info)
	default:
		return errors.New("Invalid domain type: " + domainType)
	}

	if err != nil {
		errTxt := fmt.Sprint("Could not load domain ", info, ". Err:", err)
		return errors.New(errTxt)
	}
	m.domains[info.ID] = domain
	m.dumpInfo(info)
	return nil
}
示例#2
0
文件: manager.go 项目: postfix/skizze
func (m *ManagerStruct) loadDomains() error {
	strg := storage.GetManager()
	for key, info := range m.info {
		var domain abstract.Counter
		var err error
		switch info.Type {
		case abstract.Cardinality:
			domain, err = hllpp.NewDomainFromData(info)
		case abstract.PurgableCardinality:
			domain, err = cuckoofilter.NewDomain(info)
		case abstract.TopK:
			domain, err = topk.NewDomainFromData(info)
		default:
			logger.Info.Println("Invalid counter type", info.Type)
		}
		if err != nil {
			errTxt := fmt.Sprint("Could not load domain ", info, ". Err: ", err)
			return errors.New(errTxt)
		}
		m.domains[info.ID] = domain
		strg.LoadData(key, 0, 0)
	}
	return nil
}