|
|
|
@ -1,7 +1,9 @@ |
|
|
|
package main |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"os" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
|
|
|
|
"github.com/yedf/dtm/dtmcli" |
|
|
|
@ -19,6 +21,25 @@ func wait() { |
|
|
|
} |
|
|
|
|
|
|
|
func main() { |
|
|
|
if len(os.Args) == 1 { |
|
|
|
for _, ln := range []string{ |
|
|
|
"dtm is a lightweight distributed transaction manager.", |
|
|
|
"usage:", |
|
|
|
"dtm [command]", |
|
|
|
"", |
|
|
|
"Available Commands:", |
|
|
|
"dtmsvr run dtm as a server. ", |
|
|
|
"", |
|
|
|
"quick_start run quick start example. dtm will create all needed table", |
|
|
|
"qs same as quick_start", |
|
|
|
} { |
|
|
|
fmt.Print(ln + "\n") |
|
|
|
} |
|
|
|
for name := range examples.Samples { |
|
|
|
fmt.Printf("%-18srun a sample includes %s\n", name, strings.Replace(name, "_", " ", 100)) |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
onlyServer := len(os.Args) > 1 && os.Args[1] == "dtmsvr" |
|
|
|
if !onlyServer { // 实际线上运行,只启动dtmsvr,不准备table相关的数据
|
|
|
|
dtmsvr.PopulateDB(true) |
|
|
|
@ -43,8 +64,8 @@ func main() { |
|
|
|
examples.GrpcStartup() |
|
|
|
examples.BaseAppStartup() |
|
|
|
|
|
|
|
fn := examples.Samples[os.Args[1]] |
|
|
|
dtmcli.LogIfFatalf(fn == nil, "no sample name for %s", os.Args[1]) |
|
|
|
fn() |
|
|
|
sample := examples.Samples[os.Args[1]] |
|
|
|
dtmcli.LogIfFatalf(sample == nil, "no sample name for %s", os.Args[1]) |
|
|
|
sample.Action() |
|
|
|
wait() |
|
|
|
} |
|
|
|
|