(ctx context.Context, reason string)
| 838 | } |
| 839 | |
| 840 | func (dc *DatabaseContext) TakeDbOffline(ctx context.Context, reason string) error { |
| 841 | |
| 842 | if atomic.CompareAndSwapUint32(&dc.State, DBOnline, DBStopping) { |
| 843 | // notify all active _changes feeds to close |
| 844 | close(dc.ExitChanges) |
| 845 | |
| 846 | // Block until all current calls have returned, including _changes feeds |
| 847 | dc.AccessLock.Lock() |
| 848 | defer dc.AccessLock.Unlock() |
| 849 | |
| 850 | dc.changeCache.Stop(ctx) |
| 851 | |
| 852 | // set DB state to Offline |
| 853 | atomic.StoreUint32(&dc.State, DBOffline) |
| 854 | |
| 855 | if err := dc.EventMgr.RaiseDBStateChangeEvent(ctx, dc.Name, "offline", reason, dc.Options.AdminInterface); err != nil { |
| 856 | base.InfofCtx(ctx, base.KeyCRUD, "Error raising database state change event: %v", err) |
| 857 | } |
| 858 | |
| 859 | return nil |
| 860 | } else { |
| 861 | dbState := atomic.LoadUint32(&dc.State) |
| 862 | // If the DB is already transitioning to: offline or is offline silently return |
| 863 | if dbState == DBOffline || dbState == DBResyncing || dbState == DBStopping { |
| 864 | return nil |
| 865 | } |
| 866 | |
| 867 | msg := "Unable to take Database offline, database must be in Online state but was " + RunStateString[dbState] |
| 868 | if dbState == DBOnline { |
| 869 | msg = "Unable to take Database offline, another operation was already in progress. Please try again." |
| 870 | } |
| 871 | |
| 872 | base.InfofCtx(ctx, base.KeyCRUD, "%s", msg) |
| 873 | return base.NewHTTPError(http.StatusServiceUnavailable, msg) |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | func (db *Database) TakeDbOffline(nonContextStruct base.NonCancellableContext, reason string) error { |
| 878 | return db.DatabaseContext.TakeDbOffline(nonContextStruct.Ctx, reason) |
nothing calls this directly
no test coverage detected