clickhousecache

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoTableName          = errors.New("no table name provided in config")
	ErrNoFieldNames         = errors.New("no field names provided in config")
	ErrNoClickhouseAddress  = errors.New("no ClickHouse address provided in config")
	ErrNoClickhouseDBName   = errors.New("no ClickHouse database name provided in config")
	ErrNoClickhouseUserName = errors.New("no ClickHouse user name provided in config")
)

Functions

func Struct2Map

func Struct2Map(model interface{}) map[string]interface{}

Types

type ClickhouseStorage

type ClickhouseStorage struct {
	Metrics      Metrics
	OnBatchError func(batch []map[string]any, err error)
	// contains filtered or unexported fields
}

func NewClickhouseStorage

func NewClickhouseStorage(cfg ClickhouseStorageConfig) (*ClickhouseStorage, error)

func (*ClickhouseStorage) Add

func (a *ClickhouseStorage) Add(s map[string]any) error

Add adds data to storage. You may use Struct2Map() func to convert struct to map

func (*ClickhouseStorage) Exit

func (a *ClickhouseStorage) Exit()

Exit - quit and store all data

func (*ClickhouseStorage) Store

func (a *ClickhouseStorage) Store()

Store - store data to Clickhouse manually

type ClickhouseStorageConfig

type ClickhouseStorageConfig struct {
	Config      TClickHouseConfig // параметры подключения к ClickHouse
	TableName   string            // имя таблицы в ClickHouse
	FieldNames  []string          // список полей (колонок) в таблице
	WriteTime   time.Duration     // период записи данных из буфера в ClickHouse
	MaxBatch    int               // максимальный размер батча для записи
	JSONFields  []string          // список полей, которые нужно сериализовать в JSON
	MaxRetries  int               // максимальное количество попыток записи при ошибке
	BackoffBase time.Duration     // базовая задержка для экспоненциального бэкоффа
	BackoffMax  time.Duration     // максимальная задержка для бэкоффа
}

type Metrics

type Metrics struct {
	SuccessInserts uint64 // count of successful batches
	FailedInserts  uint64 // count of failed batches
	LastBatchSize  uint64 // size of the last batch (successful or not)
}

Metrics holds counters for monitoring ClickHouse storage operations.

func (*Metrics) Get

func (m *Metrics) Get() Metrics

func (*Metrics) IncFailed

func (m *Metrics) IncFailed(batchSize int)

func (*Metrics) IncSuccess

func (m *Metrics) IncSuccess(batchSize int)

type TClickHouseConfig

type TClickHouseConfig struct {
	ClkAddress   []string // list of clickhouse servers (host:port)
	ClkDBName    string
	ClkUserName  string
	ClkPassword  string
	MaxOpenConns int
	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

TClickHouseConfig holds ClickHouse connection parameters

Jump to

Keyboard shortcuts

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