indexserver: introduce indexMutex (#389)
This struct abstracts away how we do locking on the index directory in a
process. Previously we had a very coarse sync.Mutex whenever kicking off
an operation which mutated the directory. We plan on introducing some
concurrency to allow multiple repositories to be indexed at once.
However, this requires us to distinguish from global locks vs locking
just for a repository. This is what indexMutex achieves.
We don't yet use "indexMutex.With" concurrently, but will in an upcoming
commit.
Additionally a slight bug is fixed on how we report indexing times.
Previously we included the time taken to acquire the index lock for
elapsed time. This means indexing might be reported to take a very long
time, but in reality we just are blocked on waiting for merge or cleanup
to finish.
Because of this bug included are a few very coarse metrics. We could go
much deeper like we do in sched.go. However, I believe this handles some
interesting cases so will leave that as follow-up work. Now when we have
the queue being very slow to process, this might point towards the
global lock being the issue.
Test Plan: go test -race
plz-review-url: https://plz.review/review/6336