@@ -3,8 +3,11 @@ package runtimeflags
33import (
44 "errors"
55 "flag"
6+ "fmt"
7+ "os"
68
79 "github.com/brimdata/super/cli/auto"
10+ "github.com/brimdata/super/runtime/exec"
811 "github.com/brimdata/super/runtime/sam/expr/agg"
912 "github.com/brimdata/super/runtime/sam/op/fuse"
1013 "github.com/brimdata/super/runtime/sam/op/sort"
@@ -28,35 +31,80 @@ func defaultMemMaxBytes() uint64 {
2831 }
2932}
3033
34+ type EngineFlags struct {
35+ sam bool
36+ vam bool
37+ Runtime exec.Runtime
38+ }
39+
3140type Flags struct {
3241 // these memory limits should be based on a shared resource model
3342 aggMemMax auto.Bytes
3443 sortMemMax auto.Bytes
3544 fuseMemMax auto.Bytes
45+ EngineFlags
46+ }
47+
48+ func (e * EngineFlags ) SetFlags (fs * flag.FlagSet ) {
49+ fs .BoolVar (& e .sam , "sam" , false , "execute query in sequential runtime" )
50+ fs .BoolVar (& e .vam , "vam" , false , "execute query in vector runtime" )
3651}
3752
38- func (f * Flags ) SetFlags (fs * flag.FlagSet ) {
39- f .aggMemMax = auto .NewBytes (uint64 (agg .MaxValueSize ))
40- fs .Var (& f .aggMemMax , "aggmem" , "maximum memory used per aggregate function value in MiB, MB, etc" )
53+ func (e * Flags ) SetFlags (fs * flag.FlagSet ) {
54+ e .aggMemMax = auto .NewBytes (uint64 (agg .MaxValueSize ))
55+ fs .Var (& e .aggMemMax , "aggmem" , "maximum memory used per aggregate function value in MiB, MB, etc" )
4156 def := defaultMemMaxBytes ()
42- f .sortMemMax = auto .NewBytes (def )
43- fs .Var (& f .sortMemMax , "sortmem" , "maximum memory used by sort in MiB, MB, etc" )
44- f .fuseMemMax = auto .NewBytes (def )
45- fs .Var (& f .fuseMemMax , "fusemem" , "maximum memory used by fuse in MiB, MB, etc" )
57+ e .sortMemMax = auto .NewBytes (def )
58+ fs .Var (& e .sortMemMax , "sortmem" , "maximum memory used by sort in MiB, MB, etc" )
59+ e .fuseMemMax = auto .NewBytes (def )
60+ fs .Var (& e .fuseMemMax , "fusemem" , "maximum memory used by fuse in MiB, MB, etc" )
61+ e .EngineFlags .SetFlags (fs )
4662}
4763
48- func (f * Flags ) Init () error {
49- if f .aggMemMax .Bytes <= 0 {
64+ func (e * EngineFlags ) Init () error {
65+ var err error
66+ e .Runtime , err = e .getRuntime ()
67+ return err
68+ }
69+
70+ func (e * Flags ) Init () error {
71+ if e .aggMemMax .Bytes <= 0 {
5072 return errors .New ("aggmem value must be greater than zero" )
5173 }
52- agg .MaxValueSize = int (f .aggMemMax .Bytes )
53- if f .sortMemMax .Bytes <= 0 {
74+ agg .MaxValueSize = int (e .aggMemMax .Bytes )
75+ if e .sortMemMax .Bytes <= 0 {
5476 return errors .New ("sortmem value must be greater than zero" )
5577 }
56- sort .MemMaxBytes = int (f .sortMemMax .Bytes )
57- if f .fuseMemMax .Bytes <= 0 {
78+ sort .MemMaxBytes = int (e .sortMemMax .Bytes )
79+ if e .fuseMemMax .Bytes <= 0 {
5880 return errors .New ("fusemem value must be greater than zero" )
5981 }
60- fuse .MemMaxBytes = int (f .fuseMemMax .Bytes )
61- return nil
82+ fuse .MemMaxBytes = int (e .fuseMemMax .Bytes )
83+ if e .sam && e .vam {
84+ return errors .New ("sam and vam flags cannot both be enabled" )
85+ }
86+ return e .EngineFlags .Init ()
87+ }
88+
89+ func (e * EngineFlags ) getRuntime () (exec.Runtime , error ) {
90+ // Flags take precedence.
91+ if e .sam {
92+ return exec .RuntimeSAM , nil
93+ }
94+ if e .vam {
95+ return exec .RuntimeVAM , nil
96+ }
97+ // Then environment variable.
98+ if rt := os .Getenv ("SUPER_RUNTIME" ); rt != "" {
99+ switch rt {
100+ case "sam" :
101+ return exec .RuntimeSAM , nil
102+ case "vam" :
103+ return exec .RuntimeVAM , nil
104+ default :
105+ return exec .RuntimeAuto , fmt .Errorf ("invalid SUPER_RUNTIME value: %q (must be \" vam\" or \" sam\" )" , rt )
106+ }
107+ }
108+ return exec .RuntimeAuto , nil
109+
62110}
0 commit comments