little fixes for debugging and shutdown (#67)
This commit is contained in:
parent
6d4b9b5e37
commit
8eb7841600
3 changed files with 14 additions and 3 deletions
10
db/db.go
10
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
|
||||
|
|
|
@ -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,
|
||||
|
|
3
main.go
3
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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue