-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Restore): Async restore operations. (#5704)
Previously, restore operations blocked the HTTP response until they were completed. This PR changes the flow so that the request returns immediately after the restore is proposed to the cluster. The request returns a unique ID for the restore operation that can be used to track the status of the response. Fixes DGRAPH-1697
- Loading branch information
Showing
10 changed files
with
337 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2020 Dgraph Labs, Inc. and Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package admin | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/dgraph-io/dgraph/graphql/resolve" | ||
"github.com/dgraph-io/dgraph/graphql/schema" | ||
"github.com/dgraph-io/dgraph/worker" | ||
) | ||
|
||
type restoreStatus struct { | ||
Status string `json:"status,omitempty"` | ||
Errors []string `json:"errors,omitempty"` | ||
} | ||
|
||
func unknownStatus(q schema.Query, err error) *resolve.Resolved { | ||
return &resolve.Resolved{ | ||
Data: map[string]interface{}{q.Name(): map[string]interface{}{ | ||
"status": "UNKNOWN", | ||
}}, | ||
Field: q, | ||
Err: schema.GQLWrapLocationf(err, q.Location(), "resolving %s failed", q.Name()), | ||
} | ||
} | ||
|
||
func resolveRestoreStatus(ctx context.Context, q schema.Query) *resolve.Resolved { | ||
restoreId := int(q.ArgValue("restoreId").(int64)) | ||
status, err := worker.ProcessRestoreStatus(ctx, restoreId) | ||
if err != nil { | ||
return unknownStatus(q, err) | ||
} | ||
if status == nil { | ||
return unknownStatus(q, err) | ||
} | ||
convertedStatus := convertStatus(status) | ||
|
||
b, err := json.Marshal(convertedStatus) | ||
if err != nil { | ||
return unknownStatus(q, err) | ||
} | ||
result := make(map[string]interface{}) | ||
err = json.Unmarshal(b, &result) | ||
if err != nil { | ||
return unknownStatus(q, err) | ||
} | ||
|
||
return &resolve.Resolved{ | ||
Data: map[string]interface{}{q.Name(): result}, | ||
Field: q, | ||
} | ||
} | ||
|
||
func convertStatus(status *worker.RestoreStatus) *restoreStatus { | ||
if status == nil { | ||
return nil | ||
} | ||
res := &restoreStatus{ | ||
Status: status.Status, | ||
Errors: make([]string, len(status.Errors)), | ||
} | ||
for i, err := range status.Errors { | ||
res.Errors[i] = err.Error() | ||
} | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.