Skip to content

Commit

Permalink
More logging to diagnose why beam locations are not saved correctly f…
Browse files Browse the repository at this point in the history
…or uploaded datasets. Fixed some error handling too
  • Loading branch information
Peter Nemere committed Mar 26, 2024
1 parent 50ae499 commit 5429eea
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 39 deletions.
14 changes: 11 additions & 3 deletions api/dataimport/internal/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ func (s *PIXLISEDataSaver) Save(

// We work out the default file name when copying output images now... because if there isn't one, we may pick one during that process.
defaultContextImage, err := copyImagesToOutput(contextImageSrcPath, []string{data.DatasetID}, data.DatasetID, outputImagesPath, data, db, jobLog)
if err != nil {
return err
}

exp.MainContextImage = defaultContextImage

// Set any matched aligned images - this happens after copyImagesToOutput because file names may be modified by it depending on formats
Expand Down Expand Up @@ -359,7 +363,7 @@ func (s *PIXLISEDataSaver) Save(

summaryData := makeSummaryFileContent(&exp, data.DatasetID, data.Instrument, data.Meta, int(fi.Size()), creationUnixTimeSec, data.CreatorUserId)

jobLog.Infof("Writing summary to DB...")
jobLog.Infof("Writing summary to DB for %v...", summaryData.Id)

coll = db.Collection(dbCollections.ScansName)
opt := options.Update().SetUpsert(true)
Expand All @@ -374,14 +378,15 @@ func (s *PIXLISEDataSaver) Save(
}

// Set ownership
ownerItem, err := wsHelpers.MakeOwnerForWrite(summaryData.Id, protos.ObjectType_OT_SCAN, summaryData.CreatorUserId, creationUnixTimeSec)
ownerItem := wsHelpers.MakeOwnerForWrite(summaryData.Id, protos.ObjectType_OT_SCAN, summaryData.CreatorUserId, creationUnixTimeSec)

ownerItem.Viewers = autoShare.Viewers
ownerItem.Editors = autoShare.Editors

coll = db.Collection(dbCollections.OwnershipName)
opt = options.Update().SetUpsert(true)

jobLog.Infof("Writing ownership to DB for scan %v...", ownerItem.Id)
result, err = coll.UpdateOne(context.TODO(), bson.D{{Key: "_id", Value: ownerItem.Id}}, bson.D{{Key: "$set", Value: ownerItem}}, opt)
if err != nil {
jobLog.Errorf("Failed to write ownership item to DB: %v", err)
Expand All @@ -408,10 +413,13 @@ func insertDefaultImage(db *mongo.Database, scanId string, defaultImage string,
coll := db.Collection(dbCollections.ScanDefaultImagesName)
opt := options.InsertOne()

defaultImageResult, err := coll.InsertOne(context.TODO(), &protos.ScanImageDefaultDB{ScanId: scanId, DefaultImageFileName: path.Join(scanId, defaultImage)}, opt)
imgPath := path.Join(scanId, defaultImage)
jobLog.Infof("Writing default image %v to DB for scan %v...", imgPath, scanId)
defaultImageResult, err := coll.InsertOne(context.TODO(), &protos.ScanImageDefaultDB{ScanId: scanId, DefaultImageFileName: imgPath}, opt)
if err != nil {
if mongo.IsDuplicateKeyError(err) {
// Don't overwrite, so we're OK with this
jobLog.Infof("Default image for scan %v already exists, not overwriting existing one in case of user edit.", scanId)
return nil
}
return err
Expand Down
7 changes: 1 addition & 6 deletions api/quantification/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,7 @@ func (r *quantNodeRunner) triggerPiquantNodes(wg *sync.WaitGroup) {
},
}

ownerItem, err := wsHelpers.MakeOwnerForWrite(r.jobId, protos.ObjectType_OT_QUANTIFICATION, r.quantStartSettings.RequestorUserId, now)
if err != nil {
msg := fmt.Sprintf("Failed to create ownership info for quant job %v. Error was: %v", r.jobId, err)
r.completeJobState(false, msg, quantOutPath, piquantLogList)
return
}
ownerItem := wsHelpers.MakeOwnerForWrite(r.jobId, protos.ObjectType_OT_QUANTIFICATION, r.quantStartSettings.RequestorUserId, now)

err = writeQuantAndOwnershipToDB(summary, ownerItem, svcs.MongoDB)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions api/quantification/importCSV.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ func ImportQuantCSV(
}

// Finally, write the summary data to DB along with ownership entry
ownerItem, err := wsHelpers.MakeOwnerForWrite(quantId, protos.ObjectType_OT_QUANTIFICATION, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())
if err != nil {
return quantId, err
}
ownerItem := wsHelpers.MakeOwnerForWrite(quantId, protos.ObjectType_OT_QUANTIFICATION, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())

summary := protos.QuantificationSummary{
Id: quantId,
Expand Down
6 changes: 2 additions & 4 deletions api/ws/handlers/element-set.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ func createElementSet(elementSet *protos.ElementSet, hctx wsHelpers.HandlerConte
elementSet.Id = id

// We need to create an ownership item along with it
ownerItem, err := wsHelpers.MakeOwnerForWrite(id, protos.ObjectType_OT_ELEMENT_SET, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())
if err != nil {
return nil, err
}
ownerItem := wsHelpers.MakeOwnerForWrite(id, protos.ObjectType_OT_ELEMENT_SET, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())

elementSet.ModifiedUnixSec = ownerItem.CreatedUnixSec

wc := writeconcern.New(writeconcern.WMajority())
Expand Down
5 changes: 1 addition & 4 deletions api/ws/handlers/expression-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ func createExpressionGroup(egroup *protos.ExpressionGroup, hctx wsHelpers.Handle
egroup.Id = id

// We need to create an ownership item along with it
ownerItem, err := wsHelpers.MakeOwnerForWrite(id, protos.ObjectType_OT_EXPRESSION_GROUP, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())
if err != nil {
return nil, err
}
ownerItem := wsHelpers.MakeOwnerForWrite(id, protos.ObjectType_OT_EXPRESSION_GROUP, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())

egroup.ModifiedUnixSec = ownerItem.CreatedUnixSec

Expand Down
5 changes: 1 addition & 4 deletions api/ws/handlers/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ func createExpression(expr *protos.DataExpression, hctx wsHelpers.HandlerContext
expr.Id = id

// We need to create an ownership item along with it
ownerItem, err := wsHelpers.MakeOwnerForWrite(id, protos.ObjectType_OT_EXPRESSION, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())
if err != nil {
return nil, err
}
ownerItem := wsHelpers.MakeOwnerForWrite(id, protos.ObjectType_OT_EXPRESSION, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())

expr.ModifiedUnixSec = ownerItem.CreatedUnixSec

Expand Down
5 changes: 1 addition & 4 deletions api/ws/handlers/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,7 @@ func createModule(name string, comments string, intialSourceCode string, tags []
}

// We need to create an ownership item along with it
ownerItem, err := wsHelpers.MakeOwnerForWrite(modId, protos.ObjectType_OT_DATA_MODULE, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())
if err != nil {
return nil, err
}
ownerItem := wsHelpers.MakeOwnerForWrite(modId, protos.ObjectType_OT_DATA_MODULE, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())

module.ModifiedUnixSec = ownerItem.CreatedUnixSec

Expand Down
5 changes: 1 addition & 4 deletions api/ws/handlers/roi.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ func createROI(roi *protos.ROIItem, hctx wsHelpers.HandlerContext, needMistEntry
roi.Id = id

// We need to create an ownership item along with it
ownerItem, err := wsHelpers.MakeOwnerForWrite(id, protos.ObjectType_OT_ROI, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())
if err != nil {
return nil, err
}
ownerItem := wsHelpers.MakeOwnerForWrite(id, protos.ObjectType_OT_ROI, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())

roi.ModifiedUnixSec = ownerItem.CreatedUnixSec

Expand Down
5 changes: 1 addition & 4 deletions api/ws/handlers/screen-configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ func writeScreenConfiguration(screenConfig *protos.ScreenConfiguration, hctx wsH
}

// We need to create an ownership item along with it
owner, err = wsHelpers.MakeOwnerForWrite(screenConfig.Id, protos.ObjectType_OT_SCREEN_CONFIG, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())
if err != nil {
return nil, err
}
owner = wsHelpers.MakeOwnerForWrite(screenConfig.Id, protos.ObjectType_OT_SCREEN_CONFIG, hctx.SessUser.User.Id, hctx.Svcs.TimeStamper.GetTimeNowSec())

screenConfig.ModifiedUnixSec = owner.CreatedUnixSec
configuration = screenConfig
Expand Down
4 changes: 2 additions & 2 deletions api/ws/wsHelpers/ownership.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"go.mongodb.org/mongo-driver/mongo/options"
)

func MakeOwnerForWrite(objectId string, objectType protos.ObjectType, creatorUserId string, createTimeUnixSec int64) (*protos.OwnershipItem, error) {
func MakeOwnerForWrite(objectId string, objectType protos.ObjectType, creatorUserId string, createTimeUnixSec int64) *protos.OwnershipItem {
ownerItem := &protos.OwnershipItem{
Id: objectId,
ObjectType: objectType,
Expand All @@ -30,7 +30,7 @@ func MakeOwnerForWrite(objectId string, objectType protos.ObjectType, creatorUse
}
}

return ownerItem, nil
return ownerItem
}

// Checks object access - if requireEdit is true, it checks for edit access
Expand Down
2 changes: 2 additions & 0 deletions core/beamLocation/experimentFileToDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func ImportBeamLocationToDB(imgName string, instrument protos.ScanInstrument, fo
})

opt := options.Replace().SetUpsert(true)
logger.Infof("Writing beam location to DB for image: %v, and scan: %v, instrument: %v, beamVersion: %v", imgName, forScanId, instrument, beamVersion)

result, err := imagesColl.ReplaceOne(context.TODO(), bson.M{"_id": imgName}, beams, opt)
if err != nil {
return err
Expand Down

0 comments on commit 5429eea

Please sign in to comment.