Skip to content

Commit

Permalink
add initial boost stream service
Browse files Browse the repository at this point in the history
Signed-off-by: Vilius Okockis <[email protected]>
  • Loading branch information
DeathBorn committed Mar 27, 2024
1 parent 5d8fa9a commit 2e48ab9
Show file tree
Hide file tree
Showing 7 changed files with 2,164 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ endif
go install $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/...
(cd go/cmd/vttablet && go run github.com/GeertJohan/go.rice/rice append --exec=../../../bin/vttablet)

# build boost only
boost:
ifndef NOBANNER
echo $$(date): Building source tree
endif
bash ./build.env
# build all the binaries by default with CGO disabled
CGO_ENABLED=0 go install $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/cmd/boost/...

# build the vitess binaries statically
build:
ifndef NOBANNER
Expand All @@ -76,6 +85,7 @@ endif
# build vtorc with CGO, because it depends on sqlite
CGO_ENABLED=1 go install $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/cmd/vtorc/...


# cross-build can be used to cross-compile Vitess client binaries
# Outside of select client binaries (namely vtctlclient & vtexplain), cross-compiled Vitess Binaries are not recommended for production deployments
# Usage: GOOS=darwin GOARCH=amd64 make cross-build
Expand Down
124 changes: 124 additions & 0 deletions go/cmd/boost/boost.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package main

import (
"context"
"fmt"
"os"
"os/signal"
"syscall"

"flag"

"vitess.io/vitess/go/cmd/boost/boost"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
)

var (
targetPort,
targetGrpcPort int
targetHost,
targetGtid,
targetFilter,
targetTabletType string

boostFlags = []string{
"host",
"port",
"grpcPort",
"gtid",
"filter",
"tabletType",
}
)

func usage() {
fmt.Printf("usage of boost:\n")
for _, name := range boostFlags {
f := flag.Lookup(name)
if f == nil {
panic("unknown flag " + name)
}
flagUsage(f)
}
}

// Cloned from the source to print out the usage for a given flag
func flagUsage(f *flag.Flag) {
s := fmt.Sprintf(" -%s", f.Name) // Two spaces before -; see next two comments.
name, usage := flag.UnquoteUsage(f)
if len(name) > 0 {
s += " " + name
}
// Boolean flags of one ASCII letter are so common we
// treat them specially, putting their usage on the same line.
if len(s) <= 4 { // space, space, '-', 'x'.
s += "\t"
} else {
// Four spaces before the tab triggers good alignment
// for both 4- and 8-space tab stops.
s += "\n \t"
}
s += usage
if name == "string" {
// put quotes on the value
s += fmt.Sprintf(" (default %q)", f.DefValue)
} else {
s += fmt.Sprintf(" (default %v)", f.DefValue)
}
fmt.Printf(s + "\n")
}

func init() {
flag.StringVar(&targetHost, "host", "127.0.0.1", "(defaults to 127.0.0.1)")
flag.IntVar(&targetPort, "port", 15306, "(defaults to 15306)")
flag.IntVar(&targetGrpcPort, "grpcPort", 15991, "(defaults to 15991)")
flag.StringVar(&targetGtid, "gtid", "{}", "(defaults to {})")
flag.StringVar(&targetFilter, "filter", "{}", "(defaults to{})")
flag.StringVar(&targetTabletType, "tabletType", "master", "(defaults to{})")
logger := logutil.NewConsoleLogger()
flag.CommandLine.SetOutput(logutil.NewLoggerWriter(logger))
flag.Usage = usage
}

func main() {
flag.Lookup("logtostderr").Value.Set("true")
flag.Parse()
defer logutil.Flush()

boost, err := boost.NewBoost(
targetPort,
targetGrpcPort,
targetHost,
targetGtid,
targetFilter,
targetTabletType,
)
if err != nil {
os.Exit(1)
}

err = boost.Init()
if err != nil {
boost.Close()
os.Exit(1)
}

// Catch SIGTERM and SIGINT so we get a chance to clean up.
ctx, cancel := context.WithCancel(context.Background())
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigChan
log.Infof("Cancelling due to signal: %v", sig)
cancel()
}()
defer boost.Close()

err = boost.Play(ctx)
if err != nil {
os.Exit(1)
}

log.Info("Stopped")
}
Loading

0 comments on commit 2e48ab9

Please sign in to comment.