mirror of
https://github.com/rqlite/rqlite.git
synced 2022-10-30 02:37:32 +03:00
Fix remote-load error handling
Error from remote node was being dropped.
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user