Skip to content

Commit

Permalink
do not enable external storage when separate file passed
Browse files Browse the repository at this point in the history
  • Loading branch information
k-anshul committed Jun 28, 2024
1 parent ddc0337 commit dad50f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
7 changes: 4 additions & 3 deletions admin/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ func (s *Service) createDeployment(ctx context.Context, opts *createDeploymentOp
Type: "duckdb",
// duckdb DSN will automatically be computed based on these parameters
Config: map[string]string{
"cpu": strconv.Itoa(alloc.CPU),
"memory_limit_gb": strconv.Itoa(alloc.MemoryGB),
"storage_limit_bytes": strconv.FormatInt(alloc.StorageBytes, 10),
"cpu": strconv.Itoa(alloc.CPU),
"memory_limit_gb": strconv.Itoa(alloc.MemoryGB),
"storage_limit_bytes": strconv.FormatInt(alloc.StorageBytes, 10),
"external_table_storage": strconv.FormatBool(true),
},
})

Expand Down
30 changes: 27 additions & 3 deletions cli/pkg/local/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"os"
"path/filepath"
"strconv"
"time"

"github.com/c2h5oh/datasize"
Expand Down Expand Up @@ -198,11 +199,23 @@ func NewApp(ctx context.Context, opts *AppOptions) (*App, error) {
}
}

// generate olap configs
// If the OLAP is the default OLAP (DuckDB in stage.db), we make it relative to the project directory (not the working directory)
defaultOLAP := false
olapCfg := make(map[string]string)
if opts.OlapDriver == DefaultOLAPDriver {
if opts.OlapDriver == DefaultOLAPDriver && opts.OlapDSN == DefaultOLAPDSN {
defaultOLAP = true
val, err := isExternalStorageEnabled(vars)
if err != nil {
return nil, err
}
olapCfg["external_table_storage"] = strconv.FormatBool(val)
}

if opts.OlapDriver == "duckdb" {
// Set default DuckDB pool size to 4
olapCfg["pool_size"] = "4"
if opts.OlapDSN != DefaultOLAPDSN {
if !defaultOLAP {
// dsn is automatically computed by duckdb driver so we set only when non default dsn is passed
olapCfg["dsn"] = opts.OlapDSN
olapCfg["error_on_incompatible_version"] = "true"
}
Expand Down Expand Up @@ -600,3 +613,14 @@ func (s skipFieldZapEncoder) AddString(key, val string) {
s.Encoder.AddString(key, val)
}
}

// isExternalStorageEnabled determines if external storage can be enabled.
func isExternalStorageEnabled(variables map[string]string) (bool, error) {
// check if flag explicitly passed
val, ok := variables["connector.duckdb.external_table_storage"]
if !ok {
// mark enabled by default
return true, nil
}
return strconv.ParseBool(val)
}
8 changes: 0 additions & 8 deletions runtime/drivers/duckdb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ func newConfig(cfgMap map[string]any) (*config, error) {
cfg.DSN = strings.Replace(cfg.DSN, ":memory:", "", 1)
}

// add defaults
if cfgMap != nil {
if _, ok := cfgMap["external_table_storage"]; !ok {
// Default to true for non in-memory dbs
cfg.ExtTableStorage = !inMemory
}
}

// Parse DSN as URL
uri, err := url.Parse(cfg.DSN)
if err != nil {
Expand Down

0 comments on commit dad50f0

Please sign in to comment.