| 1480 | } |
| 1481 | |
| 1482 | func (sc *ServerContext) TakeDbOnline(nonContextStruct base.NonCancellableContext, database *db.DatabaseContext) { |
| 1483 | |
| 1484 | // Take a write lock on the Database context, so that we can cycle the underlying Database |
| 1485 | // without any other call running concurrently |
| 1486 | database.AccessLock.Lock() |
| 1487 | defer database.AccessLock.Unlock() |
| 1488 | |
| 1489 | // We can only transition to Online from Offline state |
| 1490 | if atomic.CompareAndSwapUint32(&database.State, db.DBOffline, db.DBStarting) { |
| 1491 | reloadedDb, err := sc.ReloadDatabase(nonContextStruct.Ctx, database.Name, true) |
| 1492 | if err != nil { |
| 1493 | base.ErrorfCtx(nonContextStruct.Ctx, "Error reloading database from config: %v", err) |
| 1494 | return |
| 1495 | } |
| 1496 | |
| 1497 | if len(reloadedDb.RequireResync) > 0 { |
| 1498 | base.ErrorfCtx(nonContextStruct.Ctx, "Database has collections that require regenerate_sequences resync before it can go online: %v", reloadedDb.RequireResync) |
| 1499 | return |
| 1500 | } |
| 1501 | // Reloaded DB should already be online in most cases, but force state to online to handle cases |
| 1502 | // where config specifies offline startup |
| 1503 | atomic.StoreUint32(&reloadedDb.State, db.DBOnline) |
| 1504 | |
| 1505 | } else { |
| 1506 | base.InfofCtx(nonContextStruct.Ctx, base.KeyCRUD, "Unable to take Database : %v online , database must be in Offline state", base.UD(database.Name)) |
| 1507 | } |
| 1508 | |
| 1509 | } |
| 1510 | |
| 1511 | // validateMetadataStore will |
| 1512 | func validateMetadataStore(ctx context.Context, metadataStore base.DataStore) error { |