open-consul/agent/consul/system_metadata.go
Daniel Nephin 8654adfc53 Handle FSM.Apply errors in raftApply
Previously we were inconsistently checking the response for errors. This
PR moves the response-is-error check into raftApply, so that all callers
can look at only the error response, instead of having to know that
errors could come from two places.

This should expose a few more errors that were previously hidden because
in some calls to raftApply we were ignoring the response return value.

Also handle errors more consistently. In some cases we would log the
error before returning it. This can be very confusing because it can
result in the same error being logged multiple times. Instead return
a wrapped error.
2021-04-20 13:29:29 -04:00

38 lines
862 B
Go

package consul
import (
"github.com/hashicorp/consul/agent/structs"
)
func (s *Server) getSystemMetadata(key string) (string, error) {
_, entry, err := s.fsm.State().SystemMetadataGet(nil, key)
if err != nil {
return "", err
}
if entry == nil {
return "", nil
}
return entry.Value, nil
}
func (s *Server) setSystemMetadataKey(key, val string) error {
args := &structs.SystemMetadataRequest{
Op: structs.SystemMetadataUpsert,
Entry: &structs.SystemMetadataEntry{Key: key, Value: val},
}
_, err := s.raftApply(structs.SystemMetadataRequestType, args)
return err
}
func (s *Server) deleteSystemMetadataKey(key string) error {
args := &structs.SystemMetadataRequest{
Op: structs.SystemMetadataDelete,
Entry: &structs.SystemMetadataEntry{Key: key},
}
_, err := s.raftApply(structs.SystemMetadataRequestType, args)
return err
}