Fix remote-load error handling

Error from remote node was being dropped.
This commit is contained in:
Philip O'Toole
2022-10-24 13:29:48 -04:00
parent ec0750a4c2
commit 65cd556549
3 changed files with 13 additions and 8 deletions

View File

@@ -337,7 +337,7 @@ func (s *Service) handleConn(conn net.Conn) {
resp.Error = "unauthorized"
} else {
if err := s.db.Load(lr); err != nil {
resp.Error = err.Error()
resp.Error = fmt.Sprintf("remote node failed to load: %s", err.Error())
}
}

View File

@@ -660,13 +660,13 @@ func (s *Service) handleBackup(w http.ResponseWriter, r *http.Request) {
username = ""
}
w.Header().Add(ServedByHTTPHeader, addr)
backupErr := s.cluster.Backup(br, addr, makeCredentials(username, password), timeout, w)
if backupErr != nil && backupErr.Error() == "unauthorized" {
http.Error(w, "remote backup not authorized", http.StatusUnauthorized)
return
}
stats.Add(numRemoteBackups, 1)
w.Header().Add(ServedByHTTPHeader, addr)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -756,13 +756,17 @@ func (s *Service) handleLoad(w http.ResponseWriter, r *http.Request) {
username = ""
}
w.Header().Add(ServedByHTTPHeader, addr)
loadErr := s.cluster.Load(lr, addr, makeCredentials(username, password), timeout)
if loadErr != nil && loadErr.Error() == "unauthorized" {
http.Error(w, "remote load not authorized", http.StatusUnauthorized)
if loadErr != nil {
if loadErr.Error() == "unauthorized" {
http.Error(w, "remote load not authorized", http.StatusUnauthorized)
return
}
http.Error(w, loadErr.Error(), http.StatusInternalServerError)
return
}
stats.Add(numRemoteLoads, 1)
w.Header().Add(ServedByHTTPHeader, addr)
// Allow this if block to exit, so response remains as before request
// forwarding was put in place.
}
@@ -1247,13 +1251,13 @@ func (s *Service) execute(w http.ResponseWriter, r *http.Request) {
username = ""
}
w.Header().Add(ServedByHTTPHeader, addr)
results, resultsErr = s.cluster.Execute(er, addr, makeCredentials(username, password), timeout)
if resultsErr != nil && resultsErr.Error() == "unauthorized" {
http.Error(w, "remote execute not authorized", http.StatusUnauthorized)
return
}
stats.Add(numRemoteExecutions, 1)
w.Header().Add(ServedByHTTPHeader, addr)
}
if resultsErr != nil {
@@ -1353,13 +1357,14 @@ func (s *Service) handleQuery(w http.ResponseWriter, r *http.Request) {
if !ok {
username = ""
}
w.Header().Add(ServedByHTTPHeader, addr)
results, resultsErr = s.cluster.Query(qr, addr, makeCredentials(username, password), timeout)
if resultsErr != nil && resultsErr.Error() == "unauthorized" {
http.Error(w, "remote query not authorized", http.StatusUnauthorized)
return
}
stats.Add(numRemoteQueries, 1)
w.Header().Add(ServedByHTTPHeader, addr)
}
if resultsErr != nil {

View File

@@ -885,7 +885,7 @@ func (s *Store) Load(lr *command.LoadRequest) error {
s.dbAppliedIndex = af.Index()
s.dbAppliedIndexMu.Unlock()
stats.Add(numLoads, 1)
s.logger.Printf("node loaded in %s", time.Since(startT))
s.logger.Printf("node loaded with in %s (%d bytes)", time.Since(startT), len(b))
return af.Error()
}