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, err := GetDBColumnFamilies(name, secondaryPath, cfNames)
|
||||||
db.OpenIterators = make(map[string][]chan struct{})
|
|
||||||
|
|
||||||
cleanupFiles := func() {
|
cleanupFiles := func() {
|
||||||
err = os.RemoveAll(secondaryPath)
|
err = os.RemoveAll(secondaryPath)
|
||||||
|
@ -688,18 +687,27 @@ func (db *ReadOnlyDBColumnFamily) Unwind() {
|
||||||
|
|
||||||
// Shutdown shuts down the db.
|
// Shutdown shuts down the db.
|
||||||
func (db *ReadOnlyDBColumnFamily) Shutdown() {
|
func (db *ReadOnlyDBColumnFamily) Shutdown() {
|
||||||
|
log.Println("Sending message to ShutdownChan...")
|
||||||
db.ShutdownChan <- struct{}{}
|
db.ShutdownChan <- struct{}{}
|
||||||
|
log.Println("Locking iterator mutex...")
|
||||||
db.ItMut.Lock()
|
db.ItMut.Lock()
|
||||||
|
log.Println("Setting ShutdownCalled to true...")
|
||||||
db.ShutdownCalled = true
|
db.ShutdownCalled = true
|
||||||
|
log.Println("Notifying iterators to shutdown...")
|
||||||
for _, it := range db.OpenIterators {
|
for _, it := range db.OpenIterators {
|
||||||
it[1] <- struct{}{}
|
it[1] <- struct{}{}
|
||||||
}
|
}
|
||||||
|
log.Println("Waiting for iterators to shutdown...")
|
||||||
for _, it := range db.OpenIterators {
|
for _, it := range db.OpenIterators {
|
||||||
<-it[0]
|
<-it[0]
|
||||||
}
|
}
|
||||||
|
log.Println("Unlocking iterator mutex...")
|
||||||
db.ItMut.Unlock()
|
db.ItMut.Unlock()
|
||||||
|
log.Println("Sending message to DoneChan...")
|
||||||
<-db.DoneChan
|
<-db.DoneChan
|
||||||
|
log.Println("Calling cleanup...")
|
||||||
db.Cleanup()
|
db.Cleanup()
|
||||||
|
log.Println("Leaving Shutdown...")
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunDetectChanges Go routine the runs continuously while the hub is active
|
// RunDetectChanges Go routine the runs continuously while the hub is active
|
||||||
|
|
|
@ -43,8 +43,8 @@ func NewIterateOptions() *IterOptions {
|
||||||
IncludeValue: false,
|
IncludeValue: false,
|
||||||
RawKey: false,
|
RawKey: false,
|
||||||
RawValue: false,
|
RawValue: false,
|
||||||
ShutdownChan: make(chan struct{}),
|
ShutdownChan: make(chan struct{}, 1),
|
||||||
DoneChan: make(chan struct{}),
|
DoneChan: make(chan struct{}, 1),
|
||||||
DB: nil,
|
DB: nil,
|
||||||
CfHandle: nil,
|
CfHandle: nil,
|
||||||
It: nil,
|
It: nil,
|
||||||
|
|
3
main.go
3
main.go
|
@ -40,12 +40,15 @@ func main() {
|
||||||
log.Println("Shutting down server...")
|
log.Println("Shutting down server...")
|
||||||
|
|
||||||
if s.EsClient != nil {
|
if s.EsClient != nil {
|
||||||
|
log.Println("Stopping es client...")
|
||||||
s.EsClient.Stop()
|
s.EsClient.Stop()
|
||||||
}
|
}
|
||||||
if s.GrpcServer != nil {
|
if s.GrpcServer != nil {
|
||||||
|
log.Println("Stopping grpc server...")
|
||||||
s.GrpcServer.GracefulStop()
|
s.GrpcServer.GracefulStop()
|
||||||
}
|
}
|
||||||
if s.DB != nil {
|
if s.DB != nil {
|
||||||
|
log.Println("Stopping database connection...")
|
||||||
s.DB.Shutdown()
|
s.DB.Shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue