Documentation
¶
Index ¶
- Constants
- Variables
- func CloseDBConn()
- func GetLabelSelector() map[string]string
- func GetSQLWriterDBAddressFunc() func(context.Context, bool) (string, error)
- func IsRecordExisted(ctx context.Context, record []string, tbl *table.Table, ...) (bool, error)
- func SetDBConn(conn *sql.DB)
- func SetLabelSelector(labels map[string]string)
- func SetSQLWriterDBAddressFunc(f func(context.Context, bool) (string, error))
- func SetSQLWriterDBUser(userName string, password string)
- func WriteRowRecords(records [][]string, tbl *table.Table, timeout time.Duration) (int, error)
- type CSVWriter
- func (w *CSVWriter) Flush()
- func (w *CSVWriter) FlushAndClose() (int, error)
- func (w *CSVWriter) GetContent() string
- func (w *CSVWriter) GetContentLength() int
- func (w *CSVWriter) Release()
- func (w *CSVWriter) ResetBuffer(buf *bytes.Buffer)
- func (w *CSVWriter) WriteRow(row *table.Row) error
- func (w *CSVWriter) WriteStrings(record []string) error
- type DBConnProvider
- type DBUser
- type ReConnectionBackOff
Constants ¶
const DBConnRetryThreshold = 8
const DBRefreshTime = time.Hour
const MOLoggerUser = "mo_logger"
const MaxConnectionNumber = 1
Variables ¶
var (
DBConnErrCount = NewReConnectionBackOff(time.Minute, DBConnRetryThreshold)
)
sqlWriterDBUser holds the db user for logger
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:
- 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
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 IsRecordExisted ¶ added in v1.0.0
func SetLabelSelector ¶ added in v1.1.2
func SetSQLWriterDBUser ¶
Types ¶
type CSVWriter ¶ added in v1.0.0
type CSVWriter struct {
// contains filtered or unexported fields
}
func NewCSVWriter ¶ added in v1.0.0
func NewCSVWriterWithBuffer ¶
func (*CSVWriter) FlushAndClose ¶
FlushAndClose implements RowWriter, but NO Close action.
func (*CSVWriter) GetContent ¶ added in v1.0.0
func (*CSVWriter) GetContentLength ¶
func (*CSVWriter) ResetBuffer ¶
func (*CSVWriter) WriteStrings ¶ added in v1.0.0
type DBConnProvider ¶ added in v1.0.0
type DBUser ¶
func GetSQLWriterDBUser ¶
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()