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 2021/09/07 10:43:05 UTC

[skywalking-banyandb] branch time-series updated: Update some notions

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

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


The following commit(s) were added to refs/heads/time-series by this push:
     new f0cdb34  Update some notions
f0cdb34 is described below

commit f0cdb346a3713c16bace82b7746189157dce2dd8
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Tue Sep 7 18:40:51 2021 +0800

    Update some notions
    
    Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
 banyand/stream/index.go             | 16 +++++-----
 banyand/stream/stream_query_test.go |  4 +--
 banyand/tsdb/series_seek_filter.go  |  2 +-
 banyand/tsdb/series_seek_sort.go    |  4 +--
 banyand/tsdb/series_write.go        | 16 +++++-----
 pkg/index/index.go                  |  6 ++--
 pkg/index/inverted/field_map.go     |  6 ++--
 pkg/index/inverted/mem.go           |  4 +--
 pkg/index/inverted/mem_test.go      | 60 ++++++++++++++++++-------------------
 pkg/index/search.go                 | 10 +++----
 10 files changed, 64 insertions(+), 64 deletions(-)

diff --git a/banyand/stream/index.go b/banyand/stream/index.go
index cfbf8e9..31c0bc9 100644
--- a/banyand/stream/index.go
+++ b/banyand/stream/index.go
@@ -87,13 +87,13 @@ func (s *stream) writeGlobalIndex(ruleIndex indexRule, ref tsdb.GlobalItemID, va
 	switch rule.GetType() {
 	case databasev2.IndexRule_TYPE_INVERTED:
 		return indexWriter.WriteInvertedIndex(index.Field{
-			Term:  []byte(rule.Metadata.Name),
-			Value: val,
+			Key:  []byte(rule.Metadata.Name),
+			Term: val,
 		})
 	case databasev2.IndexRule_TYPE_TREE:
 		return indexWriter.WriteLSMIndex(index.Field{
-			Term:  []byte(rule.Metadata.Name),
-			Value: val,
+			Key:  []byte(rule.Metadata.Name),
+			Term: val,
 		})
 	}
 	return err
@@ -108,13 +108,13 @@ func writeLocalIndex(writer tsdb.Writer, ruleIndex indexRule, value *streamv2.El
 	switch rule.GetType() {
 	case databasev2.IndexRule_TYPE_INVERTED:
 		return writer.WriteInvertedIndex(index.Field{
-			Term:  []byte(rule.Metadata.Name),
-			Value: val,
+			Key:  []byte(rule.Metadata.Name),
+			Term: val,
 		})
 	case databasev2.IndexRule_TYPE_TREE:
 		return writer.WriteLSMIndex(index.Field{
-			Term:  []byte(rule.Metadata.Name),
-			Value: val,
+			Key:  []byte(rule.Metadata.Name),
+			Term: val,
 		})
 	}
 	return err
diff --git a/banyand/stream/stream_query_test.go b/banyand/stream/stream_query_test.go
index 65311ce..a060ff3 100644
--- a/banyand/stream/stream_query_test.go
+++ b/banyand/stream/stream_query_test.go
@@ -345,8 +345,8 @@ func Test_Stream_Global_Index(t *testing.T) {
 			err := func() error {
 				for _, shard := range shards {
 					itemIDs, err := shard.Index().Seek(index.Field{
-						Term:  []byte("trace_id"),
-						Value: []byte(tt.traceID),
+						Key:  []byte("trace_id"),
+						Term: []byte(tt.traceID),
 					})
 					if err != nil {
 						return errors.WithStack(err)
diff --git a/banyand/tsdb/series_seek_filter.go b/banyand/tsdb/series_seek_filter.go
index 990d1ae..bd55f1c 100644
--- a/banyand/tsdb/series_seek_filter.go
+++ b/banyand/tsdb/series_seek_filter.go
@@ -54,7 +54,7 @@ func (s *seekerBuilder) buildIndexFilter() (filterFn, error) {
 			return nil, ErrUnsupportedIndexRule
 		}
 		cond := make(index.Condition)
-		term := index.Term{
+		term := index.FieldKey{
 			SeriesID:  s.seriesSpan.seriesID,
 			IndexRule: condition.indexRule,
 		}
diff --git a/banyand/tsdb/series_seek_sort.go b/banyand/tsdb/series_seek_sort.go
index 8e45a91..7e9a308 100644
--- a/banyand/tsdb/series_seek_sort.go
+++ b/banyand/tsdb/series_seek_sort.go
@@ -54,7 +54,7 @@ func (s *seekerBuilder) buildSeries(filters []filterFn) []Iterator {
 func (s *seekerBuilder) buildSeriesByIndex(filters []filterFn) (series []Iterator) {
 	for _, b := range s.seriesSpan.blocks {
 		var inner index.FieldIterator
-		term := index.Term{
+		term := index.FieldKey{
 			SeriesID:  s.seriesSpan.seriesID,
 			IndexRule: s.indexRuleForSorting.GetMetadata().GetName(),
 		}
@@ -123,7 +123,7 @@ func (s *searcherIterator) Next() bool {
 			v := s.fieldIterator.Val()
 			s.cur = v.Value.Iterator()
 			s.curKey = v.Key
-			s.l.Trace().Uint64("series_id", uint64(s.seriesID)).Hex("term_field", s.curKey).Msg("got a new field")
+			s.l.Trace().Uint64("series_id", uint64(s.seriesID)).Hex("term", s.curKey).Msg("got a new field")
 		} else {
 			return false
 		}
diff --git a/banyand/tsdb/series_write.go b/banyand/tsdb/series_write.go
index b335be9..60fba52 100644
--- a/banyand/tsdb/series_write.go
+++ b/banyand/tsdb/series_write.go
@@ -130,20 +130,20 @@ func (w *writer) ItemID() GlobalItemID {
 }
 
 func (w *writer) WriteLSMIndex(field index.Field) error {
-	t := index.Term{
+	t := index.FieldKey{
 		SeriesID:  w.itemID.SeriesID,
-		IndexRule: string(field.Term),
+		IndexRule: string(field.Key),
 	}
-	field.Term = t.Marshal()
+	field.Key = t.Marshal()
 	return w.block.writeLSMIndex(field, w.itemID.ID)
 }
 
 func (w *writer) WriteInvertedIndex(field index.Field) error {
-	t := index.Term{
+	t := index.FieldKey{
 		SeriesID:  w.itemID.SeriesID,
-		IndexRule: string(field.Term),
+		IndexRule: string(field.Key),
 	}
-	field.Term = t.Marshal()
+	field.Key = t.Marshal()
 	return w.block.writeInvertedIndex(field, w.itemID.ID)
 }
 
@@ -172,7 +172,7 @@ func (w *writer) Write() (GlobalItemID, error) {
 		}
 	}
 	return id, w.block.writePrimaryIndex(index.Field{
-		Term:  id.SeriesID.Marshal(),
-		Value: convert.Int64ToBytes(w.ts.UnixNano()),
+		Key:  id.SeriesID.Marshal(),
+		Term: convert.Int64ToBytes(w.ts.UnixNano()),
 	}, id.ID)
 }
diff --git a/pkg/index/index.go b/pkg/index/index.go
index d6cbf86..bec268e 100644
--- a/pkg/index/index.go
+++ b/pkg/index/index.go
@@ -25,12 +25,12 @@ import (
 )
 
 type Field struct {
-	Term  []byte
-	Value []byte
+	Key  []byte
+	Term []byte
 }
 
 func (f Field) Marshal() []byte {
-	return bytes.Join([][]byte{f.Term, f.Value}, nil)
+	return bytes.Join([][]byte{f.Key, f.Term}, nil)
 }
 
 type RangeOpts struct {
diff --git a/pkg/index/inverted/field_map.go b/pkg/index/inverted/field_map.go
index 57826d1..85c7771 100644
--- a/pkg/index/inverted/field_map.go
+++ b/pkg/index/inverted/field_map.go
@@ -65,11 +65,11 @@ func (fm *fieldMap) getWithoutLock(key []byte) (*fieldValue, bool) {
 func (fm *fieldMap) put(fv index.Field, id common.ItemID) error {
 	fm.mutex.Lock()
 	defer fm.mutex.Unlock()
-	pm, ok := fm.getWithoutLock(fv.Term)
+	pm, ok := fm.getWithoutLock(fv.Key)
 	if !ok {
-		pm = fm.createKey(fv.Term)
+		pm = fm.createKey(fv.Key)
 	}
-	return pm.value.put(fv.Value, id)
+	return pm.value.put(fv.Term, id)
 }
 
 type fieldValue struct {
diff --git a/pkg/index/inverted/mem.go b/pkg/index/inverted/mem.go
index a6e2c12..f8db9b7 100644
--- a/pkg/index/inverted/mem.go
+++ b/pkg/index/inverted/mem.go
@@ -129,11 +129,11 @@ func (m *MemTable) FieldIterator(fieldName []byte, order modelv2.QueryOrder_Sort
 }
 
 func (m *MemTable) MatchTerms(field index.Field) (list posting.List) {
-	fieldsValues, ok := m.terms.get(field.Term)
+	fieldsValues, ok := m.terms.get(field.Key)
 	if !ok {
 		return roaring.EmptyPostingList
 	}
-	return fieldsValues.value.get(field.Value).Clone()
+	return fieldsValues.value.get(field.Term).Clone()
 }
 
 func (m *MemTable) Range(fieldName []byte, opts index.RangeOpts) (list posting.List) {
diff --git a/pkg/index/inverted/mem_test.go b/pkg/index/inverted/mem_test.go
index d3c4731..99caa2c 100644
--- a/pkg/index/inverted/mem_test.go
+++ b/pkg/index/inverted/mem_test.go
@@ -53,8 +53,8 @@ func TestMemTable_Range(t *testing.T) {
 				},
 			},
 			wantList: m.MatchTerms(index.Field{
-				Term:  []byte("duration"),
-				Value: convert.Uint16ToBytes(200),
+				Key:  []byte("duration"),
+				Term: convert.Uint16ToBytes(200),
 			}),
 		},
 		{
@@ -68,8 +68,8 @@ func TestMemTable_Range(t *testing.T) {
 			},
 			wantList: union(m,
 				index.Field{
-					Term:  []byte("duration"),
-					Value: convert.Uint16ToBytes(200),
+					Key:  []byte("duration"),
+					Term: convert.Uint16ToBytes(200),
 				},
 			),
 		},
@@ -85,12 +85,12 @@ func TestMemTable_Range(t *testing.T) {
 			},
 			wantList: union(m,
 				index.Field{
-					Term:  []byte("duration"),
-					Value: convert.Uint16ToBytes(50),
+					Key:  []byte("duration"),
+					Term: convert.Uint16ToBytes(50),
 				},
 				index.Field{
-					Term:  []byte("duration"),
-					Value: convert.Uint16ToBytes(200),
+					Key:  []byte("duration"),
+					Term: convert.Uint16ToBytes(200),
 				},
 			),
 		},
@@ -106,12 +106,12 @@ func TestMemTable_Range(t *testing.T) {
 			},
 			wantList: union(m,
 				index.Field{
-					Term:  []byte("duration"),
-					Value: convert.Uint16ToBytes(200),
+					Key:  []byte("duration"),
+					Term: convert.Uint16ToBytes(200),
 				},
 				index.Field{
-					Term:  []byte("duration"),
-					Value: convert.Uint16ToBytes(1000),
+					Key:  []byte("duration"),
+					Term: convert.Uint16ToBytes(1000),
 				},
 			),
 		},
@@ -128,16 +128,16 @@ func TestMemTable_Range(t *testing.T) {
 			},
 			wantList: union(m,
 				index.Field{
-					Term:  []byte("duration"),
-					Value: convert.Uint16ToBytes(50),
+					Key:  []byte("duration"),
+					Term: convert.Uint16ToBytes(50),
 				},
 				index.Field{
-					Term:  []byte("duration"),
-					Value: convert.Uint16ToBytes(200),
+					Key:  []byte("duration"),
+					Term: convert.Uint16ToBytes(200),
 				},
 				index.Field{
-					Term:  []byte("duration"),
-					Value: convert.Uint16ToBytes(1000),
+					Key:  []byte("duration"),
+					Term: convert.Uint16ToBytes(1000),
 				},
 			),
 		},
@@ -154,8 +154,8 @@ func TestMemTable_Range(t *testing.T) {
 			},
 			wantList: union(m,
 				index.Field{
-					Term:  []byte("duration"),
-					Value: convert.Uint16ToBytes(200),
+					Key:  []byte("duration"),
+					Term: convert.Uint16ToBytes(200),
 				},
 			),
 		},
@@ -227,13 +227,13 @@ func setUp(t *testing.T, mt *MemTable) {
 	for i := 0; i < 100; i++ {
 		if i%2 == 0 {
 			assert.NoError(t, mt.Insert(index.Field{
-				Term:  []byte("service_name"),
-				Value: []byte("gateway"),
+				Key:  []byte("service_name"),
+				Term: []byte("gateway"),
 			}, common.ItemID(i)))
 		} else {
 			assert.NoError(t, mt.Insert(index.Field{
-				Term:  []byte("service_name"),
-				Value: []byte("webpage"),
+				Key:  []byte("service_name"),
+				Term: []byte("webpage"),
 			}, common.ItemID(i)))
 		}
 	}
@@ -241,18 +241,18 @@ func setUp(t *testing.T, mt *MemTable) {
 		switch {
 		case i%3 == 0:
 			assert.NoError(t, mt.Insert(index.Field{
-				Term:  []byte("duration"),
-				Value: convert.Uint16ToBytes(50),
+				Key:  []byte("duration"),
+				Term: convert.Uint16ToBytes(50),
 			}, common.ItemID(i)))
 		case i%3 == 1:
 			assert.NoError(t, mt.Insert(index.Field{
-				Term:  []byte("duration"),
-				Value: convert.Uint16ToBytes(200),
+				Key:  []byte("duration"),
+				Term: convert.Uint16ToBytes(200),
 			}, common.ItemID(i)))
 		case i%3 == 2:
 			assert.NoError(t, mt.Insert(index.Field{
-				Term:  []byte("duration"),
-				Value: convert.Uint16ToBytes(1000),
+				Key:  []byte("duration"),
+				Term: convert.Uint16ToBytes(1000),
 			}, common.ItemID(i)))
 		}
 	}
diff --git a/pkg/index/search.go b/pkg/index/search.go
index 833d904..3f304d5 100644
--- a/pkg/index/search.go
+++ b/pkg/index/search.go
@@ -40,19 +40,19 @@ type Tree interface {
 	Executor
 }
 
-type Term struct {
+type FieldKey struct {
 	SeriesID  common.SeriesID
 	IndexRule string
 }
 
-func (t *Term) Marshal() []byte {
+func (t *FieldKey) Marshal() []byte {
 	return bytes.Join([][]byte{
 		t.SeriesID.Marshal(),
 		[]byte(t.IndexRule),
 	}, []byte(":"))
 }
 
-type Condition map[Term][]ConditionValue
+type Condition map[FieldKey][]ConditionValue
 
 type ConditionValue struct {
 	Values [][]byte
@@ -289,8 +289,8 @@ type eq struct {
 
 func (eq *eq) Execute() (posting.List, error) {
 	return eq.searcher.MatchTerms(Field{
-		Term:  eq.Key,
-		Value: bytes.Join(eq.Values, nil),
+		Key:  eq.Key,
+		Term: bytes.Join(eq.Values, nil),
 	}), nil
 }