Skip to content

Conversation

@RIT3shSapata
Copy link
Contributor

CBG-4579

Describe your PR here...

  • Added SgwUIntStat to use uint64 instead of int64 for few metrics such as sequence and timestamps
  • int64 stats have a possibility of overflowing which would then make the number negative
  • Fixed few type conversions in unit tests which use the updated metrics

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Dependencies (if applicable)

  • Link upstream PRs
  • Update Go module dependencies when merged

Integration Tests

@Copilot Copilot AI review requested due to automatic review settings October 17, 2025 08:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds uint64 support to sequence and timestamp-related metrics in Sync Gateway to prevent potential integer overflow issues that could cause negative values when using int64.

  • Introduces SgwUIntStat type and AtomicUInt utility to handle unsigned 64-bit integer statistics
  • Converts sequence-related metrics (assigned, reserved, released counts and last values) and cache sequence metrics to use uint64 instead of int64
  • Updates compaction timestamp metrics to use uint64 for Unix timestamp storage

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
base/util.go Adds AtomicUInt struct with thread-safe operations for uint64 values
base/stats.go Introduces SgwUIntStat type and updates stat definitions for sequences and timestamps to use uint64
db/sequence_allocator.go Removes int64 type conversions when setting sequence metrics
db/change_cache.go Updates cache stat calls to use uint64 values directly
db/database_stats.go Removes int64 conversion for HighSeqCached metric
db/background_mgr_tombstone_compaction.go Adds uint64 conversion for Unix timestamp
db/background_mgr_attachment_compaction.go Adds uint64 conversion for Unix timestamp
db/sequence_allocator_test.go Updates test assertions to expect uint64 values
db/database_test.go Updates test assertions to expect uint64 values
db/crud_test.go Updates test assertions to expect uint64 values
db/change_cache_test.go Updates test assertions to expect uint64 values

Copy link
Collaborator

@torcolvin torcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very small nits on this.

@torcolvin torcolvin assigned RIT3shSapata and unassigned torcolvin Oct 17, 2025
@torcolvin torcolvin assigned RIT3shSapata and unassigned torcolvin Oct 21, 2025
Copy link
Collaborator

@torcolvin torcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some fiddly nits.

return wrappedStat, nil
}

func (s *SgwUint64Stat) FormatString() string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (s *SgwUint64Stat) FormatString() string {
// FormatString returns a name of the stat type used for generating documentation.
func (s *SgwUint64Stat) FormatString() string {

This shows up in documentation https://docs.couchbase.com/sync-gateway/current/manage/stats-monitoring-prometheus.html and https://docs.couchbase.com/sync-gateway/current/manage/stats-monitoring-json.html

but curiously neither page use this value and it isn't generated by the generator that is used to update these pages.

Format string `json:"-"` // The format of the value such as int, float, duration

@torcolvin torcolvin merged commit d0f88c3 into main Oct 23, 2025
42 checks passed
@torcolvin torcolvin deleted the CBG-4579 branch October 23, 2025 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants