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