MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / copyVectorDataToShards

Method copyVectorDataToShards

dgraph/cmd/bulk/reduce.go:507–549  ·  view source on GitHub ↗

copyVectorDataToShards copies vector data from the shared vectorTmpDb to the correct output DBs. It uses the predToOutputShard map to determine which predicate goes to which shard.

(vectorDb *badger.DB, predToShard map[string]int)

Source from the content-addressed store, hash-verified

505// copyVectorDataToShards copies vector data from the shared vectorTmpDb to the correct output DBs.
506// It uses the predToOutputShard map to determine which predicate goes to which shard.
507func (r *reducer) copyVectorDataToShards(vectorDb *badger.DB, predToShard map[string]int) {
508 if len(predToShard) == 0 {
509 return
510 }
511
512 // Group predicates by output shard
513 shardPreds := make(map[int][]string)
514 for pred, shardId := range predToShard {
515 shardPreds[shardId] = append(shardPreds[shardId], pred)
516 }
517
518 // Copy each shard's predicates to its output DB
519 for shardId, preds := range shardPreds {
520 if shardId >= len(r.dbs) {
521 glog.Errorf("Invalid shard ID %d for predicates %v (only %d DBs)", shardId, preds, len(r.dbs))
522 continue
523 }
524
525 destDb := r.dbs[shardId]
526
527 // Collect all predicate keys (base + HNSW suffixes) and sort for efficient iteration
528 var allPreds []string
529 for _, pred := range preds {
530 allPreds = append(allPreds, pred)
531 allPreds = append(allPreds, hnsw.ConcatStrings(pred, hnsw.VecKeyword)) // __vector_
532 allPreds = append(allPreds, hnsw.ConcatStrings(pred, hnsw.VecEntry)) // __vector_entry
533 allPreds = append(allPreds, hnsw.ConcatStrings(pred, hnsw.VecDead)) // __vector_dead
534 }
535 sort.Strings(allPreds)
536
537 fmt.Printf("Copying %d vector predicates to shard %d\n", len(preds), shardId)
538
539 // Copy each predicate
540 totalCount := 0
541 for _, pred := range allPreds {
542 count := r.copyPredicateWithBatchCount(destDb, vectorDb, pred)
543 totalCount += count
544 }
545
546 fmt.Printf("Copied %d total KV entries for %d predicates to shard %d\n",
547 totalCount, len(preds), shardId)
548 }
549}
550
551// copyPredicateWithBatchCount is like copyPredicateWithBatch but returns the count of entries copied.
552func (r *reducer) copyPredicateWithBatchCount(destDb *badger.DB, srcDb *badger.DB, pred string) int {

Callers 1

runMethod · 0.95

Calls 3

ConcatStringsFunction · 0.92
ErrorfMethod · 0.45

Tested by

no test coverage detected