Skip to content

Commit

Permalink
nsqd: remove ID from metadata filename
Browse files Browse the repository at this point in the history
  • Loading branch information
ploxiln committed Jan 5, 2017
1 parent 5553c3c commit d940129
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions nsqd/nsqd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit d940129

Please sign in to comment.