Log table count (#5112)

* Log table count

* uncomment stats interface

* [ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/update.sh

* plus one

Co-authored-by: max-hoffman <max-hoffman@users.noreply.github.com>
This commit is contained in:
Maximilian Hoffman
2023-01-06 14:57:54 -08:00
committed by GitHub
parent e9f359c969
commit 9abda5f5fa
7 changed files with 65 additions and 24 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ require (
github.com/cenkalti/backoff/v4 v4.1.3
github.com/cespare/xxhash v1.1.0
github.com/creasty/defaults v1.6.0
github.com/dolthub/go-mysql-server v0.14.1-0.20230106182545-4722c4cfd575
github.com/dolthub/go-mysql-server v0.14.1-0.20230106202621-d6b8cf17bbed
github.com/google/flatbuffers v2.0.6+incompatible
github.com/kch42/buzhash v0.0.0-20160816060738-9bdec3dec7c6
github.com/mitchellh/go-ps v1.0.0
+2 -2
View File
@@ -161,8 +161,8 @@ github.com/dolthub/flatbuffers v1.13.0-dh.1 h1:OWJdaPep22N52O/0xsUevxJ6Qfw1M2txC
github.com/dolthub/flatbuffers v1.13.0-dh.1/go.mod h1:CorYGaDmXjHz1Z7i50PYXG1Ricn31GcA2wNOTFIQAKE=
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.14.1-0.20230106182545-4722c4cfd575 h1:KMqkKE23Ai05AVtPm/Gy2AD7iH2/LSiV5HR3G3hIhKU=
github.com/dolthub/go-mysql-server v0.14.1-0.20230106182545-4722c4cfd575/go.mod h1:2ZHPn64+LPJWSfj/GvlaI/6yLSeVnbHTC3ih3ZBhtWg=
github.com/dolthub/go-mysql-server v0.14.1-0.20230106202621-d6b8cf17bbed h1:ku3ieGAfXzPcrJyYMDWOU7FAIWM+67rDuLfr7oCppds=
github.com/dolthub/go-mysql-server v0.14.1-0.20230106202621-d6b8cf17bbed/go.mod h1:2ZHPn64+LPJWSfj/GvlaI/6yLSeVnbHTC3ih3ZBhtWg=
github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488 h1:0HHu0GWJH0N6a6keStrHhUAK5/o9LVfkh44pvsV4514=
github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488/go.mod h1:ehexgi1mPxRTk0Mok/pADALuHbvATulTh6gzr7NzZto=
github.com/dolthub/jsonpath v0.0.0-20210609232853-d49537a30474 h1:xTrR+l5l+1Lfq0NvhiEsctylXinUMFhhsqaEcl414p8=
@@ -116,7 +116,7 @@ func LoadData(branchControlFilePath string, doltConfigDirPath string) (*Controll
}
// The Deserialize functions acquire write locks, so we don't acquire them here
if err = controller.Access.Deserialize(access); err != nil {
return nil, err
return nil, fmt.Errorf("failed to deserialize config at '%s': %w", branchControlFilePath, err)
}
if err = controller.Namespace.Deserialize(namespace); err != nil {
return nil, err
+12
View File
@@ -17,6 +17,9 @@ package doltdb
import (
"context"
"errors"
"fmt"
"github.com/dolthub/dolt/go/store/prolly"
"github.com/dolthub/dolt/go/store/datas"
"github.com/dolthub/dolt/go/store/hash"
@@ -103,6 +106,15 @@ func (c *Commit) GetParent(ctx context.Context, idx int) (*Commit, error) {
return NewCommit(ctx, c.vrw, c.ns, c.parents[idx])
}
func (c *Commit) GetCommitClosure(ctx context.Context) (prolly.CommitClosure, error) {
switch v := c.dCommit.NomsValue().(type) {
case types.SerialMessage:
return datas.NewParentsClosure(ctx, c.dCommit, v, c.vrw, c.ns)
default:
return prolly.CommitClosure{}, fmt.Errorf("old format lacks commit closure")
}
}
var ErrNoCommonAncestor = errors.New("no common ancestor")
func GetCommitAncestor(ctx context.Context, cm1, cm2 *Commit) (*Commit, error) {
@@ -26,6 +26,8 @@ import (
var _ sql.Table = (*LogTable)(nil)
var _ sql.StatisticsTable = (*LogTable)(nil)
// LogTable is a sql.Table implementation that implements a system table which shows the dolt commit log
type LogTable struct {
ddb *doltdb.DoltDB
@@ -37,6 +39,22 @@ func NewLogTable(_ *sql.Context, ddb *doltdb.DoltDB, head *doltdb.Commit) sql.Ta
return &LogTable{ddb: ddb, head: head}
}
// DataLength implements sql.StatisticsTable
func (dt *LogTable) DataLength(ctx *sql.Context) (uint64, error) {
return uint64(4*sql.Text.MaxByteLength()*4 + 16), nil
}
// RowCount implements sql.StatisticsTable
func (dt *LogTable) RowCount(ctx *sql.Context) (uint64, error) {
cc, err := dt.head.GetCommitClosure(ctx)
if err != nil {
// TODO: remove this when we deprecate LD
return 1000, nil
}
cnt, err := cc.Count()
return uint64(cnt + 1), err
}
// Name is a sql.Table interface function which returns the name of the table which is defined by the constant
// LogTableName
func (dt *LogTable) Name() string {
+27 -20
View File
@@ -28,34 +28,41 @@ import (
"github.com/dolthub/dolt/go/store/types"
)
func NewParentsClosure(ctx context.Context, c *Commit, sv types.SerialMessage, vr types.ValueReader, ns tree.NodeStore) (prolly.CommitClosure, error) {
var msg serial.Commit
err := serial.InitCommitRoot(&msg, sv, serial.MessagePrefixSz)
if err != nil {
return prolly.CommitClosure{}, err
}
addr := hash.New(msg.ParentClosureBytes())
if addr.IsEmpty() {
return prolly.CommitClosure{}, nil
}
v, err := vr.ReadValue(ctx, addr)
if err != nil {
return prolly.CommitClosure{}, err
}
if types.IsNull(v) {
return prolly.CommitClosure{}, fmt.Errorf("internal error or data loss: dangling commit parent closure for addr %s or commit %s", addr.String(), c.Addr().String())
}
node, err := tree.NodeFromBytes(v.(types.SerialMessage))
if err != nil {
return prolly.CommitClosure{}, err
}
return prolly.NewCommitClosure(node, ns)
}
func newParentsClosureIterator(ctx context.Context, c *Commit, vr types.ValueReader, ns tree.NodeStore) (parentsClosureIter, error) {
sv := c.NomsValue()
if _, ok := sv.(types.SerialMessage); ok {
var msg serial.Commit
err := serial.InitCommitRoot(&msg, sv.(types.SerialMessage), serial.MessagePrefixSz)
if sm, ok := sv.(types.SerialMessage); ok {
cc, err := NewParentsClosure(ctx, c, sm, vr, ns)
if err != nil {
return nil, err
}
addr := hash.New(msg.ParentClosureBytes())
if addr.IsEmpty() {
if cc.IsEmpty() {
return nil, nil
}
v, err := vr.ReadValue(ctx, addr)
if err != nil {
return nil, err
}
if types.IsNull(v) {
return nil, fmt.Errorf("internal error or data loss: dangling commit parent closure for addr %s or commit %s", addr.String(), c.Addr().String())
}
node, err := tree.NodeFromBytes(v.(types.SerialMessage))
if err != nil {
return nil, err
}
cc, err := prolly.NewCommitClosure(node, ns)
if err != nil {
return nil, err
}
ci, err := cc.IterAllReverse(ctx)
if err != nil {
return nil, err
+4
View File
@@ -96,6 +96,10 @@ func (c CommitClosure) IterAllReverse(ctx context.Context) (CommitClosureIter, e
return c.closure.IterAllReverse(ctx)
}
func (c CommitClosure) IsEmpty() bool {
return c.Node().Size() == 0
}
func DecodeCommitClosureKey(key []byte) (height uint64, addr hash.Hash) {
height = binary.LittleEndian.Uint64(key)
addr = hash.New(key[8:])