-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #935 from iotaledger/remove/snap-endpoint-target-slot
Remove target slot from `engine.WriteSnapshot`
- Loading branch information
Showing
7 changed files
with
198 additions
and
173 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,24 @@ | ||
package management | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/labstack/echo/v4" | ||
|
||
"github.com/iotaledger/hive.go/ierrors" | ||
"github.com/iotaledger/inx-app/pkg/httpserver" | ||
"github.com/iotaledger/iota.go/v4/api" | ||
) | ||
|
||
func createSnapshots(c echo.Context) (*api.CreateSnapshotResponse, error) { | ||
func createSnapshots(_ echo.Context) (*api.CreateSnapshotResponse, error) { | ||
if deps.Protocol.Engines.Main.Get().IsSnapshotting() || deps.Protocol.Engines.Main.Get().Storage.IsPruning() { | ||
return nil, ierrors.WithMessage(echo.ErrServiceUnavailable, "node is already creating a snapshot or pruning is running") | ||
} | ||
|
||
request := &api.CreateSnapshotRequest{} | ||
if err := c.Bind(request); err != nil { | ||
return nil, ierrors.WithMessagef(httpserver.ErrInvalidParameter, "invalid request: %w", err) | ||
} | ||
if request.Slot == 0 { | ||
return nil, ierrors.WithMessage(httpserver.ErrInvalidParameter, "slot needs to be specified") | ||
} | ||
|
||
directory := filepath.Dir(deps.SnapshotFilePath) | ||
fileName := filepath.Base(deps.SnapshotFilePath) | ||
fileExt := filepath.Ext(fileName) | ||
fileNameWithoutExt := strings.TrimSuffix(fileName, fileExt) | ||
filePath := filepath.Join(directory, fmt.Sprintf("%s_%d%s", fileNameWithoutExt, request.Slot, fileExt)) | ||
|
||
if err := deps.Protocol.Engines.Main.Get().WriteSnapshot(filePath, request.Slot); err != nil { | ||
targetSlot, filePath, err := deps.Protocol.Engines.Main.Get().ExportSnapshot(deps.SnapshotFilePath, true, true) | ||
if err != nil { | ||
return nil, ierrors.WithMessagef(echo.ErrInternalServerError, "creating snapshot failed: %w", err) | ||
} | ||
|
||
return &api.CreateSnapshotResponse{ | ||
Slot: request.Slot, | ||
Slot: targetSlot, | ||
FilePath: filePath, | ||
}, nil | ||
} |
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.