Bläddra i källkod

100% sqllogictest

Danilo Fragoso 4 månader sedan
förälder
incheckning
08fb379b94
5 ändrade filer med 91 tillägg och 25 borttagningar
  1. BIN
      bin/pizzasql
  2. BIN
      bin/sqllogictest
  3. 11 11
      cmd/sqllogictest/main.go
  4. 29 14
      main.go
  5. 51 0
      pprof_enabled.go

BIN
bin/pizzasql


BIN
bin/sqllogictest


+ 11 - 11
cmd/sqllogictest/main.go

@@ -48,9 +48,9 @@ type lineInfo struct {
 type record struct {
 	isStatement bool
 	isQuery     bool
-	expectOK    bool     // statement: true → expect success
-	typeStr     string   // query: column type chars (I/R/T)
-	sortMode    string   // nosort | rowsort | valuesort
+	expectOK    bool   // statement: true → expect success
+	typeStr     string // query: column type chars (I/R/T)
+	sortMode    string // nosort | rowsort | valuesort
 	label       string
 	sql         string
 	expected    []string // flattened expected values, one per line
@@ -85,19 +85,19 @@ type runner struct {
 	passed     int
 	failed     int
 	skipped    int
-	total      int    // total files to run
-	filesDone  int    // files completed
+	total      int // total files to run
+	filesDone  int // files completed
 	logW       *bufio.Writer
 	logPath    string
 }
 
 func main() {
-	urlFlag     := flag.String("url", "http://localhost:8080", "PizzaSQL server URL")
-	dirFlag     := flag.String("dir", "testdata/sqllogictest", "Directory containing .test files")
-	fileFlag    := flag.String("file", "", "Single .test file to run (overrides -dir)")
+	urlFlag := flag.String("url", "http://localhost:8080", "PizzaSQL server URL")
+	dirFlag := flag.String("dir", "testdata/sqllogictest", "Directory containing .test files")
+	fileFlag := flag.String("file", "", "Single .test file to run (overrides -dir)")
 	verboseFlag := flag.Bool("v", false, "Print each passing record")
-	stopFlag    := flag.Bool("stop", false, "Stop on first failure")
-	logFlag     := flag.String("log", "sqllogictest-failures.log", "File to write failures to ('' to disable)")
+	stopFlag := flag.Bool("stop", false, "Stop on first failure")
+	logFlag := flag.String("log", "sqllogictest-failures.log", "File to write failures to ('' to disable)")
 	flag.Parse()
 
 	r := &runner{
@@ -254,7 +254,7 @@ func (r *runner) printProgress(currentFile string, start time.Time) {
 	var etaStr string
 	if r.filesDone > 0 {
 		rate := float64(r.filesDone) / elapsed.Seconds()
-		eta := time.Duration(float64(r.total-r.filesDone)/rate * float64(time.Second)).Round(time.Second)
+		eta := time.Duration(float64(r.total-r.filesDone) / rate * float64(time.Second)).Round(time.Second)
 		etaStr = "eta " + eta.String()
 	} else {
 		etaStr = "eta --"

+ 29 - 14
main.go

@@ -25,20 +25,21 @@ import (
 )
 
 var (
-	kvAddr     = flag.String("kvaddr", "localhost:8085", "PizzaKV server address (ignored if -kv is set)")
-	kvLaunch   = flag.Bool("kv", false, "Launch PizzaKV automatically")
-	kvFlags    = flag.String("kvflags", "", "Flags to pass to PizzaKV (e.g., \"-iwal -port=9090\")")
-	kvInfoFile = flag.String("kvinfo", ".pizzakv.json", "Path to PizzaKV info file")
-	database   = flag.String("db", "pizzasql", "Database name")
-	poolSize   = flag.Int("pool", 5, "Connection pool size")
-	timeout    = flag.Duration("timeout", 30*time.Second, "Query timeout")
-	httpEnable = flag.Bool("http", false, "Enable HTTP server")
-	httpHost   = flag.String("http-host", "localhost", "HTTP server host")
-	httpPort   = flag.Int("http-port", 8080, "HTTP server port")
-	httpCORS   = flag.Bool("http-cors", true, "Enable CORS")
-	httpAuth   = flag.Bool("http-auth", false, "Enable authentication")
-	httpQuiet  = flag.Bool("quiet", false, "Disable request logging")
-	apiKeys    = flag.String("api-keys", "", "Comma-separated API keys")
+	kvAddr          = flag.String("kvaddr", "localhost:8085", "PizzaKV server address (ignored if -kv is set)")
+	kvLaunch        = flag.Bool("kv", false, "Launch PizzaKV automatically")
+	kvFlags         = flag.String("kvflags", "", "Flags to pass to PizzaKV (e.g., \"-iwal -port=9090\")")
+	kvInfoFile      = flag.String("kvinfo", ".pizzakv.json", "Path to PizzaKV info file")
+	database        = flag.String("db", "pizzasql", "Database name")
+	poolSize        = flag.Int("pool", 5, "Connection pool size")
+	timeout         = flag.Duration("timeout", 30*time.Second, "Query timeout")
+	httpEnable      = flag.Bool("http", false, "Enable HTTP server")
+	httpHost        = flag.String("http-host", "localhost", "HTTP server host")
+	httpPort        = flag.Int("http-port", 8080, "HTTP server port")
+	httpCORS        = flag.Bool("http-cors", true, "Enable CORS")
+	httpAuth        = flag.Bool("http-auth", false, "Enable authentication")
+	httpCompression = flag.Bool("http-compression", true, "Enable HTTP response compression")
+	httpQuiet       = flag.Bool("quiet", false, "Disable request logging")
+	apiKeys         = flag.String("api-keys", "", "Comma-separated API keys")
 
 	// Export/Import flags
 	exportFile   = flag.String("o", "", "Output file for export")
@@ -51,6 +52,7 @@ var (
 )
 
 var kvManager *kvmanager.Manager
+var startPprofServerHook func() *http.Server
 
 func main() {
 	flag.Parse()
@@ -749,6 +751,7 @@ func runHTTPServer() {
 	config.Port = *httpPort
 	config.EnableCORS = *httpCORS
 	config.EnableAuth = *httpAuth
+	config.EnableCompression = *httpCompression
 	config.EnableLogging = !*httpQuiet
 
 	if *apiKeys != "" {
@@ -757,6 +760,10 @@ func runHTTPServer() {
 
 	// Create and start server with multi-database support
 	server := httpserver.NewWithDatabaseManager(config, dbManager)
+	var pprofServer *http.Server
+	if startPprofServerHook != nil {
+		pprofServer = startPprofServerHook()
+	}
 
 	// Handle graceful shutdown
 	stop := make(chan os.Signal, 1)
@@ -771,6 +778,9 @@ func runHTTPServer() {
 	}()
 
 	fmt.Printf("PizzaSQL HTTP server started on http://%s:%d\n", *httpHost, *httpPort)
+	if pprofServer != nil {
+		fmt.Printf("pprof debug server started on http://%s/debug/pprof/\n", pprofServer.Addr)
+	}
 	fmt.Printf("Default database: %s\n", *database)
 	fmt.Printf("PizzaKV: %s\n", *kvAddr)
 	fmt.Println()
@@ -807,6 +817,11 @@ func runHTTPServer() {
 	if err := server.Shutdown(ctx); err != nil {
 		fmt.Fprintf(os.Stderr, "Error during shutdown: %v\n", err)
 	}
+	if pprofServer != nil {
+		if err := pprofServer.Shutdown(ctx); err != nil {
+			fmt.Fprintf(os.Stderr, "Error during pprof shutdown: %v\n", err)
+		}
+	}
 
 	fmt.Println("Server stopped")
 }

+ 51 - 0
pprof_enabled.go

@@ -0,0 +1,51 @@
+//go:build pprof
+
+package main
+
+import (
+	"flag"
+	"fmt"
+	"net/http"
+	_ "net/http/pprof"
+	"os"
+	"runtime"
+	"time"
+)
+
+var (
+	pprofAddr          = flag.String("pprof", "", "Enable pprof debug server on this address (e.g. localhost:6060)")
+	pprofBlockRate     = flag.Int("pprof-block-rate", 0, "Set runtime block profile rate when pprof is enabled (0 disables block profiling)")
+	pprofMutexFraction = flag.Int("pprof-mutex-fraction", 0, "Set runtime mutex profile fraction when pprof is enabled (0 disables mutex profiling)")
+)
+
+func init() {
+	startPprofServerHook = startPprofServer
+}
+
+func startPprofServer() *http.Server {
+	if *pprofAddr == "" {
+		return nil
+	}
+
+	if *pprofBlockRate > 0 {
+		runtime.SetBlockProfileRate(*pprofBlockRate)
+	}
+	if *pprofMutexFraction > 0 {
+		runtime.SetMutexProfileFraction(*pprofMutexFraction)
+	}
+
+	srv := &http.Server{
+		Addr:         *pprofAddr,
+		Handler:      http.DefaultServeMux,
+		ReadTimeout:  5 * time.Second,
+		WriteTimeout: 120 * time.Second,
+	}
+
+	go func() {
+		if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
+			fmt.Fprintf(os.Stderr, "pprof server error: %v\n", err)
+		}
+	}()
+
+	return srv
+}