Skip to content

Commit

Permalink
Fix the dolt_history_{table} for shallow clones
Browse files Browse the repository at this point in the history
Also some todo clean up
  • Loading branch information
macneale4 committed Feb 14, 2024
1 parent 0212c7b commit 1e03716
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
1 change: 0 additions & 1 deletion go/libraries/doltcore/doltdb/commit_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func pushDataset(ctx context.Context, destDB, srcDB datas.Database, ds datas.Dat
return err
}

// NM4 tmp to compile.
err := pullHash(ctx, destDB, srcDB, []hash.Hash{addr}, tmpDir, nil, nil)
if err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions go/libraries/doltcore/doltdb/commit_itr.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ func (cmItr *commitItr) Next(ctx context.Context) (hash.Hash, *OptionalCommit, e
next := cmItr.unprocessed[numUnprocessed-1]
cmItr.unprocessed = cmItr.unprocessed[:numUnprocessed-1]
cmItr.curr, err = HashToCommit(ctx, cmItr.ddb.ValueReadWriter(), cmItr.ddb.ns, next)

if err != nil {
if err != nil && err != ErrGhostCommitEncountered {
return hash.Hash{}, nil, err
}
if err == ErrGhostCommitEncountered {
cmItr.curr = nil
}

return next, &OptionalCommit{cmItr.curr, next}, nil
}
Expand Down
6 changes: 1 addition & 5 deletions go/libraries/doltcore/sqle/dtables/commits_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,11 @@ func NewCommitsRowItr(ctx *sql.Context, ddb *doltdb.DoltDB) (CommitsRowItr, erro
func (itr CommitsRowItr) Next(ctx *sql.Context) (sql.Row, error) {
h, optCmt, err := itr.itr.Next(ctx)
if err != nil {
if err == doltdb.ErrGhostCommitEncountered {
return nil, io.EOF
}

return nil, err
}
cm, ok := optCmt.ToCommit()
if !ok {
return nil, doltdb.ErrGhostCommitRuntimeFailure
return nil, io.EOF
}

meta, err := cm.GetCommitMeta(ctx)
Expand Down
2 changes: 1 addition & 1 deletion go/libraries/doltcore/sqle/history_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func (cp commitPartitioner) Next(ctx *sql.Context) (sql.Partition, error) {
}
cm, ok := optCmt.ToCommit()
if !ok {
return nil, doltdb.ErrGhostCommitEncountered // NM4 TEST.
return nil, io.EOF
}

return &commitPartition{h, cm}, nil
Expand Down
2 changes: 1 addition & 1 deletion go/store/chunks/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c Chunk) IsEmpty() bool {
return len(c.data) == 0
}

// IsGhost returns true if the chunk is a ghost chunk. Ghost chunks have not data, so if IsGhost() returns true, Data() will be an empty slice.
// IsGhost returns true if the chunk is a ghost chunk. Ghost chunks have no data, so if IsGhost() returns true, Data() will be an empty slice.
func (c Chunk) IsGhost() bool {
return c.ghost
}
Expand Down
20 changes: 12 additions & 8 deletions integration-tests/bats/shallow-clone.bats
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@ seed_and_start_serial_remote() {
# dolt_diff table will show two rows, because each row is a delta.
run dolt sql -q "select * from dolt_diff"
[ "$status" -eq 0 ]
[[ "$output" =~ "Added Val: 5 " ]] || false
[[ "$output" =~ "Added Val: 4 " ]] || false
! [[ "$output" =~ "Added Val: 3 " ]] || false
! [[ "$output" =~ "Added Val: 2 " ]] || false

run dolt sql -q "select * from dolt_commits"
[ "$status" -eq 0 ]
Expand All @@ -157,13 +155,19 @@ seed_and_start_serial_remote() {
[[ "$output" =~ "Added Val: 3 " ]] || false
! [[ "$output" =~ "Added Val: 2 " ]] || false

# A full clone would have 5 commits with i=1, so if we have 3, we are looking good.
run dolt sql -q "select count(*) = 3 from dolt_history_vals where i = 1"
[ "$status" -eq 0 ]
[[ "$output" =~ "true" ]] || false

# NM4 - not sure what dolt_history_{table} should do. Currently errors out every time.
# run dolt sql -q "select * from dolt_history_vals"
# [ "$status" -eq 0 ]
# [[ "$output" =~ "yo mama" ]] || false
# [[ "$output" =~ "4 " ]] || false
# [[ "$output" =~ "3 " ]] || false
# A full clone would have 2 commits with i=4, and our shallow clone has all the commits for that row.
run dolt sql -q "select count(*) = 2 from dolt_history_vals where i = 4"
[ "$status" -eq 0 ]
[[ "$output" =~ "true" ]] || false

run dolt sql -q "select count(distinct commit_hash) = 3 from dolt_history_vals"
[ "$status" -eq 0 ]
[[ "$output" =~ "true" ]] || false

# Verify that the table is complete.
run dolt sql -q "select sum(i) from vals"
Expand Down

0 comments on commit 1e03716

Please sign in to comment.