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 2022/04/16 05:29:01 UTC

[skywalking-banyandb] branch patch-metadata created (now 716e471)

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

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


      at 716e471  Make sure index rule ID is set by

This branch includes the following new commits:

     new 716e471  Make sure index rule ID is set by

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking-banyandb] 01/01: Make sure index rule ID is set by

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 716e471ab2ab52dab03cae99b0a976b81189e9d6
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Sat Apr 16 05:19:52 2022 +0000

    Make sure index rule ID is set by
    
      * Add a default value based on 32 bits CRC to the ID
      * Check the ID on getting and listing index rules
    
    Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
 banyand/metadata/schema/index.go | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/banyand/metadata/schema/index.go b/banyand/metadata/schema/index.go
index c79ebfc..ce35d7b 100644
--- a/banyand/metadata/schema/index.go
+++ b/banyand/metadata/schema/index.go
@@ -19,16 +19,19 @@ package schema
 
 import (
 	"context"
+	"hash/crc32"
 
 	"google.golang.org/protobuf/proto"
 
 	commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
 	databasev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1"
+	"github.com/pkg/errors"
 )
 
 var (
 	IndexRuleBindingKeyPrefix = "/index-rule-bindings/"
 	IndexRuleKeyPrefix        = "/index-rules/"
+	ErrEmptyIndexRuleID       = errors.New("the index rule id is empty")
 )
 
 func (e *etcdSchemaRegistry) GetIndexRuleBinding(ctx context.Context, metadata *commonv1.Metadata) (*databasev1.IndexRuleBinding, error) {
@@ -93,6 +96,9 @@ func (e *etcdSchemaRegistry) GetIndexRule(ctx context.Context, metadata *commonv
 	if err := e.get(ctx, formatIndexRuleKey(metadata), &entity); err != nil {
 		return nil, err
 	}
+	if entity.Metadata.Id == 0 {
+		return nil, errors.WithMessagef(ErrEmptyIndexRuleID, "index rule: %v", metadata)
+	}
 	return &entity, nil
 }
 
@@ -108,12 +114,21 @@ func (e *etcdSchemaRegistry) ListIndexRule(ctx context.Context, opt ListOpt) ([]
 	}
 	entities := make([]*databasev1.IndexRule, 0, len(messages))
 	for _, message := range messages {
-		entities = append(entities, message.(*databasev1.IndexRule))
+		entity := message.(*databasev1.IndexRule)
+		if entity.Metadata.Id == 0 {
+			return nil, errors.WithMessagef(ErrEmptyIndexRuleID, "index rule: %v", entity.Metadata)
+		}
+		entities = append(entities, entity)
 	}
 	return entities, nil
 }
 
 func (e *etcdSchemaRegistry) CreateIndexRule(ctx context.Context, indexRule *databasev1.IndexRule) error {
+	if indexRule.Metadata.Id == 0 {
+		buf := []byte(indexRule.Metadata.Group)
+		buf = append(buf, indexRule.Metadata.Name...)
+		indexRule.Metadata.Id = crc32.ChecksumIEEE(buf)
+	}
 	return e.create(ctx, Metadata{
 		TypeMeta: TypeMeta{
 			Kind:  KindIndexRule,