Skip to content

Commit d0c2664

Browse files
author
Sicheng Pan
committed
Use provided uuid
1 parent 4855d78 commit d0c2664

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

Diff for: go/pkg/sysdb/coordinator/model/collection.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ type UpdateCollection struct {
6363

6464
type ForkCollection struct {
6565
SourceCollectionID types.UniqueID
66-
TargetCollectionName *string
66+
TargetCollectionID types.UniqueID
67+
TargetCollectionName string
6768
}
6869

6970
type FlushCollectionCompaction struct {

Diff for: go/pkg/sysdb/coordinator/table_catalog.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -700,16 +700,13 @@ func (tc *Catalog) getLineageFile(ctx context.Context, collection *model.Collect
700700
}
701701

702702
func (tc *Catalog) ForkCollection(ctx context.Context, forkCollection *model.ForkCollection) (*model.Collection, []*model.Segment, error) {
703-
log.Info("Forking collection", zap.String("sourceCollectionId", forkCollection.SourceCollectionID.String()), zap.String("targetCollectionName", *forkCollection.TargetCollectionName))
704-
705-
var newCollectionID types.UniqueID
703+
log.Info("Forking collection", zap.String("sourceCollectionId", forkCollection.SourceCollectionID.String()), zap.String("targetCollectionId", forkCollection.TargetCollectionID.String()), zap.String("targetCollectionName", forkCollection.TargetCollectionName))
706704

707705
err := tc.txImpl.Transaction(ctx, func(txCtx context.Context) error {
708706
var err error
709707
var rootCollection *model.Collection
710708
var sourceCollection *model.Collection
711709
var sourceSegments []*model.Segment
712-
var newCollection *model.Collection
713710
var newLineageFileFullName string
714711

715712
sourceCollectionIDStr := forkCollection.SourceCollectionID.String()
@@ -732,8 +729,8 @@ func (tc *Catalog) ForkCollection(ctx context.Context, forkCollection *model.For
732729
ts := time.Now().UTC()
733730

734731
createCollection := &model.CreateCollection{
735-
ID: types.NewUniqueID(),
736-
Name: *forkCollection.TargetCollectionName,
732+
ID: forkCollection.TargetCollectionID,
733+
Name: forkCollection.TargetCollectionName,
737734
ConfigurationJsonStr: sourceCollection.ConfigurationJsonStr,
738735
Dimension: sourceCollection.Dimension,
739736
Metadata: sourceCollection.Metadata,
@@ -749,18 +746,17 @@ func (tc *Catalog) ForkCollection(ctx context.Context, forkCollection *model.For
749746
ID: types.NewUniqueID(),
750747
Type: segment.Type,
751748
Scope: segment.Scope,
752-
CollectionID: createCollection.ID,
749+
CollectionID: forkCollection.TargetCollectionID,
753750
Metadata: segment.Metadata,
754751
Ts: ts.Unix(),
755752
}
756753
createSegments = append(createSegments, createSegment)
757754
}
758755

759-
newCollection, _, err = tc.CreateCollectionAndSegments(ctx, createCollection, createSegments, ts.Unix())
756+
_, _, err = tc.CreateCollectionAndSegments(ctx, createCollection, createSegments, ts.Unix())
760757
if err != nil {
761758
return err
762759
}
763-
newCollectionID = newCollection.ID
764760

765761
if rootCollectionID == nil {
766762
rootCollection = sourceCollection
@@ -774,10 +770,10 @@ func (tc *Catalog) ForkCollection(ctx context.Context, forkCollection *model.For
774770
lineageFile.Dependencies = append(lineageFile.Dependencies, &coordinatorpb.CollectionVersionDependency{
775771
SourceCollectionId: sourceCollectionIDStr,
776772
SourceCollectionVersion: uint64(sourceCollection.Version),
777-
TargetCollectionId: newCollection.ID.String(),
773+
TargetCollectionId: forkCollection.TargetCollectionID.String(),
778774
})
779775

780-
newLineageFileBaseName := fmt.Sprintf("%d/%d/%d/%d-%d-%d-%s-%d-%s.binpb", ts.Year(), ts.Month(), ts.Day(), ts.Hour(), ts.Minute(), ts.Second(), sourceCollectionIDStr, sourceCollection.Version, newCollectionID.String())
776+
newLineageFileBaseName := fmt.Sprintf("%d/%d/%d/%d-%d-%d-%s-%d-%s.binpb", ts.Year(), ts.Month(), ts.Day(), ts.Hour(), ts.Minute(), ts.Second(), sourceCollectionIDStr, sourceCollection.Version, forkCollection.TargetCollectionID.String())
781777
newLineageFileFullName, err = tc.s3Store.PutLineageFile(rootCollection.TenantID, rootCollection.DatabaseName, rootCollectionIDStr, newLineageFileBaseName, lineageFile)
782778
if err != nil {
783779
return err
@@ -789,7 +785,7 @@ func (tc *Catalog) ForkCollection(ctx context.Context, forkCollection *model.For
789785
return nil, nil, err
790786
}
791787

792-
return tc.GetCollectionWithSegments(ctx, newCollectionID)
788+
return tc.GetCollectionWithSegments(ctx, forkCollection.TargetCollectionID)
793789
}
794790

795791
func (tc *Catalog) CreateSegment(ctx context.Context, createSegment *model.CreateSegment, ts types.Timestamp) (*model.Segment, error) {

Diff for: go/pkg/sysdb/grpc/collection_service.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -343,23 +343,30 @@ func (s *Server) UpdateCollection(ctx context.Context, req *coordinatorpb.Update
343343
}
344344

345345
func (s *Server) ForkCollection(ctx context.Context, req *coordinatorpb.ForkCollectionRequest) (*coordinatorpb.ForkCollectionResponse, error) {
346-
collectionID := req.SourceCollectionId
347-
348346
res := &coordinatorpb.ForkCollectionResponse{}
349347

350-
parsedCollectionID, err := types.ToUniqueID(&collectionID)
348+
sourceCollectionID := req.SourceCollectionId
349+
parsedSourceCollectionID, err := types.ToUniqueID(&sourceCollectionID)
350+
if err != nil {
351+
log.Error("ForkCollection failed. Failed to parse source collection id", zap.Error(err), zap.String("collection_id", sourceCollectionID))
352+
return res, grpcutils.BuildInternalGrpcError(err.Error())
353+
}
354+
355+
targetCollectionID := req.TargetCollectionId
356+
parsedTargetCollectionID, err := types.ToUniqueID(&targetCollectionID)
351357
if err != nil {
352-
log.Error("ForkCollection failed. Failed to parse source collection id", zap.Error(err), zap.String("collection_id", collectionID))
358+
log.Error("ForkCollection failed. Failed to parse Target collection id", zap.Error(err), zap.String("collection_id", targetCollectionID))
353359
return res, grpcutils.BuildInternalGrpcError(err.Error())
354360
}
355361

356362
forkCollection := &model.ForkCollection{
357-
SourceCollectionID: parsedCollectionID,
358-
TargetCollectionName: &req.TargetCollectionName,
363+
SourceCollectionID: parsedSourceCollectionID,
364+
TargetCollectionID: parsedTargetCollectionID,
365+
TargetCollectionName: req.TargetCollectionName,
359366
}
360367
collection, segments, err := s.coordinator.ForkCollection(ctx, forkCollection)
361368
if err != nil {
362-
log.Error("ForkCollection failed. ", zap.Error(err), zap.String("collection_id", collectionID))
369+
log.Error("ForkCollection failed. ", zap.Error(err), zap.String("collection_id", sourceCollectionID))
363370
if err == common.ErrCollectionNotFound {
364371
return res, grpcutils.BuildNotFoundGrpcError(err.Error())
365372
}

0 commit comments

Comments
 (0)