-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
75 lines (58 loc) · 1.77 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"log"
"ivanj26/sonic/constant"
"ivanj26/sonic/lib/migrator"
"ivanj26/sonic/util"
"ivanj26/sonic/util/logger"
)
func main() {
var sourceIp string
flag.StringVar(&sourceIp, "s", "", "Redis source master ip address")
var destIp string
flag.StringVar(&destIp, "d", "", "Redis dest master ip address")
var password string
flag.StringVar(&password, "a", "", "Redis password")
var slotRaw string
flag.StringVar(&slotRaw, "l", "", "Slots. Could be range 6500,6600 or single slot 6600")
var nbOfSlot int
flag.IntVar(&nbOfSlot, "n", 0, "Number of slots. Must be positive integer >0.")
var maxConcurrent int
flag.IntVar(&maxConcurrent, "p", 5, "Number of parallel slot migration (equivalent to number of go routine)")
var logFilePath string
flag.StringVar(&logFilePath, "log-path", constant.DEFAULT_LOG_FILENAME, "Path to log file")
var enableInfoLog bool
flag.BoolVar(&enableInfoLog, "enable-info-log", true, "To disable info log, set as false")
flag.Parse()
// Initialize the logger
err := logger.New().
SetFilePath(logFilePath).
SetInfoEnabled(enableInfoLog).
Initialize()
if err != nil {
log.Fatalf("Failed to initialize logger: %v", err)
}
if util.IsEmpty(sourceIp) ||
util.IsEmpty(destIp) ||
util.IsEmpty(password) {
logger.Fatal("Please fill the arguments to execute the reshard")
}
sonicMigrator, closeConn := migrator.New().
SetSource(sourceIp, constant.DEFAULT_REDIS_PORT, password).
SetDestination(destIp, constant.DEFAULT_REDIS_PORT, password).
SetMaxConcurrency(maxConcurrent).
Build()
defer closeConn()
// Perform resharding
var slotI interface{}
if util.IsEmpty(slotRaw) {
slotI = nbOfSlot
} else {
slotI = slotRaw
}
err = sonicMigrator.Reshard(slotI)
if err != nil {
logger.Error(err.Error())
}
}