Skip to content

Commit

Permalink
Merge branch 'main' into max/blob-perf
Browse files Browse the repository at this point in the history
  • Loading branch information
max-hoffman committed May 21, 2024
2 parents b024e60 + 9165f6b commit d360df3
Show file tree
Hide file tree
Showing 50 changed files with 926 additions and 554 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cd-release-pgo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ jobs:
- name: Set minver TBD to version
run: sed -i -e 's/minver:"TBD"/minver:"'"$NEW_VERSION"'"/' "$FILE"
env:
FILE: ${{ format('{0}/go/cmd/dolt/commands/sqlserver/yaml_config.go', github.workspace) }}
FILE: ${{ format('{0}/go/libraries/doltcore/servercfg/yaml_config.go', github.workspace) }}
NEW_VERSION: ${{ needs.format-version.outputs.version }}
- name: update minver_validation.txt
working-directory: ./go
run: go run -mod=readonly ./utils/genminver_validation/ $FILE
env:
FILE: ${{ format('{0}/go/cmd/dolt/commands/sqlserver/testdata/minver_validation.txt', github.workspace) }}
FILE: ${{ format('{0}/go/libraries/doltcore/servercfg/testdata/minver_validation.txt', github.workspace) }}
- uses: EndBug/add-and-commit@v9.1.4
with:
message: ${{ format('[ga-bump-release] Update Dolt version to {0} and release v{0}', needs.format-version.outputs.version) }}
add: ${{ format('["{0}/go/cmd/dolt/doltversion/version.go", "{0}/go/cmd/dolt/commands/sqlserver/yaml_config.go", "{0}/go/cmd/dolt/commands/sqlserver/testdata/minver_validation.txt"]', github.workspace) }}
add: ${{ format('["{0}/go/cmd/dolt/doltversion/version.go", "{0}/go/libraries/doltcore/servercfg/yaml_config.go", "{0}/go/libraries/doltcore/servercfg/testdata/minver_validation.txt"]', github.workspace) }}
cwd: "."
pull: "--ff"
- name: Build PGO Binaries
Expand Down
29 changes: 29 additions & 0 deletions go/Godeps/LICENSES

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go/cmd/dolt/cli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (hc SubCommandHandler) handleCommand(ctx context.Context, commandStr string
// CheckEnvIsValid validates that a DoltEnv has been initialized properly and no errors occur during load, and prints
// error messages to the user if there are issues with the environment or if errors were encountered while loading it.
func CheckEnvIsValid(dEnv *env.DoltEnv) bool {
if !dEnv.HasDoltDir() {
if !dEnv.HasDoltDataDir() {
PrintErrln(color.RedString("The current directory is not a valid dolt repository."))
PrintErrln("run: dolt init before trying to run this command")
return false
Expand Down
72 changes: 18 additions & 54 deletions go/cmd/dolt/commands/cnfcmds/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ import (
"github.com/dolthub/dolt/go/cmd/dolt/errhand"
eventsapi "github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
"github.com/dolthub/dolt/go/libraries/doltcore/env"
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlutil"
"github.com/dolthub/dolt/go/libraries/doltcore/table/untyped/tabular"
"github.com/dolthub/dolt/go/libraries/utils/argparser"
"github.com/dolthub/dolt/go/libraries/utils/iohelp"
"github.com/dolthub/dolt/go/store/types"
)

type mergeStatus struct {
Expand Down Expand Up @@ -176,19 +173,14 @@ func printConflicts(queryist cli.Queryist, sqlCtx *sql.Context, tblNames []strin
return fmt.Errorf("error: failed to get conflict rows for table '%s': %w", tblName, err)
}

targetSch, err := getUnionSchemaFromConflictsSchema(confSqlSch)
sqlTargetSch, err := getUnionSchemaFromConflictsSchema(confSqlSch)
if err != nil {
return fmt.Errorf("error: failed to get union schema for table '%s': %w", tblName, err)
}

sqlTargetSch, err := sqlutil.FromDoltSchema(sqlCtx.GetCurrentDatabase(), tblName, targetSch)
if err != nil {
return fmt.Errorf("error: failed to convert dolt schema to sql schema for table '%s': %w", tblName, err)
}
tw := tabular.NewFixedWidthConflictTableWriter(sqlTargetSch, stdOut, 100)

tw := tabular.NewFixedWidthConflictTableWriter(sqlTargetSch.Schema, stdOut, 100)

err = writeConflictResults(sqlCtx, confSqlSch, sqlTargetSch.Schema, rowItr, tw)
err = writeConflictResults(sqlCtx, confSqlSch, sqlTargetSch, rowItr, tw)
if err != nil {
return fmt.Errorf("error: failed to write conflict results for table '%s': %w", tblName, err)
}
Expand All @@ -197,57 +189,29 @@ func printConflicts(queryist cli.Queryist, sqlCtx *sql.Context, tblNames []strin
return nil
}

func getUnionSchemaFromConflictsSchema(conflictsSch sql.Schema) (schema.Schema, error) {
func getUnionSchemaFromConflictsSchema(conflictsSch sql.Schema) (sql.Schema, error) {
// using array to preserve column order
baseColNames, theirColNames, ourColNames := []string{}, []string{}, []string{}

for _, col := range conflictsSch {
conflictCpy := conflictsSch.Copy()
var baseCols, theirCols, ourCols sql.Schema
for _, col := range conflictCpy {
conflictColName := col.Name
_, shouldIgnore := conflictColsToIgnore[conflictColName]
if shouldIgnore {
continue
}

if strings.HasPrefix(conflictColName, basePrefix) {
colName := conflictColName[len(basePrefix):]
baseColNames = append(baseColNames, colName)
} else if strings.HasPrefix(conflictColName, theirPrefix) {
colName := conflictColName[len(theirPrefix):]
theirColNames = append(theirColNames, colName)
} else if strings.HasPrefix(conflictColName, ourPrefix) {
colName := conflictColName[len(ourPrefix):]
ourColNames = append(ourColNames, colName)
}
}

unionColNames := []string{}
for _, colName := range baseColNames {
if !isStringInArray(colName, unionColNames) {
unionColNames = append(unionColNames, colName)
}
}
for _, colName := range theirColNames {
if !isStringInArray(colName, unionColNames) {
unionColNames = append(unionColNames, colName)
}
}
for _, colName := range ourColNames {
if !isStringInArray(colName, unionColNames) {
unionColNames = append(unionColNames, colName)
switch {
case strings.HasPrefix(conflictColName, basePrefix):
col.Name = conflictColName[len(basePrefix):]
baseCols = append(baseCols, col)
case strings.HasPrefix(conflictColName, theirPrefix):
col.Name = conflictColName[len(theirPrefix):]
theirCols = append(theirCols, col)
case strings.HasPrefix(conflictColName, ourPrefix):
col.Name = conflictColName[len(ourPrefix):]
ourCols = append(ourCols, col)
}
}

unionCols := []schema.Column{}
for _, colName := range unionColNames {
col := schema.NewColumn(colName, 0, types.StringKind, false)
unionCols = append(unionCols, col)
}
unionColl := schema.NewColCollection(unionCols...)
unionSchema, err := schema.SchemaFromCols(unionColl)
if err != nil {
return nil, fmt.Errorf("error: failed to create union schema: %w", err)
}
return unionSchema, nil
return append(append(baseCols, theirCols...), ourCols...), nil
}

func printSchemaConflicts(queryist cli.Queryist, sqlCtx *sql.Context, wrCloser io.WriteCloser, table string) error {
Expand Down
16 changes: 5 additions & 11 deletions go/cmd/dolt/commands/engine/jwtplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,24 @@ import (
"github.com/dolthub/go-mysql-server/sql/mysql_db"
"github.com/sirupsen/logrus"

"github.com/dolthub/dolt/go/libraries/doltcore/servercfg"
"github.com/dolthub/dolt/go/libraries/utils/jwtauth"
)

type JwksConfig struct {
Name string `yaml:"name"`
LocationUrl string `yaml:"location_url"`
Claims map[string]string `yaml:"claims"`
FieldsToLog []string `yaml:"fields_to_log"`
}

// authenticateDoltJWTPlugin is used to authenticate plaintext user plugins
type authenticateDoltJWTPlugin struct {
jwksConfig []JwksConfig
jwksConfig []servercfg.JwksConfig
}

func NewAuthenticateDoltJWTPlugin(jwksConfig []JwksConfig) mysql_db.PlaintextAuthPlugin {
func NewAuthenticateDoltJWTPlugin(jwksConfig []servercfg.JwksConfig) mysql_db.PlaintextAuthPlugin {
return &authenticateDoltJWTPlugin{jwksConfig: jwksConfig}
}

func (p *authenticateDoltJWTPlugin) Authenticate(db *mysql_db.MySQLDb, user string, userEntry *mysql_db.User, pass string) (bool, error) {
return validateJWT(p.jwksConfig, user, userEntry.Identity, pass, time.Now())
}

func validateJWT(config []JwksConfig, username, identity, token string, reqTime time.Time) (bool, error) {
func validateJWT(config []servercfg.JwksConfig, username, identity, token string, reqTime time.Time) (bool, error) {
if len(config) == 0 {
return false, errors.New("ValidateJWT: JWKS server config not found")
}
Expand Down Expand Up @@ -116,7 +110,7 @@ func getClaimFromKey(claims *jwtauth.Claims, field string) string {
return ""
}

func getMatchingJwksConfig(config []JwksConfig, name string) (*JwksConfig, error) {
func getMatchingJwksConfig(config []servercfg.JwksConfig, name string) (*servercfg.JwksConfig, error) {
for _, item := range config {
if item.Name == name {
return &item, nil
Expand Down
6 changes: 4 additions & 2 deletions go/cmd/dolt/commands/engine/jwtplugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"testing"
"time"

"github.com/dolthub/dolt/go/libraries/doltcore/servercfg"

"github.com/stretchr/testify/require"
)

Expand All @@ -30,7 +32,7 @@ var onBehalfOf = "my_user"
var jwt = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImUwNjA2Y2QwLTkwNWQtNGFiYS05MjBjLTZlNTE0YTFjYmIyNiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsibXlfcmVzb3VyY2UiXSwiZXhwIjoxNjU4Mjc1OTAzLCJpYXQiOjE2NTgyNzU4NzMsImlzcyI6ImRvbHRodWIuY29tIiwianRpIjoiN2ViZTg3YmMtOTkzMi00ZTljLTk5N2EtNjQzMDk0NTBkMWVjIiwib25fYmVoYWxmX29mIjoibXlfdXNlciIsInN1YiI6InRlc3RfdXNlciJ9.u2cUGUkQ2hk4AaxtNQB-6Jcdf5LtehFA7XX2FG8LGgTf6KfwE3cuuGaBIU8Jz9ktD9g8TjAbfAfbrNaFNYnKG6SnDUHp0t7VbfLdgfNDQqSyH0nOK2UF8ffxqa46PRxeMwTSJv8prE07rcmiZNL9Ie4vSGYLncJfMzo_RdE-A-PH7z-ZyZ_TxOMhkgMFq2Af5Px3zFuAKq-Y-PrQNopSuzjPJc0DQ93Q7EcIHfU6Fx6gOVTkzHxnOFcg3Nj-4HhqBSvBa_BdMYEzHJKx3F_9rrCCPqEGUFnxXAqFFmnZUQuQKpN2yW_zhviCVqrvbP7vOCIXmxi8YXLiGiV-4KlxHA"

func TestJWTAuth(t *testing.T) {
jwksConfig := []JwksConfig{
jwksConfig := []servercfg.JwksConfig{
{
Name: jwksName,
LocationUrl: "file:///testdata/test_jwks.json",
Expand Down Expand Up @@ -62,7 +64,7 @@ func TestJWTAuth(t *testing.T) {
require.False(t, authed)

// Jwks config doesn't exist
authed, err = validateJWT([]JwksConfig{}, sub, fmt.Sprintf("jwks=%s,sub=%s,iss=%s,aud=%s", jwksName, sub, iss, aud), jwt, tokenCreated)
authed, err = validateJWT([]servercfg.JwksConfig{}, sub, fmt.Sprintf("jwks=%s,sub=%s,iss=%s,aud=%s", jwksName, sub, iss, aud), jwt, tokenCreated)
require.Error(t, err)
require.False(t, authed)

Expand Down
3 changes: 2 additions & 1 deletion go/cmd/dolt/commands/engine/sqlengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/branch_control"
"github.com/dolthub/dolt/go/libraries/doltcore/dconfig"
"github.com/dolthub/dolt/go/libraries/doltcore/env"
"github.com/dolthub/dolt/go/libraries/doltcore/servercfg"
dsqle "github.com/dolthub/dolt/go/libraries/doltcore/sqle"
dblr "github.com/dolthub/dolt/go/libraries/doltcore/sqle/binlogreplication"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/cluster"
Expand Down Expand Up @@ -72,7 +73,7 @@ type SqlEngineConfig struct {
Autocommit bool
DoltTransactionCommit bool
Bulk bool
JwksConfig []JwksConfig
JwksConfig []servercfg.JwksConfig
SystemVariables SystemVariables
ClusterController *cluster.Controller
BinlogReplicaController binlogreplication.BinlogReplicaController
Expand Down
6 changes: 6 additions & 0 deletions go/cmd/dolt/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ func (cmd InitCmd) Exec(ctx context.Context, commandStr string, args []string, d
types.Format_Default = types.Format_DOLT
}

if dEnv.HasDoltSqlServerInfo() {
cli.PrintErrln(color.RedString("Detected that a Dolt sql-server is running from this directory. " +
"Stop the sql-server before initializing this directory as a Dolt database."))
return 1
}

name, _ := apr.GetValue(usernameParamName)
email, _ := apr.GetValue(emailParamName)
initBranch, _ := apr.GetValue(initBranchParamName)
Expand Down
Loading

0 comments on commit d360df3

Please sign in to comment.