2020-12-03 02:45:25 +03:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-04-12 17:35:10 +03:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 16:38:26 +03:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
2023-07-06 15:36:41 +03:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2020-12-03 02:45:25 +03: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 {
|
2023-04-24 10:33:12 +03:00
|
|
|
return s.get(ctx, RequestParameters{
|
|
|
|
commonPrm: prm.commonPrm,
|
|
|
|
})
|
2020-12-07 20:49:47 +03: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 {
|
2023-04-24 10:33:12 +03:00
|
|
|
return s.get(ctx, RequestParameters{
|
|
|
|
commonPrm: prm.commonPrm,
|
|
|
|
rng: prm.rng,
|
|
|
|
})
|
2021-05-18 15:13:40 +03:00
|
|
|
}
|
2023-10-31 14:56:55 +03:00
|
|
|
|
2020-12-08 19:18:24 +03: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 16:34:02 +03: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.
|
2023-04-24 10:33:12 +03:00
|
|
|
reqPrm := RequestParameters{
|
2020-12-08 19:18:24 +03:00
|
|
|
commonPrm: prm.commonPrm,
|
2023-04-24 10:33:12 +03:00
|
|
|
rng: &rng,
|
2020-12-08 19:18:24 +03:00
|
|
|
}
|
2023-04-24 10:33:12 +03:00
|
|
|
reqPrm.SetChunkWriter(&hasherWrapper{
|
2021-01-11 16:50:49 +03:00
|
|
|
hash: util.NewSaltingWriter(h, prm.salt),
|
2020-12-08 19:18:24 +03:00
|
|
|
})
|
|
|
|
|
2023-04-24 10:33:12 +03:00
|
|
|
if err := s.get(ctx, reqPrm); err != nil {
|
2020-12-08 19:18:24 +03:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
hashes = append(hashes, h.Sum(nil))
|
|
|
|
}
|
|
|
|
|
|
|
|
return &RangeHashRes{
|
|
|
|
hashes: hashes,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-12-09 13:32:33 +03: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 {
|
2023-04-24 10:33:12 +03:00
|
|
|
return s.get(ctx, RequestParameters{
|
|
|
|
head: true,
|
|
|
|
commonPrm: prm.commonPrm,
|
|
|
|
})
|
2020-12-09 13:32:33 +03:00
|
|
|
}
|
|
|
|
|
2023-04-24 10:33:12 +03:00
|
|
|
func (s *Service) get(ctx context.Context, prm RequestParameters) error {
|
2023-04-24 12:09:43 +03:00
|
|
|
exec := &request{
|
2023-04-24 11:36:15 +03:00
|
|
|
keyStore: s.keyStore,
|
|
|
|
traverserGenerator: s.traverserGenerator,
|
|
|
|
remoteStorageConstructor: s.remoteStorageConstructor,
|
|
|
|
epochSource: s.epochSource,
|
|
|
|
localStorage: s.localStorage,
|
|
|
|
|
2023-04-24 10:33:12 +03:00
|
|
|
prm: prm,
|
2023-07-06 15:36:41 +03:00
|
|
|
infoSplit: objectSDK.NewSplitInfo(),
|
2020-12-03 02:45:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
exec.setLogger(s.log)
|
|
|
|
|
2023-03-31 14:49:40 +03:00
|
|
|
exec.execute(ctx)
|
2020-12-03 02:45:25 +03:00
|
|
|
|
2023-04-20 10:58:43 +03:00
|
|
|
return exec.statusError.err
|
2020-12-03 02:45:25 +03:00
|
|
|
}
|
|
|
|
|
2023-04-24 12:09:43 +03:00
|
|
|
func (exec *request) execute(ctx context.Context) {
|
2023-04-13 15:51:36 +03:00
|
|
|
exec.log.Debug(logs.ServingRequest)
|
2020-12-03 02:45:25 +03:00
|
|
|
|
|
|
|
// perform local operation
|
2023-03-31 14:49:40 +03:00
|
|
|
exec.executeLocal(ctx)
|
2020-12-03 02:45:25 +03:00
|
|
|
|
2023-03-31 14:49:40 +03:00
|
|
|
exec.analyzeStatus(ctx, true)
|
2020-12-03 02:45:25 +03:00
|
|
|
}
|
|
|
|
|
2023-04-24 12:09:43 +03:00
|
|
|
func (exec *request) analyzeStatus(ctx context.Context, execCnr bool) {
|
2020-12-03 02:45:25 +03:00
|
|
|
// analyze local result
|
|
|
|
switch exec.status {
|
|
|
|
case statusOK:
|
2023-04-13 15:51:36 +03:00
|
|
|
exec.log.Debug(logs.OperationFinishedSuccessfully)
|
2020-12-03 02:45:25 +03:00
|
|
|
case statusINHUMED:
|
2023-04-12 17:35:10 +03:00
|
|
|
exec.log.Debug(logs.GetRequestedObjectWasMarkedAsRemoved)
|
2020-12-03 02:45:25 +03:00
|
|
|
case statusVIRTUAL:
|
2023-04-12 17:35:10 +03:00
|
|
|
exec.log.Debug(logs.GetRequestedObjectIsVirtual)
|
2023-03-31 14:49:40 +03:00
|
|
|
exec.assemble(ctx)
|
2020-12-07 20:49:47 +03:00
|
|
|
case statusOutOfRange:
|
2023-04-12 17:35:10 +03:00
|
|
|
exec.log.Debug(logs.GetRequestedRangeIsOutOfObjectBounds)
|
2020-12-03 02:45:25 +03:00
|
|
|
default:
|
2023-04-13 15:51:36 +03:00
|
|
|
exec.log.Debug(logs.OperationFinishedWithError,
|
2023-04-24 13:11:44 +03:00
|
|
|
zap.Error(exec.err),
|
2020-12-03 02:45:25 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
if execCnr {
|
2023-03-31 14:49:40 +03:00
|
|
|
exec.executeOnContainer(ctx)
|
|
|
|
exec.analyzeStatus(ctx, false)
|
2020-12-03 02:45:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|