Skip to content

Commit

Permalink
fsrepo: Ugly kludge to keep metrics with concurrent FSRepos
Browse files Browse the repository at this point in the history
Tests want to open multiple FSRepos, but metrics are a single
namespace with no conflicts allowed. Kludge the non-first FSRepos to
put a sequence number in their metrics path.
  • Loading branch information
tv42 committed Apr 29, 2015
1 parent d1cd471 commit 264be51
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions repo/fsrepo/fsrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,18 @@ var (
// daemon, `ipfs config` tries to save work by not building the
// full IpfsNode, but accessing the Repo directly.
onlyOne repo.OnlyOne

// reposCreated counts FSRepos created, to keep their metrics at
// unique paths. Guarded by packageLock.
reposCreated uint
)

// FSRepo represents an IPFS FileSystem Repo. It is safe for use by multiple
// callers.
type FSRepo struct {
// How manieth FSRepo instantiated is this. Used to keep metrics
// separated.
repoSeq uint
// has Close been called already
closed bool
// path is the file-system path
Expand Down Expand Up @@ -330,14 +337,21 @@ func (r *FSRepo) openDatastore() error {
return errors.New("unable to open flatfs datastore")
}

// called must hold packageLock
reposCreated++
seqStr := ""
if reposCreated > 1 {
seqStr = strconv.FormatUint(uint64(reposCreated), 10)
}
prefix := "datastore" + seqStr
mountDS := mount.New([]mount.Mount{
{
Prefix: ds.NewKey("/blocks"),
Datastore: measure.New("datastore.blocks", blocksDS),
Datastore: measure.New(prefix+".blocks", blocksDS),
},
{
Prefix: ds.NewKey("/"),
Datastore: measure.New("datastore.leveldb", r.leveldbDS),
Datastore: measure.New(prefix+".leveldb", r.leveldbDS),
},
})
// Make sure it's ok to claim the virtual datastore from mount as
Expand Down

0 comments on commit 264be51

Please sign in to comment.