forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtjanitor.go
65 lines (53 loc) · 1.82 KB
/
vtjanitor.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
package main
import (
"flag"
"fmt"
"os"
"time"
log "github.com/golang/glog"
"github.com/youtube/vitess/go/flagutil"
"github.com/youtube/vitess/go/vt/janitor"
"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/tabletmanager/actionnode"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/wrangler"
)
var (
sleepTime = flag.Duration("sleep_time", 3*time.Minute, "how long to sleep between janitor runs")
lockTimeout = flag.Duration("lock_timeout", actionnode.DefaultLockTimeout, "lock time for wrangler/topo operations")
actionTimeout = flag.Duration("action_timeout", wrangler.DefaultActionTimeout, "time to wait for an action before resorting to force")
keyspace = flag.String("keyspace", "", "keyspace to manage")
shard = flag.String("shard", "", "shard to manage")
dryRunModules flagutil.StringListValue
activeModules flagutil.StringListValue
)
func init() {
servenv.RegisterDefaultFlags()
flag.Var(&dryRunModules, "dry_run_modules", "modules to run in dry run mode")
flag.Var(&activeModules, "active_modules", "modules to run in active mode")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
fmt.Fprintf(os.Stderr, "Available modules:\n")
for _, m := range janitor.AvailableModules() {
fmt.Fprintf(os.Stderr, " %v\n", m)
}
fmt.Fprint(os.Stderr, "\n")
flag.PrintDefaults()
}
}
func main() {
flag.Parse()
servenv.Init()
ts := topo.GetServer()
scheduler, err := janitor.New(*keyspace, *shard, ts, wrangler.New(ts, *actionTimeout, *lockTimeout), *sleepTime)
if err != nil {
log.Fatalf("janitor.New: %v", err)
}
if len(activeModules)+len(dryRunModules) < 1 {
log.Fatal("no modules to run specified")
}
scheduler.Enable(activeModules)
scheduler.EnableDryRun(dryRunModules)
go scheduler.Run()
servenv.RunDefault()
}