db_holder

package
v0.0.0-debug-20260702 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DBConnRetryThreshold = 8
View Source
const DBRefreshTime = time.Hour
View Source
const MOLoggerUser = "mo_logger"
View Source
const MaxConnectionNumber = 1

Variables

sqlWriterDBUser holds the db user for logger

View Source
var GetOrInitDBConn = func(forceNewConn bool, randomCN bool) (*sql.DB, error) {
	current, refreshDue := getDBConnSnapshot()
	if current != nil && !forceNewConn && !refreshDue {
		return current, nil
	}
	if current != nil && !forceNewConn && refreshDue && !dbRebuildMux.TryLock() {
		return current, nil
	}
	if current == nil || forceNewConn || !refreshDue {
		dbRebuildMux.Lock()
	}
	defer dbRebuildMux.Unlock()

	if forceNewConn {
		current, _ = getDBConnSnapshot()
		if current != nil && DBConnErrCount.Check() {
			return current, nil
		}
	}

	return rebuildDBConn(forceNewConn, randomCN)
}

GetOrInitDBConn get the target cn to do the load query. if @forceNewConn is true, it will re-find new cn and replace the old db conn after the new one is ready. The reconnect decision is rechecked after acquiring the rebuild lock, so callers queued behind a successful reconnect reuse the fresh current db conn instead of serially rebuilding more pools. if @forceNewConn is false, it will normally fetch the current db connection. BUT in 1 cases, it will re-find the cn:

  1. DBRefreshTime interval, it will try to fetch the 'new' ob-sys cn.

Functions

func CloseDBConn added in v1.0.1

func CloseDBConn()

func GetLabelSelector added in v1.1.2

func GetLabelSelector() map[string]string

GetLabelSelector Tips: more details in route.RouteForSuperTenant function. It mainly depends on S1. Tips: gLabels better contain {"account":"sys"}. - Because clusterservice.Selector using clusterservice.globbing do regex-match in route.RouteForSuperTenant - If you use labels{"account":"sys", "role":"ob"}, the Selector can match those pods, which have labels{"account":"*", "role":"ob"}

func GetSQLWriterDBAddressFunc

func GetSQLWriterDBAddressFunc() func(context.Context, bool) (string, error)

func IsRecordExisted added in v1.0.0

func IsRecordExisted(ctx context.Context, record []string, tbl *table.Table, getDBConn DBConnProvider) (bool, error)

func SetDBConn

func SetDBConn(conn *sql.DB)

func SetLabelSelector added in v1.1.2

func SetLabelSelector(labels map[string]string)

func SetSQLWriterDBAddressFunc

func SetSQLWriterDBAddressFunc(f func(context.Context, bool) (string, error))

func SetSQLWriterDBUser

func SetSQLWriterDBUser(userName string, password string)

func WriteRowRecords

func WriteRowRecords(records [][]string, tbl *table.Table, timeout time.Duration) (int, error)

Types

type CSVWriter added in v1.0.0

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

func NewCSVWriter added in v1.0.0

func NewCSVWriter(ctx context.Context) *CSVWriter

func NewCSVWriterWithBuffer

func NewCSVWriterWithBuffer(ctx context.Context, buf *bytes.Buffer) *CSVWriter

func (*CSVWriter) Flush

func (w *CSVWriter) Flush()

func (*CSVWriter) FlushAndClose

func (w *CSVWriter) FlushAndClose() (int, error)

FlushAndClose implements RowWriter, but NO Close action.

func (*CSVWriter) GetContent added in v1.0.0

func (w *CSVWriter) GetContent() string

func (*CSVWriter) GetContentLength

func (w *CSVWriter) GetContentLength() int

func (*CSVWriter) Release added in v1.0.0

func (w *CSVWriter) Release()

func (*CSVWriter) ResetBuffer

func (w *CSVWriter) ResetBuffer(buf *bytes.Buffer)

func (*CSVWriter) WriteRow

func (w *CSVWriter) WriteRow(row *table.Row) error

func (*CSVWriter) WriteStrings added in v1.0.0

func (w *CSVWriter) WriteStrings(record []string) error

type DBConnProvider added in v1.0.0

type DBConnProvider func(forceNewConn bool, randomCN bool) (*sql.DB, error)

type DBUser

type DBUser struct {
	UserName string
	Password string
}

func GetSQLWriterDBUser

func GetSQLWriterDBUser() (*DBUser, error)

type ReConnectionBackOff

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

func NewReConnectionBackOff

func NewReConnectionBackOff(window time.Duration, threshold int) *ReConnectionBackOff

func (*ReConnectionBackOff) Check

func (b *ReConnectionBackOff) Check() bool

Check return same as Count, but without changed.

func (*ReConnectionBackOff) Count

func (b *ReConnectionBackOff) Count() bool

Count implement table.BackOff return true, means not in backoff cycle. You can run your code.

func (*ReConnectionBackOff) Reset

func (b *ReConnectionBackOff) Reset()

Jump to

Keyboard shortcuts

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