Skip to content

Commit

Permalink
Add logs and interrupt handler. Persister should call when finished.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Du committed Dec 4, 2018
1 parent d8af0ed commit 034bf75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion services/eventdb/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package main

import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"

"github.com/m3db/m3cluster/shard"
m3config "github.com/m3db/m3x/config"
Expand All @@ -23,12 +27,14 @@ func main() {
// Parse command line args.
flag.Parse()

logger.Info("loading config...")
var cfg config.Config
if err := m3config.LoadFile(&cfg, configFilePath); err != nil {
logger.Fatalf("logstore load config error: %v", err)
}

// Instantiate DB.
logger.Info("instantiating database...")
shardIDs := make([]uint32, 0, cfg.Database.NumShards)
for i := 0; i < cfg.Database.NumShards; i++ {
shardIDs = append(shardIDs, uint32(i))
Expand All @@ -46,14 +52,22 @@ func main() {
defer db.Close()

// Instantiate service and run server.
logger.Info("instantiating and running server...")
svc := handlers.NewService(db, nil)
server := http.NewServer(cfg.Server.Address, svc, cfg.Server.NewServerOptions())
if err := server.ListenAndServe(); err != nil {
logger.Fatalf("error serving: %v", err)
}
defer server.Close()
logger.Infof("server is running @ %s", cfg.Server.Address)

select {}
logger.Warnf("interrupt: %v", interrupt())
}

func interrupt() error {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
return fmt.Errorf("%s", <-c)
}

func init() {
Expand Down
1 change: 1 addition & 0 deletions storage/flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (m *flushManager) Flush() error {
if err != nil {
return err
}
defer persister.Done()

namespaces, err := m.database.GetOwnedNamespaces()
if err != nil {
Expand Down

0 comments on commit 034bf75

Please sign in to comment.