MCPcopy
hub / github.com/prometheus/prometheus / getOrCreateWithOptionalID

Method getOrCreateWithOptionalID

tsdb/head.go:1919–1949  ·  view source on GitHub ↗

If id is zero, one will be allocated.

(id chunks.HeadSeriesRef, hash uint64, lset labels.Labels, pendingCommit bool)

Source from the content-addressed store, hash-verified

1917
1918// If id is zero, one will be allocated.
1919func (h *Head) getOrCreateWithOptionalID(id chunks.HeadSeriesRef, hash uint64, lset labels.Labels, pendingCommit bool) (*memSeries, bool, error) {
1920 if preCreationErr := h.series.seriesLifecycleCallback.PreCreation(lset); preCreationErr != nil {
1921 return nil, false, preCreationErr
1922 }
1923 if id == 0 {
1924 // Note this id is wasted in the case where a concurrent operation creates the same series first.
1925 id = chunks.HeadSeriesRef(h.lastSeriesID.Inc())
1926 }
1927
1928 shardHash := uint64(0)
1929 if h.opts.EnableSharding {
1930 shardHash = labels.StableHash(lset)
1931 }
1932 optimisticallyCreatedSeries := newMemSeries(lset, id, shardHash, h.opts.IsolationDisabled, pendingCommit)
1933
1934 s, created := h.series.setUnlessAlreadySet(hash, lset, optimisticallyCreatedSeries)
1935 if !created {
1936 return s, false, nil
1937 }
1938
1939 h.metrics.seriesCreated.Inc()
1940 h.numSeries.Inc()
1941
1942 h.postings.Add(storage.SeriesRef(id), lset)
1943
1944 // Adding the series in the postings marks the creation of series
1945 // as any further calls to this and the read methods would return that series.
1946 h.series.postCreation(lset)
1947
1948 return s, true, nil
1949}
1950
1951// onChunkCreated bumps the head chunk metrics for any newly created chunk, in-order or OOO.
1952// If prevHeadChunkCount < 2 and series.headChunkCount == 2, the corresponding

Callers 4

getOrCreateMethod · 0.95
loadWALMethod · 0.95
loadChunkSnapshotMethod · 0.95

Calls 9

HeadSeriesRefTypeAlias · 0.92
StableHashFunction · 0.92
SeriesRefTypeAlias · 0.92
newMemSeriesFunction · 0.85
IncMethod · 0.80
setUnlessAlreadySetMethod · 0.80
postCreationMethod · 0.80
PreCreationMethod · 0.65
AddMethod · 0.65

Tested by 1