Skip to content

Commit

Permalink
Merge pull request #9 from liubo0127/liubo/auto_add_partition
Browse files Browse the repository at this point in the history
modify to create partition early for next month/day/year
  • Loading branch information
liubo0127 authored Mar 2, 2021
2 parents 7ff8894 + c236324 commit ca41fbc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions crontab_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,16 @@ func (c createPartition) Run() {
)
if ptinterval == "month" {
t1 = "200601"
threshold = fmt.Sprintf("%s-01 00:00:00", nowTime.AddDate(0, 1, 0).Format("2006-01"))
threshold = fmt.Sprintf("%s-01 00:00:00", nowTime.AddDate(0, 2, 0).Format("2006-01"))
newPT = fmt.Sprintf("%s%s", ptprefix, nowTime.AddDate(0, 1, 0).Format(t1))
} else if ptinterval == "day" {
t1 = "20060102"
threshold = fmt.Sprintf("%s 00:00:00", nowTime.AddDate(0, 0, 1).Format("2006-01-02"))
newPT = fmt.Sprintf("%s%s", ptprefix, nowTime.AddDate(0, 1, 0).Format(t1))
threshold = fmt.Sprintf("%s 00:00:00", nowTime.AddDate(0, 0, 2).Format("2006-01-02"))
newPT = fmt.Sprintf("%s%s", ptprefix, nowTime.AddDate(0, 0, 1).Format(t1))
} else if ptinterval == "year" {
t1 = "2006"
threshold = fmt.Sprintf("%s-01-01 00:00:00", nowTime.AddDate(1, 0, 0).Format("2006"))
newPT = fmt.Sprintf("%s%s", ptprefix, nowTime.AddDate(0, 1, 0).Format(t1))
threshold = fmt.Sprintf("%s-01-01 00:00:00", nowTime.AddDate(2, 0, 0).Format("2006"))
newPT = fmt.Sprintf("%s%s", ptprefix, nowTime.AddDate(1, 0, 0).Format(t1))
}

results, err := runQuery(DB, fmt.Sprintf("select PARTITION_NAME,PARTITION_EXPRESSION,CREATE_TIME from information_schema.partitions "+
Expand Down Expand Up @@ -324,11 +324,11 @@ func main() {
var spec string

if ptinterval == "month" {
spec = "0 0 * 1 * *"
spec = "0 0 * 3 * *"
} else if ptinterval == "day" {
spec = "0 0 * * * *"
spec = "0 3 * * * *"
} else if ptinterval == "year" {
spec = "0 0 * 1 1 *"
spec = "0 0 * 3 1 *"
} else {
logger.Println("[INFO] --ptinterval must be one of month/year/day")
fmt.Println("--ptinterval must be one of month/year/day")
Expand Down

0 comments on commit ca41fbc

Please # to comment.