write

package
v2.0.0-...-7567dab Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package write provides service and its stuff

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

type Batch struct {
	// lines to send
	Batch string
	// retry attempts so far
	RetryAttempts uint
	// true if it was removed from queue
	Evicted bool
	// time when this batch expires
	Expires time.Time
}

Batch holds information for sending points batch

func NewBatch

func NewBatch(data string, expireDelayMs uint) *Batch

NewBatch creates new batch

type BatchErrorCallback

type BatchErrorCallback func(batch *Batch, error2 http2.Error) bool

BatchErrorCallback is synchronously notified in case non-blocking write fails. It returns true if WriteAPI should continue with retrying, false will discard the batch.

type Service

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

Service is responsible for reliable writing of batches

func NewService

func NewService(org string, bucket string, httpService http2.Service, options *write.Options) *Service

NewService creates new write service

func (*Service) EncodePoints

func (w *Service) EncodePoints(points ...*write.Point) (string, error)

EncodePoints creates line protocol string from points

func (*Service) Flush

func (w *Service) Flush()

Flush sends batches from retry queue immediately, without retrying

func (*Service) HandleWrite

func (w *Service) HandleWrite(ctx context.Context, batch *Batch) error

HandleWrite handles writes of batches and handles retrying. Retrying is triggered by new writes, there is no scheduler. It first checks retry queue, because it has the highest priority. If there are some batches in retry queue, those are written and incoming batch is added to end of retry queue. Immediate write is allowed only in case there was success or not retryable error. Otherwise, delay is checked based on recent batch. If write of batch fails with retryable error (connection errors and HTTP code >= 429), Batch retry time is calculated based on #of attempts. If writes continues failing and # of attempts reaches maximum or total retry time reaches maxRetryTime, batch is discarded.

func (*Service) SetBatchErrorCallback

func (w *Service) SetBatchErrorCallback(cb BatchErrorCallback)

SetBatchErrorCallback sets callback allowing custom handling of failed writes. If callback returns true, failed batch will be retried, otherwise discarded.

func (*Service) WriteBatch

func (w *Service) WriteBatch(ctx context.Context, batch *Batch) *http2.Error

WriteBatch performs actual writing via HTTP service

func (*Service) WriteURL

func (w *Service) WriteURL() string

WriteURL returns current write URL

Jump to

Keyboard shortcuts

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