db.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package consts
  15. import "yunion.io/x/log"
  16. var (
  17. QueryOffsetOptimization = false
  18. OpsLogWithClickhouse = false
  19. defaultDBDialect string
  20. defaultDBConnectionString string
  21. defaultDBChecksumHashAlgorithm string
  22. taskWorkerCount int
  23. localTaskWorkerCount int
  24. taskArchiveThresholdHours int
  25. taskArchiveBatchLimit int
  26. enableChangeOwnerAutoRename = false
  27. enableDefaultPolicy = true
  28. )
  29. func SetDefaultPolicy(enable bool) {
  30. enableDefaultPolicy = enable
  31. }
  32. func IsEnableDefaultPolicy() bool {
  33. return enableDefaultPolicy == true
  34. }
  35. func SetDefaultDB(dialect, connStr string) {
  36. defaultDBDialect = dialect
  37. defaultDBConnectionString = connStr
  38. }
  39. func DefaultDBDialect() string {
  40. return defaultDBDialect
  41. }
  42. func DefaultDBConnStr() string {
  43. return defaultDBConnectionString
  44. }
  45. func SetDefaultDBChecksumHashAlgorithm(alg string) {
  46. log.Infof("Set default DB checksum hash algorithm: %s", alg)
  47. defaultDBChecksumHashAlgorithm = alg
  48. }
  49. func DefaultDBChecksumHashAlgorithm() string {
  50. if len(defaultDBChecksumHashAlgorithm) > 0 {
  51. return defaultDBChecksumHashAlgorithm
  52. }
  53. return "sha256"
  54. }
  55. func SetTaskWorkerCount(cnt int) {
  56. taskWorkerCount = cnt
  57. }
  58. func SetLocalTaskWorkerCount(cnt int) {
  59. localTaskWorkerCount = cnt
  60. }
  61. func SetChangeOwnerAutoRename(enable bool) {
  62. enableChangeOwnerAutoRename = enable
  63. }
  64. func GetChangeOwnerAutoRename() bool {
  65. return enableChangeOwnerAutoRename
  66. }
  67. func SetTaskArchiveThresholdHours(hours int) {
  68. taskArchiveThresholdHours = hours
  69. }
  70. func SetTaskArchiveBatchLimit(limit int) {
  71. taskArchiveBatchLimit = limit
  72. }
  73. func TaskWorkerCount() int {
  74. return taskWorkerCount
  75. }
  76. func LocalTaskWorkerCount() int {
  77. return localTaskWorkerCount
  78. }
  79. func TaskArchiveThresholdHours() int {
  80. return taskArchiveThresholdHours
  81. }
  82. func TaskArchiveBatchLimit() int {
  83. return taskArchiveBatchLimit
  84. }