From 10d48346b5dd22a6967a5ec19c73f87114fcc208 Mon Sep 17 00:00:00 2001 From: Levente Liu Date: Fri, 19 Apr 2019 14:43:37 +0800 Subject: [PATCH 01/11] Add json tags for resource meta --- types/init_service_type.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/types/init_service_type.go b/types/init_service_type.go index 5a94439df..988db30a4 100644 --- a/types/init_service_type.go +++ b/types/init_service_type.go @@ -31,15 +31,15 @@ type InitService struct { // ResourceMeta defines single database resource meta. type ResourceMeta struct { - TargetMiners []proto.AccountAddress // designated miners - Node uint16 // reserved node count - Space uint64 // reserved storage space in bytes - Memory uint64 // reserved memory in bytes - LoadAvgPerCPU float64 // max loadAvg15 per CPU - EncryptionKey string // encryption key for database instance - UseEventualConsistency bool // use eventual consistency replication if enabled - ConsistencyLevel float64 // customized strong consistency level - IsolationLevel int // customized isolation level + TargetMiners []proto.AccountAddress `json:"target-miners,omitempty"` // designated miners + Node uint16 `json:"node,omitempty"` // reserved node count + Space uint64 `json:"space,omitempty"` // reserved storage space in bytes + Memory uint64 `json:"memory",omitempty` // reserved memory in bytes + LoadAvgPerCPU float64 `json:"load-avg-per-cpu"` // max loadAvg15 per CPU + EncryptionKey string `json:"encrypt-key,omitempty"` // encryption key for database instance + UseEventualConsistency bool `json:"enentual-consistency,omitempty"` // use eventual consistency replication if enabled + ConsistencyLevel float64 `json:"consistency-level,omitempty"` // customized strong consistency level + IsolationLevel int `json:"isolation-level,omitempty"` // customized isolation level } // ServiceInstance defines single instance to be initialized. From 7b81c4b1a416fc5cb77b53bff92988f266f9623b Mon Sep 17 00:00:00 2001 From: Levente Liu Date: Fri, 19 Apr 2019 17:38:09 +0800 Subject: [PATCH 02/11] Format some usage messages --- cmd/cql/internal/adapter.go | 4 ++-- cmd/cql/internal/base.go | 8 ++++++-- cmd/cql/internal/cfg.go | 10 +++++----- cmd/cql/internal/console.go | 2 +- cmd/cql/internal/create.go | 2 +- cmd/cql/internal/drop.go | 2 +- cmd/cql/internal/explorer.go | 4 ++-- cmd/cql/internal/generate.go | 2 +- cmd/cql/internal/grant.go | 2 +- cmd/cql/internal/help.go | 16 ++++++++++------ cmd/cql/internal/idminer.go | 2 +- cmd/cql/internal/mirror.go | 4 ++-- cmd/cql/internal/rpc.go | 2 +- cmd/cql/internal/transfer.go | 2 +- cmd/cql/internal/wallet.go | 4 ++-- 15 files changed, 37 insertions(+), 29 deletions(-) diff --git a/cmd/cql/internal/adapter.go b/cmd/cql/internal/adapter.go index 644bd76a0..baf3202c1 100644 --- a/cmd/cql/internal/adapter.go +++ b/cmd/cql/internal/adapter.go @@ -31,8 +31,8 @@ var ( // CmdAdapter is cql adapter command entity. var CmdAdapter = &Command{ - UsageLine: "cql adapter [-config file] [-tmp-path path] [-bg-log-level level] [-mirror addr] listen_address", - Short: "start a SQLChain adapter", + UsageLine: "cql adapter [common params] [-tmp-path path] [-bg-log-level level] [-mirror addr] listen_address", + Short: "start a SQLChain adapter server", Long: ` Adapter command serves a SQLChain adapter e.g. diff --git a/cmd/cql/internal/base.go b/cmd/cql/internal/base.go index 7ccf52fd7..4112be57f 100644 --- a/cmd/cql/internal/base.go +++ b/cmd/cql/internal/base.go @@ -39,6 +39,10 @@ var ( func init() { ConsoleLog = logrus.New() + ConsoleLog.SetFormatter(&logrus.TextFormatter{ + DisableTimestamp: true, + DisableLevelTruncation: true, + }) } // A Command is an implementation of a cql command @@ -85,8 +89,8 @@ func (c *Command) Name() string { // Usage print base usage help info. func (c *Command) Usage() { - fmt.Fprintf(os.Stderr, "usage: %s\n", c.UsageLine) - fmt.Fprintf(os.Stderr, "Run 'cql help %s' for details.\n", c.LongName()) + fmt.Fprintf(os.Stdout, "usage: %s\n", c.UsageLine) + fmt.Fprintf(os.Stdout, "Run 'cql help %s' for details.\n", c.LongName()) os.Exit(2) } diff --git a/cmd/cql/internal/cfg.go b/cmd/cql/internal/cfg.go index 9a6c8f2a6..f4f0f15c2 100644 --- a/cmd/cql/internal/cfg.go +++ b/cmd/cql/internal/cfg.go @@ -56,7 +56,7 @@ func addCommonFlags(cmd *Command) { "Config file for covenantsql (Usually no need to set, default is enough.)") // debugging flags. - cmd.Flag.StringVar(&consoleLogLevel, "log-level", "error", + cmd.Flag.StringVar(&consoleLogLevel, "log-level", "info", "Console log level: trace debug info warning error fatal panic") cmd.Flag.StringVar(&password, "password", "", "Master key password for covenantsql (NOT SAFE, for debug or script only)") @@ -69,15 +69,15 @@ func addCommonFlags(cmd *Command) { func configInit(cmd *Command) { if help { - _, _ = fmt.Fprintf(os.Stderr, "usage: %s\n", cmd.UsageLine) - _, _ = fmt.Fprintf(os.Stderr, cmd.Long) - _, _ = fmt.Fprintf(os.Stderr, "\nParams:\n") + _, _ = fmt.Fprintf(os.Stdout, "usage: %s\n", cmd.UsageLine) + _, _ = fmt.Fprintf(os.Stdout, cmd.Long) + _, _ = fmt.Fprintf(os.Stdout, "\nParams:\n") cmd.Flag.PrintDefaults() Exit() } if lvl, err := logrus.ParseLevel(consoleLogLevel); err != nil { - ConsoleLog.SetLevel(logrus.ErrorLevel) + ConsoleLog.SetLevel(log.InfoLevel) } else { ConsoleLog.SetLevel(lvl) } diff --git a/cmd/cql/internal/console.go b/cmd/cql/internal/console.go index a154ba518..d3f068a2a 100644 --- a/cmd/cql/internal/console.go +++ b/cmd/cql/internal/console.go @@ -46,7 +46,7 @@ import ( // CmdConsole is cql console command entity. var CmdConsole = &Command{ - UsageLine: "cql console [-config file] [-dsn dsn_string] [-command sqlcommand] [-file filename] [-out outputfile] [-no-rc true/false] [-single-transaction] [-variable variables] [-explorer explorer_addr] [-adapter adapter_addr]", + UsageLine: "cql console [common params] [-dsn dsn_string] [-command sqlcommand] [-file filename] [-out outputfile] [-no-rc true/false] [-single-transaction] [-variable variables] [-explorer explorer_addr] [-adapter adapter_addr]", Short: "run a console for interactive sql operation", Long: ` Console command can run a interactive SQL console for CovenantSQL diff --git a/cmd/cql/internal/create.go b/cmd/cql/internal/create.go index f7b3bfa42..385603d07 100644 --- a/cmd/cql/internal/create.go +++ b/cmd/cql/internal/create.go @@ -26,7 +26,7 @@ import ( // CmdCreate is cql create command entity. var CmdCreate = &Command{ - UsageLine: "cql create [-config file] [-wait-tx-confirm] db_meta_json", + UsageLine: "cql create [common params] [-wait-tx-confirm] db_meta_json", Short: "create a database", Long: ` Create CovenantSQL database by database meta info JSON string, meta info must include node count. diff --git a/cmd/cql/internal/drop.go b/cmd/cql/internal/drop.go index 5bc0a0583..dcef9ddff 100644 --- a/cmd/cql/internal/drop.go +++ b/cmd/cql/internal/drop.go @@ -22,7 +22,7 @@ import ( // CmdDrop is cql drop command entity. var CmdDrop = &Command{ - UsageLine: "cql drop [-config file] [-wait-tx-confirm] dsn", + UsageLine: "cql drop [common params] [-wait-tx-confirm] dsn", Short: "drop a database by dsn or database id", Long: ` Drop command can drop a database by DSN or database id diff --git a/cmd/cql/internal/explorer.go b/cmd/cql/internal/explorer.go index a1a9cc9be..e4341603e 100644 --- a/cmd/cql/internal/explorer.go +++ b/cmd/cql/internal/explorer.go @@ -32,8 +32,8 @@ var ( // CmdExplorer is cql explorer command. var CmdExplorer = &Command{ - UsageLine: "cql explorer [-config file] [-tmp-path path] [-bg-log-level level] listen_address", - Short: "start a SQLChain explorer explorer", + UsageLine: "cql explorer [common params] [-tmp-path path] [-bg-log-level level] listen_address", + Short: "start a SQLChain explorer server", Long: ` Explorer command serves a SQLChain web explorer. e.g. diff --git a/cmd/cql/internal/generate.go b/cmd/cql/internal/generate.go index 0870bb633..dd0b25eda 100644 --- a/cmd/cql/internal/generate.go +++ b/cmd/cql/internal/generate.go @@ -36,7 +36,7 @@ import ( // CmdGenerate is cql generate command entity. var CmdGenerate = &Command{ - UsageLine: "cql generate [-config file] config/public", + UsageLine: "cql generate [common params] config | public", Short: "generate config related file or keys", Long: ` Generate command can generate private.key and config.yaml for CovenantSQL. diff --git a/cmd/cql/internal/grant.go b/cmd/cql/internal/grant.go index a608771d8..e584aca0a 100644 --- a/cmd/cql/internal/grant.go +++ b/cmd/cql/internal/grant.go @@ -26,7 +26,7 @@ import ( // CmdGrant is cql grant command entity. var CmdGrant = &Command{ - UsageLine: "cql grant [-config file] [-wait-tx-confirm] permission_meta_json", + UsageLine: "cql grant [common params] [-wait-tx-confirm] permission_meta_json", Short: "grant a user's permissions on specific sqlchain", Long: ` Grant command can give a user some specific permissions on your database diff --git a/cmd/cql/internal/help.go b/cmd/cql/internal/help.go index a9ad89fa4..989832d06 100644 --- a/cmd/cql/internal/help.go +++ b/cmd/cql/internal/help.go @@ -69,7 +69,11 @@ func runVersion(cmd *Command, args []string) { } func runHelp(cmd *Command, args []string) { - if len(args) != 1 { + if l := len(args); l != 1 { + if l > 1 { + // Don't support multiple commands + SetExitStatus(2) + } MainUsage() } @@ -78,9 +82,9 @@ func runHelp(cmd *Command, args []string) { if cmd.Name() != cmdName { continue } - fmt.Fprintf(os.Stderr, "usage: %s\n", cmd.UsageLine) - fmt.Fprintf(os.Stderr, cmd.Long) - fmt.Fprintf(os.Stderr, "\nParams:\n") + fmt.Fprintf(os.Stdout, "usage: %s\n", cmd.UsageLine) + fmt.Fprintf(os.Stdout, cmd.Long) + fmt.Fprintf(os.Stdout, "\nParams:\n") cmd.Flag.PrintDefaults() return } @@ -96,7 +100,7 @@ func MainUsage() { Usage: - cql [-params] [arguments] + cql [params] [arguments] The commands are: @@ -118,6 +122,6 @@ Use "cql help " for more information about a command. } helpMsg += helpTail - fmt.Fprintf(os.Stderr, helpMsg) + fmt.Fprintf(os.Stdout, helpMsg) Exit() } diff --git a/cmd/cql/internal/idminer.go b/cmd/cql/internal/idminer.go index 230501dc4..965822d72 100644 --- a/cmd/cql/internal/idminer.go +++ b/cmd/cql/internal/idminer.go @@ -39,7 +39,7 @@ var ( // CmdIDMiner is cql idminer command entity. var CmdIDMiner = &Command{ - UsageLine: "cql idminer [-config file] [-difficulty number] [-loop false]", + UsageLine: "cql idminer [common params] [-difficulty number] [-loop [true]]", Short: "calculate nonce and node id for config.yaml file", Long: ` IDMiner command can calculate legal node id and it's nonce. Default 24 difficulty and no endless loop. diff --git a/cmd/cql/internal/mirror.go b/cmd/cql/internal/mirror.go index 1b7e76050..eeca76ce0 100644 --- a/cmd/cql/internal/mirror.go +++ b/cmd/cql/internal/mirror.go @@ -31,8 +31,8 @@ var ( // CmdMirror is cql mirror command. var CmdMirror = &Command{ - UsageLine: "cql mirror [-config file] [-tmp-path path] [-bg-log-level level] dsn listen_address", - Short: "start a SQLChain database mirror", + UsageLine: "cql mirror [common params] [-tmp-path path] [-bg-log-level level] dsn listen_address", + Short: "start a SQLChain database mirror server", Long: ` Mirror command subscribes database updates and serves a read-only database mirror. e.g. diff --git a/cmd/cql/internal/rpc.go b/cmd/cql/internal/rpc.go index 7f2369f5d..3f1d03ec7 100644 --- a/cmd/cql/internal/rpc.go +++ b/cmd/cql/internal/rpc.go @@ -52,7 +52,7 @@ var ( // CmdRPC is cql rpc command entity. var CmdRPC = &Command{ - UsageLine: "cql rpc [-config file] [-wait-tx-confirm] -name rpc_name -endpoint rpc_endpoint -req rpc_request", + UsageLine: "cql rpc [common params] [-wait-tx-confirm] -name rpc_name -endpoint rpc_endpoint -req rpc_request", Short: "make a rpc request", Long: ` Rpc command make a RPC request to server diff --git a/cmd/cql/internal/transfer.go b/cmd/cql/internal/transfer.go index fa2f6f1d8..e8a9185c3 100644 --- a/cmd/cql/internal/transfer.go +++ b/cmd/cql/internal/transfer.go @@ -29,7 +29,7 @@ import ( // CmdTransfer is cql transfer command entity. var CmdTransfer = &Command{ - UsageLine: "cql transfer [-config file] [-wait-tx-confirm] meta_json", + UsageLine: "cql transfer [common params] [-wait-tx-confirm] meta_json", Short: "transfer token to target account", Long: ` Transfer command can transfer your token to the target account. diff --git a/cmd/cql/internal/wallet.go b/cmd/cql/internal/wallet.go index 110c22f33..9d7fc6b28 100644 --- a/cmd/cql/internal/wallet.go +++ b/cmd/cql/internal/wallet.go @@ -31,7 +31,7 @@ var ( // CmdWallet is cql wallet command entity. var CmdWallet = &Command{ - UsageLine: "cql wallet [-config file] [-balance token_name]", + UsageLine: "cql wallet [common params] [-balance type]", Short: "get the wallet address and the balance of current account", Long: ` Wallet command can get CovenantSQL wallet address and the token balance of current account @@ -110,6 +110,6 @@ func runWallet(cmd *Command, args []string) { SetExitStatus(1) return } - ConsoleLog.Infof("%s balance is: %d", tokenType.String(), tokenBalance) + fmt.Printf("%s balance is: %d\n", tokenType, tokenBalance) } } From fb44ae4ecd04020ca81be6c1bf6815dbf800c003 Mon Sep 17 00:00:00 2001 From: Levente Liu Date: Fri, 19 Apr 2019 18:30:09 +0800 Subject: [PATCH 03/11] Add common parameters in help message --- cmd/cql/internal/help.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/cmd/cql/internal/help.go b/cmd/cql/internal/help.go index 989832d06..beba8c7a6 100644 --- a/cmd/cql/internal/help.go +++ b/cmd/cql/internal/help.go @@ -17,6 +17,7 @@ package internal import ( + "bytes" "fmt" "os" "runtime" @@ -105,23 +106,30 @@ Usage: The commands are: ` + helpCommon := ` +The common params for commands (except help and version) are: + +` + helpTail := ` Use "cql help " for more information about a command. ` - helpMsg := helpHead + output := bytes.NewBuffer(nil) + output.WriteString(helpHead) for _, cmd := range CqlCommands { if cmd.Name() == "help" { continue } - cmdName := cmd.Name() - for len(cmdName) < 10 { - cmdName += " " - } - helpMsg += "\t" + cmdName + "\t" + cmd.Short + "\n" + fmt.Fprintf(output, "\t%-10s\t%s\n", cmd.Name(), cmd.Short) } - helpMsg += helpTail - fmt.Fprintf(os.Stdout, helpMsg) + addCommonFlags(CmdHelp) + fmt.Fprint(output, helpCommon) + CmdHelp.Flag.SetOutput(output) + CmdHelp.Flag.PrintDefaults() + + fmt.Fprint(output, helpTail) + fmt.Fprintf(os.Stdout, output.String()) Exit() } From 0d72a79b81a12779009c4ebccc440a09c90e3bc5 Mon Sep 17 00:00:00 2001 From: Levente Liu Date: Fri, 19 Apr 2019 19:37:48 +0800 Subject: [PATCH 04/11] Write help message to stdout --- cmd/cql/internal/console.go | 4 ++-- cmd/cql/internal/create.go | 16 ++++++++++++++-- cmd/cql/internal/drop.go | 4 ++-- cmd/cql/internal/grant.go | 4 ++-- cmd/cql/internal/help.go | 3 ++- cmd/cql/internal/transfer.go | 4 ++-- types/init_service_type.go | 2 +- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/cmd/cql/internal/console.go b/cmd/cql/internal/console.go index d3f068a2a..8fcaac7ff 100644 --- a/cmd/cql/internal/console.go +++ b/cmd/cql/internal/console.go @@ -51,12 +51,12 @@ var CmdConsole = &Command{ Long: ` Console command can run a interactive SQL console for CovenantSQL e.g. - cql console -dsn covenantsql://the_dsn_of_your_database + cql console -dsn covenantsql://4119ef997dedc585bfbcfae00ab6b87b8486fab323a8e107ea1fd4fc4f7eba5c There is also a -command param for SQL script, and a -file param for reading SQL in a file. If those params are set, it will run SQL script and exit without staying console mode. e.g. - cql console -dsn covenantsql://the_dsn_of_your_database -command "create table test1(test2 int);" + cql console -dsn covenantsql://4119ef997dedc585bfbcfae00ab6b87b8486fab323a8e107ea1fd4fc4f7eba5c -command "create table test1(test2 int);" `, } diff --git a/cmd/cql/internal/create.go b/cmd/cql/internal/create.go index 385603d07..e0afb014f 100644 --- a/cmd/cql/internal/create.go +++ b/cmd/cql/internal/create.go @@ -31,11 +31,23 @@ var CmdCreate = &Command{ Long: ` Create CovenantSQL database by database meta info JSON string, meta info must include node count. e.g. - cql create '{"node":2}' + cql create '{"node": 2}' + +A complete introduction of db_meta_json fields: + + target-miners []string // List of target miner addresses + node int // Target node number + space int // Minimum disk space requirement, 0 for none + memory int // Minimum memory requirement, 0 for none + load-avg-per-cpu float // Minimum idle CPU requirement, 0 for none + encrypt-key string // Encryption key for persistence data + eventual-consistency bool // Use eventual consistency to sync among miner nodes + consistency-level float // Consistency level, node*consistency_level is the node number to perform strong consistency + isolation-level int // Isolation level in a single node Since CovenantSQL is blockchain database, you may want get confirm of creation. e.g. - cql create -wait-tx-confirm '{"node":2}' + cql create -wait-tx-confirm '{"node": 2}' `, } diff --git a/cmd/cql/internal/drop.go b/cmd/cql/internal/drop.go index dcef9ddff..45d6bfbda 100644 --- a/cmd/cql/internal/drop.go +++ b/cmd/cql/internal/drop.go @@ -27,11 +27,11 @@ var CmdDrop = &Command{ Long: ` Drop command can drop a database by DSN or database id e.g. - cql drop covenantsql://the_dsn_of_your_database + cql drop covenantsql://4119ef997dedc585bfbcfae00ab6b87b8486fab323a8e107ea1fd4fc4f7eba5c Since CovenantSQL is blockchain database, you may want get confirm of drop operation. e.g. - cql drop -wait-tx-confirm covenantsql://the_dsn_of_your_database + cql drop -wait-tx-confirm covenantsql://4119ef997dedc585bfbcfae00ab6b87b8486fab323a8e107ea1fd4fc4f7eba5c `, } diff --git a/cmd/cql/internal/grant.go b/cmd/cql/internal/grant.go index e584aca0a..dfde7f0c3 100644 --- a/cmd/cql/internal/grant.go +++ b/cmd/cql/internal/grant.go @@ -31,11 +31,11 @@ var CmdGrant = &Command{ Long: ` Grant command can give a user some specific permissions on your database e.g. - cql grant '{"chain":"your_chain_addr","user":"user_addr","perm":"perm_struct"}' + cql grant '{"chain": "your_chain_addr", "user": "user_addr", "perm": "perm_struct"}' Since CovenantSQL is blockchain database, you may want get confirm of permission update. e.g. - cql grant -wait-tx-confirm '{"chain":"your_chain_addr","user":"user_addr","perm":"perm_struct"}' + cql grant -wait-tx-confirm '{"chain": "your_chain_addr", "user": "user_addr", "perm": "perm_struct"}' `, } diff --git a/cmd/cql/internal/help.go b/cmd/cql/internal/help.go index beba8c7a6..ef3571d4f 100644 --- a/cmd/cql/internal/help.go +++ b/cmd/cql/internal/help.go @@ -59,7 +59,7 @@ func PrintVersion(printLog bool) string { name, Version, runtime.GOOS, runtime.GOARCH, runtime.Version()) if printLog { - ConsoleLog.Infof("cql build: %s\n", version) + fmt.Println("cql build:", version) } return version @@ -86,6 +86,7 @@ func runHelp(cmd *Command, args []string) { fmt.Fprintf(os.Stdout, "usage: %s\n", cmd.UsageLine) fmt.Fprintf(os.Stdout, cmd.Long) fmt.Fprintf(os.Stdout, "\nParams:\n") + cmd.Flag.SetOutput(os.Stdout) cmd.Flag.PrintDefaults() return } diff --git a/cmd/cql/internal/transfer.go b/cmd/cql/internal/transfer.go index e8a9185c3..4a141dc92 100644 --- a/cmd/cql/internal/transfer.go +++ b/cmd/cql/internal/transfer.go @@ -35,11 +35,11 @@ var CmdTransfer = &Command{ Transfer command can transfer your token to the target account. Command argument is JSON meta info of a token transaction. e.g. - cql transfer '{"addr":"your_account_addr","amount":"100 Particle"}' + cql transfer '{"addr": "43602c17adcc96acf2f68964830bb6ebfbca6834961c0eca0915fcc5270e0b40", "amount": "100 Particle"}' Since CovenantSQL is blockchain database, you may want get confirm of permission update. e.g. - cql transfer -wait-tx-confirm '{"addr":"your_account_addr","amount":"100 Particle"}' + cql transfer -wait-tx-confirm '{"addr": "43602c17adcc96acf2f68964830bb6ebfbca6834961c0eca0915fcc5270e0b40", "amount": "100 Particle"}' `, } diff --git a/types/init_service_type.go b/types/init_service_type.go index 988db30a4..7c9696266 100644 --- a/types/init_service_type.go +++ b/types/init_service_type.go @@ -37,7 +37,7 @@ type ResourceMeta struct { Memory uint64 `json:"memory",omitempty` // reserved memory in bytes LoadAvgPerCPU float64 `json:"load-avg-per-cpu"` // max loadAvg15 per CPU EncryptionKey string `json:"encrypt-key,omitempty"` // encryption key for database instance - UseEventualConsistency bool `json:"enentual-consistency,omitempty"` // use eventual consistency replication if enabled + UseEventualConsistency bool `json:"eventual-consistency,omitempty"` // use eventual consistency replication if enabled ConsistencyLevel float64 `json:"consistency-level,omitempty"` // customized strong consistency level IsolationLevel int `json:"isolation-level,omitempty"` // customized isolation level } From af75e74d8a4a58a60295f2d83c3ac2dfeab2a2c3 Mon Sep 17 00:00:00 2001 From: laodouya Date: Mon, 22 Apr 2019 00:26:12 +0800 Subject: [PATCH 05/11] Change default version print to debug level --- cmd/cql/internal/help.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cql/internal/help.go b/cmd/cql/internal/help.go index ef3571d4f..15ae4c7ab 100644 --- a/cmd/cql/internal/help.go +++ b/cmd/cql/internal/help.go @@ -59,7 +59,7 @@ func PrintVersion(printLog bool) string { name, Version, runtime.GOOS, runtime.GOARCH, runtime.Version()) if printLog { - fmt.Println("cql build:", version) + ConsoleLog.Debugf("cql build: %s\n", version) } return version From 12e8bfd760e0b135784a16d647f5e5dcab442692 Mon Sep 17 00:00:00 2001 From: Levente Liu Date: Mon, 22 Apr 2019 11:11:28 +0800 Subject: [PATCH 06/11] Fix test script --- test/compatibility/specific_old.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/compatibility/specific_old.sh b/test/compatibility/specific_old.sh index 594dd128d..85ab9a25e 100755 --- a/test/compatibility/specific_old.sh +++ b/test/compatibility/specific_old.sh @@ -51,7 +51,7 @@ sleep 20 ${CLIENTBIN} wallet -config node_c/config.yaml -balance all -no-password -${CLIENTBIN} create -config node_c/config.yaml -wait-tx-confirm -no-password '{"node":2}' | tee dsn.txt +${CLIENTBIN} create -config node_c/config.yaml -wait-tx-confirm -no-password '{"node":2}' | tail -n1 | tee dsn.txt #get dsn dsn=$(cat dsn.txt) From 4420c8c83670b86582822938398e289d970e2785 Mon Sep 17 00:00:00 2001 From: Levente Liu Date: Mon, 22 Apr 2019 17:42:37 +0800 Subject: [PATCH 07/11] Fix issue caused by json tag change --- client/driver.go | 32 +++++++++++++++++++++++++++----- types/init_service_type.go | 18 +++++++++--------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/client/driver.go b/client/driver.go index 83f33dc43..2bb6d5d77 100644 --- a/client/driver.go +++ b/client/driver.go @@ -100,9 +100,19 @@ func (d *covenantSQLDriver) Open(dsn string) (conn driver.Conn, err error) { // ResourceMeta defines new database resources requirement descriptions. type ResourceMeta struct { - types.ResourceMeta - GasPrice uint64 - AdvancePayment uint64 + // copied fields from types.ResourceMeta + TargetMiners []proto.AccountAddress `json:"target-miners,omitempty"` // designated miners + Node uint16 `json:"node,omitempty"` // reserved node count + Space uint64 `json:"space,omitempty"` // reserved storage space in bytes + Memory uint64 `json:"memory",omitempty` // reserved memory in bytes + LoadAvgPerCPU float64 `json:"load-avg-per-cpu"` // max loadAvg15 per CPU + EncryptionKey string `json:"encrypt-key,omitempty"` // encryption key for database instance + UseEventualConsistency bool `json:"eventual-consistency,omitempty"` // use eventual consistency replication if enabled + ConsistencyLevel float64 `json:"consistency-level,omitempty"` // customized strong consistency level + IsolationLevel int `json:"isolation-level,omitempty"` // customized isolation level + + GasPrice uint64 `json:"gas-price"` // customized gas price + AdvancePayment uint64 `json:"advance-payment"` // customized advance payment } func defaultInit() (err error) { @@ -186,8 +196,18 @@ func Create(meta ResourceMeta) (txHash hash.Hash, dsn string, err error) { req.TTL = 1 req.Tx = types.NewCreateDatabase(&types.CreateDatabaseHeader{ - Owner: clientAddr, - ResourceMeta: meta.ResourceMeta, + Owner: clientAddr, + ResourceMeta: types.ResourceMeta{ + TargetMiners: meta.TargetMiners, + Node: meta.Node, + Space: meta.Space, + Memory: meta.Memory, + LoadAvgPerCPU: meta.LoadAvgPerCPU, + EncryptionKey: meta.EncryptionKey, + UseEventualConsistency: meta.UseEventualConsistency, + ConsistencyLevel: meta.ConsistencyLevel, + IsolationLevel: meta.IsolationLevel, + }, GasPrice: meta.GasPrice, AdvancePayment: meta.AdvancePayment, TokenType: types.Particle, @@ -199,6 +219,8 @@ func Create(meta ResourceMeta) (txHash hash.Hash, dsn string, err error) { return } + log.Debugf("req: %v", req) + if err = requestBP(route.MCCAddTx, req, resp); err != nil { err = errors.Wrap(err, "call create database transaction failed") return diff --git a/types/init_service_type.go b/types/init_service_type.go index 7c9696266..5a94439df 100644 --- a/types/init_service_type.go +++ b/types/init_service_type.go @@ -31,15 +31,15 @@ type InitService struct { // ResourceMeta defines single database resource meta. type ResourceMeta struct { - TargetMiners []proto.AccountAddress `json:"target-miners,omitempty"` // designated miners - Node uint16 `json:"node,omitempty"` // reserved node count - Space uint64 `json:"space,omitempty"` // reserved storage space in bytes - Memory uint64 `json:"memory",omitempty` // reserved memory in bytes - LoadAvgPerCPU float64 `json:"load-avg-per-cpu"` // max loadAvg15 per CPU - EncryptionKey string `json:"encrypt-key,omitempty"` // encryption key for database instance - UseEventualConsistency bool `json:"eventual-consistency,omitempty"` // use eventual consistency replication if enabled - ConsistencyLevel float64 `json:"consistency-level,omitempty"` // customized strong consistency level - IsolationLevel int `json:"isolation-level,omitempty"` // customized isolation level + TargetMiners []proto.AccountAddress // designated miners + Node uint16 // reserved node count + Space uint64 // reserved storage space in bytes + Memory uint64 // reserved memory in bytes + LoadAvgPerCPU float64 // max loadAvg15 per CPU + EncryptionKey string // encryption key for database instance + UseEventualConsistency bool // use eventual consistency replication if enabled + ConsistencyLevel float64 // customized strong consistency level + IsolationLevel int // customized isolation level } // ServiceInstance defines single instance to be initialized. From 62085bab9b02bd5b2f78cd428f4bcb52887b2f90 Mon Sep 17 00:00:00 2001 From: Levente Liu Date: Mon, 22 Apr 2019 18:00:28 +0800 Subject: [PATCH 08/11] Minor fix --- cmd/cql-minerd/integration_test.go | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/cmd/cql-minerd/integration_test.go b/cmd/cql-minerd/integration_test.go index 6aee862bd..c21f1ee6e 100644 --- a/cmd/cql-minerd/integration_test.go +++ b/cmd/cql-minerd/integration_test.go @@ -410,11 +410,9 @@ func TestFullProcess(t *testing.T) { // client send create database transaction meta := client.ResourceMeta{ - ResourceMeta: types.ResourceMeta{ - TargetMiners: minersAddrs, - Node: uint16(len(minersAddrs)), - IsolationLevel: int(sql.LevelReadUncommitted), - }, + TargetMiners: minersAddrs, + Node: uint16(len(minersAddrs)), + IsolationLevel: int(sql.LevelReadUncommitted), GasPrice: testGasPrice, AdvancePayment: testAdvancePayment, } @@ -844,11 +842,9 @@ func benchMiner(b *testing.B, minerCount uint16) { if minerCount > 0 { // create meta := client.ResourceMeta{ - ResourceMeta: types.ResourceMeta{ - Node: minerCount, - UseEventualConsistency: benchEventualConsistency, - IsolationLevel: int(sql.LevelReadUncommitted), - }, + Node: minerCount, + UseEventualConsistency: benchEventualConsistency, + IsolationLevel: int(sql.LevelReadUncommitted), } // wait for chain service var ctx1, cancel1 = context.WithTimeout(context.Background(), 1*time.Minute) @@ -962,13 +958,11 @@ func benchOutsideMinerWithTargetMinerList( if minerCount > 0 { // create meta := client.ResourceMeta{ - ResourceMeta: types.ResourceMeta{ - TargetMiners: targetMiners, - Node: minerCount, - UseEventualConsistency: benchEventualConsistency, - IsolationLevel: int(sql.LevelReadUncommitted), - }, - AdvancePayment: 1000000000, + TargetMiners: targetMiners, + Node: minerCount, + UseEventualConsistency: benchEventualConsistency, + IsolationLevel: int(sql.LevelReadUncommitted), + AdvancePayment: 1000000000, } // wait for chain service var ctx1, cancel1 = context.WithTimeout(context.Background(), 1*time.Minute) From 2339d16d5ea4425a2a3db2ce6518e4de4e4676df Mon Sep 17 00:00:00 2001 From: Levente Liu Date: Tue, 23 Apr 2019 13:22:31 +0800 Subject: [PATCH 09/11] Update help info for cql --- cmd/cql/internal/adapter.go | 2 +- cmd/cql/internal/console.go | 2 +- cmd/cql/internal/create.go | 6 ++++-- cmd/cql/internal/drop.go | 5 +++-- cmd/cql/internal/explorer.go | 2 +- cmd/cql/internal/generate.go | 2 +- cmd/cql/internal/grant.go | 5 +++-- cmd/cql/internal/idminer.go | 3 ++- cmd/cql/internal/mirror.go | 2 +- cmd/cql/internal/rpc.go | 2 +- cmd/cql/internal/transfer.go | 7 ++++--- cmd/cql/internal/wallet.go | 2 +- 12 files changed, 23 insertions(+), 17 deletions(-) diff --git a/cmd/cql/internal/adapter.go b/cmd/cql/internal/adapter.go index baf3202c1..03c7abab0 100644 --- a/cmd/cql/internal/adapter.go +++ b/cmd/cql/internal/adapter.go @@ -34,7 +34,7 @@ var CmdAdapter = &Command{ UsageLine: "cql adapter [common params] [-tmp-path path] [-bg-log-level level] [-mirror addr] listen_address", Short: "start a SQLChain adapter server", Long: ` -Adapter command serves a SQLChain adapter +Adapter serves a SQLChain adapter. e.g. cql adapter 127.0.0.1:7784 `, diff --git a/cmd/cql/internal/console.go b/cmd/cql/internal/console.go index 8fcaac7ff..a14443f2d 100644 --- a/cmd/cql/internal/console.go +++ b/cmd/cql/internal/console.go @@ -49,7 +49,7 @@ var CmdConsole = &Command{ UsageLine: "cql console [common params] [-dsn dsn_string] [-command sqlcommand] [-file filename] [-out outputfile] [-no-rc true/false] [-single-transaction] [-variable variables] [-explorer explorer_addr] [-adapter adapter_addr]", Short: "run a console for interactive sql operation", Long: ` -Console command can run a interactive SQL console for CovenantSQL +Console runs an interactive SQL console for CovenantSQL. e.g. cql console -dsn covenantsql://4119ef997dedc585bfbcfae00ab6b87b8486fab323a8e107ea1fd4fc4f7eba5c diff --git a/cmd/cql/internal/create.go b/cmd/cql/internal/create.go index e0afb014f..6d41d7ef1 100644 --- a/cmd/cql/internal/create.go +++ b/cmd/cql/internal/create.go @@ -29,7 +29,8 @@ var CmdCreate = &Command{ UsageLine: "cql create [common params] [-wait-tx-confirm] db_meta_json", Short: "create a database", Long: ` -Create CovenantSQL database by database meta info JSON string, meta info must include node count. +Create creates a CovenantSQL database by database meta info JSON string. The meta info must include +node count. e.g. cql create '{"node": 2}' @@ -45,7 +46,8 @@ A complete introduction of db_meta_json fields: consistency-level float // Consistency level, node*consistency_level is the node number to perform strong consistency isolation-level int // Isolation level in a single node -Since CovenantSQL is blockchain database, you may want get confirm of creation. +Since CovenantSQL is built on top of blockchains, you may want to wait for the transaction +confirmation before the creation takes effect. e.g. cql create -wait-tx-confirm '{"node": 2}' `, diff --git a/cmd/cql/internal/drop.go b/cmd/cql/internal/drop.go index 45d6bfbda..38c5d903a 100644 --- a/cmd/cql/internal/drop.go +++ b/cmd/cql/internal/drop.go @@ -25,11 +25,12 @@ var CmdDrop = &Command{ UsageLine: "cql drop [common params] [-wait-tx-confirm] dsn", Short: "drop a database by dsn or database id", Long: ` -Drop command can drop a database by DSN or database id +Drop drops a CovenantSQL database by DSN or database ID. e.g. cql drop covenantsql://4119ef997dedc585bfbcfae00ab6b87b8486fab323a8e107ea1fd4fc4f7eba5c -Since CovenantSQL is blockchain database, you may want get confirm of drop operation. +Since CovenantSQL is built on top of blockchains, you may want to wait for the transaction +confirmation before the drop operation takes effect. e.g. cql drop -wait-tx-confirm covenantsql://4119ef997dedc585bfbcfae00ab6b87b8486fab323a8e107ea1fd4fc4f7eba5c `, diff --git a/cmd/cql/internal/explorer.go b/cmd/cql/internal/explorer.go index e4341603e..8ec1f4a9f 100644 --- a/cmd/cql/internal/explorer.go +++ b/cmd/cql/internal/explorer.go @@ -35,7 +35,7 @@ var CmdExplorer = &Command{ UsageLine: "cql explorer [common params] [-tmp-path path] [-bg-log-level level] listen_address", Short: "start a SQLChain explorer server", Long: ` -Explorer command serves a SQLChain web explorer. +Explorer serves a SQLChain web explorer. e.g. cql explorer 127.0.0.1:8546 `, diff --git a/cmd/cql/internal/generate.go b/cmd/cql/internal/generate.go index dd0b25eda..89c8254ba 100644 --- a/cmd/cql/internal/generate.go +++ b/cmd/cql/internal/generate.go @@ -39,7 +39,7 @@ var CmdGenerate = &Command{ UsageLine: "cql generate [common params] config | public", Short: "generate config related file or keys", Long: ` -Generate command can generate private.key and config.yaml for CovenantSQL. +Generate generates private.key and config.yaml for CovenantSQL. e.g. cql generate config `, diff --git a/cmd/cql/internal/grant.go b/cmd/cql/internal/grant.go index dfde7f0c3..3a3eaabf3 100644 --- a/cmd/cql/internal/grant.go +++ b/cmd/cql/internal/grant.go @@ -29,11 +29,12 @@ var CmdGrant = &Command{ UsageLine: "cql grant [common params] [-wait-tx-confirm] permission_meta_json", Short: "grant a user's permissions on specific sqlchain", Long: ` -Grant command can give a user some specific permissions on your database +Grant grants specific permissions for the target user. e.g. cql grant '{"chain": "your_chain_addr", "user": "user_addr", "perm": "perm_struct"}' -Since CovenantSQL is blockchain database, you may want get confirm of permission update. +Since CovenantSQL is built on top of blockchains, you may want to wait for the transaction +confirmation before the permission takes effect. e.g. cql grant -wait-tx-confirm '{"chain": "your_chain_addr", "user": "user_addr", "perm": "perm_struct"}' `, diff --git a/cmd/cql/internal/idminer.go b/cmd/cql/internal/idminer.go index 965822d72..6a3969361 100644 --- a/cmd/cql/internal/idminer.go +++ b/cmd/cql/internal/idminer.go @@ -42,7 +42,8 @@ var CmdIDMiner = &Command{ UsageLine: "cql idminer [common params] [-difficulty number] [-loop [true]]", Short: "calculate nonce and node id for config.yaml file", Long: ` -IDMiner command can calculate legal node id and it's nonce. Default 24 difficulty and no endless loop. +IDMiner calculates legal node id and it's nonce. Default parameters are difficulty of 24 and +no endless loop. e.g. cql idminer -difficulty 24 diff --git a/cmd/cql/internal/mirror.go b/cmd/cql/internal/mirror.go index eeca76ce0..68804d7aa 100644 --- a/cmd/cql/internal/mirror.go +++ b/cmd/cql/internal/mirror.go @@ -34,7 +34,7 @@ var CmdMirror = &Command{ UsageLine: "cql mirror [common params] [-tmp-path path] [-bg-log-level level] dsn listen_address", Short: "start a SQLChain database mirror server", Long: ` -Mirror command subscribes database updates and serves a read-only database mirror. +Mirror subscribes database updates and serves a read-only database mirror. e.g. cql mirror dsn 127.0.0.1:9389 `, diff --git a/cmd/cql/internal/rpc.go b/cmd/cql/internal/rpc.go index 3f1d03ec7..8b6c4b4da 100644 --- a/cmd/cql/internal/rpc.go +++ b/cmd/cql/internal/rpc.go @@ -55,7 +55,7 @@ var CmdRPC = &Command{ UsageLine: "cql rpc [common params] [-wait-tx-confirm] -name rpc_name -endpoint rpc_endpoint -req rpc_request", Short: "make a rpc request", Long: ` -Rpc command make a RPC request to server +RPC makes a RPC request to the target endpoint. e.g. cql rpc -name 'MCC.QuerySQLChainProfile' \ -endpoint 000000fd2c8f68d54d55d97d0ad06c6c0d91104e4e51a7247f3629cc2a0127cf \ diff --git a/cmd/cql/internal/transfer.go b/cmd/cql/internal/transfer.go index 4a141dc92..7bc8080c7 100644 --- a/cmd/cql/internal/transfer.go +++ b/cmd/cql/internal/transfer.go @@ -32,12 +32,13 @@ var CmdTransfer = &Command{ UsageLine: "cql transfer [common params] [-wait-tx-confirm] meta_json", Short: "transfer token to target account", Long: ` -Transfer command can transfer your token to the target account. -Command argument is JSON meta info of a token transaction. +Transfer transfers your token to the target account. +The command argument is a token transaction in JSON format. e.g. cql transfer '{"addr": "43602c17adcc96acf2f68964830bb6ebfbca6834961c0eca0915fcc5270e0b40", "amount": "100 Particle"}' -Since CovenantSQL is blockchain database, you may want get confirm of permission update. +Since CovenantSQL is built on top of blockchains, you may want to wait for the transaction +confirmation before the transfer takes effect. e.g. cql transfer -wait-tx-confirm '{"addr": "43602c17adcc96acf2f68964830bb6ebfbca6834961c0eca0915fcc5270e0b40", "amount": "100 Particle"}' `, diff --git a/cmd/cql/internal/wallet.go b/cmd/cql/internal/wallet.go index 9d7fc6b28..d54fd403b 100644 --- a/cmd/cql/internal/wallet.go +++ b/cmd/cql/internal/wallet.go @@ -34,7 +34,7 @@ var CmdWallet = &Command{ UsageLine: "cql wallet [common params] [-balance type]", Short: "get the wallet address and the balance of current account", Long: ` -Wallet command can get CovenantSQL wallet address and the token balance of current account +Wallet gets the CovenantSQL wallet address and the token balances of the current account. e.g. cql wallet From d7d417d2702ee0ac2c77e131ade09229432cbd0c Mon Sep 17 00:00:00 2001 From: Levente Liu Date: Tue, 23 Apr 2019 14:13:21 +0800 Subject: [PATCH 10/11] Minor fix --- client/driver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/driver.go b/client/driver.go index 2bb6d5d77..a77f98613 100644 --- a/client/driver.go +++ b/client/driver.go @@ -105,7 +105,7 @@ type ResourceMeta struct { Node uint16 `json:"node,omitempty"` // reserved node count Space uint64 `json:"space,omitempty"` // reserved storage space in bytes Memory uint64 `json:"memory",omitempty` // reserved memory in bytes - LoadAvgPerCPU float64 `json:"load-avg-per-cpu"` // max loadAvg15 per CPU + LoadAvgPerCPU float64 `json:"load-avg-per-cpu",omitempty` // max loadAvg15 per CPU EncryptionKey string `json:"encrypt-key,omitempty"` // encryption key for database instance UseEventualConsistency bool `json:"eventual-consistency,omitempty"` // use eventual consistency replication if enabled ConsistencyLevel float64 `json:"consistency-level,omitempty"` // customized strong consistency level From 5c4c1fbb643ead90a287e15e65ed1d05c3dd7dfb Mon Sep 17 00:00:00 2001 From: Levente Liu Date: Tue, 23 Apr 2019 14:17:09 +0800 Subject: [PATCH 11/11] Remove debug log in driver --- client/driver.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/driver.go b/client/driver.go index a77f98613..a5314818a 100644 --- a/client/driver.go +++ b/client/driver.go @@ -219,8 +219,6 @@ func Create(meta ResourceMeta) (txHash hash.Hash, dsn string, err error) { return } - log.Debugf("req: %v", req) - if err = requestBP(route.MCCAddTx, req, resp); err != nil { err = errors.Wrap(err, "call create database transaction failed") return