Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions embedded/store/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ var (
Help: "The highest id of indexed transaction",
}, []string{
"db",
"index",
})
metricsLastCommittedTrx = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "immudb_last_committed_trx_id",
Help: "The highest id of committed transaction",
}, []string{
"db",
"index",
})
)

Expand Down Expand Up @@ -179,8 +181,9 @@ func newIndexer(path string, store *ImmuStore, opts *Options) (*indexer, error)
}

dbName := filepath.Base(store.path)
indexer.metricsLastIndexedTrx = metricsLastIndexedTrxId.WithLabelValues(dbName)
indexer.metricsLastCommittedTrx = metricsLastCommittedTrx.WithLabelValues(dbName)
idxName := filepath.Base(path)
indexer.metricsLastIndexedTrx = metricsLastIndexedTrxId.WithLabelValues(dbName, idxName)
indexer.metricsLastCommittedTrx = metricsLastCommittedTrx.WithLabelValues(dbName, idxName)

return indexer, nil
}
Expand Down Expand Up @@ -498,7 +501,7 @@ func (idx *indexer) handleWriteStalling(err error) error {
if err := idx.store.FlushIndexes(0, false); err != nil {
return err
}

// NOSONAR (rand is fine here)
sleepTime := writeStallingSleepDurationMin + time.Duration(rand.Intn(int(writeStallingSleepDurationMax-writeStallingSleepDurationMin+1)))
time.Sleep(sleepTime)
return nil
Expand Down
7 changes: 7 additions & 0 deletions embedded/store/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ func TestNewIndexerFailure(t *testing.T) {
require.ErrorIs(t, err, ErrIllegalArguments)
}

func TestNewIndexer(t *testing.T) {
stor := ImmuStore{}
indexer, err := newIndexer(t.TempDir(), &stor, DefaultOptions())
require.Nil(t, err)
require.NotNil(t, indexer)
}

func TestClosedIndexerFailures(t *testing.T) {
store, err := Open(t.TempDir(), DefaultOptions().WithIndexOptions(
DefaultIndexOptions().WithCompactionThld(1),
Expand Down
Loading