You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2023/06/15 01:59:31 UTC

[skywalking-banyandb] 02/02: Generalize the index's docID to uint64.

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

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

commit 39815f5d1a7428571fa7c76b72652d4f2b3bdcc4
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Thu Jun 15 01:53:25 2023 +0000

    Generalize the index's docID to uint64.
    
    Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
 CHANGES.md                          |  3 ++-
 pkg/index/index.go                  |  1 +
 pkg/index/inverted/inverted.go      | 14 ++++++--------
 pkg/index/inverted/inverted_test.go |  4 +---
 pkg/index/lsm/lsm.go                |  3 +--
 pkg/index/testcases/duration.go     |  2 +-
 6 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 942e1903..7337f963 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -20,7 +20,8 @@ Release Notes.
 - Introduce TSTable to customize the block's structure
 - Add `/system` endpoint to the monitoring server that displays a list of nodes' system information.
 - Enhance the `liaison` module by implementing access logging.
-- Add the Istio scenario stress test based on the data generated by the integration access log. 
+- Add the Istio scenario stress test based on the data generated by the integration access log.
+- Generalize the index's docID to uint64.
 
 ### Bugs
 
diff --git a/pkg/index/index.go b/pkg/index/index.go
index 3314fd8f..1667d85b 100644
--- a/pkg/index/index.go
+++ b/pkg/index/index.go
@@ -59,6 +59,7 @@ func (f FieldKey) Marshal() []byte {
 	return b
 }
 
+// HasSeriesID reports whether f has a series id.
 func (f FieldKey) HasSeriesID() bool {
 	return f.SeriesID > 0
 }
diff --git a/pkg/index/inverted/inverted.go b/pkg/index/inverted/inverted.go
index 308132e1..8d3d5d30 100644
--- a/pkg/index/inverted/inverted.go
+++ b/pkg/index/inverted/inverted.go
@@ -325,7 +325,7 @@ func (s *store) run() {
 					if fk.HasSeriesID() {
 						docIDBuffer.Write(fk.SeriesID.Marshal())
 					}
-					docIDBuffer.Write(convert.Uint64ToBytes(uint64(d.docID)))
+					docIDBuffer.Write(convert.Uint64ToBytes(d.docID))
 					doc := bluge.NewDocument(docIDBuffer.String())
 					toAddSeriesIDField := false
 					for _, f := range d.fields {
@@ -420,14 +420,12 @@ func (bmi *blugeMatchIterator) nextTerm() bool {
 	var term []byte
 	bmi.err = match.VisitStoredFields(func(field string, value []byte) bool {
 		if field == docIDField {
-			var id uint64
 			if len(value) == 8 {
-				id = convert.BytesToUint64(value)
+				docID = convert.BytesToUint64(value)
 			} else if len(value) == 16 {
 				// value = seriesID(8bytes)+docID(8bytes)
-				id = convert.BytesToUint64(value[8:])
+				docID = convert.BytesToUint64(value[8:])
 			}
-			docID = uint64(id)
 			i++
 		}
 		if field == bmi.fieldKey {
@@ -452,18 +450,18 @@ func (bmi *blugeMatchIterator) nextTerm() bool {
 	if bmi.agg == nil {
 		bmi.agg = &index.PostingValue{
 			Term:  term,
-			Value: roaring.NewPostingListWithInitialData(uint64(docID)),
+			Value: roaring.NewPostingListWithInitialData(docID),
 		}
 		return true
 	}
 	if bytes.Equal(bmi.agg.Term, term) {
-		bmi.agg.Value.Insert(uint64(docID))
+		bmi.agg.Value.Insert(docID)
 		return true
 	}
 	bmi.current = bmi.agg
 	bmi.agg = &index.PostingValue{
 		Term:  term,
-		Value: roaring.NewPostingListWithInitialData(uint64(docID)),
+		Value: roaring.NewPostingListWithInitialData(docID),
 	}
 	return false
 }
diff --git a/pkg/index/inverted/inverted_test.go b/pkg/index/inverted/inverted_test.go
index b8d458f1..4d818b99 100644
--- a/pkg/index/inverted/inverted_test.go
+++ b/pkg/index/inverted/inverted_test.go
@@ -161,7 +161,6 @@ func TestStore_SeriesMatch(t *testing.T) {
 		matches []string
 		wantErr bool
 	}{
-
 		{
 			matches: []string{"test"},
 			want:    roaring.NewPostingListWithInitialData(1, 2, 3),
@@ -190,7 +189,7 @@ func TestStore_SeriesMatch(t *testing.T) {
 	}
 }
 
-func setup(tester *assert.Assertions, s index.Store, serviceName, serviceName1 index.FieldKey) index.Store {
+func setup(tester *assert.Assertions, s index.Store, serviceName, serviceName1 index.FieldKey) {
 	tester.NoError(s.Write([]index.Field{{
 		Key:  serviceName,
 		Term: []byte("GET::/product/order"),
@@ -217,7 +216,6 @@ func setup(tester *assert.Assertions, s index.Store, serviceName, serviceName1 i
 		Term: []byte("test.c"),
 	}}, 3))
 	s.(*store).flush()
-	return s
 }
 
 func TestStore_MatchTerm(t *testing.T) {
diff --git a/pkg/index/lsm/lsm.go b/pkg/index/lsm/lsm.go
index 1db33826..b0ec2bb4 100644
--- a/pkg/index/lsm/lsm.go
+++ b/pkg/index/lsm/lsm.go
@@ -50,8 +50,7 @@ func (s *store) Close() (err error) {
 
 func (s *store) Write(fields []index.Field, docID uint64) (err error) {
 	for _, field := range fields {
-		docIDInt := uint64(docID)
-		err = multierr.Append(err, s.lsm.PutWithVersion(field.Marshal(), convert.Uint64ToBytes(docIDInt), docIDInt))
+		err = multierr.Append(err, s.lsm.PutWithVersion(field.Marshal(), convert.Uint64ToBytes(docID), docID))
 	}
 	return err
 }
diff --git a/pkg/index/testcases/duration.go b/pkg/index/testcases/duration.go
index 16d728a8..2a61322b 100644
--- a/pkg/index/testcases/duration.go
+++ b/pkg/index/testcases/duration.go
@@ -339,7 +339,7 @@ func setUpPartialDuration(t *assert.Assertions, store index.Writer, r map[int]po
 				Key:  duration,
 				Term: convert.Int64ToBytes(int64(term)),
 			}}, id))
-			r[term].Insert(uint64(id))
+			r[term].Insert(id)
 		}
 	}
 	return r