bigqueue

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2018 License: MIT Imports: 6 Imported by: 5

README

bigqueue Build Status Go Report Card MIT license GoDoc codecov

BigQueue implementation in Golang

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyQueue is returned when peek/dequeue is performed on an empty queue
	ErrEmptyQueue = errors.New("queue is empty")
)

Functions

This section is empty.

Types

type Arena

type Arena struct {
	*mmap.Mmap
	// contains filtered or unexported fields
}

Arena is an abstraction for a memory mapped file of a given size

func NewArena

func NewArena(file string, size int) (*Arena, error)

NewArena returns pointer to an Arena. It takes a file location and mmaps it. If file location does not exist, it creates file of given size.

type BigQueue

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

BigQueue implements IBigQueue interface

func NewBigQueue

func NewBigQueue(dir string) (*BigQueue, error)

NewBigQueue constructs an instance of *BigQueue

func (*BigQueue) Close

func (bq *BigQueue) Close()

Close will unmap all arenas

func (*BigQueue) Dequeue

func (bq *BigQueue) Dequeue() ([]byte, error)

Dequeue removes an element from the queue and returns it

func (*BigQueue) Enqueue

func (bq *BigQueue) Enqueue(message []byte) error

Enqueue adds a new element to the tail of the queue

func (*BigQueue) IsEmpty

func (bq *BigQueue) IsEmpty() bool

IsEmpty returns true when queue is empty

func (*BigQueue) Peek

func (bq *BigQueue) Peek() ([]byte, error)

Peek returns the head of the queue

type IBigQueue

type IBigQueue interface {
	IsEmpty() bool
	Peek() []byte
	Enqueue(elem []byte) error
	Dequeue() ([]byte, error)
	Close()
}

IBigQueue provides an interface to big, fast and persistent queue

type QueueIndex

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

QueueIndex stores head and tail for a BigQueue in an arena

func NewQueueIndex

func NewQueueIndex(dataDir string) (*QueueIndex, error)

NewQueueIndex creates/reads index for a BigQueue

func (*QueueIndex) Flush

func (i *QueueIndex) Flush()

Flush writes the memory state of the index arena on to disk

func (*QueueIndex) GetHead

func (i *QueueIndex) GetHead() (int, int)

GetHead reads the value of head of the queue from the index arena. Head of a BigQueue can be identified using -

  1. Arena ID

  2. Position (offset) in the arena

    <------- head aid ------> <------- head pos ------> +------------+------------+------------+------------+ | byte 01-03 | byte 04-07 | byte 08-11 | byte 12-15 | +------------+------------+------------+------------+

func (*QueueIndex) GetTail

func (i *QueueIndex) GetTail() (int, int)

GetTail reads the values of tail of the queue from the index arena. Tail of a BigQueue, similar to head, can be identified using -

  1. Arena ID

  2. Position (offset) in the arena

    <------- tail aid ------> <------- tail pos ------> +------------+------------+------------+------------+ | byte 16-19 | byte 20-23 | byte 24-27 | byte 28-31 | +------------+------------+------------+------------+

func (*QueueIndex) UpdateHead

func (i *QueueIndex) UpdateHead(aid, pos int)

UpdateHead writes the value of head in the index arena

func (*QueueIndex) UpdateTail

func (i *QueueIndex) UpdateTail(aid, pos int)

UpdateTail writes the value of tail in the index arena

Directories

Path Synopsis
examples
extsort command

Jump to

Keyboard shortcuts

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