mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-08 15:41:15 +02:00
* rust volume: accept odd-length needle id hex in file ids Go formats the needle id with strconv.FormatUint and parses it back with strconv.ParseUint, neither of which pads to an even number of hex digits. hex::decode rejected such file ids with "Odd number of digits", so volume.fsck could not purge orphans from a rust volume server. Parse the needle id and cookie with from_str_radix, matching Go's ParseNeedleId and ParseCookie. * storage: emit even-length needle id hex in NeedleId.FileId volume.fsck and volume.check_disk build purge file ids here with unpadded FormatUint hex, while every other fid formatter strips whole leading zero bytes. Pad to even length so the output matches the canonical fid format and strict hex parsers accept it.
83 lines
2.1 KiB
Go
83 lines
2.1 KiB
Go
package needle
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
|
)
|
|
|
|
func TestParseFileIdFromString(t *testing.T) {
|
|
fidStr1 := "100,12345678"
|
|
_, err := ParseFileIdFromString(fidStr1)
|
|
if err == nil {
|
|
t.Errorf("%s : KeyHash is too short", fidStr1)
|
|
}
|
|
|
|
fidStr1 = "100, 12345678"
|
|
_, err = ParseFileIdFromString(fidStr1)
|
|
if err == nil {
|
|
t.Errorf("%s : needleId invalid syntax", fidStr1)
|
|
}
|
|
|
|
fidStr1 = "100,123456789"
|
|
_, err = ParseFileIdFromString(fidStr1)
|
|
if err != nil {
|
|
t.Errorf("%s : should be OK", fidStr1)
|
|
}
|
|
|
|
var fileId *FileId
|
|
fidStr1 = "100,123456789012345678901234"
|
|
fileId, err = ParseFileIdFromString(fidStr1)
|
|
if err != nil {
|
|
t.Errorf("%s : should be OK", fidStr1)
|
|
}
|
|
if !(fileId.VolumeId == VolumeId(100) &&
|
|
fileId.Key == types.NeedleId(0x1234567890123456) &&
|
|
fileId.Cookie == types.Cookie(types.Uint32ToCookie(uint32(0x78901234)))) {
|
|
t.Errorf("src : %s, dest : %v", fidStr1, fileId)
|
|
}
|
|
|
|
fidStr1 = "100,abcd0000abcd"
|
|
fileId, err = ParseFileIdFromString(fidStr1)
|
|
if err != nil {
|
|
t.Errorf("%s : should be OK", fidStr1)
|
|
}
|
|
if !(fileId.VolumeId == VolumeId(100) &&
|
|
fileId.Key == types.NeedleId(0xabcd) &&
|
|
fileId.Cookie == types.Cookie(types.Uint32ToCookie(uint32(0xabcd)))) {
|
|
t.Errorf("src : %s, dest : %v", fidStr1, fileId)
|
|
}
|
|
|
|
fidStr1 = "100,1234567890123456789012345"
|
|
_, err = ParseFileIdFromString(fidStr1)
|
|
if err == nil {
|
|
t.Errorf("%s : needleId is too long", fidStr1)
|
|
}
|
|
}
|
|
|
|
func TestNeedleIdFileId(t *testing.T) {
|
|
tests := []struct {
|
|
key types.NeedleId
|
|
volumeId uint32
|
|
want string
|
|
}{
|
|
{types.NeedleId(1), 3, "3,0100000000"},
|
|
{types.NeedleId(0x123), 3, "3,012300000000"},
|
|
{types.NeedleId(0x1234), 7, "7,123400000000"},
|
|
}
|
|
for _, tt := range tests {
|
|
fid := tt.key.FileId(tt.volumeId)
|
|
if fid != tt.want {
|
|
t.Errorf("NeedleId(%d).FileId(%d) = %s, want %s", tt.key, tt.volumeId, fid, tt.want)
|
|
}
|
|
fileId, err := ParseFileIdFromString(fid)
|
|
if err != nil {
|
|
t.Errorf("%s : should be OK: %v", fid, err)
|
|
continue
|
|
}
|
|
if fileId.VolumeId != VolumeId(tt.volumeId) || fileId.Key != tt.key || fileId.Cookie != 0 {
|
|
t.Errorf("src : %s, dest : %v", fid, fileId)
|
|
}
|
|
}
|
|
}
|