Skip to content

Commit

Permalink
[v0.9] remove orderSchemas, update postgres docker image (#1413)
Browse files Browse the repository at this point in the history
* update pg docker w/ more locks, 16.8

* engine/execution: remove orderSchemas

The orderSchemas function is no longer relevant as it was with extensions prior.

* version 0.9.4
  • Loading branch information
jchappelow authored Feb 24, 2025
1 parent e80cf9d commit 80ba39b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 54 deletions.
4 changes: 2 additions & 2 deletions build/package/docker/postgres.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM postgres:16.5
FROM postgres:16.8

# Inject the init script that makes the kwild superuser and a kwild database
# owned by that kwild user, as well as a kwil_test_db database for tests.
Expand All @@ -15,4 +15,4 @@ COPY ./pginit.sql /docker-entrypoint-initdb.d/init.sql
# Override the default entrypoint/command to include the additional configuration
CMD ["postgres", "-c", "wal_level=logical", "-c", "max_wal_senders=10", "-c", "max_replication_slots=10", \
"-c", "track_commit_timestamp=true", "-c", "wal_sender_timeout=0", "-c", "max_prepared_transactions=2", \
"-c", "max_locks_per_transaction=256", "-c", "max_connections=128"]
"-c", "max_locks_per_transaction=4096", "-c", "max_connections=128"]
53 changes: 2 additions & 51 deletions internal/engine/execution/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"sort"
"sync"

"github.com/kwilteam/kwil-db/common"
Expand Down Expand Up @@ -154,7 +153,7 @@ func NewGlobalContext(ctx context.Context, db sql.Executor, extensionInitializer
// we need to make sure schemas are ordered by their dependencies
// if one schema is dependent on another, it must be loaded after the other
// this is handled by the orderSchemas function
for _, schema := range orderSchemas(schemas) {
for _, schema := range schemas {
err := g.loadDataset(ctx, schema)
if err != nil {
return nil, fmt.Errorf("%w: schema (%s / %s / %s)", err, schema.Name, schema.DBID(), schema.Owner)
Expand All @@ -175,7 +174,7 @@ func (g *GlobalContext) Reload(ctx context.Context, db sql.Executor) error {
return err
}

for _, schema := range orderSchemas(schemas) {
for _, schema := range schemas {
err := g.loadDataset(ctx, schema)
if err != nil {
return err
Expand Down Expand Up @@ -455,51 +454,3 @@ func (g *GlobalContext) unloadDataset(dbid string) {
delete(g.datasets, dbid)
delete(g.initializers, dbid)
}

// orderSchemas orders schemas based on their dependencies to other schemas.
func orderSchemas(schemas []*types.Schema) []*types.Schema {
// Mapping from schema DBID to its extensions
schemaMap := make(map[string][]string)
for _, schema := range schemas {
var exts []string
for _, ext := range schema.Extensions {
exts = append(exts, ext.Name)
}
schemaMap[schema.DBID()] = exts
}

// Topological sort
var result []string
visited := make(map[string]bool)
var visitAll func(items []string)

visitAll = func(items []string) {
for _, item := range items {
if !visited[item] {
visited[item] = true
visitAll(schemaMap[item])
result = append(result, item)
}
}
}

keys := make([]string, 0, len(schemaMap))
for key := range schemaMap {
keys = append(keys, key)
}
sort.Strings(keys) // sort the keys for deterministic output
visitAll(keys)

// Reorder schemas based on result
var orderedSchemas []*types.Schema
for _, dbid := range result {
for _, schema := range schemas {
if schema.DBID() == dbid {
orderedSchemas = append(orderedSchemas, schema)
break
}
}
}

return orderedSchemas
}
2 changes: 1 addition & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// - 0.6.0+release
// - 0.6.1
// - 0.6.2-alpha0+go1.21.nocgo
const kwilVersion = "0.9.3"
const kwilVersion = "0.9.4"

// KwildVersion may be set at compile time by:
//
Expand Down

0 comments on commit 80ba39b

Please sign in to comment.