blocklog

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BLog

type BLog struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

BLog is an external append only log of the blocks. Blocks should only be written

  • to the log after they're irreversible as the log is append only. There is a secondary
  • index file of only block positions that enables O(1) random access lookup by block number. *
  • A block data in the BLog is formatted as len+payload, len is a uint32 *
  • +---------+----------------+---------+----------------+-----+------------+-------------------+
  • | Block 1 | Pos of Block 1 | Block 2 | Pos of Block 2 | ... | Head Block | Pos of Head Block |
  • +---------+----------------+---------+----------------+-----+------------+-------------------+ *
  • +----------------+----------------+-----+-------------------+
  • | Pos of Block 1 | Pos of Block 2 | ... | Pos of Head Block |
  • +----------------+----------------+-----+-------------------+ * *
  • Blocks can be accessed at random via block number through the index file. Seek to 8 * (block_num - 1)
  • to find the position of the block in the main file. *
  • The main file is the only file that needs to persist. The index file can be reconstructed during a
  • linear scan of the main file.

func (*BLog) Append

func (bl *BLog) Append(sb common.ISignedBlock) error

Append appends a common.SignedBlock to the BLog

func (*BLog) Empty

func (bl *BLog) Empty() bool

Empty returns true if it contains no block

func (*BLog) Open

func (bl *BLog) Open(dir string) (err error)

Open opens the block log & index file

func (*BLog) ReadBlock

func (bl *BLog) ReadBlock(sb common.ISignedBlock, blockNum int64) error

ReadBlock reads a block at blockNum, blockNum start at 0

func (*BLog) Remove

func (bl *BLog) Remove(dir string)

Remove remove log and index file

func (*BLog) Size

func (bl *BLog) Size() int64

Size...

Jump to

Keyboard shortcuts

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