This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch patch/trace
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit 6807954afc880a713d6639870095c075919c3e0b
Author: Gao Hongtao <[email protected]>
AuthorDate: Thu Aug 28 12:25:03 2025 +0800

    Implement atomic counters for total queries and writes in sidx
    
    - Added atomic counters for tracking total queries and writes in the sidx 
struct.
    - Updated Write and Query methods to increment respective counters.
    - Modified Stats method to return the new counters for queries and writes.
---
 banyand/internal/sidx/sidx.go | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/banyand/internal/sidx/sidx.go b/banyand/internal/sidx/sidx.go
index 4c7fdc4f..a5c8083d 100644
--- a/banyand/internal/sidx/sidx.go
+++ b/banyand/internal/sidx/sidx.go
@@ -39,6 +39,8 @@ type sidx struct {
        l                          *logger.Logger
        totalIntroduceLoopStarted  atomic.Int64
        totalIntroduceLoopFinished atomic.Int64
+       totalQueries               atomic.Int64
+       totalWrites                atomic.Int64
        mu                         sync.RWMutex
 }
 
@@ -79,6 +81,9 @@ func (s *sidx) Write(ctx context.Context, reqs 
[]WriteRequest) error {
                }
        }
 
+       // Increment write counter
+       s.totalWrites.Add(1)
+
        // Create elements from requests
        es := generateElements()
        defer releaseElements(es)
@@ -116,6 +121,9 @@ func (s *sidx) Query(ctx context.Context, req QueryRequest) 
(QueryResult, error)
                return nil, err
        }
 
+       // Increment query counter
+       s.totalQueries.Add(1)
+
        // Get current snapshot
        snap := s.currentSnapshot()
        if snap == nil {
@@ -145,8 +153,8 @@ func (s *sidx) Stats(_ context.Context) (*Stats, error) {
        }
 
        // Load atomic counters
-       stats.QueryCount.Store(s.totalIntroduceLoopStarted.Load())
-       stats.WriteCount.Store(s.totalIntroduceLoopFinished.Load())
+       stats.QueryCount.Store(s.totalQueries.Load())
+       stats.WriteCount.Store(s.totalWrites.Load())
 
        return stats, nil
 }

Reply via email to