MCPcopy
hub / github.com/alibaba/MongoShake / getPrimaryShard

Function getPrimaryShard

tools/pre-split/pre_split.go:343–355  ·  view source on GitHub ↗

getPrimaryShard return the primary shard name of specified db

(c *mongo.Client, dbName string)

Source from the content-addressed store, hash-verified

341
342// getPrimaryShard return the primary shard name of specified db
343func getPrimaryShard(c *mongo.Client, dbName string) (string, error) {
344 filter := bson.D{{"_id", fmt.Sprintf("%s", dbName)}}
345 var result bson.M
346 err := c.Database(DbConfig).Collection(CollDatabases).FindOne(context.Background(), filter).Decode(&result)
347 if err != nil {
348 return "", fmt.Errorf("find db:%s in config.databses failed: %v", dbName, err)
349 }
350 primaryShard, ok := result["primary"].(string)
351 if !ok {
352 return "", fmt.Errorf("unexpected doc:%+v", result)
353 }
354 return primaryShard, nil
355}
356
357func moveChunkIfNeeded(dstC *mongo.Client, dbName, collName string, hasHashed bool) error {
358 // get new uuid for namespace

Callers 1

moveChunkIfNeededFunction · 0.70

Calls 1

ErrorfMethod · 0.80

Tested by

no test coverage detected