From 960f2b8693e920ac86c19c352182b1732e39115b Mon Sep 17 00:00:00 2001 From: Pierce Lopez Date: Thu, 5 Jan 2017 14:33:16 -0500 Subject: [PATCH] nsqd: remove ID from metadata filename --- nsqd/nsqd.go | 20 +++++++++++++++++--- nsqd/nsqd_test.go | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/nsqd/nsqd.go b/nsqd/nsqd.go index 55be82709..53eb34aea 100644 --- a/nsqd/nsqd.go +++ b/nsqd/nsqd.go @@ -271,13 +271,21 @@ func (n *NSQD) LoadMetadata() { atomic.StoreInt32(&n.isLoading, 1) defer atomic.StoreInt32(&n.isLoading, 0) - fn := fmt.Sprintf(path.Join(n.getOpts().DataPath, "nsqd.%d.dat"), n.getOpts().ID) + fn := path.Join(n.getOpts().DataPath, "nsqd.dat") + oldFn := fmt.Sprintf(path.Join(n.getOpts().DataPath, "nsqd.%d.dat"), n.getOpts().ID) + data, err := ioutil.ReadFile(fn) if err != nil { if !os.IsNotExist(err) { n.logf("ERROR: failed to read channel metadata from %s - %s", fn, err) } - return + data, err = ioutil.ReadFile(oldFn) + if err != nil { + if !os.IsNotExist(err) { + n.logf("ERROR: failed to read channel metadata from %s - %s", fn, err) + } + return + } } var m meta @@ -313,7 +321,8 @@ func (n *NSQD) LoadMetadata() { func (n *NSQD) PersistMetadata() error { // persist metadata about what topics/channels we have // so that upon restart we can get back to the same state - fileName := fmt.Sprintf(path.Join(n.getOpts().DataPath, "nsqd.%d.dat"), n.getOpts().ID) + fileName := path.Join(n.getOpts().DataPath, "nsqd.dat") + oldFileName := fmt.Sprintf(path.Join(n.getOpts().DataPath, "nsqd.%d.dat"), n.getOpts().ID) n.logf("NSQ: persisting topic/channel metadata to %s", fileName) js := make(map[string]interface{}) @@ -370,6 +379,11 @@ func (n *NSQD) PersistMetadata() error { return err } + err = os.Remove(oldFileName) + if err != nil && !os.IsNotExist(err) { + n.logf("NSQ: WARNING: failed to delete old metadata file %s: %s", oldFileName, err) + } + return nil } diff --git a/nsqd/nsqd_test.go b/nsqd/nsqd_test.go index dcc3ba501..51e61dacb 100644 --- a/nsqd/nsqd_test.go +++ b/nsqd/nsqd_test.go @@ -24,7 +24,7 @@ const ( ) func getMetadata(n *NSQD) (*meta, error) { - fn := fmt.Sprintf(path.Join(n.getOpts().DataPath, "nsqd.%d.dat"), n.getOpts().ID) + fn := path.Join(n.getOpts().DataPath, "nsqd.dat") data, err := ioutil.ReadFile(fn) if err != nil { return nil, err