Merge pull request #5902 from dolthub/aaron/clone-works-better-with-chunk-journal

go/store/datas/pull/clone.go: Fix to clone to interact with sql-server remotes better.
This commit is contained in:
Aaron Son
2023-05-10 12:01:51 -07:00
committed by GitHub

View File

@@ -55,7 +55,7 @@ func Clone(ctx context.Context, srcCS, sinkCS chunks.ChunkStore, eventCh chan<-
return fmt.Errorf("%w: sink db is not a Table File Store", ErrCloneUnsupported)
}
return clone(ctx, srcTS, sinkTS, eventCh)
return clone(ctx, srcTS, sinkTS, sinkCS, eventCh)
}
type CloneTableFileEvent int
@@ -91,7 +91,7 @@ func mapTableFiles(tblFiles []chunks.TableFile) ([]string, map[string]chunks.Tab
const concurrentTableFileDownloads = 3
func clone(ctx context.Context, srcTS, sinkTS chunks.TableFileStore, eventCh chan<- TableFileEvent) error {
func clone(ctx context.Context, srcTS, sinkTS chunks.TableFileStore, sinkCS chunks.ChunkStore, eventCh chan<- TableFileEvent) error {
root, sourceFiles, appendixFiles, err := srcTS.Sources(ctx)
if err != nil {
return err
@@ -211,6 +211,24 @@ func clone(ctx context.Context, srcTS, sinkTS chunks.TableFileStore, eventCh cha
}
sinkTS.AddTableFilesToManifest(ctx, fileIDToNumChunks)
// AddTableFilesToManifest can set the root chunk if there is a chunk
// journal which we downloaded in the clone. If that happened, the
// chunk journal is actually more accurate on what the current root is
// than the result of |Sources| up above. We choose not to touch
// anything in that case.
err = sinkCS.Rebase(ctx)
if err != nil {
return err
}
sinkRoot, err := sinkCS.Root(ctx)
if err != nil {
return err
}
if !sinkRoot.IsEmpty() {
return nil
}
return sinkTS.SetRootChunk(ctx, root, hash.Hash{})
}