satellite/metainfo: UpdateProjectSegmentUsage enabled only with segment validation

updating project segment usage entry to redis is enabled only if
segment validation is enabled in config value, so no incompatible
changes will be added while deployment.

Change-Id: I1288cb9ff0a8a00f095dc94e20d2f14393e9a613
This commit is contained in:
Michał Niewrzał 2022-01-13 10:13:10 +01:00
parent 3a987ac00f
commit 18ab464b51

View File

@ -1977,21 +1977,23 @@ func (endpoint *Endpoint) CommitSegment(ctx context.Context, req *pb.SegmentComm
return nil, endpoint.convertMetabaseErr(err) return nil, endpoint.convertMetabaseErr(err)
} }
// Update the current segment cache value incrementing by 1 as we commit single segment. if endpoint.config.ProjectLimits.ValidateSegmentLimit {
err = endpoint.projectUsage.UpdateProjectSegmentUsage(ctx, keyInfo.ProjectID, 1) // Update the current segment cache value incrementing by 1 as we commit single segment.
if err != nil { err = endpoint.projectUsage.UpdateProjectSegmentUsage(ctx, keyInfo.ProjectID, 1)
if errs2.IsCanceled(err) { if err != nil {
return nil, rpcstatus.Wrap(rpcstatus.Canceled, err) if errs2.IsCanceled(err) {
} return nil, rpcstatus.Wrap(rpcstatus.Canceled, err)
}
// log it and continue. it's most likely our own fault that we couldn't // log it and continue. it's most likely our own fault that we couldn't
// track it, and the only thing that will be affected is our per-project // track it, and the only thing that will be affected is our per-project
// segment limits. // segment limits.
endpoint.log.Error( endpoint.log.Error(
"Could not track the new project's segment usage when committing segment", "Could not track the new project's segment usage when committing segment",
zap.Stringer("Project ID", keyInfo.ProjectID), zap.Stringer("Project ID", keyInfo.ProjectID),
zap.Error(err), zap.Error(err),
) )
}
} }
return &pb.SegmentCommitResponse{ return &pb.SegmentCommitResponse{
@ -2113,21 +2115,23 @@ func (endpoint *Endpoint) MakeInlineSegment(ctx context.Context, req *pb.Segment
endpoint.log.Info("Inline Segment Upload", zap.Stringer("Project ID", keyInfo.ProjectID), zap.String("operation", "put"), zap.String("type", "inline")) endpoint.log.Info("Inline Segment Upload", zap.Stringer("Project ID", keyInfo.ProjectID), zap.String("operation", "put"), zap.String("type", "inline"))
mon.Meter("req_put_inline").Mark(1) mon.Meter("req_put_inline").Mark(1)
// Update the current segment cache value incrementing by 1 as we commit single segment. if endpoint.config.ProjectLimits.ValidateSegmentLimit {
err = endpoint.projectUsage.UpdateProjectSegmentUsage(ctx, keyInfo.ProjectID, 1) // Update the current segment cache value incrementing by 1 as we commit single segment.
if err != nil { err = endpoint.projectUsage.UpdateProjectSegmentUsage(ctx, keyInfo.ProjectID, 1)
if errs2.IsCanceled(err) { if err != nil {
return nil, rpcstatus.Wrap(rpcstatus.Canceled, err) if errs2.IsCanceled(err) {
} return nil, rpcstatus.Wrap(rpcstatus.Canceled, err)
}
// log it and continue. it's most likely our own fault that we couldn't // log it and continue. it's most likely our own fault that we couldn't
// track it, and the only thing that will be affected is our per-project // track it, and the only thing that will be affected is our per-project
// segment limits. // segment limits.
endpoint.log.Error( endpoint.log.Error(
"Could not track the new project's segment usage when committing segment", "Could not track the new project's segment usage when committing segment",
zap.Stringer("Project ID", keyInfo.ProjectID), zap.Stringer("Project ID", keyInfo.ProjectID),
zap.Error(err), zap.Error(err),
) )
}
} }
return &pb.SegmentMakeInlineResponse{}, nil return &pb.SegmentMakeInlineResponse{}, nil