diff --git a/db/db.go b/db/db.go index debff0d..b659ff4 100644 --- a/db/db.go +++ b/db/db.go @@ -556,7 +556,6 @@ func GetProdDB(name string, secondaryPath string) (*ReadOnlyDBColumnFamily, func } db, err := GetDBColumnFamilies(name, secondaryPath, cfNames) - db.OpenIterators = make(map[string][]chan struct{}) cleanupFiles := func() { err = os.RemoveAll(secondaryPath) @@ -688,18 +687,27 @@ func (db *ReadOnlyDBColumnFamily) Unwind() { // Shutdown shuts down the db. func (db *ReadOnlyDBColumnFamily) Shutdown() { + log.Println("Sending message to ShutdownChan...") db.ShutdownChan <- struct{}{} + log.Println("Locking iterator mutex...") db.ItMut.Lock() + log.Println("Setting ShutdownCalled to true...") db.ShutdownCalled = true + log.Println("Notifying iterators to shutdown...") for _, it := range db.OpenIterators { it[1] <- struct{}{} } + log.Println("Waiting for iterators to shutdown...") for _, it := range db.OpenIterators { <-it[0] } + log.Println("Unlocking iterator mutex...") db.ItMut.Unlock() + log.Println("Sending message to DoneChan...") <-db.DoneChan + log.Println("Calling cleanup...") db.Cleanup() + log.Println("Leaving Shutdown...") } // RunDetectChanges Go routine the runs continuously while the hub is active diff --git a/db/iteroptions.go b/db/iteroptions.go index aa728a3..6d1ea7f 100644 --- a/db/iteroptions.go +++ b/db/iteroptions.go @@ -43,8 +43,8 @@ func NewIterateOptions() *IterOptions { IncludeValue: false, RawKey: false, RawValue: false, - ShutdownChan: make(chan struct{}), - DoneChan: make(chan struct{}), + ShutdownChan: make(chan struct{}, 1), + DoneChan: make(chan struct{}, 1), DB: nil, CfHandle: nil, It: nil, diff --git a/main.go b/main.go index 0be9f4d..1e42b45 100644 --- a/main.go +++ b/main.go @@ -40,12 +40,15 @@ func main() { log.Println("Shutting down server...") if s.EsClient != nil { + log.Println("Stopping es client...") s.EsClient.Stop() } if s.GrpcServer != nil { + log.Println("Stopping grpc server...") s.GrpcServer.GracefulStop() } if s.DB != nil { + log.Println("Stopping database connection...") s.DB.Shutdown() } diff --git a/version.txt b/version.txt index 65b0c96..f78335d 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v0.2022.10.04.1 \ No newline at end of file +v0.2022.08.16.1 \ No newline at end of file