Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into doltcore-doltdb-errs
Browse files Browse the repository at this point in the history
  • Loading branch information
alrs committed Feb 12, 2022
2 parents c44f7f3 + 3c606a9 commit ec37f14
Show file tree
Hide file tree
Showing 82 changed files with 3,252 additions and 338 deletions.
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 @@ -167,7 +167,8 @@ func (se *SqlEngine) NewContext(ctx context.Context) (*sql.Context, error) {
}

func (se *SqlEngine) NewDoltSession(ctx context.Context, mysqlSess *sql.BaseSession) (*dsess.DoltSession, error) {
return se.dsessFactory(ctx, mysqlSess, se.engine.Analyzer.Catalog.AllDatabases())
tempCtx := sql.NewContext(ctx, sql.WithSession(mysqlSess))
return se.dsessFactory(ctx, mysqlSess, se.engine.Analyzer.Catalog.AllDatabases(tempCtx))
}

// GetReturnFormat() returns the printing format the engine is associated with.
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/dolt/commands/indexcmds/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (cmd RebuildCmd) Exec(ctx context.Context, commandStr string, args []string
if err != nil {
return HandleErr(errhand.BuildDError("Unable to rebuild index `%s` on table `%s`.", indexName, tableName).AddCause(err).Build(), nil)
}
updatedTable, err := table.SetIndexRowData(ctx, indexName, indexRowData)
updatedTable, err := table.SetNomsIndexRows(ctx, indexName, indexRowData)
if err != nil {
return HandleErr(errhand.BuildDError("Unable to set rebuilt index.").AddCause(err).Build(), nil)
}
Expand Down
167 changes: 167 additions & 0 deletions go/cmd/dolt/commands/inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// Copyright 2021 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package commands

import (
"context"
"fmt"
"io"
"math"
"path/filepath"

"github.com/dolthub/dolt/go/cmd/dolt/cli"
"github.com/dolthub/dolt/go/cmd/dolt/errhand"
"github.com/dolthub/dolt/go/libraries/doltcore/dbfactory"
"github.com/dolthub/dolt/go/libraries/doltcore/env"
"github.com/dolthub/dolt/go/libraries/utils/argparser"
"github.com/dolthub/dolt/go/libraries/utils/filesys"
"github.com/dolthub/dolt/go/store/nbs"
)

const tableFileIndexFlag = "index"

type InspectCmd struct {
}

// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
func (cmd InspectCmd) Name() string {
return "inspect"
}

// Hidden should return true if this command should be hidden from the help text
func (cmd InspectCmd) Hidden() bool {
return true
}

// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
// that it be run from within a data repository directory
func (cmd InspectCmd) RequiresRepo() bool {
return true
}

// Description returns a description of the command
func (cmd InspectCmd) Description() string {
return "Inspects a Dolt Database and collects stats."
}

// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
func (cmd InspectCmd) CreateMarkdown(wr io.Writer, commandStr string) error {
return nil
}

func (cmd InspectCmd) ArgParser() *argparser.ArgParser {
ap := argparser.NewArgParser()
ap.SupportsFlag(tableFileIndexFlag, "i", "Measure distribution error in table file chunk indexes.")
return ap
}

// Exec executes the command
func (cmd InspectCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
ap := cmd.ArgParser()
help, usage := cli.HelpAndUsagePrinters(cli.GetCommandDocumentation(commandStr, cli.CommandDocumentationContent{}, ap))
apr := cli.ParseArgsOrDie(ap, args, help)

var verr errhand.VerboseError
if apr.Contains(tableFileIndexFlag) {
verr = cmd.measureChunkIndexDistribution(ctx, dEnv)
}

return HandleVErrAndExitCode(verr, usage)
}

func (cmd InspectCmd) measureChunkIndexDistribution(ctx context.Context, dEnv *env.DoltEnv) errhand.VerboseError {
newGen := filepath.Join(dEnv.GetDoltDir(), dbfactory.DataDir)
oldGen := filepath.Join(newGen, "oldgen")

itr, err := NewTableFileIter([]string{newGen, oldGen}, dEnv.FS)
if err != nil {
return errhand.VerboseErrorFromError(err)
}

sumErr, sumCnt := 0.0, 0
for {
path, _ := itr.next()
if path == "" {
break
}

summary, err := cmd.processTableFile(path, dEnv.FS)
if err != nil {
return errhand.VerboseErrorFromError(err)
}
sumErr += summary.sumErr
sumCnt += int(summary.count)

cli.Println(summary.format())
}
cli.Printf("average guess error: %f", sumErr/float64(sumCnt))

return nil
}

func (cmd InspectCmd) processTableFile(path string, fs filesys.Filesys) (sum *chunkIndexSummary, err error) {
var rdr io.ReadCloser
rdr, err = fs.OpenForRead(path)
if err != nil {
return sum, err
}
defer func() {
cerr := rdr.Close()
if err == nil {
err = cerr
}
}()

var prefixes []uint64
prefixes, err = nbs.GetTableIndexPrefixes(rdr.(io.ReadSeeker))
if err != nil {
return sum, err
}

sum = &chunkIndexSummary{
file: path,
count: uint32(len(prefixes)),
//errs: make([]float64, 0, len(prefixes)),
}

for i, prefix := range prefixes {
sum.addPrefix(i, prefix)
}
return
}

type chunkIndexSummary struct {
file string
count uint32
//errs []float64
sumErr float64
maxErr float64
}

func (s *chunkIndexSummary) format() string {
return fmt.Sprintf("file: %s \t count: %d sum error: %f \t max error: %f ",
s.file, s.count, s.sumErr, s.maxErr)
}

func (s *chunkIndexSummary) addPrefix(i int, prefix uint64) {
g := nbs.GuessPrefixOrdinal(prefix, s.count)
guessErr := math.Abs(float64(i - g))

//s.errs = append(s.errs, guessErr)
s.sumErr += guessErr
if guessErr > s.maxErr {
s.maxErr = guessErr
}
}
7 changes: 7 additions & 0 deletions go/cmd/dolt/commands/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ var loginDocs = cli.CommandDocumentationContent{
Synopsis: []string{"[{{.LessThan}}creds{{.GreaterThan}}]"},
}

// The LoginCmd doesn't handle its own signals, but should stop cancel global context when receiving SIGINT signal
func (cmd LoginCmd) InstallsSignalHandlers() bool {
return true
}

type LoginCmd struct{}

var _ cli.SignalCommand = SqlCmd{}

// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
func (cmd LoginCmd) Name() string {
return "login"
Expand Down
4 changes: 4 additions & 0 deletions go/cmd/dolt/commands/roots.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ func NewTableFileIter(dirs []string, fs filesys.Filesys) (*TableFileIter, error)
}

func (itr *TableFileIter) next() (string, time.Time) {
if itr.pos >= len(itr.files) {
return "", time.Time{}
}

curr := itr.files[itr.pos]
itr.pos++

Expand Down
2 changes: 1 addition & 1 deletion go/cmd/dolt/commands/schcmds/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func importSchema(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPars

var indexSet durable.IndexSet
if tblExists {
indexSet, err = tbl.GetIndexData(ctx)
indexSet, err = tbl.GetIndexSet(ctx)
if err != nil {
return errhand.BuildDError("error: failed to create table.").AddCause(err).Build()
}
Expand Down
3 changes: 2 additions & 1 deletion go/cmd/dolt/dolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
)

const (
Version = "0.36.1"
Version = "0.36.2"
)

var dumpDocsCommand = &commands.DumpDocsCmd{}
Expand Down Expand Up @@ -97,6 +97,7 @@ var doltCommand = cli.NewSubCommandHandler("dolt", "it's git for data", []cli.Co
commands.RootsCmd{},
commands.VersionCmd{VersionStr: Version},
commands.DumpCmd{},
commands.InspectCmd{},
dumpDocsCommand,
dumpZshCommand,
})
Expand Down
20 changes: 10 additions & 10 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/HdrHistogram/hdrhistogram-go v1.0.0
github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
github.com/attic-labs/kingpin v2.2.7-0.20180312050558-442efcfac769+incompatible
Expand All @@ -21,29 +20,24 @@ require (
github.com/dolthub/ishell v0.0.0-20220112232610-14e753f0f371
github.com/dolthub/mmap-go v1.0.4-0.20201107010347-f9f2a9588a66
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
github.com/dolthub/vitess v0.0.0-20220205072827-9c6acb39686a
github.com/dolthub/vitess v0.0.0-20220207220721-35d6793fac38
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.9.0
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568
github.com/go-kit/kit v0.10.0 // indirect
github.com/go-openapi/errors v0.19.6 // indirect
github.com/go-openapi/strfmt v0.19.5 // indirect
github.com/go-sql-driver/mysql v1.6.0
github.com/gocraft/dbr/v2 v2.7.2
github.com/golang/glog v0.0.0-20210429001901-424d2337a529 // indirect
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.1
github.com/google/go-cmp v0.5.7
github.com/google/uuid v1.2.0
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/jedib0t/go-pretty v4.3.1-0.20191104025401-85fe5d6a7c4d+incompatible
github.com/jpillora/backoff v1.0.0
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d
github.com/lestrrat-go/strftime v1.0.4 // indirect
github.com/mattn/go-isatty v0.0.12
github.com/mattn/go-runewidth v0.0.9
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.3.2 // indirect
github.com/opentracing/opentracing-go v1.2.0
github.com/pkg/errors v0.9.1
Expand All @@ -67,17 +61,15 @@ require (
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20220111092808-5a964db01320
google.golang.org/api v0.32.0
google.golang.org/genproto v0.0.0-20210506142907-4a47615972c2 // indirect
google.golang.org/grpc v1.37.0
google.golang.org/protobuf v1.27.1
gopkg.in/square/go-jose.v2 v2.5.1
gopkg.in/src-d/go-errors.v1 v1.0.0
gopkg.in/yaml.v2 v2.3.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)

require (
github.com/dolthub/go-mysql-server v0.11.1-0.20220205073531-abbcc57d6d1e
github.com/dolthub/go-mysql-server v0.11.1-0.20220211113841-bb16284a110e
github.com/google/flatbuffers v2.0.5+incompatible
github.com/kch42/buzhash v0.0.0-20160816060738-9bdec3dec7c6
github.com/prometheus/client_golang v1.11.0
Expand All @@ -89,22 +81,28 @@ require (
require (
cloud.google.com/go v0.66.0 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/apache/thrift v0.13.1-0.20201008052519-daf620915714 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-kit/kit v0.10.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/glog v0.0.0-20210429001901-424d2337a529 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/klauspost/compress v1.10.10 // indirect
github.com/lestrrat-go/strftime v1.0.4 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mattn/go-colorable v0.1.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 // indirect
github.com/pierrec/lz4/v4 v4.1.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand All @@ -126,6 +124,8 @@ require (
golang.org/x/tools v0.1.9 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210506142907-4a47615972c2 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)

replace (
Expand Down
8 changes: 4 additions & 4 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
github.com/dolthub/go-mysql-server v0.11.1-0.20220205073531-abbcc57d6d1e h1:PloDu3xEk+Mhg4RVWzz1gA/0MqQ+YLB38gjmcEHRnr4=
github.com/dolthub/go-mysql-server v0.11.1-0.20220205073531-abbcc57d6d1e/go.mod h1:X2i6+DzsBgl5uDu1dzNayauCEZFUE+qIEriSv4M8v3s=
github.com/dolthub/go-mysql-server v0.11.1-0.20220211113841-bb16284a110e h1:zcZ1TlGyrv8kA4NJBPIWIb+0M/YC4XD9nJw+y7OSwyk=
github.com/dolthub/go-mysql-server v0.11.1-0.20220211113841-bb16284a110e/go.mod h1:fa5urhUZz6+UWMVrTcgxl/INnDGaqmkl89V/4mocqrY=
github.com/dolthub/ishell v0.0.0-20220112232610-14e753f0f371 h1:oyPHJlzumKta1vnOQqUnfdz+pk3EmnHS3Nd0cCT0I2g=
github.com/dolthub/ishell v0.0.0-20220112232610-14e753f0f371/go.mod h1:dhGBqcCEfK5kuFmeO5+WOx3hqc1k3M29c1oS/R7N4ms=
github.com/dolthub/jsonpath v0.0.0-20210609232853-d49537a30474 h1:xTrR+l5l+1Lfq0NvhiEsctylXinUMFhhsqaEcl414p8=
Expand All @@ -182,8 +182,8 @@ github.com/dolthub/mmap-go v1.0.4-0.20201107010347-f9f2a9588a66 h1:WRPDbpJWEnPxP
github.com/dolthub/mmap-go v1.0.4-0.20201107010347-f9f2a9588a66/go.mod h1:N5ZIbMGuDUpTpOFQ7HcsN6WSIpTGQjHP+Mz27AfmAgk=
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE=
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
github.com/dolthub/vitess v0.0.0-20220205072827-9c6acb39686a h1:+61CpK9SwG/QFNE+vn6Fxk00GRQgtR+CA6Nvsr87y8g=
github.com/dolthub/vitess v0.0.0-20220205072827-9c6acb39686a/go.mod h1:qpZ4j0dval04OgZJ5fyKnlniSFUosTH280pdzUjUJig=
github.com/dolthub/vitess v0.0.0-20220207220721-35d6793fac38 h1:qUbVRsX2CPyjj/uLrPu9L69rGiYRb5vwzw7PC5c/Wh8=
github.com/dolthub/vitess v0.0.0-20220207220721-35d6793fac38/go.mod h1:qpZ4j0dval04OgZJ5fyKnlniSFUosTH280pdzUjUJig=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
Expand Down
Loading

0 comments on commit ec37f14

Please sign in to comment.