This commit is contained in:
RPRX
2026-11-25 16:35:49 +00:00
committed by GitHub
parent b56ffef338
commit 499a9e1df5
14 changed files with 3551 additions and 2299 deletions
+42
View File
@@ -0,0 +1,42 @@
package xdrive
import (
"bytes"
"crypto/sha256"
"encoding/binary"
)
const (
commitSuffix = ".commit"
walCommitMagic = "XDWALC01"
walCommitBytes = 8 + 8 + sha256.Size
)
func (*templateStorage) requiresWALCommit() bool {
return true
}
func requiresWALCommit(storage Storage) bool {
s, ok := storage.(interface{ requiresWALCommit() bool })
return ok && s.requiresWALCommit()
}
func encodeWALCommit(data []byte) []byte {
commit := make([]byte, walCommitBytes)
copy(commit, walCommitMagic)
binary.BigEndian.PutUint64(commit[8:16], uint64(len(data)))
sum := sha256.Sum256(data)
copy(commit[16:], sum[:])
return commit
}
func validWALCommit(commit, data []byte) bool {
if len(commit) != walCommitBytes || string(commit[:8]) != walCommitMagic || len(data) == 0 || len(data) > maxSegmentBytes {
return false
}
if binary.BigEndian.Uint64(commit[8:16]) != uint64(len(data)) {
return false
}
sum := sha256.Sum256(data)
return bytes.Equal(commit[16:], sum[:])
}