Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue open-horizon#154 - Bug: Failed to create index when it exists #155

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions core/storage/mongoStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type leaderDocument struct {
}

type isMasterResult struct {
IsMaster bool `bson:"isMaster"`
IsMaster bool `bson:"ismaster"`
LocalTime time.Time `bson:"localTime"`
OK bool `bson:"ok"`
}
Expand Down Expand Up @@ -104,15 +104,6 @@ type aclObject struct {
LastUpdate time.Time `bson:"last-update"`
}

type dataInfoObject struct {
ID string `bson:"_id"`
ChunkSize int32 `bson:"chunkSize"`
UploadDate time.Time `bson:"uploadDate"`
Length int32 `bson:"length"`
MD5 string `bson:"md5"`
Filename string `bson:"filename"`
}

const maxUpdateTries = 5

var sleepInMS int
Expand All @@ -138,7 +129,7 @@ func (store *MongoStorage) Init() common.SyncServiceError {
var mongoClient *mongo.Client
var err error
if trace.IsLogging(logger.INFO) {
trace.Info("CConnecting to mongo...")
trace.Info("Connecting to mongo...")
}
// Set up MongoDB client options
clientOptions := options.Client().ApplyURI(common.Configuration.MongoAddressCsv)
Expand Down Expand Up @@ -271,12 +262,15 @@ func (store *MongoStorage) Init() common.SyncServiceError {
{"metadata.destination-policy.services.service-name", -1},
},
Options: options.Index().SetName("syncObjects-destination-policy.services.service-id").SetSparse(true),
// need to set index name???
})

if err != nil {
message := fmt.Sprintf("Failed to create an index on %s. Error: %s", objects, err)
log.Error(message)
return &Error{message}
// check if error is IndexKeySpecsConflict
if casterr := err.(mongo.CommandError); casterr.Code != 86 {
message := fmt.Sprintf("Failed to create an index on %s. Error: %s", objects, err)
log.Error(message)
return &Error{message}
}
}

_, err = objectsCollection.Indexes().CreateOne(
Expand Down
2 changes: 1 addition & 1 deletion core/storage/mongoStorageHelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func (store *MongoStorage) createFile(id string, data io.Reader) common.SyncServ

func (store *MongoStorage) run(cmd interface{}, result interface{}) common.SyncServiceError {
function := func(db *mongo.Database) error {
return db.RunCommand(context.TODO(), cmd).Decode(&result)
return db.RunCommand(context.TODO(), cmd).Decode(result)
}

retry, err := store.withDBHelper(function, true)
Expand Down
Loading