addInvalidDatabase adds a db to invalid dbconfig map if it doesn't exist in there yet and will log for it at warning level if the db already exists there we will calculate if we need to log again according to the config update interval
(ctx context.Context, dbname string, cnf DatabaseConfig, bucket string, databaseErr *db.DatabaseError)
| 358 | // addInvalidDatabase adds a db to invalid dbconfig map if it doesn't exist in there yet and will log for it at warning level |
| 359 | // if the db already exists there we will calculate if we need to log again according to the config update interval |
| 360 | func (d *invalidDatabaseConfigs) addInvalidDatabase(ctx context.Context, dbname string, cnf DatabaseConfig, bucket string, databaseErr *db.DatabaseError) { |
| 361 | d.m.Lock() |
| 362 | defer d.m.Unlock() |
| 363 | if d.dbNames[dbname] == nil { |
| 364 | // db hasn't been tracked as invalid config yet so add it |
| 365 | d.dbNames[dbname] = &invalidConfigInfo{ |
| 366 | configBucketName: *cnf.Bucket, |
| 367 | persistedBucketName: bucket, |
| 368 | collectionConflicts: cnf.Version == invalidDatabaseConflictingCollectionsVersion, |
| 369 | databaseError: databaseErr, |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | logMessage := "Must repair invalid database config for %q for it to be usable!" |
| 374 | logArgs := []interface{}{base.MD(dbname)} |
| 375 | |
| 376 | // build log message |
| 377 | if isBucketMismatch := *cnf.Bucket != bucket; isBucketMismatch { |
| 378 | base.SyncGatewayStats.GlobalStats.ConfigStat.DatabaseBucketMismatches.Add(1) |
| 379 | logMessage += " Mismatched buckets (config bucket: %q, actual bucket: %q)" |
| 380 | logArgs = append(logArgs, base.MD(d.dbNames[dbname].configBucketName), base.MD(d.dbNames[dbname].persistedBucketName)) |
| 381 | } else if cnf.Version == invalidDatabaseConflictingCollectionsVersion { |
| 382 | base.SyncGatewayStats.GlobalStats.ConfigStat.DatabaseRollbackCollectionCollisions.Add(1) |
| 383 | logMessage += " Conflicting collections detected" |
| 384 | } else if databaseErr != nil { |
| 385 | logMessage += " Error encountered loading database." |
| 386 | } else { |
| 387 | // Nothing is expected to hit this case, but we might add more invalid sentinel values and forget to update this code. |
| 388 | logMessage += " Database was marked invalid. See logs for details." |
| 389 | } |
| 390 | |
| 391 | // if we get here we already have the db logged as an invalid config, so now we need to work out iof we should log for it now |
| 392 | if !d.dbNames[dbname].logged { |
| 393 | // we need to log at warning if we haven't already logged for this particular corrupt db config |
| 394 | base.WarnfCtx(ctx, logMessage, logArgs...) |
| 395 | d.dbNames[dbname].logged = true |
| 396 | } else { |
| 397 | // already logged this entry at warning so need to log at info now |
| 398 | base.InfofCtx(ctx, base.KeyConfig, logMessage, logArgs...) |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | func (d *invalidDatabaseConfigs) exists(dbname string) (*invalidConfigInfo, bool) { |
| 403 | d.m.RLock() |