项目文件夹

文件
wehub-resource-sync 75f3dd141c
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CI and Release / lint-frontend (push) Has been cancelled
CI and Release / dockerfile-scan (push) Has been cancelled
CI and Release / test-frontend (push) Has been cancelled
CI and Release / lint-verification-agent (push) Has been cancelled
CI and Release / test-verification-agent (push) Has been cancelled
CI and Release / e2e-verification-agent (push) Has been cancelled
CI and Release / test-backend (push) Has been cancelled
CI and Release / build-dev-image (push) Has been cancelled
CI and Release / push-dev-image (push) Has been cancelled
CI and Release / build-image (push) Has been cancelled
CI and Release / build-verification-image (push) Has been cancelled
CI and Release / determine-version (push) Has been cancelled
CI and Release / push-image (push) Has been cancelled
CI and Release / push-verification-image (12) (push) Has been cancelled
CI and Release / lint-backend (push) Has been cancelled
CI and Release / push-verification-image (17) (push) Has been cancelled
CI and Release / push-verification-image (18) (push) Has been cancelled
CI and Release / release (push) Has been cancelled
CI and Release / publish-helm-chart (push) Has been cancelled
CI and Release / push-verification-image (13) (push) Has been cancelled
CI and Release / push-verification-image (14) (push) Has been cancelled
CI and Release / push-verification-image (15) (push) Has been cancelled
CI and Release / push-verification-image (16) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:11:07 +08:00

82 行
2.2 KiB
Go

// Adapted from wal-g/internal/databases/postgres/timeline.go.
// Copyright 2017 Citus Data Inc. Licensed under the Apache License, Version 2.0.
package walmath
import (
"fmt"
"regexp"
"strconv"
)
var regexpTimelineAndLogSegNo = regexp.MustCompile(PatternTimelineAndLogSegNo)
func ParseWALFilename(name string) (timelineID uint32, logSegNo uint64, err error) {
return ParseWALFilenameWithSize(name, WalSegmentSize)
}
func ParseWALFilenameWithSize(name string, segmentSize uint64) (timelineID uint32, logSegNo uint64, err error) {
if len(name) != 24 {
return 0, 0, NotWalFilenameError{Filename: name}
}
if segmentSize == 0 || 0x100000000%segmentSize != 0 {
return 0, 0, IncorrectLogSegNoError{Filename: name}
}
timelineID64, err := strconv.ParseUint(name[0:8], 0x10, hexUint32Bits)
if err != nil {
return 0, 0, NotWalFilenameError{Filename: name}
}
logSegNoHi, err := strconv.ParseUint(name[8:16], 0x10, hexUint32Bits)
if err != nil {
return 0, 0, NotWalFilenameError{Filename: name}
}
logSegNoLo, err := strconv.ParseUint(name[16:24], 0x10, hexUint32Bits)
if err != nil {
return 0, 0, NotWalFilenameError{Filename: name}
}
segmentsPerLogID := 0x100000000 / segmentSize
if logSegNoLo >= segmentsPerLogID {
return 0, 0, IncorrectLogSegNoError{Filename: name}
}
timelineID = uint32(timelineID64)
logSegNo = logSegNoHi*segmentsPerLogID + logSegNoLo
return timelineID, logSegNo, nil
}
func formatWALFileName(timeline uint32, logSegNo uint64) string {
return fmt.Sprintf(walFileFormat, timeline, logSegNo/xLogSegmentsPerXLogID, logSegNo%xLogSegmentsPerXLogID)
}
func GetNextWalFilename(name string) (string, error) {
timelineID, logSegNo, err := ParseWALFilename(name)
if err != nil {
return "", err
}
return formatWALFileName(timelineID, logSegNo+1), nil
}
func TryFetchTimelineAndLogSegNo(objectName string) (uint32, uint64, bool) {
foundLsn := regexpTimelineAndLogSegNo.FindAllString(objectName, maxCountOfLSN)
if len(foundLsn) > 0 {
timelineID, logSegNo, err := ParseWALFilename(foundLsn[0])
if err == nil {
return timelineID, logSegNo, true
}
}
return 0, 0, false
}
func IsWalFilename(filename string) bool {
_, _, err := ParseWALFilename(filename)
return err == nil
}