Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions vfs/lfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ func checkpointFileName(regionID int64) string {
}

// serializedIndex serializes the index to a recoverable file snapshot record format:
// | INUM 8 | RID 8 | POS 8 | LEN 4 | EAT 8 | CAT 8 | T 1 | CRC32 4 | = len(48 bytes)
// | INUM 8 | RID 8 | POS 8 | EAT 8 | CAT 8 | LEN 4 | CRC32 4 | = len(48 bytes)
func serializedIndex(buf *bytes.Buffer, inum uint64, inode *inode) ([]byte, error) {
// reset a byte buffer
buf.Reset()
Expand All @@ -1220,9 +1220,9 @@ func serializedIndex(buf *bytes.Buffer, inum uint64, inode *inode) ([]byte, erro
binary.Write(buf, binary.LittleEndian, inum)
binary.Write(buf, binary.LittleEndian, inode.RegionID)
binary.Write(buf, binary.LittleEndian, inode.Position)
binary.Write(buf, binary.LittleEndian, inode.Length)
binary.Write(buf, binary.LittleEndian, inode.ExpiredAt)
binary.Write(buf, binary.LittleEndian, inode.CreatedAt)
binary.Write(buf, binary.LittleEndian, inode.Length)

// Calculate CRC32 checksum
checksum := crc32.ChecksumIEEE(buf.Bytes())
Expand All @@ -1235,7 +1235,7 @@ func serializedIndex(buf *bytes.Buffer, inum uint64, inode *inode) ([]byte, erro
}

// deserializedIndex restores the index file snapshot to an in-memory struct:
// | INUM 8 | RID 8 | OFS 8 | LEN 4 | EAT 8 | CAT 8 | CRC32 4 | = len(48 bytes)
// | INUM 8 | RID 8 | OFS 8 | EAT 8 | CAT 8 | LEN 4 | CRC32 4 | = len(48 bytes)
func deserializedIndex(data []byte) (uint64, *inode, error) {
buf := bytes.NewReader(data)
var inum uint64
Expand All @@ -1256,17 +1256,17 @@ func deserializedIndex(data []byte) (uint64, *inode, error) {
return 0, nil, err
}

err = binary.Read(buf, binary.LittleEndian, &inode.Length)
err = binary.Read(buf, binary.LittleEndian, &inode.ExpiredAt)
if err != nil {
return 0, nil, err
}

err = binary.Read(buf, binary.LittleEndian, &inode.ExpiredAt)
err = binary.Read(buf, binary.LittleEndian, &inode.CreatedAt)
if err != nil {
return 0, nil, err
}

err = binary.Read(buf, binary.LittleEndian, &inode.CreatedAt)
err = binary.Read(buf, binary.LittleEndian, &inode.Length)
if err != nil {
return 0, nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions vfs/lfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func TestSerializedIndex(t *testing.T) {
in := &inode{
RegionID: 1234,
Position: 5678,
Length: 100,
ExpiredAt: 1617181723,
CreatedAt: 1617181623,
Length: 100,
}

buf := new(bytes.Buffer)
Expand Down Expand Up @@ -68,15 +68,15 @@ func TestSerializedIndex(t *testing.T) {
if dnode.Position != in.Position {
t.Errorf("expected Offset %d, got %d", in.Position, dnode.RegionID)
}
if dnode.Length != in.Length {
t.Errorf("expected Length %d, got %d", in.Length, dnode.Length)
}
if dnode.ExpiredAt != in.ExpiredAt {
t.Errorf("expected ExpiredAt %d, got %d", in.ExpiredAt, dnode.ExpiredAt)
}
if dnode.CreatedAt != in.CreatedAt {
t.Errorf("expected CreatedAt %d, got %d", in.CreatedAt, dnode.CreatedAt)
}
if dnode.Length != in.Length {
t.Errorf("expected Length %d, got %d", in.Length, dnode.Length)
}

}

Expand Down