fix(access): remove token if last slice only has one blob

. #1000155215

Signed-off-by: slasher <shenjie1@oppo.com>
This commit is contained in:
slasher 2025-06-03 14:50:11 +08:00
parent d4288318de
commit 2ebab23f6c
4 changed files with 63 additions and 4 deletions

View File

@ -573,6 +573,15 @@ func TestAccessServiceTokens(t *testing.T) {
return
}
if loc.Slices[len(loc.Slices)-1].Count == 1 {
require.Equal(t, len(loc.Slices), len(tokens))
idx := len(loc.Slices) - 1
blob := loc.Slices[idx]
token := security.DecodeToken(tokens[idx])
require.True(t, token.IsValid(loc.ClusterID, blob.Vid, blob.MinSliceID, lastSize, skey))
return
}
require.Equal(t, len(loc.Slices)+1, len(tokens))
for ii := 0; ii < len(loc.Slices)-1; ii++ {
token := security.DecodeToken(tokens[ii])

View File

@ -528,10 +528,13 @@ func (h *Handler) readOneShard(ctx context.Context, serviceController controller
}
if err != nil {
if err == errPunishedDisk || err == errCanceledReadShard {
if err == errPunishedDisk {
span.Warnf("read %s on %s: %s", blob.ID(), vuid.ID(), err.Error())
return shardResult
}
if err == errCanceledReadShard {
return shardResult
}
span.Warnf("rpc read %s on %s: %s", blob.ID(), vuid.ID(), errors.Detail(err))
return shardResult
}

View File

@ -192,9 +192,11 @@ func genTokens(location *proto.Location) []string {
if idx == len(location.Slices)-1 && lastSize > 0 {
count--
}
tokens = append(tokens, EncodeToken(NewUploadToken(location.ClusterID,
blob.Vid, blob.MinSliceID, count,
location.SliceSize, _tokenExpiration, tokenSecretKeys[0][:])))
if count > 0 {
tokens = append(tokens, EncodeToken(NewUploadToken(location.ClusterID,
blob.Vid, blob.MinSliceID, count,
location.SliceSize, _tokenExpiration, tokenSecretKeys[0][:])))
}
}
// token of the last blob

View File

@ -181,6 +181,51 @@ func TestAccessServiceLocationSignCrc(t *testing.T) {
}
}
func TestAccessServiceTokenLast(t *testing.T) {
{
loc := &proto.Location{
ClusterID: 1,
Size_: 4097,
SliceSize: 1024,
Slices: []proto.Slice{{
MinSliceID: 11,
Vid: 100,
Count: 4,
}, {
MinSliceID: 22,
Vid: 200,
Count: 1,
}},
}
tokens := genTokens(loc)
require.Equal(t, 2, len(tokens))
token := DecodeToken(tokens[0])
require.True(t, token.IsValid(1, 100, 11, 1024, TokenSecretKeys()[0][:]))
token = DecodeToken(tokens[1])
require.True(t, token.IsValid(1, 200, 22, 1, TokenSecretKeys()[0][:]))
}
{
loc := &proto.Location{
ClusterID: 1,
Size_: 4096,
SliceSize: 1024,
Slices: []proto.Slice{{
MinSliceID: 11,
Vid: 100,
Count: 4,
}},
}
tokens := genTokens(loc)
require.Equal(t, 1, len(tokens))
token := DecodeToken(tokens[0])
require.True(t, token.IsValid(1, 100, 11, 1024, TokenSecretKeys()[0][:]))
}
}
func calcCrcWithoutMagic(loc *proto.Location) (uint32, error) {
crcWriter := crc32.New(_crcTable)