2020-12-11 08:04:04 +00:00
|
|
|
package deletesvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
2020-12-11 08:04:04 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Delete serves requests to remote the objects.
|
|
|
|
func (s *Service) Delete(ctx context.Context, prm Prm) error {
|
2022-09-28 12:05:19 +00:00
|
|
|
// If session token is not found we will fail during tombstone PUT.
|
|
|
|
// Here we fail immediately to ensure no unnecessary network communication is done.
|
|
|
|
if tok := prm.common.SessionToken(); tok != nil {
|
|
|
|
_, err := s.keyStorage.GetKey(&util.SessionInfo{
|
|
|
|
ID: tok.ID(),
|
|
|
|
Owner: tok.Issuer(),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
exec := &execCtx{
|
|
|
|
svc: s,
|
|
|
|
prm: prm,
|
|
|
|
}
|
|
|
|
|
|
|
|
exec.setLogger(s.log)
|
|
|
|
|
2023-04-04 09:45:59 +00:00
|
|
|
exec.execute(ctx)
|
2020-12-11 08:04:04 +00:00
|
|
|
|
|
|
|
return exec.statusError.err
|
|
|
|
}
|
|
|
|
|
2023-04-04 09:45:59 +00:00
|
|
|
func (exec *execCtx) execute(ctx context.Context) {
|
2023-04-13 12:51:36 +00:00
|
|
|
exec.log.Debug(logs.ServingRequest)
|
2020-12-11 08:04:04 +00:00
|
|
|
|
|
|
|
// perform local operation
|
2023-04-04 09:45:59 +00:00
|
|
|
exec.executeLocal(ctx)
|
2020-12-11 08:04:04 +00:00
|
|
|
|
|
|
|
exec.analyzeStatus(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) analyzeStatus(execCnr bool) {
|
|
|
|
// analyze local result
|
|
|
|
switch exec.status {
|
|
|
|
case statusOK:
|
2023-04-13 12:51:36 +00:00
|
|
|
exec.log.Debug(logs.OperationFinishedSuccessfully)
|
2020-12-11 08:04:04 +00:00
|
|
|
default:
|
2023-04-13 12:51:36 +00:00
|
|
|
exec.log.Debug(logs.OperationFinishedWithError,
|
2020-12-11 08:04:04 +00:00
|
|
|
zap.String("error", exec.err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
if execCnr {
|
|
|
|
exec.executeOnContainer()
|
|
|
|
exec.analyzeStatus(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|