Movatterモバイル変換


[0]ホーム

URL:


dsqueue

packagemodule
v0.1.1Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License:Apache-2.0, MITImports:13Imported by:4

Details

Repository

github.com/ipfs/go-dsqueue

Links

README

go-dsqueue

Build StatusGoDoc

Buffered FIFO interface to the datastore

The dsqueue package provides a buffered FIFO queue backed by aBatching Datastore. Queued items are persisted in the datastore when the input buffer is full, after some amount of idle time, and when the queue is shuddown.

Documentation

https://pkg.go.dev/github.com/ipfs/go-dsqueue

Example

ds = getBatchingDatastore() dsq := dsqueue.New(ds, "ExampleQueue")defer dsq.Close()c, err := cid.Decode("QmPNHBy5h7f19yJDt7ip9TvmMRbqmYsa6aetkrsc1ghjLB")if err != nil {    panic(err)}dsq.Put(c.Bytes())out := <-dsq.Out()c2, err := cid.Parse(out)if err != nil {    panic(err)}if c2 != c {    fmt.Fprintln(os.Stderr, "cids are not quual")}

Lead Maintainer

@gammazero

Contributing

Contributions are welcome! This repository is part of the IPFS project and therefore governed by ourcontributing guidelines.

License

SPDX-License-Identifier: Apache-2.0 OR MIT

Documentation

Overview

Package dsqueue provides a buffered FIFO interface to the datastore forstoring and retrieving items. Queued items are persisted across restarts.

Index

Constants

View Source
const (DefaultBufferSize    = 16 * 1024DefaultIdleWriteTime =time.MinuteDefaultCloseTimeout  = 10 *time.Second)

Variables

This section is empty.

Functions

This section is empty.

Types

typeDSQueue

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

DSQueue provides a FIFO interface to the datastore for storing items.

Items in the process of being provided when a crash or shutdown occurs maybe in the queue when the node is brought back online depending on whetherthey were fully written to the underlying datastore.

Input to the queue is buffered in memory. The contents of the buffer arewritten to the datastore when the input buffer is full (seeWithBufferSize), or when the queue has been idle for some time (seeWithIdleWriteTime) since the previous batch write or dequeue. Items todequeue are read, in order, from the input buffer if there are none in thedatastore. Otherwise they are read from the datastore.

If queued items are read from the input buffer before it reaches its limit,then queued items can remain in memory. When the queue is closed, anyremaining items in memory are written to the datastore.

funcNew

func New(ds datastore.Batching, namestring, options ...Option) *DSQueue

New creates a queue for strings.

func (*DSQueue)Clear

func (q *DSQueue) Clear()int

Clear clears all queued records from memory and the datastore. Returns thenumber of items removed from the queue.

func (*DSQueue)Close

func (q *DSQueue) Close()error

Close stops the queue.

func (*DSQueue)GetNadded inv0.0.4

func (q *DSQueue) GetN(nint) ([][]byte,error)

GetN retrieves up to n items that are currently available in the queue. Ifthere are no items currently available, then none are returned and GetN doesnot wait for any.

GetN is used to poll the DSQueue for items and return batches of thoseitems. This is the most efficient way of fetching currently available items.

GetN and Out can both be used to read items from the DSQueue, but theyshould not be used concurrently as items will be returned by one or theother indeterminately.

func (*DSQueue)Name

func (q *DSQueue) Name()string

Name returns the name of this DSQueue instance.

func (*DSQueue)Outadded inv0.0.2

func (q *DSQueue) Out() <-chan []byte

Out returns a channel that for reading entries from the queue,

func (*DSQueue)Putadded inv0.0.2

func (q *DSQueue) Put(item []byte) (errerror)

Put puts an item into the queue.

typeOption

type Option func(*config)

Option is a function that sets a value in a config.

funcWithBufferSize

func WithBufferSize(nint)Option

WithBufferSize sets the limit on number of items kept in input buffermemory, at which they are all written to the datastore. A value of 0 meansthe buffer size is unlimited, and items are only written to the datastorewhen the queue has been idle more then the idle write time or when the queueis closed.

funcWithCloseTimeout

func WithCloseTimeout(dtime.Duration)Option

WithCloseTimeout sets the duration that Close waits to finish writing itemsto the datastore. A value of 0 means wait until finished with no timeout.

funcWithDedupCacheSize

func WithDedupCacheSize(nint)Option

WithDedupCacheSize sets the size of the LRU cache used to deduplicate itemsin the queue.

By default, the deduplication cache is disabled (size = 0).

funcWithIdleWriteTime

func WithIdleWriteTime(dtime.Duration)Option

WithIdleWriteTime sets the amout of time that the queue must be idle (noinput or output) before all buffered input items are written to thedatastore. A value of zero means that buffered input items are notautomatically flushed to the datastore. A non-zero value must be greaterthan one second.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp