2019-12-20 12:25:40 +00:00
|
|
|
package debug
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2021-02-09 02:31:37 +00:00
|
|
|
"strconv"
|
2020-05-04 05:55:51 +00:00
|
|
|
"sync"
|
2020-02-12 11:34:44 +00:00
|
|
|
"sync/atomic"
|
2021-02-09 02:31:37 +00:00
|
|
|
"time"
|
2019-12-20 12:25:40 +00:00
|
|
|
)
|
|
|
|
|
2020-02-16 16:50:24 +00:00
|
|
|
// atomic: bit 0 is the value, bit 1 is the initialized flag
|
|
|
|
var getNodeData uint32
|
|
|
|
|
|
|
|
const (
|
|
|
|
gndValueFlag = 1 << iota
|
|
|
|
gndInitializedFlag
|
|
|
|
)
|
2020-02-10 17:05:32 +00:00
|
|
|
|
2020-02-12 11:34:44 +00:00
|
|
|
// IsGetNodeData indicates whether the GetNodeData functionality should be enabled.
|
2020-02-16 16:50:24 +00:00
|
|
|
// By default that's driven by the presence or absence of DISABLE_GET_NODE_DATA environment variable.
|
2020-02-10 17:05:32 +00:00
|
|
|
func IsGetNodeData() bool {
|
2020-02-12 11:34:44 +00:00
|
|
|
x := atomic.LoadUint32(&getNodeData)
|
2020-02-16 16:50:24 +00:00
|
|
|
if x&gndInitializedFlag != 0 { // already initialized
|
|
|
|
return x&gndValueFlag != 0
|
2020-02-12 11:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RestoreGetNodeData()
|
|
|
|
return IsGetNodeData()
|
|
|
|
}
|
|
|
|
|
|
|
|
// RestoreGetNodeData enables or disables the GetNodeData functionality
|
2020-05-02 18:00:57 +00:00
|
|
|
// according to the presence or absence of GET_NODE_DATA environment variable.
|
2020-02-12 11:34:44 +00:00
|
|
|
func RestoreGetNodeData() {
|
2020-05-02 18:00:57 +00:00
|
|
|
_, envVarSet := os.LookupEnv("GET_NODE_DATA")
|
|
|
|
OverrideGetNodeData(envVarSet)
|
2020-02-12 11:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OverrideGetNodeData allows to explicitly enable or disable the GetNodeData functionality.
|
|
|
|
func OverrideGetNodeData(val bool) {
|
|
|
|
if val {
|
2020-02-16 16:50:24 +00:00
|
|
|
atomic.StoreUint32(&getNodeData, gndInitializedFlag|gndValueFlag)
|
2020-02-12 11:34:44 +00:00
|
|
|
} else {
|
2020-02-16 16:50:24 +00:00
|
|
|
atomic.StoreUint32(&getNodeData, gndInitializedFlag)
|
2020-02-12 11:34:44 +00:00
|
|
|
}
|
2020-02-10 17:05:32 +00:00
|
|
|
}
|
2020-05-04 05:55:51 +00:00
|
|
|
|
2020-06-05 09:25:33 +00:00
|
|
|
var (
|
|
|
|
testDB string
|
|
|
|
getTestDB sync.Once
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDB() string {
|
|
|
|
getTestDB.Do(func() {
|
|
|
|
testDB, _ = os.LookupEnv("TEST_DB")
|
|
|
|
if testDB == "" {
|
2020-06-18 18:13:58 +00:00
|
|
|
testDB = ""
|
2020-06-05 09:25:33 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
return testDB
|
|
|
|
}
|
2021-02-09 02:31:37 +00:00
|
|
|
|
|
|
|
var (
|
|
|
|
bigRoTx uint
|
|
|
|
getBigRoTx sync.Once
|
|
|
|
)
|
|
|
|
|
|
|
|
// DEBUG_BIG_RO_TX_KB - print logs with info about large read-only transactions
|
|
|
|
// DEBUG_BIG_RW_TX_KB - print logs with info about large read-write transactions
|
|
|
|
// DEBUG_SLOW_COMMIT_MS - print logs with commit timing details if commit is slower than this threshold
|
|
|
|
func BigRoTxKb() uint {
|
|
|
|
getBigRoTx.Do(func() {
|
|
|
|
v, _ := os.LookupEnv("DEBUG_BIG_RO_TX_KB")
|
|
|
|
if v != "" {
|
|
|
|
i, err := strconv.Atoi(v)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
bigRoTx = uint(i)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return bigRoTx
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
bigRwTx uint
|
|
|
|
getBigRwTx sync.Once
|
|
|
|
)
|
|
|
|
|
|
|
|
func BigRwTxKb() uint {
|
|
|
|
getBigRwTx.Do(func() {
|
|
|
|
v, _ := os.LookupEnv("DEBUG_BIG_RW_TX_KB")
|
|
|
|
if v != "" {
|
|
|
|
i, err := strconv.Atoi(v)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
bigRwTx = uint(i)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return bigRwTx
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
slowCommit time.Duration
|
|
|
|
getSlowCommit sync.Once
|
|
|
|
)
|
|
|
|
|
|
|
|
func SlowCommit() time.Duration {
|
|
|
|
getSlowCommit.Do(func() {
|
|
|
|
v, _ := os.LookupEnv("DEBUG_SLOW_COMMIT_MS")
|
|
|
|
if v != "" {
|
|
|
|
i, err := strconv.Atoi(v)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
slowCommit = time.Duration(i) * time.Millisecond
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return slowCommit
|
|
|
|
}
|