walparser

package
v0.12.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2024 License: MIT, Apache-2.0 Imports: 7 Imported by: 0

README

Why copy code?

The code in this directory has been copied from https://github.com/wal-g/wal-g/tree/master/internal/walparser.

It cannot be used directly because is an internal package of the wal-g module.

Thanks :)

Documentation

Index

Constants

View Source
const (
	RmXlogID = iota
	RmXactID
	RmSmgrID
	RmClogID
	RmDBaseID
	RmTblSpcID
	RmMultiXactID
	RmRelMapID
	RmStandbyID
	RmHeap2ID
	RmHeapID
	RmBTreeID
	RmHashID
	RmGinID
	RmGistID
	RmSeqID
	RmSPGistID
	RmBrinID
	RmCommitTSID
	RmReplOriginID
	RmGenericID
	RmLogicalMsgID

	RmNextFreeID
)
View Source
const (
	WalPageSize         uint16 = 8192
	BlockSize           uint16 = 8192
	XLogRecordAlignment        = 8
)
View Source
const (

	/* When record crosses page boundary, set this flag in new page's header */
	XlpFirstIsContRecord = 0x0001
	/* This flag indicates a "long" page header */
	XlpLongHeader = 0x0002
	/* This flag indicates backup blocks starting in this page are optional */
	XlpBkpRemovable = 0x0004
	/* All defined flag bits in xlp_info (used for validity checking of header) */
	XlpAllFlags = 0x0007
)
View Source
const (
	XLogSwitch          = 0x40
	WalSwitchRecordSize = XLogRecordHeaderSize
)
View Source
const (
	XlrMaxBlockID       = 32
	XlrBlockIDDataShort = 255
	XlrBlockIDDataLong  = 254
	XlrBlockIDOrigin    = 253

	BkpBlockForkMask uint8 = 0x0F
	BkpBlockFlagMask uint8 = 0xF0
	BkpBlockHasImage uint8 = 0x10
	BkpBlockHasData  uint8 = 0x20
	BkpBlockWillInit uint8 = 0x40
	BkpBlockSameRel  uint8 = 0x80
)
View Source
const (
	BkpImageHasHole      uint8 = 0x01
	BkpImageIsCompressed uint8 = 0x02
	BkpImageApply        uint8 = 0x04
)
View Source
const (
	XlrInfoMask     = 0x0F
	XlrRmgrInfoMask = 0xF0

	XlrSpecialRelUpdate  = 0x01
	XlrCheckConsistency  = 0x02
	XLogRecordHeaderSize = 24
)

Variables

View Source
var TerminalLocation = *NewBlockLocation(0, 0, 0, 0)

Functions

func NewInvalidPageHeaderError

func NewInvalidPageHeaderError() error

func NewNotEnoughDataToShrinkError

func NewNotEnoughDataToShrinkError(dataRemained int, toShrink int) error

func NewZeroPageHeaderError

func NewZeroPageHeaderError() error

func WriteLocationsTo

func WriteLocationsTo(writer io.Writer, locations []BlockLocation) error

Types

type AlignedReader

type AlignedReader struct {
	// contains filtered or unexported fields
}

func NewAlignedReader

func NewAlignedReader(source io.Reader, alignment int) *AlignedReader

func (*AlignedReader) Read

func (reader *AlignedReader) Read(p []byte) (n int, err error)

func (*AlignedReader) ReadToAlignment

func (reader *AlignedReader) ReadToAlignment() error

type BlockLocation

type BlockLocation struct {
	RelationFileNode RelFileNode
	BlockNo          uint32
}

func ExtractBlockLocations

func ExtractBlockLocations(records []XLogRecord) []BlockLocation

func ExtractLocationsFromWalFile

func ExtractLocationsFromWalFile(parser *WalParser, walFile io.ReadCloser) ([]BlockLocation, error)

TODO : unit tests

func NewBlockLocation

func NewBlockLocation(spcNode, dbNode, relNode Oid, blockNo uint32) *BlockLocation

func ReadLocationsFrom

func ReadLocationsFrom(reader io.Reader) ([]BlockLocation, error)

type BlockLocationReader

type BlockLocationReader struct {
	// contains filtered or unexported fields
}

func NewBlockLocationReader

func NewBlockLocationReader(underlying io.Reader) *BlockLocationReader

func (*BlockLocationReader) ReadNextLocation

func (reader *BlockLocationReader) ReadNextLocation() (*BlockLocation, error)

ReadNextLocation returns any reader error wrapped with errors.Wrap

type BlockLocationWriter

type BlockLocationWriter struct {
	Underlying io.Writer
}

func NewBlockLocationWriter

func NewBlockLocationWriter(underlying io.Writer) *BlockLocationWriter

func (*BlockLocationWriter) WriteLocation

func (locationWriter *BlockLocationWriter) WriteLocation(location BlockLocation) error

type CantSavePartialParserError

type CantSavePartialParserError struct {
	// contains filtered or unexported fields
}

func NewCantSavePartialParserError

func NewCantSavePartialParserError() CantSavePartialParserError

func (CantSavePartialParserError) Error

func (err CantSavePartialParserError) Error() string

type ContinuationNotFoundError

type ContinuationNotFoundError struct {
	// contains filtered or unexported fields
}

func NewContinuationNotFoundError

func NewContinuationNotFoundError() ContinuationNotFoundError

type InconsistentBlockDataStateError

type InconsistentBlockDataStateError struct {
	// contains filtered or unexported fields
}

func NewInconsistentBlockDataStateError

func NewInconsistentBlockDataStateError(hasData bool, dataLength uint16) InconsistentBlockDataStateError

func (InconsistentBlockDataStateError) Error

type InconsistentBlockImageHoleStateError

type InconsistentBlockImageHoleStateError struct {
	// contains filtered or unexported fields
}

func NewInconsistentBlockImageHoleStateError

func NewInconsistentBlockImageHoleStateError(holeOffset uint16,
	holeLength uint16,
	imageLength uint16,
	hasHole bool) InconsistentBlockImageHoleStateError

func (InconsistentBlockImageHoleStateError) Error

type InconsistentBlockImageLengthError

type InconsistentBlockImageLengthError struct {
	// contains filtered or unexported fields
}

func NewInconsistentBlockImageLengthError

func NewInconsistentBlockImageLengthError(hasHole bool,
	isCompressed bool,
	length uint16) InconsistentBlockImageLengthError

func (InconsistentBlockImageLengthError) Error

type InconsistentXLogRecordTotalLengthError

type InconsistentXLogRecordTotalLengthError struct {
	// contains filtered or unexported fields
}

func NewInconsistentXLogRecordTotalLengthError

func NewInconsistentXLogRecordTotalLengthError(totalRecordLength uint32) InconsistentXLogRecordTotalLengthError

func (InconsistentXLogRecordTotalLengthError) Error

type InvalidPageHeaderError

type InvalidPageHeaderError struct {
	// contains filtered or unexported fields
}

func (InvalidPageHeaderError) Error

func (err InvalidPageHeaderError) Error() string

type InvalidRecordBlockIDError

type InvalidRecordBlockIDError struct {
	// contains filtered or unexported fields
}

func NewInvalidRecordBlockIDError

func NewInvalidRecordBlockIDError(blockID uint8) InvalidRecordBlockIDError

func (InvalidRecordBlockIDError) Error

func (err InvalidRecordBlockIDError) Error() string

type InvalidXLogRecordResourceManagerIDError

type InvalidXLogRecordResourceManagerIDError struct {
	// contains filtered or unexported fields
}

func NewInvalidXLogRecordResourceManagerIDError

func NewInvalidXLogRecordResourceManagerIDError(resourceManagerID uint8) InvalidXLogRecordResourceManagerIDError

func (InvalidXLogRecordResourceManagerIDError) Error

type NoPrevRelFileNodeError

type NoPrevRelFileNodeError struct {
	// contains filtered or unexported fields
}

func NewNoPrevRelFileNodeError

func NewNoPrevRelFileNodeError() NoPrevRelFileNodeError

func (NoPrevRelFileNodeError) Error

func (err NoPrevRelFileNodeError) Error() string

type NotEnoughDataToShrinkError

type NotEnoughDataToShrinkError struct {
	// contains filtered or unexported fields
}

func (NotEnoughDataToShrinkError) Error

func (err NotEnoughDataToShrinkError) Error() string

type Oid

type Oid uint32

type OutOfOrderBlockIDError

type OutOfOrderBlockIDError struct {
	// contains filtered or unexported fields
}

func NewOutOfOrderBlockIDError

func NewOutOfOrderBlockIDError(actualBlockID int, expectedBlockID int) OutOfOrderBlockIDError

func (OutOfOrderBlockIDError) Error

func (err OutOfOrderBlockIDError) Error() string

type PartialPageError

type PartialPageError struct {
	// contains filtered or unexported fields
}

func NewPartialPageError

func NewPartialPageError() PartialPageError

func (PartialPageError) Error

func (err PartialPageError) Error() string

type RelFileNode

type RelFileNode struct {
	SpcNode Oid
	DBNode  Oid
	RelNode Oid
}

This struct corresponds to postgres struct RelFileNode. * For clarification you can find it in postgres: * src/include/storage/relfilenode.h

type ShrinkableReader

type ShrinkableReader struct {
	// contains filtered or unexported fields
}

func (*ShrinkableReader) Read

func (reader *ShrinkableReader) Read(p []byte) (n int, err error)

func (*ShrinkableReader) Shrink

func (reader *ShrinkableReader) Shrink(length int) error

type TimeLineID

type TimeLineID uint32

type WalPageReader

type WalPageReader struct {
	// contains filtered or unexported fields
}

func NewWalPageReader

func NewWalPageReader(walFileReader io.Reader) *WalPageReader

func (*WalPageReader) ReadPageData

func (reader *WalPageReader) ReadPageData() ([]byte, error)

ReadPageData reads data corresponding to one page

type WalParser

type WalParser struct {
	// contains filtered or unexported fields
}

func LoadWalParser

func LoadWalParser(reader io.Reader) (*WalParser, error)

func LoadWalParserFromCurrentRecordHead

func LoadWalParserFromCurrentRecordHead(currentRecordHead []byte) *WalParser

func NewWalParser

func NewWalParser() *WalParser

func (*WalParser) GetCurrentRecordData

func (parser *WalParser) GetCurrentRecordData() []byte

func (*WalParser) Invalidate

func (parser *WalParser) Invalidate()

func (*WalParser) ParseRecordsFromPage

func (parser *WalParser) ParseRecordsFromPage(reader io.Reader) (prevRecordTail []byte,
	pageRecords []XLogRecord, err error)

For now we suppose that no wal record crosses whole wal page. If there is no currentRecordData (e. g. we look at the first record in the file), then we return prevRecordTail and discard it in parser.

func (*WalParser) Save

func (parser *WalParser) Save(writer io.Writer) error

type XLogPage

type XLogPage struct {
	Header                 XLogPageHeader
	PrevRecordTrailingData []byte
	Records                []XLogRecord
	NextRecordHeadingData  []byte
}

type XLogPageHeader

type XLogPageHeader struct {
	Magic            uint16
	Info             uint16
	TimeLineID       TimeLineID
	PageAddress      XLogRecordPtr
	RemainingDataLen uint32
}

This struct corresponds to postgres struct XLogPageHeaderData. * For clarification you can find it in postgres: * src/include/access/xlog_internal.h

func (*XLogPageHeader) HasContinuationRecord

func (pageHeader *XLogPageHeader) HasContinuationRecord() bool

func (*XLogPageHeader) IsLong

func (pageHeader *XLogPageHeader) IsLong() bool

func (*XLogPageHeader) IsValid

func (pageHeader *XLogPageHeader) IsValid() bool

type XLogRecord

type XLogRecord struct {
	Header      XLogRecordHeader
	MainDataLen uint32
	Origin      uint16
	Blocks      []XLogRecordBlock
	MainData    []byte
}

func NewXLogRecord

func NewXLogRecord(header XLogRecordHeader) *XLogRecord

func ParseXLogRecordFromBytes

func ParseXLogRecordFromBytes(data []byte) (*XLogRecord, error)

func (*XLogRecord) IsZero

func (record *XLogRecord) IsZero() bool

type XLogRecordBlock

type XLogRecordBlock struct {
	Header XLogRecordBlockHeader
	Image  []byte
	Data   []byte
}

type XLogRecordBlockHeader

type XLogRecordBlockHeader struct {
	BlockID       uint8
	ForkFlags     uint8
	DataLength    uint16
	ImageHeader   XLogRecordBlockImageHeader
	BlockLocation BlockLocation
}

func NewXLogRecordBlockHeader

func NewXLogRecordBlockHeader(blockID uint8) *XLogRecordBlockHeader

func (*XLogRecordBlockHeader) ForkNum

func (blockHeader *XLogRecordBlockHeader) ForkNum() uint8

func (*XLogRecordBlockHeader) HasData

func (blockHeader *XLogRecordBlockHeader) HasData() bool

func (*XLogRecordBlockHeader) HasImage

func (blockHeader *XLogRecordBlockHeader) HasImage() bool

func (*XLogRecordBlockHeader) HasSameRel

func (blockHeader *XLogRecordBlockHeader) HasSameRel() bool

func (*XLogRecordBlockHeader) WillInit

func (blockHeader *XLogRecordBlockHeader) WillInit() bool

type XLogRecordBlockImageHeader

type XLogRecordBlockImageHeader struct {
	ImageLength uint16
	HoleOffset  uint16
	HoleLength  uint16
	Info        uint8
}

func (*XLogRecordBlockImageHeader) ApplyImage

func (imageHeader *XLogRecordBlockImageHeader) ApplyImage() bool

func (*XLogRecordBlockImageHeader) HasHole

func (imageHeader *XLogRecordBlockImageHeader) HasHole() bool

func (*XLogRecordBlockImageHeader) IsCompressed

func (imageHeader *XLogRecordBlockImageHeader) IsCompressed() bool

type XLogRecordHeader

type XLogRecordHeader struct {
	TotalRecordLength uint32
	XactID            uint32
	PrevRecordPtr     XLogRecordPtr
	Info              uint8
	ResourceManagerID uint8
	/* 2 bytes of padding here, initialize to zero */
	Crc32Hash uint32
}

This struct corresponds to postgres struct XLogRecord. * For clarification you can find it in postgres: * src/include/access/xlogrecord.h

type XLogRecordPtr

type XLogRecordPtr uint64

type ZeroPageError

type ZeroPageError struct {
	// contains filtered or unexported fields
}

func NewZeroPageError

func NewZeroPageError() ZeroPageError

func (ZeroPageError) Error

func (err ZeroPageError) Error() string

type ZeroPageHeaderError

type ZeroPageHeaderError struct {
	// contains filtered or unexported fields
}

func (ZeroPageHeaderError) Error

func (err ZeroPageHeaderError) Error() string

type ZeroRecordHeaderError

type ZeroRecordHeaderError struct {
	// contains filtered or unexported fields
}

func NewZeroRecordHeaderError

func NewZeroRecordHeaderError() ZeroRecordHeaderError

func (ZeroRecordHeaderError) Error

func (err ZeroRecordHeaderError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL