2020-12-02 23:45:25 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/util"
|
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/object"
|
2020-12-02 23:45:25 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Get serves a request to get an object by address, and returns Streamer instance.
|
|
|
|
func (s *Service) Get(ctx context.Context, prm Prm) error {
|
2020-12-09 10:32:33 +00:00
|
|
|
return s.get(ctx, prm.commonPrm).err
|
2020-12-07 17:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetRange serves a request to get an object by address, and returns Streamer instance.
|
|
|
|
func (s *Service) GetRange(ctx context.Context, prm RangePrm) error {
|
2021-05-18 12:13:40 +00:00
|
|
|
return s.getRange(ctx, prm)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) getRange(ctx context.Context, prm RangePrm, opts ...execOption) error {
|
|
|
|
return s.get(ctx, prm.commonPrm, append(opts, withPayloadRange(prm.rng))...).err
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-08 16:18:24 +00:00
|
|
|
func (s *Service) GetRangeHash(ctx context.Context, prm RangeHashPrm) (*RangeHashRes, error) {
|
|
|
|
hashes := make([][]byte, 0, len(prm.rngs))
|
|
|
|
|
|
|
|
for _, rng := range prm.rngs {
|
|
|
|
h := prm.hashGen()
|
|
|
|
|
2022-02-07 13:34:02 +00:00
|
|
|
// For big ranges we could fetch range-hashes from different nodes and concatenate them locally.
|
|
|
|
// However,
|
|
|
|
// 1. Potential gains are insignificant when operating in the Internet given typical latencies and losses.
|
|
|
|
// 2. Parallel solution is more complex in terms of code.
|
|
|
|
// 3. TZ-hash is likely to be disabled in private installations.
|
2020-12-08 16:18:24 +00:00
|
|
|
rngPrm := RangePrm{
|
|
|
|
commonPrm: prm.commonPrm,
|
|
|
|
}
|
|
|
|
|
2022-03-15 12:11:35 +00:00
|
|
|
rngPrm.SetRange(&rng)
|
2020-12-08 16:18:24 +00:00
|
|
|
rngPrm.SetChunkWriter(&hasherWrapper{
|
2021-01-11 13:50:49 +00:00
|
|
|
hash: util.NewSaltingWriter(h, prm.salt),
|
2020-12-08 16:18:24 +00:00
|
|
|
})
|
|
|
|
|
2021-05-20 08:04:20 +00:00
|
|
|
if err := s.getRange(ctx, rngPrm); err != nil {
|
2020-12-08 16:18:24 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
hashes = append(hashes, h.Sum(nil))
|
|
|
|
}
|
|
|
|
|
|
|
|
return &RangeHashRes{
|
|
|
|
hashes: hashes,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
// Head reads object header from container.
|
|
|
|
//
|
|
|
|
// Returns ErrNotFound if the header was not received for the call.
|
|
|
|
// Returns SplitInfoError if object is virtual and raw flag is set.
|
|
|
|
func (s *Service) Head(ctx context.Context, prm HeadPrm) error {
|
|
|
|
return s.get(ctx, prm.commonPrm, headOnly()).err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) get(ctx context.Context, prm commonPrm, opts ...execOption) statusError {
|
2020-12-02 23:45:25 +00:00
|
|
|
exec := &execCtx{
|
2020-12-09 10:32:33 +00:00
|
|
|
svc: s,
|
|
|
|
ctx: ctx,
|
|
|
|
prm: RangePrm{
|
|
|
|
commonPrm: prm,
|
|
|
|
},
|
2022-12-30 11:00:01 +00:00
|
|
|
splitInfo: object.NewSplitInfo(),
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
for i := range opts {
|
|
|
|
opts[i](exec)
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
exec.setLogger(s.log)
|
|
|
|
|
|
|
|
exec.execute()
|
|
|
|
|
|
|
|
return exec.statusError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) execute() {
|
|
|
|
exec.log.Debug("serving request...")
|
|
|
|
|
|
|
|
// perform local operation
|
|
|
|
exec.executeLocal()
|
|
|
|
|
|
|
|
exec.analyzeStatus(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) analyzeStatus(execCnr bool) {
|
|
|
|
// analyze local result
|
|
|
|
switch exec.status {
|
|
|
|
case statusOK:
|
|
|
|
exec.log.Debug("operation finished successfully")
|
|
|
|
case statusINHUMED:
|
|
|
|
exec.log.Debug("requested object was marked as removed")
|
|
|
|
case statusVIRTUAL:
|
|
|
|
exec.log.Debug("requested object is virtual")
|
|
|
|
exec.assemble()
|
2020-12-07 17:49:47 +00:00
|
|
|
case statusOutOfRange:
|
|
|
|
exec.log.Debug("requested range is out of object bounds")
|
2020-12-02 23:45:25 +00:00
|
|
|
default:
|
|
|
|
exec.log.Debug("operation finished with error",
|
|
|
|
zap.String("error", exec.err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
if execCnr {
|
|
|
|
exec.executeOnContainer()
|
|
|
|
exec.analyzeStatus(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|