func (c *CfgMetaKv) getRawLOCKED(key string, cas uint64) ([]byte, uint64, error) { path := c.keyToPath(key) v, _, err := metakv.Get(path) // TODO: Handle rev. if err != nil { return nil, 0, err } return v, 1, nil }
func GetSettingsConfig(cfg Config) (Config, error) { newConfig := cfg.Clone() current, _, err := metakv.Get(IndexingSettingsMetaPath) if err == nil { if len(current) > 0 { newConfig.Update(current) } } else { logging.Errorf("GetSettingsConfig() failed: %v", err) } return newConfig, err }
func (s *settingsManager) handleCompactionTrigger(w http.ResponseWriter, r *http.Request) { if !s.validateAuth(w, r) { return } _, rev, err := metakv.Get(indexCompactonMetaPath) if err != nil { s.writeError(w, err) return } newToken := time.Now().String() if err = metakv.Set(indexCompactonMetaPath, []byte(newToken), rev); err != nil { s.writeError(w, err) return } s.writeOk(w) }
func MetakvGet(path string, v interface{}) bool { raw, _, err := metakv.Get(path) if err != nil { log.Fatalf("Failed to fetch %s from metakv: %s", path, err.Error()) } if raw == nil { return false } err = json.Unmarshal(raw, v) if err != nil { log.Fatalf("Failed unmarshalling value for %s: %s\n%s", path, err.Error(), string(raw)) } return true }
func (s *settingsManager) handleSettingsReq(w http.ResponseWriter, r *http.Request) { if !s.validateAuth(w, r) { return } if r.Method == "POST" { bytes, _ := ioutil.ReadAll(r.Body) config := s.config.FilterConfig(".settings.") current, rev, err := metakv.Get(common.IndexingSettingsMetaPath) if err == nil { if len(current) > 0 { config.Update(current) } err = config.Update(bytes) } if err != nil { s.writeError(w, err) return } //settingsConfig := config.FilterConfig(".settings.") newSettingsBytes := config.Json() if err = metakv.Set(common.IndexingSettingsMetaPath, newSettingsBytes, rev); err != nil { s.writeError(w, err) return } s.writeOk(w) } else if r.Method == "GET" { settingsConfig, err := common.GetSettingsConfig(s.config) if err != nil { s.writeError(w, err) return } s.writeJson(w, settingsConfig.FilterConfig(".settings.").Json()) } else { s.writeError(w, errors.New("Unsupported method")) return } }