wal

package
v0.0.0-...-c42b739 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2018 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Unknown     = iota // Unknown describes an entry in the WAL that is not interesting to us
	Insert             // Insert describes a tuple being inserted into a heap
	Update             // Update describes a tuple (either regular or heap-only) being updated in the heap
	Delete             // Delete describes a tuple being deleted from the heap
	Commit             // Commit describes a transaction being committed (either normally or compact)
	Abort              // Abort describes a transaction being aborted
	MultiInsert        // MultiInsert describes a block of tuples being inserted into a heap
)

These constants describe the type of heap tuple found in the WAL

View Source
const EntryBytesSize = 61

EntryBytesSize is the size of the entries.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

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

Cursor models a position in the WAL of a PostgreSQL system

func NewCursorAtCheckpoint

func NewCursorAtCheckpoint(path string) (cursor *Cursor, err error)

NewCursorAtCheckpoint creates a new cursor pointing at the current checkpoint

func NewCursorAtPrevCheckpoint

func NewCursorAtPrevCheckpoint(path string) (cursor *Cursor, err error)

NewCursorAtPrevCheckpoint creates a new cursor pointing at the current checkpoint

func (Cursor) MoveTo

func (c Cursor) MoveTo(location Location) Cursor

MoveTo sets the cursor to point at the specified location in the WAL even if its invalid

func (Cursor) ReadEntries

func (c Cursor) ReadEntries() (entries []Entry, cur Cursor, err error)

ReadEntries will read the XLogRecord at the current location and if successful return the entries and a new cursor at the next location

func (Cursor) String

func (c Cursor) String() string

type DeleteData

type DeleteData []byte

DeleteData reads heap data as a delete

func (DeleteData) DatabaseID

func (d DeleteData) DatabaseID() uint32

DatabaseID is the id of the database this tuple is found in

func (DeleteData) FromBlock

func (d DeleteData) FromBlock() uint32

FromBlock is the page number where this tuple previously resided

func (DeleteData) FromOffset

func (d DeleteData) FromOffset() uint16

FromOffset is the item number where this tuple previously resided

func (DeleteData) RelationID

func (d DeleteData) RelationID() uint32

RelationID is the id of the relation this tuple is found in

func (DeleteData) String

func (d DeleteData) String() string

func (DeleteData) TablespaceID

func (d DeleteData) TablespaceID() uint32

TablespaceID is the id of the tablespace this tuple is found in

func (DeleteData) ToBlock

func (d DeleteData) ToBlock() uint32

ToBlock is not available for deletes

func (DeleteData) ToOffset

func (d DeleteData) ToOffset() uint16

ToOffset is not available for deletes

type Entry

type Entry struct {
	Type          RecordType
	ReadFrom      Location
	Previous      Location
	TimelineID    uint32
	LogID         uint32
	TransactionID uint32
	TablespaceID  uint32
	DatabaseID    uint32
	RelationID    uint32
	FromBlock     uint32
	FromOffset    uint16
	ToBlock       uint32
	ToOffset      uint16
	ParseTime     int64
}

Entry contains the data extracted from insert/update/delete/commit records

func EntryFromBytes

func EntryFromBytes(bs []byte) Entry

EntryFromBytes reconstructs an entry from a slice of bytes

func NewEntries

func NewEntries(page *Page, recordHeader *RecordHeader, recordBody *RecordBody) (entries []Entry)

NewEntries builds an entry from a page, record header, record body and a location

func (Entry) String

func (e Entry) String() string

func (Entry) ToBytes

func (e Entry) ToBytes() []byte

ToBytes converts an entry to a slice of bytes

type HeapData

type HeapData interface {
	TablespaceID() uint32
	DatabaseID() uint32
	RelationID() uint32
	FromBlock() uint32
	FromOffset() uint16
	ToBlock() uint32
	ToOffset() uint16
	fmt.Stringer
}

HeapData describes heap resource manager specific details from a record

func NewHeapData

func NewHeapData(recordType RecordType, isInit bool, data []byte, version uint16) []HeapData

NewHeapData will interpret the heap data based on record type

type InsertData

type InsertData []byte

InsertData reads heap data as an insert

func (InsertData) DatabaseID

func (d InsertData) DatabaseID() uint32

DatabaseID is the id of the database this tuple is found in

func (InsertData) FromBlock

func (d InsertData) FromBlock() uint32

FromBlock is not available for inserts

func (InsertData) FromOffset

func (d InsertData) FromOffset() uint16

FromOffset is not available for inserts

func (InsertData) RelationID

func (d InsertData) RelationID() uint32

RelationID is the id of the relation this tuple is found in

func (InsertData) String

func (d InsertData) String() string

func (InsertData) TablespaceID

func (d InsertData) TablespaceID() uint32

TablespaceID is the id of the tablespace this tuple is found in

func (InsertData) ToBlock

func (d InsertData) ToBlock() uint32

ToBlock is the page number where this tuple now resides

func (InsertData) ToOffset

func (d InsertData) ToOffset() uint16

ToOffset is the item number where this tuple now resides

type Location

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

Location models a 64 bit address in the WAL

func LocationFromUint32s

func LocationFromUint32s(high, low uint32) Location

LocationFromUint32s constructs a location from two parts

func NewLocation

func NewLocation(loc uint64, timelineID, fileSize, pageSize, wordSize uint32) Location

NewLocation constructs a new location from an offset

func NewLocationWithDefaults

func NewLocationWithDefaults(loc uint64) Location

NewLocationWithDefaults constructs a new location from an offset with common defaults

func (Location) Add

func (l Location) Add(amount uint64) Location

Add increases the offset of the Location by some amount

func (Location) Aligned

func (l Location) Aligned() Location

Aligned calculates the location aligned to the given word size

func (Location) Difference

func (l Location) Difference(other Location) uint64

Difference calculates how much larger this offset is than another

func (Location) Filename

func (l Location) Filename() string

Filename is the name of the WAL segment file this location is in

func (Location) FromStartOfFile

func (l Location) FromStartOfFile() uint64

FromStartOfFile calculates the number of bytes from the start of the file to the location

func (Location) FromStartOfPage

func (l Location) FromStartOfPage() uint64

FromStartOfPage calculates the number of bytes from the start of the page to the location

func (Location) IsOnSamePageAs

func (l Location) IsOnSamePageAs(other Location) bool

IsOnSamePageAs determines if a location is on the same page as this one

func (Location) LogID

func (l Location) LogID() uint32

LogID is the upper 32 bits of the location

func (Location) Offset

func (l Location) Offset() uint64

Offset returns the offset this location is based on

func (Location) RecordOffset

func (l Location) RecordOffset() uint32

RecordOffset is the lower 32 bits of the location

func (Location) SegmentID

func (l Location) SegmentID() uint32

SegmentID is the segment id of the location

func (Location) StartOfFile

func (l Location) StartOfFile() Location

StartOfFile calculates the location of the first byte in the file this location is in

func (Location) StartOfNextFile

func (l Location) StartOfNextFile() Location

StartOfNextFile calculates the location of the first byte in the next file after the one this location is in

func (Location) StartOfNextPage

func (l Location) StartOfNextPage() Location

StartOfNextPage calculates the location of the first byte in the next page after the one this location is in

func (Location) StartOfPage

func (l Location) StartOfPage() Location

StartOfPage calculates the location of the first byte in the page this location is in

func (Location) StartOfPreviousFile

func (l Location) StartOfPreviousFile() Location

StartOfPreviousFile calculates the location of the first byte in the prevous file before the one this location is in

func (Location) StartOfPreviousPage

func (l Location) StartOfPreviousPage() Location

StartOfPreviousPage calculates the location of the first byte in the previous page before the one this location is in

func (Location) String

func (l Location) String() string

func (Location) Subtract

func (l Location) Subtract(amount uint64) Location

Subtract decreases the offset of the Location by some amount

func (Location) ToEndOfFile

func (l Location) ToEndOfFile() uint64

ToEndOfFile calculates the number of bytes from the location to the end of the file

func (Location) ToEndOfPage

func (l Location) ToEndOfPage() uint64

ToEndOfPage calculates the number of bytes from the location to the end of the page

type MultiInsertData

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

MultiInsertData reads heap data as an insert

func (MultiInsertData) DatabaseID

func (d MultiInsertData) DatabaseID() uint32

DatabaseID is the id of the database this tuple is found in

func (MultiInsertData) FromBlock

func (d MultiInsertData) FromBlock() uint32

FromBlock is not available for inserts

func (MultiInsertData) FromOffset

func (d MultiInsertData) FromOffset() uint16

FromOffset is not available for inserts

func (MultiInsertData) RelationID

func (d MultiInsertData) RelationID() uint32

RelationID is the id of the relation this tuple is found in

func (MultiInsertData) String

func (d MultiInsertData) String() string

func (MultiInsertData) TablespaceID

func (d MultiInsertData) TablespaceID() uint32

TablespaceID is the id of the tablespace this tuple is found in

func (MultiInsertData) ToBlock

func (d MultiInsertData) ToBlock() uint32

ToBlock is the page number where this tuple now resides

func (MultiInsertData) ToOffset

func (d MultiInsertData) ToOffset() uint16

ToOffset is the item number where this tuple now resides

type Page

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

Page contains methods for reading values from a WAL page header and for detecting/reading a continuation

func (Page) BlockSize

func (p Page) BlockSize() uint32

BlockSize is the size of a page in a WAL file

func (Page) Continuation

func (p Page) Continuation() []byte

Continuation will return the bytes of a continuation of the previous record's body if present on the page

func (Page) HeaderLength

func (p Page) HeaderLength() uint64

HeaderLength returns the size in bytes of the portion of the page used for its header

func (Page) Info

func (p Page) Info() uint16

Info can be used to determine if a page header is long (bit 2 is set) or if it contains a continuation (bit 1 is set)

func (Page) Is91

func (p Page) Is91() bool

Is91 indicates if a Page is from version 9.1

func (Page) Is94

func (p Page) Is94() bool

Is94 indicates if a Page is from version 9.4

func (Page) IsCont

func (p Page) IsCont() bool

IsCont checks the page's info to see if it has a continuation record

func (Page) IsLong

func (p Page) IsLong() bool

IsLong checks if the page has extra fields which is typical in the beginning of a file

func (Page) Location

func (p Page) Location() Location

Location is the Location this page starts at

func (Page) Magic

func (p Page) Magic() uint16

Magic returns the format version of the page

func (Page) MagicValueIsValid

func (p Page) MagicValueIsValid() bool

MagicValueIsValid indicates if a Page is correct or not

func (Page) SegmentSize

func (p Page) SegmentSize() uint32

SegmentSize is the size in bytes of a single WAL file

func (Page) SystemID

func (p Page) SystemID() uint64

SystemID can be used to determine if a page was written by a particular server

func (Page) TimelineID

func (p Page) TimelineID() uint32

TimelineID is the timeline this page is found on

type RecordBody

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

RecordBody collects the bytes that make up the body of a record

func NewRecordBody

func NewRecordBody(recordHeader *RecordHeader) *RecordBody

NewRecordBody creates a new RecordBody based on a RecordHeader

func (*RecordBody) AppendBodyAfterHeader

func (r *RecordBody) AppendBodyAfterHeader(block []byte, location Location) uint64

AppendBodyAfterHeader reads what is available of the body on the same page and appends it to the body

func (*RecordBody) AppendContinuation

func (r *RecordBody) AppendContinuation(page Page) uint64

AppendContinuation reads a continuation from a page and appends it to the body

func (*RecordBody) HeapData

func (r *RecordBody) HeapData() []HeapData

HeapData interprets the body based on the type indicated in the record header

func (*RecordBody) IsComplete

func (r *RecordBody) IsComplete() bool

IsComplete indicates that needs to be read of a body has been read

type RecordHeader

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

RecordHeader contains methods to read fields of an xlog record header

func NewRecordHeader

func NewRecordHeader(block []byte, location Location, version uint16, reader blockReader) *RecordHeader

NewRecordHeader creates a new RecordHeader from a block and a location

func (RecordHeader) AlignedSize

func (r RecordHeader) AlignedSize() uint64

AlignedSize will return the size of the header plus alignment

func (RecordHeader) Crc

func (r RecordHeader) Crc() uint32

Crc is the crc of the record

func (RecordHeader) Info

func (r RecordHeader) Info() uint8

Info contains resource manager specific data

func (RecordHeader) IsInit

func (r RecordHeader) IsInit() bool

IsInit indicates if this record initializes a page

func (RecordHeader) Length

func (r RecordHeader) Length() uint32

Length is the length of resource manager specific data after the header

func (RecordHeader) Previous

func (r RecordHeader) Previous() Location

Previous is the location of the record that preceeds this one

func (RecordHeader) ResourceManagerID

func (r RecordHeader) ResourceManagerID() uint8

ResourceManagerID is the ID of the resource manager that created this record

func (RecordHeader) Size

func (r RecordHeader) Size() uint64

Size will return the size of the header

func (RecordHeader) TotalLength

func (r RecordHeader) TotalLength() uint32

TotalLength is the length of the body after the header but before the next record

func (RecordHeader) TransactionID

func (r RecordHeader) TransactionID() uint32

TransactionID is the transaction that this record is apart of

func (RecordHeader) Type

func (r RecordHeader) Type() RecordType

Type indicates how the resource data should be interpreted

type RecordType

type RecordType uint8

RecordType is a constant representing how an xlog record should be interpreted

type UpdateData

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

UpdateData reads heap data as an update

func (UpdateData) DatabaseID

func (d UpdateData) DatabaseID() uint32

DatabaseID is the id of the database this tuple is found in

func (UpdateData) FromBlock

func (d UpdateData) FromBlock() uint32

FromBlock is the page number of the old version of this tuple

func (UpdateData) FromOffset

func (d UpdateData) FromOffset() uint16

FromOffset is the item number of the old version of this tuple

func (UpdateData) RelationID

func (d UpdateData) RelationID() uint32

RelationID is the id of the relation this tuple is found in

func (UpdateData) String

func (d UpdateData) String() string

func (UpdateData) TablespaceID

func (d UpdateData) TablespaceID() uint32

TablespaceID is the id of the tablespace this tuple is found in

func (UpdateData) ToBlock

func (d UpdateData) ToBlock() uint32

ToBlock is the page number of the new version of this tuple

func (UpdateData) ToOffset

func (d UpdateData) ToOffset() uint16

ToOffset is item number of the new version of this tuple

Jump to

Keyboard shortcuts

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