Skip to content

Commit 6aa48c8

Browse files
committed
changing uuid API, add session timeout for 30 minutes, changing KILL approach
1 parent e9db532 commit 6aa48c8

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

chc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var opts struct {
6161

6262
var clickhouseSetting = make(map[string]string)
6363

64-
const versionString = "v0.1.4"
64+
const versionString = "v0.1.5"
6565

6666
func parseArgs() {
6767
argsParser := flags.NewNamedParser("chc (ClickHouse CLI portable)", flags.Default&^flags.HelpFlag) // , HelpFlag

clickhouse_http.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ func prepareRequest(query, format string, extraSettings map[string]string) (req
5555
return prepareRequestReader(strings.NewReader(query), format, extraSettings)
5656
}
5757

58-
func serviceRequestWithExtraSetting(query string, extraSettings map[string]string) (data [][]string, err error) {
58+
func serviceRequestWithExtraSetting(query string, extraSettings map[string]string, timeout_sec uint) (data [][]string, err error) {
5959

60-
timeout := time.Duration(3 * time.Second)
60+
timeout := time.Duration(time.Duration(timeout_sec) * time.Second)
6161
cx, cancel := context.WithTimeout(context.Background(), timeout)
6262
defer cancel()
6363
req, err0 := prepareRequest(query, formatTabSeparated, extraSettings)
@@ -93,15 +93,15 @@ func serviceRequestWithExtraSetting(query string, extraSettings map[string]strin
9393

9494
func serviceRequest(query string) (data [][]string, err error) {
9595
extraSettings := map[string]string{"log_queries": "0"}
96-
return serviceRequestWithExtraSetting(query, extraSettings)
96+
return serviceRequestWithExtraSetting(query, extraSettings, 3)
9797
}
9898

9999
// TODO: ensure if it was really killed
100100
func killQuery(queryID string) bool {
101-
query := fmt.Sprintf("SELECT 'query_id %s killed by replace'", queryID)
102-
extraSettings := map[string]string{"log_queries": "0", "replace_running_query": "1", "query_id": queryID}
101+
query := fmt.Sprintf("KILL QUERY WHERE query_id = '%s' SYNC", queryID)
102+
extraSettings := map[string]string{"log_queries": "0"}
103103

104-
_, err := serviceRequestWithExtraSetting(query, extraSettings)
104+
_, err := serviceRequestWithExtraSetting(query, extraSettings, 900)
105105
if err != nil {
106106
return false
107107
}
@@ -144,7 +144,7 @@ func makeQuery(cx context.Context, query, queryID, format string, interactive bo
144144
start := time.Now()
145145
var count uint64 // = 0
146146
countRows := getRowsCounter(format)
147-
extraSettings := map[string]string{"log_queries": "1", "query_id": queryID, "session_id": sessionID}
147+
extraSettings := map[string]string{"log_queries": "1", "query_id": queryID, "session_id": sessionID, "session_timeout": "1800" } // 30 min
148148
defer func() { finishTickerChannel <- true }()
149149
var req *http.Request
150150
var err error

clickhouse_requests.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,22 @@ import (
1717
"github.com/satori/go.uuid" // generate sessionID and queryID
1818
)
1919

20-
var sessionID = uuid.NewV4().String()
20+
func get_id() string {
21+
uu,err := uuid.NewV4()
22+
23+
if err == nil {
24+
return uu.String()
25+
}
26+
27+
uu,err = uuid.NewV1()
28+
if err == nil {
29+
return uu.String()
30+
}
31+
32+
return fmt.Sprintf( "faultyuu %v", time.Now() )
33+
}
34+
35+
var sessionID = get_id()
2136

2237
type progressInfo struct {
2338
Elapsed float64
@@ -179,7 +194,7 @@ type queryExecution struct {
179194
}
180195

181196
func queryToStdout(cx context.Context, query, format string, interactive bool) int {
182-
queryID := uuid.NewV4().String()
197+
queryID := get_id()
183198
defer chcOutput.releaseOutput()
184199

185200
status := -1

0 commit comments

Comments
 (0)