github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/index_sharding_backward_compatibility.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package db 13 14 import ( 15 "os" 16 "path/filepath" 17 "strings" 18 19 "github.com/pkg/errors" 20 "github.com/weaviate/weaviate/usecases/sharding" 21 ) 22 23 func (i *Index) checkSingleShardMigration(shardState *sharding.State) error { 24 res, err := os.ReadDir(i.Config.RootPath) 25 if err != nil { 26 return err 27 } 28 29 for _, entry := range res { 30 if !strings.HasPrefix(entry.Name(), i.ID()+"_single") { 31 // either not part of this index, or not a "_single" shard 32 continue 33 } 34 35 // whatever is left now, needs to be migrated 36 shards := shardState.AllPhysicalShards() 37 if len(shards) != 1 { 38 return errors.Errorf("cannot migrate '_single' shard into config with %d "+ 39 "desired shards", len(shards)) 40 } 41 42 shardName := shards[0] 43 newName := i.ID() + "_" + shardName + strings.TrimPrefix(entry.Name(), i.ID()+"_single") 44 oldPath := filepath.Join(i.Config.RootPath, entry.Name()) 45 newPath := filepath.Join(i.Config.RootPath, newName) 46 47 if err := os.Rename(oldPath, newPath); err != nil { 48 return errors.Wrapf(err, "migrate shard %q to %q", oldPath, newPath) 49 } 50 51 i.logger.WithField("action", "index_startup_migrate_shards_successful"). 52 WithField("old_shard", oldPath). 53 WithField("new_shard", newPath). 54 Infof("successfully migrated shard file %q (created in an earlier version) to %q", 55 oldPath, newPath) 56 } 57 58 return nil 59 }