clickhouse

package
v0.0.0-...-a89fa9e Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 24 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DropHost

func DropHost(host string)

DropHost deletes host from the pool TODO we need to be able to remove entries from the pool

func EnforceVerifiedLegacyTLS

func EnforceVerifiedLegacyTLS()

EnforceVerifiedLegacyTLS re-registers the legacy tlsSettingsLegacy key with a verifying tls.Config (system trust store, no InsecureSkipVerify). Called from the FIPS startup gate when chopconf.security.policy=Enforced so any DSN that didn't go through setupTLSAdvanced still gets verified TLS rather than the default-insecure legacy registration. Pre-FIPS behavior preserved by NOT calling this when FIPS is disabled.

MinVersion is set explicitly to TLS 1.2 (the FIPS spec floor) rather than relying on the Go stdlib default. 1.2 is chosen over 1.3 because this legacy code path serves unkeyed DSNs that may target older ClickHouse servers; users can raise the floor at the per-cluster security.clickhouse.tls.minVersion knob without affecting this legacy fallback.

Types

type Cluster

type Cluster struct {
	*ClusterConnectionParams
	Hosts []string
	// contains filtered or unexported fields
}

Cluster specifies clickhouse cluster object

func NewCluster

func NewCluster() *Cluster

NewCluster creates new clickhouse cluster object

func (*Cluster) ExecAll

func (c *Cluster) ExecAll(ctx context.Context, queries []string, _opts ...*QueryOptions) error

ExecAll runs set of SQL queries on all endpoints of the cluster. No data is expected to be returned back. Retry logic traverses the list of SQLs multiple times until all SQLs succeed. Every endpoint receives the full list of queries. The queries slice is not modified.

func (*Cluster) QueryAny

func (c *Cluster) QueryAny(ctx context.Context, sql string) (*QueryResult, error)

QueryAny walks over all endpoints and runs query sequentially on each of them. In case endpoint returned result, walk is completed and result is returned. In case endpoint failed, continue with the next endpoint.

func (*Cluster) SetHosts

func (c *Cluster) SetHosts(hosts []string) *Cluster

SetHosts sets hosts

func (*Cluster) SetLog

func (c *Cluster) SetLog(a log.Announcer) *Cluster

SetLog sets new logger/announcer

type ClusterConnectionParams

type ClusterConnectionParams struct {
	*ClusterCredentials
	*Timeouts
}

ClusterConnectionParams represents connection parameters to the whole cluster

func NewClusterConnectionParams

func NewClusterConnectionParams(scheme, username, password, rootCA string, port int) *ClusterConnectionParams

NewClusterConnectionParams creates new ClusterConnectionParams

func NewClusterConnectionParamsFromCHOpConfig

func NewClusterConnectionParamsFromCHOpConfig(config *api.OperatorConfig) *ClusterConnectionParams

NewClusterConnectionParamsFromCHOpConfig is the same as NewClusterConnectionParams, but works with CHOp config to get parameters from

func (*ClusterConnectionParams) NewEndpointConnectionParams

func (p *ClusterConnectionParams) NewEndpointConnectionParams(host string) *EndpointConnectionParams

NewEndpointConnectionParams creates endpoint connection params for a specified host in the cluster

func (*ClusterConnectionParams) OverlayClusterSecurityTLS

OverlayClusterSecurityTLS layers the per-cluster TLS knobs over the CHOP-config-derived defaults. Empty fields in tls leave the existing value alone (per-cluster fill-empty, matching the normalize-time semantics). Called at schemer construction time, after the base ClusterConnectionParams is built from chopconf — without this step the 3-level inheritance from InheritClusterSecurityFrom + normalizeClusterSecurity would never reach the dial.

func (*ClusterConnectionParams) SetTimeouts

func (p *ClusterConnectionParams) SetTimeouts(timeouts *Timeouts) *ClusterConnectionParams

SetTimeouts sets timeout

type ClusterCredentials

type ClusterCredentials struct {
	Scheme   string
	Username string
	Password string
	RootCA   string
	Port     int

	// TLS hardening knobs — empty values preserve current behavior. Populated
	// from chopconf security.clickhouse.tls.* by NewClusterConnectionParamsFromCHOpConfig
	// and then overlaid per-cluster by OverlayClusterSecurityTLS. Valid values
	// are the api.TLSVerify*/api.TLSMinVersion* constants; empty preserves the
	// legacy path.
	TLSVerify     api.TLSVerify
	TLSMinVersion api.TLSMinVersion
	TLSServerName string
}

ClusterCredentials specifies cluster endpoint credentials

func NewClusterCredentials

func NewClusterCredentials(scheme, username, password, rootCA string, port int) *ClusterCredentials

NewClusterCredentials creates new ClusterCredentials

func (*ClusterCredentials) SetTLSSecurity

func (c *ClusterCredentials) SetTLSSecurity(verify api.TLSVerify, minVersion api.TLSMinVersion, serverName string) *ClusterCredentials

SetTLSSecurity injects TLS hardening knobs. Empty values preserve legacy behavior.

type Connection

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

Connection specifies clickhouse database connection object

func GetPooledDBConnection

func GetPooledDBConnection(params *EndpointConnectionParams) *Connection

GetPooledDBConnection gets connection out of the pool. In case no connection available new connection is created and returned.

func NewConnection

func NewConnection(params *EndpointConnectionParams) *Connection

NewConnection creates new clickhouse connection

func (*Connection) Exec

func (c *Connection) Exec(_ctx context.Context, sql string, opts *QueryOptions) error

Exec runs given sql query

func (*Connection) Params

func (c *Connection) Params() *EndpointConnectionParams

Params gets connection params

func (*Connection) Query

func (c *Connection) Query(sql string) (*QueryResult, error)

Query runs given sql query

func (*Connection) QueryContext

func (c *Connection) QueryContext(ctx context.Context, sql string) (*QueryResult, error)

QueryContext runs given sql query on behalf of specified context

func (*Connection) SetLog

func (c *Connection) SetLog(l log.Announcer) *Connection

SetLog sets log announcer

type EndpointConnectionParams

type EndpointConnectionParams struct {
	*EndpointCredentials
	*Timeouts
}

EndpointConnectionParams represents connection parameters

func NewEndpointConnectionParams

func NewEndpointConnectionParams(scheme, hostname, username, password, rootCA string, port int) *EndpointConnectionParams

NewEndpointConnectionParams creates new EndpointConnectionParams

func (*EndpointConnectionParams) SetTimeouts

func (p *EndpointConnectionParams) SetTimeouts(timeouts *Timeouts) *EndpointConnectionParams

SetTimeouts sets timeout

type EndpointCredentials

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

EndpointCredentials specifies credentials to access specified endpoint

func NewEndpointCredentials

func NewEndpointCredentials(scheme, hostname, username, password, rootCA string, port int) *EndpointCredentials

NewEndpointCredentials creates new EndpointCredentials object

func (*EndpointCredentials) GetDSN

func (c *EndpointCredentials) GetDSN() string

GetDSN gets DSN

func (*EndpointCredentials) GetDSNLogQueries

func (c *EndpointCredentials) GetDSNLogQueries() string

GetDSNLogQuery gets DSN with hidden sensitive info

func (*EndpointCredentials) GetDSNWithHiddenCredentials

func (c *EndpointCredentials) GetDSNWithHiddenCredentials() string

GetDSNWithHiddenCredentials gets DSN with hidden sensitive info

func (*EndpointCredentials) Hostname

func (c *EndpointCredentials) Hostname() string

Hostname returns the dial host (used as ServerName fallback in setupTLSAdvanced).

func (*EndpointCredentials) RootCA

func (c *EndpointCredentials) RootCA() string

RootCA returns the raw rootCA payload (PEM or base64-wrapped).

func (*EndpointCredentials) SetTLSSecurity

func (c *EndpointCredentials) SetTLSSecurity(verify api.TLSVerify, minVersion api.TLSMinVersion, serverName string) *EndpointCredentials

SetTLSSecurity injects TLS hardening knobs. Empty values preserve legacy behavior. Recomputes the DSN(s) since the tls_config registry key is derived from these knobs.

func (*EndpointCredentials) TLSConfigKey

func (c *EndpointCredentials) TLSConfigKey() string

TLSConfigKey returns the go-clickhouse RegisterTLSConfig registry key for this endpoint.

func (*EndpointCredentials) TLSMinVersion

func (c *EndpointCredentials) TLSMinVersion() api.TLSMinVersion

TLSMinVersion returns the configured min TLS version.

func (*EndpointCredentials) TLSServerName

func (c *EndpointCredentials) TLSServerName() string

TLSServerName returns the explicit ServerName for the TLS handshake, or empty.

func (*EndpointCredentials) TLSVerify

func (c *EndpointCredentials) TLSVerify() api.TLSVerify

TLSVerify returns the resolved TLS verify policy.

type QueryOptions

type QueryOptions struct {
	Retry      bool
	Tries      int
	Parallel   bool
	Silent     bool
	LogQueries bool
	*Timeouts
}

QueryOptions specifies options of a query

func NewQueryOptions

func NewQueryOptions() *QueryOptions

NewQueryOptions creates new query options

func QueryOptionsNormalize

func QueryOptionsNormalize(opts ...*QueryOptions) *QueryOptions

QueryOptionsNormalize normalizes options

func (*QueryOptions) GetLogQueries

func (o *QueryOptions) GetLogQueries() bool

GetLogQueries gets log_queries status

func (*QueryOptions) GetRetry

func (o *QueryOptions) GetRetry() bool

GetRetry gets retry option

func (*QueryOptions) GetSilent

func (o *QueryOptions) GetSilent() bool

GetSilent gets silent option

func (*QueryOptions) Normalize

func (o *QueryOptions) Normalize() *QueryOptions

Normalize normalizes options

func (*QueryOptions) SetLogQueries

func (o *QueryOptions) SetLogQueries(logQueries bool) *QueryOptions

SetLogQueries sets log_queries option

func (*QueryOptions) SetRetry

func (o *QueryOptions) SetRetry(retry bool) *QueryOptions

SetRetry sets retry option

func (*QueryOptions) SetSilent

func (o *QueryOptions) SetSilent(silent bool) *QueryOptions

SetSilent sets silent option

type QueryResult

type QueryResult struct {

	// Query result rows
	Rows *databasesql.Rows
	// contains filtered or unexported fields
}

QueryResult specifies result of a query

func NewQueryResult

func NewQueryResult(ctx context.Context, cancelFunc context.CancelFunc, rows *databasesql.Rows) *QueryResult

NewQueryResult creates new query result

func (*QueryResult) Close

func (q *QueryResult) Close()

Close closes query result and releases all allocated resources. Should be called on each query result

func (*QueryResult) Int

func (q *QueryResult) Int() (int, error)

Int fetches one int from the query result

func (*QueryResult) String

func (q *QueryResult) String() (string, error)

String fetches one string from the query result

func (*QueryResult) UnzipColumnsAsStrings

func (q *QueryResult) UnzipColumnsAsStrings(columns ...*[]string) error

UnzipColumnsAsStrings splits result table into string columns

type Timeouts

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

Timeouts specifies set of timeouts for a clickhouse connection

func NewTimeouts

func NewTimeouts(timeouts ...time.Duration) *Timeouts

NewTimeouts creates new set of timeouts

func (*Timeouts) GetConnectTimeout

func (t *Timeouts) GetConnectTimeout() time.Duration

GetConnectTimeout gets connect timeout

func (*Timeouts) GetQueryTimeout

func (t *Timeouts) GetQueryTimeout() time.Duration

GetQueryTimeout gets query timeout

func (*Timeouts) SetConnectTimeout

func (t *Timeouts) SetConnectTimeout(timeout time.Duration) *Timeouts

SetConnectTimeout sets connect timeout

func (*Timeouts) SetQueryTimeout

func (t *Timeouts) SetQueryTimeout(timeout time.Duration) *Timeouts

SetQueryTimeout sets query timeout

Jump to

Keyboard shortcuts

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