Exemple #1
0
/*
save ...
*/
func (sp *SketchProxy) save(force bool) {
	if !sp.dirty {
		return
	}
	id := fmt.Sprintf("%s.%s", sp.ID, sp.Type)

	if sp.ops%config.GetConfig().SaveThresholdOps == 0 || force {
		sp.ops++
		sp.dirty = false
		manager := storage.Manager()
		serialized, err := sp.sketch.Marshal()
		if err != nil {
			logger.Error.Println(err)
		}
		err = manager.SaveData(id, serialized, 0)
		if err != nil {
			logger.Error.Println(err)
		}
		info, _ := json.Marshal(sp.Info)
		err = manager.SaveInfo(sp.Info.ID, info)
		if err != nil {
			logger.Error.Println(err)
		}
	}
}
Exemple #2
0
func loadSketch(info *abstract.Info) (*SketchProxy, error) {
	var sketch abstract.Sketch

	id := fmt.Sprintf("%s.%s", info.ID, info.Type)
	data, err := storage.Manager().LoadData(id, 0, 0)
	if err != nil {
		return nil, fmt.Errorf("Error loading data for sketch: %s", id)
	}

	switch info.Type {
	case abstract.HLLPP:
		sketch, err = hllpp.Unmarshal(info, data)
	case abstract.TopK:
		sketch, err = topk.Unmarshal(info, data)
	case abstract.CML:
		sketch, err = cml.Unmarshal(info, data)
	case abstract.Dict:
		sketch, err = dict.Unmarshal(info, data)
	case abstract.Bloom:
		sketch, err = bloom.Unmarshal(info, data)
	default:
		logger.Info.Println("Invalid sketch type", info.Type)
	}
	sp := SketchProxy{info, sketch, sync.RWMutex{}, 0, false}

	if err != nil {
		return nil, fmt.Errorf("Error loading data for sketch: %s", id)
	}

	go sp.autosave()
	return &sp, nil
}
Exemple #3
0
func (m *ManagerStruct) dumpInfo(info *abstract.Info) {
	// FIXME: Should we panic here?
	id := fmt.Sprintf("%s.%s", info.ID, info.Type)

	m.info[id] = info
	manager := storage.Manager()
	infoData, err := json.Marshal(info)
	utils.PanicOnError(err)
	err = manager.SaveInfo(id, infoData)
	utils.PanicOnError(err)
}
Exemple #4
0
/*
DeleteSketch ...
*/
func (m *ManagerStruct) DeleteSketch(sketchID string, sketchType string) error {
	id := fmt.Sprintf("%s.%s", sketchID, sketchType)

	if _, ok := m.sketches[id]; !ok {
		return errors.New("No such sketch " + sketchID)
	}
	delete(m.sketches, id)
	delete(m.info, id)
	manager := storage.Manager()
	err := manager.DeleteInfo(id)
	if err != nil {
		return err
	}
	return manager.DeleteData(id)
}
Exemple #5
0
func (m *ManagerStruct) loadInfo() error {
	manager := storage.Manager()
	infos, err := manager.LoadAllInfo()
	if err != nil {
		return err
	}
	for _, infoData := range infos {
		var infoStruct abstract.Info
		err := json.Unmarshal(infoData, &infoStruct)
		if err != nil {
			return err
		}
		id := fmt.Sprintf("%s.%s", infoStruct.ID, infoStruct.Type)
		m.info[id] = &infoStruct
	}
	return nil
}