diff --git a/nsqd/nsqd.go b/nsqd/nsqd.go index 55be82709..dcbf446f5 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 !os.IsNotExist(err) { + n.logf("NSQ: WARNING: failed to delete old metadata file %s: %s", oldFileName, err) + } + return nil }