From 769f6eec0565e4dc3c6b966ed730217739f44ef3 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 5 Jul 2023 15:50:33 +0300 Subject: [PATCH 001/288] [#105] client: Fix revive linter warning Signed-off-by: Evgenii Stratonikov --- client/object_put_transformer.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/client/object_put_transformer.go b/client/object_put_transformer.go index 636e56bd..b010deb6 100644 --- a/client/object_put_transformer.go +++ b/client/object_put_transformer.go @@ -44,14 +44,15 @@ func (x *objectWriterTransformer) WritePayloadChunk(ctx context.Context, chunk [ } func (x *objectWriterTransformer) Close(ctx context.Context) (*ResObjectPut, error) { - if ai, err := x.ot.Close(ctx); err != nil { + ai, err := x.ot.Close(ctx) + if err != nil { return nil, err - } else { - if ai != nil && ai.ParentID != nil { - x.it.res.obj = *ai.ParentID - } - return x.it.res, nil } + + if ai != nil && ai.ParentID != nil { + x.it.res.obj = *ai.ParentID + } + return x.it.res, nil } type internalTarget struct { From 37e22b33ad40e19a20743d278ba586c9e50d8b70 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Tue, 4 Jul 2023 17:05:50 +0300 Subject: [PATCH 002/288] [#103] sdk-go: Update api-go version Signed-off-by: Dmitrii Stepanov --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 89f6fe3d..bdb3df55 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.frostfs.info/TrueCloudLab/frostfs-sdk-go go 1.19 require ( - git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230531114046-62edd68f47ac + git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230704092742-285516a94ebe git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 git.frostfs.info/TrueCloudLab/hrw v1.2.1 diff --git a/go.sum b/go.sum index a409e2ff..bd0d7911 100644 --- a/go.sum +++ b/go.sum @@ -33,6 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230531114046-62edd68f47ac h1:a6/Zc5BejflmguShwbllgJdEehnM9gshkLrLbKQHCU0= git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230531114046-62edd68f47ac/go.mod h1:pKJJRLOChW4zDQsAt1e8k/snWKljJtpkiPfxV53ngjI= +git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230704092742-285516a94ebe h1:SB102RiEg+4h9qcwyG97zHBtwduMRbedbtkwRDVSps8= +git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230704092742-285516a94ebe/go.mod h1:pKJJRLOChW4zDQsAt1e8k/snWKljJtpkiPfxV53ngjI= git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb h1:S/TrbOOu9qEXZRZ9/Ddw7crnxbBUQLo68PSzQWYrc9M= git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb/go.mod h1:nkR5gaGeez3Zv2SE7aceP0YwxG2FzIB5cGKpQO2vV2o= git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 h1:FxqFDhQYYgpe41qsIHVOcdzSVCB8JNSfPG7Uk4r2oSk= From 98cab7ed61663452b1f9abfca22cd746539f3fe6 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 6 Jul 2023 17:06:17 +0300 Subject: [PATCH 003/288] [#103] object: Add PutSingle method code Signed-off-by: Dmitrii Stepanov --- client/object_put_single.go | 116 +++++++++++++++++++++++++++++++ client/object_put_transformer.go | 54 ++++++++++++-- 2 files changed, 163 insertions(+), 7 deletions(-) create mode 100644 client/object_put_single.go diff --git a/client/object_put_single.go b/client/object_put_single.go new file mode 100644 index 00000000..4ed03a67 --- /dev/null +++ b/client/object_put_single.go @@ -0,0 +1,116 @@ +package client + +import ( + "context" + "crypto/ecdsa" + "fmt" + + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl" + v2object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" + rpcapi "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc" + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" + v2session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/signature" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session" +) + +// PrmObjectPutSingle groups parameters of PutSingle operation. +type PrmObjectPutSingle struct { + copyNum []uint32 + meta v2session.RequestMetaHeader + object *v2object.Object + key *ecdsa.PrivateKey +} + +// SetCopiesNumber sets ordered list of minimal required object copies numbers +// per placement vector. List's length MUST equal container's placement vector number, +// otherwise request will fail. +func (x *PrmObjectPutSingle) SetCopiesNumber(v []uint32) { + x.copyNum = v +} + +// UseKey specifies private key to sign the requests. +// If key is not provided, then Client default key is used. +func (x *PrmObjectPutSingle) UseKey(key *ecdsa.PrivateKey) { + x.key = key +} + +// WithBearerToken attaches bearer token to be used for the operation. +// Should be called once before any writing steps. +func (x *PrmObjectPutSingle) WithBearerToken(t bearer.Token) { + v2token := &acl.BearerToken{} + t.WriteToV2(v2token) + x.meta.SetBearerToken(v2token) +} + +// WithinSession specifies session within which object should be stored. +// Should be called once before any writing steps. +func (x *PrmObjectPutSingle) WithinSession(t session.Object) { + tv2 := &v2session.Token{} + t.WriteToV2(tv2) + x.meta.SetSessionToken(tv2) +} + +// ExecuteLocal tells the server to execute the operation locally. +func (x *PrmObjectPutSingle) ExecuteLocal() { + x.meta.SetTTL(1) +} + +// WithXHeaders specifies list of extended headers (string key-value pairs) +// to be attached to the request. Must have an even length. +// +// Slice must not be mutated until the operation completes. +func (x *PrmObjectPutSingle) WithXHeaders(hs ...string) { + writeXHeadersToMeta(hs, &x.meta) +} + +// SetObject specifies prepared object to put. +func (x *PrmObjectPutSingle) SetObject(o *v2object.Object) { + x.object = o +} + +// ResObjectPutSingle groups resulting values of PutSingle operation. +type ResObjectPutSingle struct { + statusRes +} + +// ObjectPutSingle writes prepared object to FrostFS. +// Object must have payload, also containerID, objectID, ownerID, payload hash, payload length of an object must be set. +// Exactly one return value is non-nil. By default, server status is returned in res structure. +// Any client's internal or transport errors are returned as Go built-in error. +// If Client is tuned to resolve FrostFS API statuses, then FrostFS failures +// codes are returned as error. +func (c *Client) ObjectPutSingle(ctx context.Context, prm PrmObjectPutSingle) (*ResObjectPutSingle, error) { + body := &v2object.PutSingleRequestBody{} + body.SetCopiesNumber(prm.copyNum) + body.SetObject(prm.object) + + req := &v2object.PutSingleRequest{} + req.SetBody(body) + + c.prepareRequest(req, &prm.meta) + + key := &c.prm.key + if prm.key != nil { + key = prm.key + } + + err := signature.SignServiceMessage(key, req) + if err != nil { + return nil, fmt.Errorf("sign request: %w", err) + } + + resp, err := rpcapi.PutSingleObject(&c.c, req, client.WithContext(ctx)) + if err != nil { + return nil, err + } + + var res ResObjectPutSingle + res.st, err = c.processResponse(resp) + if err != nil { + return nil, err + } + + return &res, nil +} diff --git a/client/object_put_transformer.go b/client/object_put_transformer.go index b010deb6..cb44f61d 100644 --- a/client/object_put_transformer.go +++ b/client/object_put_transformer.go @@ -5,6 +5,8 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) func (c *Client) objectPutInitTransformer(prm PrmObjectPutInit) (*objectWriterTransformer, error) { @@ -56,11 +58,12 @@ func (x *objectWriterTransformer) Close(ctx context.Context) (*ResObjectPut, err } type internalTarget struct { - current *object.Object - client *Client - res *ResObjectPut - prm PrmObjectPutInit - payload []byte + current *object.Object + client *Client + res *ResObjectPut + prm PrmObjectPutInit + payload []byte + useStream bool } func (it *internalTarget) WriteHeader(_ context.Context, object *object.Object) error { @@ -75,9 +78,19 @@ func (it *internalTarget) Write(_ context.Context, p []byte) (n int, err error) func (it *internalTarget) Close(ctx context.Context) (*transformer.AccessIdentifiers, error) { it.current.SetPayload(it.payload) + + putSingleImplemented, err := it.tryPutSingle(ctx) + if putSingleImplemented { + return nil, err + } + it.useStream = true + return nil, it.putAsStream(ctx) +} + +func (it *internalTarget) putAsStream(ctx context.Context) error { wrt, err := it.client.objectPutInitRaw(ctx, it.prm) if err != nil { - return nil, err + return err } if wrt.WriteHeader(ctx, *it.current) { wrt.WritePayloadChunk(ctx, it.current.Payload()) @@ -85,5 +98,32 @@ func (it *internalTarget) Close(ctx context.Context) (*transformer.AccessIdentif it.res, err = wrt.Close(ctx) it.current = nil it.payload = nil - return nil, err + return err +} + +func (it *internalTarget) tryPutSingle(ctx context.Context) (bool, error) { + if it.useStream { + return false, nil + } + var prm PrmObjectPutSingle + prm.SetCopiesNumber(it.prm.copyNum) + prm.SetObject(it.current.ToV2()) + prm.UseKey(prm.key) + prm.meta = it.prm.meta + + res, err := it.client.ObjectPutSingle(ctx, prm) + if err != nil && status.Code(err) == codes.Unimplemented { + return false, err + } + + if err == nil { + id, _ := it.current.ID() + it.res = &ResObjectPut{ + statusRes: res.statusRes, + obj: id, + } + } + it.current = nil + it.payload = nil + return true, err } From fe28c332772c0e2eaefaed3b251457ba9071fed1 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 5 Jul 2023 14:25:24 +0300 Subject: [PATCH 004/288] [#104] netmap: Add test with quote escaping Signed-off-by: Alex Vanin --- netmap/policy_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/netmap/policy_test.go b/netmap/policy_test.go index 75167dca..98ce5f2b 100644 --- a/netmap/policy_test.go +++ b/netmap/policy_test.go @@ -31,6 +31,10 @@ FILTER NOT (NOT (City EQ SPB) AND SSD EQ true OR City EQ SPB AND Rating GE 5) AS `UNIQUE REP 1 REP 1`, + + `REP 1 IN X +SELECT 1 FROM F AS X +FILTER 'UN-LOCODE' EQ 'RU LED' AS F`, } var p PlacementPolicy From 14ed3e177dc260199022d6e69f7cfa179dc6880b Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 5 Jul 2023 14:25:18 +0300 Subject: [PATCH 005/288] [#104] nemtap: Escape special symbols in filters Signed-off-by: Alex Vanin --- netmap/policy.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/netmap/policy.go b/netmap/policy.go index 06e1cbaa..323050eb 100644 --- a/netmap/policy.go +++ b/netmap/policy.go @@ -471,7 +471,7 @@ func writeFilterStringTo(w io.StringWriter, f netmap.Filter) error { unspecified := op == 0 if s = f.GetKey(); s != "" { - _, err = w.WriteString(fmt.Sprintf("%s %s %s", s, op, f.GetValue())) + _, err = w.WriteString(fmt.Sprintf("%s %s %s", escapeString(s), op, escapeString(f.GetValue()))) if err != nil { return err } @@ -816,3 +816,12 @@ func operationFromString(s string) (op netmap.Operation) { return } + +// escapeString returns single quote wrapped string if it contains special +// characters '-' and whitespace. +func escapeString(s string) string { + if strings.ContainsAny(s, " -\t") { + return "'" + s + "'" + } + return s +} From 388d1ca1de0cd37a874147b81a4ee79dc68c1c81 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 7 Jul 2023 12:57:53 +0300 Subject: [PATCH 006/288] [#107] pool/tree: Support grpc schemas Signed-off-by: Denis Kirillov --- pool/tree/client.go | 41 ++++++++++++++++++++++++++++++++--------- pool/tree/pool.go | 2 +- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/pool/tree/client.go b/pool/tree/client.go index 60377dbf..326a8ccd 100644 --- a/pool/tree/client.go +++ b/pool/tree/client.go @@ -2,11 +2,15 @@ package tree import ( "context" + "crypto/tls" "fmt" "sync" + apiClient "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" grpcService "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool/tree/service" "google.golang.org/grpc" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" ) type treeClient struct { @@ -35,12 +39,10 @@ func (c *treeClient) dial(ctx context.Context) error { } var err error - c.conn, err = grpc.DialContext(ctx, c.address, c.opts...) - if err != nil { - return fmt.Errorf("grpc dial node tree service: %w", err) + if c.conn, c.service, err = dialClient(ctx, c.address, c.opts...); err != nil { + return err } - c.service = grpcService.NewTreeServiceClient(c.conn) if _, err = c.service.Healthcheck(ctx, &grpcService.HealthcheckRequest{}); err != nil { return fmt.Errorf("healthcheck tree service: %w", err) } @@ -55,12 +57,9 @@ func (c *treeClient) redialIfNecessary(ctx context.Context) (healthHasChanged bo defer c.mu.Unlock() if c.conn == nil { - c.conn, err = grpc.DialContext(ctx, c.address, c.opts...) - if err != nil { - return false, fmt.Errorf("grpc dial node tree service: %w", err) + if c.conn, c.service, err = dialClient(ctx, c.address, c.opts...); err != nil { + return false, err } - - c.service = grpcService.NewTreeServiceClient(c.conn) } wasHealthy := c.healthy @@ -74,6 +73,30 @@ func (c *treeClient) redialIfNecessary(ctx context.Context) (healthHasChanged bo return !wasHealthy, nil } +func dialClient(ctx context.Context, addr string, clientOptions ...grpc.DialOption) (*grpc.ClientConn, grpcService.TreeServiceClient, error) { + host, tlsEnable, err := apiClient.ParseURI(addr) + if err != nil { + return nil, nil, fmt.Errorf("parse address: %w", err) + } + + creds := insecure.NewCredentials() + if tlsEnable { + creds = credentials.NewTLS(&tls.Config{}) + } + + options := []grpc.DialOption{grpc.WithTransportCredentials(creds)} + + // the order is matter, we want client to be able to overwrite options. + opts := append(options, clientOptions...) + + conn, err := grpc.DialContext(ctx, host, opts...) + if err != nil { + return nil, nil, fmt.Errorf("grpc dial node tree service: %w", err) + } + + return conn, grpcService.NewTreeServiceClient(conn), nil +} + func (c *treeClient) serviceClient() (grpcService.TreeServiceClient, error) { c.mu.RLock() defer c.mu.RUnlock() diff --git a/pool/tree/pool.go b/pool/tree/pool.go index ff155dcb..7fca21be 100644 --- a/pool/tree/pool.go +++ b/pool/tree/pool.go @@ -196,7 +196,7 @@ func (p *Pool) Dial(ctx context.Context) error { for j, node := range nodes { clients[j] = newTreeClient(node.Address(), p.dialOptions...) if err := clients[j].dial(ctx); err != nil { - p.log(zap.WarnLevel, "failed to build client", zap.String("address", node.Address()), zap.Error(err)) + p.log(zap.WarnLevel, "failed to dial tree client", zap.String("address", node.Address()), zap.Error(err)) continue } From fe35373d8f1b927a971fa3e4f27cd34a5e14dc6b Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 7 Jul 2023 12:58:24 +0300 Subject: [PATCH 007/288] [#107] go.mod: Tidy dependencies Signed-off-by: Denis Kirillov --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index bd0d7911..d59bea83 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230531114046-62edd68f47ac h1:a6/Zc5BejflmguShwbllgJdEehnM9gshkLrLbKQHCU0= -git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230531114046-62edd68f47ac/go.mod h1:pKJJRLOChW4zDQsAt1e8k/snWKljJtpkiPfxV53ngjI= git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230704092742-285516a94ebe h1:SB102RiEg+4h9qcwyG97zHBtwduMRbedbtkwRDVSps8= git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230704092742-285516a94ebe/go.mod h1:pKJJRLOChW4zDQsAt1e8k/snWKljJtpkiPfxV53ngjI= git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb h1:S/TrbOOu9qEXZRZ9/Ddw7crnxbBUQLo68PSzQWYrc9M= From 35346a01c9352549cd90072bb179b725000d0938 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 7 Jul 2023 14:24:34 +0300 Subject: [PATCH 008/288] [#109] Bump neo-go version Synced version with frostfs-node, see frostfs-node#417 Signed-off-by: Alex Vanin --- go.mod | 6 +++--- go.sum | 11 ++++++----- ns/nns.go | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index bdb3df55..11486308 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/google/uuid v1.3.0 github.com/hashicorp/golang-lru/v2 v2.0.2 github.com/mr-tron/base58 v1.2.0 - github.com/nspcc-dev/neo-go v0.101.1 + github.com/nspcc-dev/neo-go v0.101.2-0.20230601131642-a0117042e8fc github.com/stretchr/testify v1.8.3 go.uber.org/zap v1.24.0 google.golang.org/grpc v1.55.0 @@ -28,11 +28,11 @@ require ( github.com/gorilla/websocket v1.5.0 // indirect github.com/hashicorp/golang-lru v0.6.0 // indirect github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 // indirect - github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20221202075445-cb5c18dc73eb // indirect + github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a // indirect github.com/nspcc-dev/rfc6979 v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/twmb/murmur3 v1.1.8 // indirect - go.uber.org/atomic v1.9.0 // indirect + go.uber.org/atomic v1.10.0 // indirect go.uber.org/goleak v1.2.1 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.9.0 // indirect diff --git a/go.sum b/go.sum index d59bea83..3376954e 100644 --- a/go.sum +++ b/go.sum @@ -268,11 +268,11 @@ github.com/nspcc-dev/hrw v1.0.9/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkP github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg= github.com/nspcc-dev/neo-go v0.98.0/go.mod h1:E3cc1x6RXSXrJb2nDWXTXjnXk3rIqVN8YdFyWv+FrqM= github.com/nspcc-dev/neo-go v0.99.4/go.mod h1:mKTolfRUfKjFso5HPvGSQtUZc70n0VKBMs16eGuC5gA= -github.com/nspcc-dev/neo-go v0.101.1 h1:TVdcIpH/+bxQBTLRwWE3+Pw3j6j/JwguENbBSGAGid0= -github.com/nspcc-dev/neo-go v0.101.1/go.mod h1:J4tspxWw7jknX06F+VSMsKvIiNpYGfVTb2IxVC005YU= +github.com/nspcc-dev/neo-go v0.101.2-0.20230601131642-a0117042e8fc h1:fySIWvUQsitK5e5qYIHnTDCXuPpwzz89SEUEIyY11sg= +github.com/nspcc-dev/neo-go v0.101.2-0.20230601131642-a0117042e8fc/go.mod h1:s9QhjMC784MWqTURovMbyYduIJc86mnCruxcMiAebpc= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220927123257-24c107e3a262/go.mod h1:23bBw0v6pBYcrWs8CBEEDIEDJNbcFoIh8pGGcf2Vv8s= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20221202075445-cb5c18dc73eb h1:GFxfkpXEYAbMIr69JpKOsQWeLOaGrd49HNAor8uDW+A= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20221202075445-cb5c18dc73eb/go.mod h1:23bBw0v6pBYcrWs8CBEEDIEDJNbcFoIh8pGGcf2Vv8s= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs= github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs= github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA= @@ -373,8 +373,9 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= +go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= diff --git a/ns/nns.go b/ns/nns.go index 3c40ab03..cb8dbd46 100644 --- a/ns/nns.go +++ b/ns/nns.go @@ -51,7 +51,7 @@ func (n *NNS) Dial(address string) error { uri, err := url.Parse(address) if err == nil && (uri.Scheme == "ws" || uri.Scheme == "wss") { - multiSchemeClient, err = rpcclient.NewWS(context.Background(), address, rpcclient.Options{}) + multiSchemeClient, err = rpcclient.NewWS(context.Background(), address, rpcclient.WSOptions{}) if err != nil { return fmt.Errorf("create Neo WebSocket client: %w", err) } From 863be6034f62b1e5459046736b4aaddb5e365276 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 7 Jul 2023 14:56:01 +0300 Subject: [PATCH 009/288] [#104] Update neo-go/pkg/interop version neo-go module uses broken commit of interop package. Signed-off-by: Alex Vanin --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 11486308..fc96fa43 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/gorilla/websocket v1.5.0 // indirect github.com/hashicorp/golang-lru v0.6.0 // indirect github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 // indirect - github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a // indirect + github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230615193820-9185820289ce // indirect github.com/nspcc-dev/rfc6979 v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/twmb/murmur3 v1.1.8 // indirect diff --git a/go.sum b/go.sum index 3376954e..11f92d0c 100644 --- a/go.sum +++ b/go.sum @@ -271,8 +271,8 @@ github.com/nspcc-dev/neo-go v0.99.4/go.mod h1:mKTolfRUfKjFso5HPvGSQtUZc70n0VKBMs github.com/nspcc-dev/neo-go v0.101.2-0.20230601131642-a0117042e8fc h1:fySIWvUQsitK5e5qYIHnTDCXuPpwzz89SEUEIyY11sg= github.com/nspcc-dev/neo-go v0.101.2-0.20230601131642-a0117042e8fc/go.mod h1:s9QhjMC784MWqTURovMbyYduIJc86mnCruxcMiAebpc= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220927123257-24c107e3a262/go.mod h1:23bBw0v6pBYcrWs8CBEEDIEDJNbcFoIh8pGGcf2Vv8s= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230615193820-9185820289ce h1:vLGuUNDkmQrWMa4rr4vTd1u8ULqejWxVmNz1L7ocTEI= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230615193820-9185820289ce/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs= github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs= github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA= From ac95b87e7c67c730edf34809646aca5a76b13eda Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Fri, 7 Jul 2023 08:47:30 +0300 Subject: [PATCH 010/288] [#101] Add `Equals` for `Address` Signed-off-by: Anton Nikiforov --- object/id/address.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/object/id/address.go b/object/id/address.go index 1f3a8648..6d5f12a7 100644 --- a/object/id/address.go +++ b/object/id/address.go @@ -169,3 +169,11 @@ func (x *Address) DecodeString(s string) error { func (x Address) String() string { return x.EncodeToString() } + +// Equals defines a comparison relation between two Address's instances. +// +// Note that comparison using '==' operator is not recommended since it MAY result +// in loss of compatibility. +func (x Address) Equals(other Address) bool { + return x.obj.Equals(other.obj) && x.cnr.Equals(other.cnr) +} From d70ef2187b5d1ac821b5b8036135d99ad9d365d5 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 6 Jul 2023 14:53:40 +0300 Subject: [PATCH 011/288] [#97] Add a method `IterateUserAttributes` in `Container` Signed-off-by: Anton Nikiforov --- container/container.go | 20 ++++++++++++++++++-- container/container_test.go | 8 +++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/container/container.go b/container/container.go index 7ecf1431..9c6c0f87 100644 --- a/container/container.go +++ b/container/container.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "strconv" + "strings" "time" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" @@ -296,7 +297,7 @@ func (x Container) PlacementPolicy() (res netmap.PlacementPolicy) { // // SetAttribute overwrites existing attribute value. // -// See also Attribute, IterateAttributes. +// See also Attribute, IterateAttributes, IterateUserAttributes. func (x *Container) SetAttribute(key, value string) { if key == "" { panic("empty attribute key") @@ -324,7 +325,7 @@ func (x *Container) SetAttribute(key, value string) { // Attribute reads value of the Container attribute by key. Empty result means // attribute absence. // -// See also SetAttribute, IterateAttributes. +// See also SetAttribute, IterateAttributes, IterateUserAttributes. func (x Container) Attribute(key string) string { attrs := x.v2.GetAttributes() for i := range attrs { @@ -347,6 +348,21 @@ func (x Container) IterateAttributes(f func(key, val string)) { } } +// IterateUserAttributes iterates over user Container attributes and passes them +// into f. The handler MUST NOT be nil. +// +// See also SetAttribute, Attribute. +func (x Container) IterateUserAttributes(f func(key, val string)) { + attrs := x.v2.GetAttributes() + for _, attr := range attrs { + var key = attr.GetKey() + if !strings.HasPrefix(key, container.SysAttributePrefix) && + !strings.HasPrefix(key, container.SysAttributePrefixNeoFS) { + f(key, attr.GetValue()) + } + } +} + // SetName sets human-readable name of the Container. Name MUST NOT be empty. // // See also Name. diff --git a/container/container_test.go b/container/container_test.go index b3ab719a..f0a22447 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -150,7 +150,7 @@ func assertContainsAttribute(t *testing.T, m v2container.Container, key, val str } func TestContainer_Attribute(t *testing.T) { - const attrKey1, attrKey2 = "key1", "key2" + const attrKey1, attrKey2 = v2container.SysAttributePrefix + "key1", v2container.SysAttributePrefixNeoFS + "key2" const attrVal1, attrVal2 = "val1", "val2" val := containertest.Container() @@ -158,6 +158,12 @@ func TestContainer_Attribute(t *testing.T) { val.SetAttribute(attrKey1, attrVal1) val.SetAttribute(attrKey2, attrVal2) + var i int + val.IterateUserAttributes(func(key, val string) { + i++ + }) + require.Equal(t, 1, i) + var msg v2container.Container val.WriteToV2(&msg) From c359a7465a7cc2674b07b7a4a6db8e90ccbdffd0 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Fri, 7 Jul 2023 15:34:31 +0300 Subject: [PATCH 012/288] [#64] transformer: Simplify interface Signed-off-by: Dmitrii Stepanov --- client/object_put_transformer.go | 42 ++++++++------------------ object/transformer/channel.go | 38 +++++------------------ object/transformer/channel_test.go | 4 +-- object/transformer/transformer.go | 26 +++++++--------- object/transformer/transformer_test.go | 39 +++++------------------- object/transformer/types.go | 15 ++++++--- 6 files changed, 52 insertions(+), 112 deletions(-) diff --git a/client/object_put_transformer.go b/client/object_put_transformer.go index cb44f61d..ad8165d6 100644 --- a/client/object_put_transformer.go +++ b/client/object_put_transformer.go @@ -21,7 +21,7 @@ func (c *Client) objectPutInitTransformer(prm PrmObjectPutInit) (*objectWriterTr } w.ot = transformer.NewPayloadSizeLimiter(transformer.Params{ Key: key, - NextTargetInit: func() transformer.ObjectTarget { return &w.it }, + NextTargetInit: func() transformer.ObjectWriter { return &w.it }, MaxSize: prm.maxSize, WithoutHomomorphicHash: prm.withoutHomomorphicHash, NetworkState: prm.epochSource, @@ -30,7 +30,7 @@ func (c *Client) objectPutInitTransformer(prm PrmObjectPutInit) (*objectWriterTr } type objectWriterTransformer struct { - ot transformer.ObjectTarget + ot transformer.ChunkedObjectWriter it internalTarget err error } @@ -58,56 +58,40 @@ func (x *objectWriterTransformer) Close(ctx context.Context) (*ResObjectPut, err } type internalTarget struct { - current *object.Object client *Client res *ResObjectPut prm PrmObjectPutInit - payload []byte useStream bool } -func (it *internalTarget) WriteHeader(_ context.Context, object *object.Object) error { - it.current = object - return nil -} - -func (it *internalTarget) Write(_ context.Context, p []byte) (n int, err error) { - it.payload = append(it.payload, p...) - return len(p), nil -} - -func (it *internalTarget) Close(ctx context.Context) (*transformer.AccessIdentifiers, error) { - it.current.SetPayload(it.payload) - - putSingleImplemented, err := it.tryPutSingle(ctx) +func (it *internalTarget) WriteObject(ctx context.Context, o *object.Object) error { + putSingleImplemented, err := it.tryPutSingle(ctx, o) if putSingleImplemented { - return nil, err + return err } it.useStream = true - return nil, it.putAsStream(ctx) + return it.putAsStream(ctx, o) } -func (it *internalTarget) putAsStream(ctx context.Context) error { +func (it *internalTarget) putAsStream(ctx context.Context, o *object.Object) error { wrt, err := it.client.objectPutInitRaw(ctx, it.prm) if err != nil { return err } - if wrt.WriteHeader(ctx, *it.current) { - wrt.WritePayloadChunk(ctx, it.current.Payload()) + if wrt.WriteHeader(ctx, *o) { + wrt.WritePayloadChunk(ctx, o.Payload()) } it.res, err = wrt.Close(ctx) - it.current = nil - it.payload = nil return err } -func (it *internalTarget) tryPutSingle(ctx context.Context) (bool, error) { +func (it *internalTarget) tryPutSingle(ctx context.Context, o *object.Object) (bool, error) { if it.useStream { return false, nil } var prm PrmObjectPutSingle prm.SetCopiesNumber(it.prm.copyNum) - prm.SetObject(it.current.ToV2()) + prm.SetObject(o.ToV2()) prm.UseKey(prm.key) prm.meta = it.prm.meta @@ -117,13 +101,11 @@ func (it *internalTarget) tryPutSingle(ctx context.Context) (bool, error) { } if err == nil { - id, _ := it.current.ID() + id, _ := o.ID() it.res = &ResObjectPut{ statusRes: res.statusRes, obj: id, } } - it.current = nil - it.payload = nil return true, err } diff --git a/object/transformer/channel.go b/object/transformer/channel.go index b7a50a94..f6d94a5a 100644 --- a/object/transformer/channel.go +++ b/object/transformer/channel.go @@ -4,47 +4,25 @@ import ( "context" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" - "github.com/nspcc-dev/neo-go/pkg/util/slice" ) type chanTarget struct { - header *objectSDK.Object - payload []byte - ch chan<- *objectSDK.Object + ch chan<- *objectSDK.Object } // NewChannelTarget returns ObjectTarget which writes // object parts to a provided channel. -func NewChannelTarget(ch chan<- *objectSDK.Object) ObjectTarget { +func NewChannelTarget(ch chan<- *objectSDK.Object) ObjectWriter { return &chanTarget{ ch: ch, } } -// WriteHeader implements the ObjectTarget interface. -func (c *chanTarget) WriteHeader(_ context.Context, object *objectSDK.Object) error { - c.header = object +func (c *chanTarget) WriteObject(ctx context.Context, o *objectSDK.Object) error { + select { + case c.ch <- o: + case <-ctx.Done(): + return ctx.Err() + } return nil } - -// Write implements the ObjectTarget interface. -func (c *chanTarget) Write(_ context.Context, p []byte) (n int, err error) { - c.payload = append(c.payload, p...) - return len(p), nil -} - -// Close implements the ObjectTarget interface. -func (c *chanTarget) Close(ctx context.Context) (*AccessIdentifiers, error) { - if len(c.payload) != 0 { - c.header.SetPayload(slice.Copy(c.payload)) - } - select { - case c.ch <- c.header: - case <-ctx.Done(): - return nil, ctx.Err() - } - - c.header = nil - c.payload = nil - return new(AccessIdentifiers), nil -} diff --git a/object/transformer/channel_test.go b/object/transformer/channel_test.go index 6b17bd59..1bb074b6 100644 --- a/object/transformer/channel_test.go +++ b/object/transformer/channel_test.go @@ -18,8 +18,8 @@ func TestChannelTarget(t *testing.T) { tt := new(testTarget) ct := NewChannelTarget(ch) - chTarget, _ := newPayloadSizeLimiter(maxSize, func() ObjectTarget { return ct }) - testTarget, _ := newPayloadSizeLimiter(maxSize, func() ObjectTarget { return tt }) + chTarget, _ := newPayloadSizeLimiter(maxSize, func() ObjectWriter { return ct }) + testTarget, _ := newPayloadSizeLimiter(maxSize, func() ObjectWriter { return tt }) ver := version.Current() cnr := cidtest.ID() diff --git a/object/transformer/transformer.go b/object/transformer/transformer.go index a1756628..6fea8dd4 100644 --- a/object/transformer/transformer.go +++ b/object/transformer/transformer.go @@ -20,6 +20,7 @@ type payloadSizeLimiter struct { written, writtenCurrent uint64 current, parent *object.Object + payload []byte currentHashers, parentHashers []payloadChecksumHasher @@ -29,12 +30,12 @@ type payloadSizeLimiter struct { parAttrs []object.Attribute - nextTarget ObjectTarget + nextTarget ObjectWriter } type Params struct { Key *ecdsa.PrivateKey - NextTargetInit func() ObjectTarget + NextTargetInit TargetInitializer SessionToken *session.Object NetworkState EpochSource MaxSize uint64 @@ -48,7 +49,7 @@ type Params struct { // is false. // // Objects w/ payload size less or equal than max size remain untouched. -func NewPayloadSizeLimiter(p Params) ObjectTarget { +func NewPayloadSizeLimiter(p Params) ChunkedObjectWriter { return &payloadSizeLimiter{ Params: p, splitID: object.NewSplitID(), @@ -120,6 +121,7 @@ func (s *payloadSizeLimiter) initializeCurrent() { s.nextTarget = s.NextTargetInit() s.writtenCurrent = 0 s.initPayloadHashers() + s.payload = make([]byte, 0) } func (s *payloadSizeLimiter) initPayloadHashers() { @@ -160,12 +162,9 @@ func (s *payloadSizeLimiter) release(ctx context.Context, finalize bool) (*Acces return nil, fmt.Errorf("fillHeader: %w", err) } - if err := s.nextTarget.WriteHeader(ctx, s.current); err != nil { - return nil, fmt.Errorf("could not write header to next target: %w", err) - } - - if _, err := s.nextTarget.Close(ctx); err != nil { - return nil, fmt.Errorf("could not close next target: %w", err) + s.current.SetPayload(s.payload) + if err := s.nextTarget.WriteObject(ctx, s.current); err != nil { + return nil, fmt.Errorf("could not write to next target: %w", err) } // save identifier of the released object @@ -262,7 +261,7 @@ func (s *payloadSizeLimiter) writeChunk(ctx context.Context, chunk []byte) error cut = leftToEdge } - if err := s.writeHashes(ctx, chunk[:cut]); err != nil { + if err := s.writeHashes(chunk[:cut]); err != nil { return fmt.Errorf("could not write chunk to target: %w", err) } @@ -278,11 +277,8 @@ func (s *payloadSizeLimiter) writeChunk(ctx context.Context, chunk []byte) error } } -func (s *payloadSizeLimiter) writeHashes(ctx context.Context, chunk []byte) error { - _, err := s.nextTarget.Write(ctx, chunk) - if err != nil { - return err - } +func (s *payloadSizeLimiter) writeHashes(chunk []byte) error { + s.payload = append(s.payload, chunk...) // The `Write` method of `hash.Hash` never returns an error. for i := range s.currentHashers { diff --git a/object/transformer/transformer_test.go b/object/transformer/transformer_test.go index 11a68434..cbfb11a1 100644 --- a/object/transformer/transformer_test.go +++ b/object/transformer/transformer_test.go @@ -20,7 +20,7 @@ func TestTransformer(t *testing.T) { tt := new(testTarget) - target, pk := newPayloadSizeLimiter(maxSize, func() ObjectTarget { return tt }) + target, pk := newPayloadSizeLimiter(maxSize, func() ObjectWriter { return tt }) cnr := cidtest.ID() hdr := newObject(cnr) @@ -99,7 +99,7 @@ func newObject(cnr cid.ID) *objectSDK.Object { return hdr } -func writeObject(t *testing.T, ctx context.Context, target ObjectTarget, header *objectSDK.Object, payload []byte) *AccessIdentifiers { +func writeObject(t *testing.T, ctx context.Context, target ChunkedObjectWriter, header *objectSDK.Object, payload []byte) *AccessIdentifiers { require.NoError(t, target.WriteHeader(ctx, header)) _, err := target.Write(ctx, payload) @@ -131,7 +131,7 @@ func benchmarkTransformer(b *testing.B, header *objectSDK.Object, payloadSize in b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - f, _ := newPayloadSizeLimiter(maxSize, func() ObjectTarget { return benchTarget{} }) + f, _ := newPayloadSizeLimiter(maxSize, func() ObjectWriter { return benchTarget{} }) if err := f.WriteHeader(ctx, header); err != nil { b.Fatalf("write header: %v", err) } @@ -144,7 +144,7 @@ func benchmarkTransformer(b *testing.B, header *objectSDK.Object, payloadSize in } } -func newPayloadSizeLimiter(maxSize uint64, nextTarget func() ObjectTarget) (ObjectTarget, *keys.PrivateKey) { +func newPayloadSizeLimiter(maxSize uint64, nextTarget TargetInitializer) (ChunkedObjectWriter, *keys.PrivateKey) { p, err := keys.NewPrivateKey() if err != nil { panic(err) @@ -167,38 +167,15 @@ func (s dummyEpochSource) CurrentEpoch() uint64 { type benchTarget struct{} -func (benchTarget) WriteHeader(_ context.Context, object *objectSDK.Object) error { +func (benchTarget) WriteObject(context.Context, *objectSDK.Object) error { return nil } -func (benchTarget) Write(_ context.Context, p []byte) (n int, err error) { - return len(p), nil -} - -func (benchTarget) Close(context.Context) (*AccessIdentifiers, error) { - return nil, nil -} - type testTarget struct { - current *objectSDK.Object - payload []byte objects []*objectSDK.Object } -func (tt *testTarget) WriteHeader(_ context.Context, object *objectSDK.Object) error { - tt.current = object - return nil -} - -func (tt *testTarget) Write(_ context.Context, p []byte) (n int, err error) { - tt.payload = append(tt.payload, p...) - return len(p), nil -} - -func (tt *testTarget) Close(_ context.Context) (*AccessIdentifiers, error) { - tt.current.SetPayload(tt.payload) - tt.objects = append(tt.objects, tt.current) - tt.current = nil - tt.payload = nil - return nil, nil // AccessIdentifiers should not be used. +func (tt *testTarget) WriteObject(_ context.Context, o *objectSDK.Object) error { + tt.objects = append(tt.objects, o) + return nil // AccessIdentifiers should not be used. } diff --git a/object/transformer/types.go b/object/transformer/types.go index a7e827ca..212f4537 100644 --- a/object/transformer/types.go +++ b/object/transformer/types.go @@ -21,8 +21,9 @@ type EpochSource interface { CurrentEpoch() uint64 } -// ObjectTarget is an interface of the object writer. -type ObjectTarget interface { +// ChunkedObjectWriter is an interface of the object writer +// that writes object chunked. +type ChunkedObjectWriter interface { // WriteHeader writes object header w/ payload part. // The payload of the object may be incomplete. // @@ -51,5 +52,11 @@ type ObjectTarget interface { Close(context.Context) (*AccessIdentifiers, error) } -// TargetInitializer represents ObjectTarget constructor. -type TargetInitializer func() ObjectTarget +// TargetInitializer represents ObjectWriter constructor. +type TargetInitializer func() ObjectWriter + +// ObjectWriter is an interface of the object writer that writes prepared object. +type ObjectWriter interface { + // WriteObject writes prepared object. + WriteObject(context.Context, *object.Object) error +} From 998fe1a7ab31ce68af433da02220754e8fd0b811 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 10 Jul 2023 14:49:40 +0300 Subject: [PATCH 013/288] [#102] netmap: properly process multiple REP Signed-off-by: Evgenii Stratonikov --- netmap/netmap.go | 28 +++++------------ netmap/selector_test.go | 67 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 21 deletions(-) diff --git a/netmap/netmap.go b/netmap/netmap.go index 7da41a86..e1a5f7d1 100644 --- a/netmap/netmap.go +++ b/netmap/netmap.go @@ -188,30 +188,16 @@ func (m NetMap) ContainerNodes(p PlacementPolicy, pivot []byte) ([][]NodeInfo, e for i := range p.replicas { sName := p.replicas[i].GetSelector() if sName == "" { - if len(p.selectors) == 0 { - var s netmap.Selector - s.SetCount(p.replicas[i].GetCount()) - s.SetFilter(mainFilterName) + var s netmap.Selector + s.SetCount(p.replicas[i].GetCount()) + s.SetFilter(mainFilterName) - nodes, err := c.getSelection(s) - if err != nil { - return nil, err - } - - result[i] = flattenNodes(nodes) + nodes, err := c.getSelection(s) + if err != nil { + return nil, err } - for i := range p.selectors { - if p.unique { - nodes, err := c.getSelection(p.selectors[i]) - if err != nil { - return nil, err - } - result[i] = append(result[i], flattenNodes(nodes)...) - } else { - result[i] = append(result[i], flattenNodes(c.selections[p.selectors[i].GetName()])...) - } - } + result[i] = append(result[i], flattenNodes(nodes)...) if p.unique { c.addUsedNodes(result[i]...) diff --git a/netmap/selector_test.go b/netmap/selector_test.go index a80d9223..ccb5eb2c 100644 --- a/netmap/selector_test.go +++ b/netmap/selector_test.go @@ -282,6 +282,73 @@ func TestPlacementPolicy_Unique(t *testing.T) { } } +func TestPlacementPolicy_MultiREP(t *testing.T) { + nodes := []NodeInfo{ + nodeInfoFromAttributes("ID", "1", "Country", "Russia", "City", "SPB"), + nodeInfoFromAttributes("ID", "2", "Country", "Germany", "City", "Berlin"), + nodeInfoFromAttributes("ID", "3", "Country", "Russia", "City", "Moscow"), + nodeInfoFromAttributes("ID", "4", "Country", "France", "City", "Paris"), + nodeInfoFromAttributes("ID", "5", "Country", "France", "City", "Lyon"), + nodeInfoFromAttributes("ID", "6", "Country", "Russia", "City", "SPB"), + nodeInfoFromAttributes("ID", "7", "Country", "Russia", "City", "Moscow"), + nodeInfoFromAttributes("ID", "8", "Country", "Germany", "City", "Darmstadt"), + nodeInfoFromAttributes("ID", "9", "Country", "Germany", "City", "Frankfurt"), + nodeInfoFromAttributes("ID", "10", "Country", "Russia", "City", "SPB"), + nodeInfoFromAttributes("ID", "11", "Country", "Russia", "City", "Moscow"), + nodeInfoFromAttributes("ID", "12", "Country", "Germany", "City", "London"), + } + for i := range nodes { + pub := make([]byte, 33) + rand.Read(pub) + nodes[i].SetPublicKey(pub) + } + + var nm NetMap + nm.SetNodes(nodes) + + ss := []Selector{newSelector("SameRU", "City", 2, "FromRU", (*Selector).SelectDistinct)} + fs := []Filter{newFilter("FromRU", "Country", "Russia", netmap.EQ)} + + for _, unique := range []bool{false, true} { + for _, additional := range []int{0, 1, 2} { + t.Run(fmt.Sprintf("unique=%t, additional=%d", unique, additional), func(t *testing.T) { + rs := []ReplicaDescriptor{newReplica(1, "SameRU")} + for i := 0; i < additional; i++ { + rs = append(rs, newReplica(1, "")) + } + + p := newPlacementPolicy(3, rs, ss, fs) + p.unique = unique + + v, err := nm.ContainerNodes(p, []byte{1}) + require.NoError(t, err) + require.Equal(t, 1+additional, len(v)) + require.Equal(t, 6, len(v[0])) + + for i := 1; i < additional; i++ { + require.Equal(t, 3, len(v[i])) + if !unique { + require.Equal(t, v[1], v[i]) + } + } + + if unique { + seen := make(map[string]bool) + for i := range v { + for j := range v[i] { + attr := v[i][j].Attribute("ID") + require.NotEmpty(t, attr) + require.False(t, seen[attr]) + + seen[attr] = true + } + } + } + }) + } + } +} + func TestPlacementPolicy_ProcessSelectorsExceptForNodes(t *testing.T) { p := newPlacementPolicy(1, nil, []Selector{ From b9afe7a2f95245ca981ce6e63c0523aa9ddafb05 Mon Sep 17 00:00:00 2001 From: Pavel Pogodaev Date: Mon, 10 Jul 2023 09:56:37 +0300 Subject: [PATCH 014/288] [#42] Add ResolveContractHash method Signed-off-by: Pavel Pogodaev --- ns/nns.go | 44 ++++++++++++++++++++++++++ ns/nns_test.go | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) diff --git a/ns/nns.go b/ns/nns.go index cb8dbd46..4af72f41 100644 --- a/ns/nns.go +++ b/ns/nns.go @@ -10,6 +10,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" "github.com/nspcc-dev/neo-go/pkg/core/state" + "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/neorpc/result" "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" @@ -116,3 +117,46 @@ func (n *NNS) ResolveContainerDomain(domain container.Domain) (cid.ID, error) { return cid.ID{}, errNotFound } + +// ResolveContractHash looks up for NNS TXT records for the given container domain +// by calling `resolve` method of NNS contract. Returns the first record which represents +// valid contract hash 20 bytes long unsigned integer. Otherwise, returns an error. +// +// ResolveContractHash MUST NOT be called before successful Dial. +// +// See also https://docs.neo.org/docs/en-us/reference/nns.html. +func (n *NNS) ResolveContractHash(domain container.Domain) (util.Uint160, error) { + item, err := unwrap.Item(n.invoker.Call(n.nnsContract, "resolve", + domain.Name()+"."+domain.Zone(), int64(nns.TXT), + )) + if err != nil { + return util.Uint160{}, fmt.Errorf("contract invocation: %w", err) + } + + if _, ok := item.(stackitem.Null); !ok { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + // unexpected for types from stackitem package + return util.Uint160{}, errors.New("invalid cast to stack item slice") + } + + for i := range arr { + recordValue, err := arr[i].TryBytes() + if err != nil { + return util.Uint160{}, fmt.Errorf("convert array item to byte slice: %w", err) + } + + strRecordValue := string(recordValue) + scriptHash, err := address.StringToUint160(strRecordValue) + if err == nil { + return scriptHash, nil + } + scriptHash, err = util.Uint160DecodeStringLE(strRecordValue) + if err == nil { + return scriptHash, nil + } + } + } + + return util.Uint160{}, errNotFound +} diff --git a/ns/nns_test.go b/ns/nns_test.go index 3180ac45..9970b885 100644 --- a/ns/nns_test.go +++ b/ns/nns_test.go @@ -154,3 +154,86 @@ func TestNNS_ResolveContainerDomain(t *testing.T) { require.Equal(t, id, res) }) } + +func TestNNS_ResolveContractHash(t *testing.T) { + var testContainerDomain container.Domain + testContainerDomain.SetName("some_container") + + var nnsContract util.Uint160 + + rand.Read(nnsContract[:]) + + testC := &testNeoClient{ + t: t, + expectedContract: nnsContract, + } + + n := NNS{ + nnsContract: nnsContract, + invoker: testC, + } + + t.Run("invocation failure", func(t *testing.T) { + err1 := errors.New("invoke err") + testC.err = err1 + + _, err2 := n.ResolveContractHash(testContainerDomain) + require.ErrorIs(t, err2, err1) + }) + + testC.err = nil + + t.Run("fault exception", func(t *testing.T) { + _, err := n.ResolveContractHash(testContainerDomain) + require.Error(t, err) + }) + + testC.res.State = vmstate.Halt.String() + + t.Run("empty stack", func(t *testing.T) { + _, err := n.ResolveContractHash(testContainerDomain) + require.Error(t, err) + }) + + testC.res.Stack = make([]stackitem.Item, 1) + + t.Run("non-array last stack item", func(t *testing.T) { + testC.res.Stack[0] = stackitem.NewBigInteger(big.NewInt(11)) + + _, err := n.ResolveContractHash(testContainerDomain) + require.Error(t, err) + }) + + t.Run("null array", func(t *testing.T) { + testC.res.Stack[0] = stackitem.Null{} + + _, err := n.ResolveContractHash(testContainerDomain) + require.ErrorIs(t, err, errNotFound) + }) + + t.Run("array stack item with non-slice value", func(t *testing.T) { + testC.res.Stack[0] = brokenArrayStackItem{} + + _, err := n.ResolveContractHash(testContainerDomain) + require.Error(t, err) + }) + + arr := make([]stackitem.Item, 2) + testC.res.Stack[0] = stackitem.NewArray(arr) + + t.Run("non-bytes array element", func(t *testing.T) { + arr[0] = stackitem.NewArray(nil) + + _, err := n.ResolveContractHash(testContainerDomain) + require.Error(t, err) + }) + + arr[0] = stackitem.NewByteArray([]byte("some byte array 1")) + + t.Run("non-container array elements", func(t *testing.T) { + arr[1] = stackitem.NewByteArray([]byte("some byte array 2")) + + _, err := n.ResolveContractHash(testContainerDomain) + require.Error(t, err) + }) +} From b91f9d8c7910c7493c036a4d007180fc07a74777 Mon Sep 17 00:00:00 2001 From: Alejandro Lopez Date: Thu, 13 Jul 2023 16:12:47 +0300 Subject: [PATCH 015/288] [#xx] Add support for SELECT-FILTER expressions Signed-off-by: Alejandro Lopez --- netmap/netmap.go | 51 +++ netmap/parser/Query.g4 | 2 + netmap/parser/Query.interp | 3 +- netmap/parser/query_base_visitor.go | 4 + netmap/parser/query_parser.go | 567 +++++++++++++++++++--------- netmap/parser/query_visitor.go | 3 + netmap/policy.go | 71 ++++ netmap/policy_test.go | 25 ++ 8 files changed, 556 insertions(+), 170 deletions(-) diff --git a/netmap/netmap.go b/netmap/netmap.go index e1a5f7d1..3e8d680d 100644 --- a/netmap/netmap.go +++ b/netmap/netmap.go @@ -158,6 +158,57 @@ func (m NetMap) PlacementVectors(vectors [][]NodeInfo, pivot []byte) ([][]NodeIn return result, nil } +// SelectFilterNodes returns a two-dimensional list of nodes as a result of applying the +// given SelectFilterExpr to the NetMap. +// If the SelectFilterExpr contains only filters, the result contains a single row with the +// result of the last filter application. +// If the SelectFilterExpr contains only selectors, the result contains the selection rows +// of the last select application. +func (m NetMap) SelectFilterNodes(expr *SelectFilterExpr) ([][]NodeInfo, error) { + p := PlacementPolicy{ + filters: expr.filters, + } + + if expr.selector != nil { + p.selectors = append(p.selectors, *expr.selector) + } + + c := newContext(m) + c.setCBF(expr.cbf) + + if err := c.processFilters(p); err != nil { + return nil, err + } + if err := c.processSelectors(p); err != nil { + return nil, err + } + + if expr.selector == nil { + var ret []NodeInfo + lastFilter := expr.filters[len(expr.filters)-1] + for _, ni := range m.nodes { + if c.match(c.processedFilters[lastFilter.GetName()], ni) { + ret = append(ret, ni) + } + } + return [][]NodeInfo{ret}, nil + } + + sel, err := c.getSelection(*c.processedSelectors[expr.selector.GetName()]) + if err != nil { + return nil, err + } + + var ret [][]NodeInfo + for i, ns := range sel { + ret = append(ret, []NodeInfo{}) + for _, n := range ns { + ret[i] = append(ret[i], n) + } + } + return ret, nil +} + // ContainerNodes returns two-dimensional list of nodes as a result of applying // given PlacementPolicy to the NetMap. Each line of the list corresponds to a // replica descriptor. Line order corresponds to order of ReplicaDescriptor list diff --git a/netmap/parser/Query.g4 b/netmap/parser/Query.g4 index abae1810..72fa880a 100644 --- a/netmap/parser/Query.g4 +++ b/netmap/parser/Query.g4 @@ -6,6 +6,8 @@ options { policy: UNIQUE? repStmt+ cbfStmt? selectStmt* filterStmt* EOF; +selectFilterExpr: cbfStmt? selectStmt? filterStmt* EOF; + repStmt: REP Count = NUMBER1 // number of object replicas (IN Selector = ident)?; // optional selector name diff --git a/netmap/parser/Query.interp b/netmap/parser/Query.interp index df98c281..a8fb219e 100644 --- a/netmap/parser/Query.interp +++ b/netmap/parser/Query.interp @@ -52,6 +52,7 @@ WS rule names: policy +selectFilterExpr repStmt cbfStmt selectStmt @@ -68,4 +69,4 @@ identWC atn: -[4, 1, 23, 138, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 1, 0, 3, 0, 30, 8, 0, 1, 0, 4, 0, 33, 8, 0, 11, 0, 12, 0, 34, 1, 0, 3, 0, 38, 8, 0, 1, 0, 5, 0, 41, 8, 0, 10, 0, 12, 0, 44, 9, 0, 1, 0, 5, 0, 47, 8, 0, 10, 0, 12, 0, 50, 9, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 58, 8, 1, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 3, 3, 67, 8, 3, 1, 3, 3, 3, 70, 8, 3, 1, 3, 1, 3, 1, 3, 1, 3, 3, 3, 76, 8, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 91, 8, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 99, 8, 5, 10, 5, 12, 5, 102, 9, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 3, 7, 115, 8, 7, 1, 8, 1, 8, 3, 8, 119, 8, 8, 1, 9, 1, 9, 1, 9, 3, 9, 124, 8, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 12, 1, 12, 3, 12, 132, 8, 12, 1, 13, 1, 13, 3, 13, 136, 8, 13, 1, 13, 0, 1, 10, 14, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 0, 3, 1, 0, 14, 15, 1, 0, 20, 21, 2, 0, 6, 8, 10, 12, 142, 0, 29, 1, 0, 0, 0, 2, 53, 1, 0, 0, 0, 4, 59, 1, 0, 0, 0, 6, 62, 1, 0, 0, 0, 8, 77, 1, 0, 0, 0, 10, 90, 1, 0, 0, 0, 12, 103, 1, 0, 0, 0, 14, 114, 1, 0, 0, 0, 16, 118, 1, 0, 0, 0, 18, 123, 1, 0, 0, 0, 20, 125, 1, 0, 0, 0, 22, 127, 1, 0, 0, 0, 24, 131, 1, 0, 0, 0, 26, 135, 1, 0, 0, 0, 28, 30, 5, 5, 0, 0, 29, 28, 1, 0, 0, 0, 29, 30, 1, 0, 0, 0, 30, 32, 1, 0, 0, 0, 31, 33, 3, 2, 1, 0, 32, 31, 1, 0, 0, 0, 33, 34, 1, 0, 0, 0, 34, 32, 1, 0, 0, 0, 34, 35, 1, 0, 0, 0, 35, 37, 1, 0, 0, 0, 36, 38, 3, 4, 2, 0, 37, 36, 1, 0, 0, 0, 37, 38, 1, 0, 0, 0, 38, 42, 1, 0, 0, 0, 39, 41, 3, 6, 3, 0, 40, 39, 1, 0, 0, 0, 41, 44, 1, 0, 0, 0, 42, 40, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, 48, 1, 0, 0, 0, 44, 42, 1, 0, 0, 0, 45, 47, 3, 12, 6, 0, 46, 45, 1, 0, 0, 0, 47, 50, 1, 0, 0, 0, 48, 46, 1, 0, 0, 0, 48, 49, 1, 0, 0, 0, 49, 51, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 51, 52, 5, 0, 0, 1, 52, 1, 1, 0, 0, 0, 53, 54, 5, 6, 0, 0, 54, 57, 5, 20, 0, 0, 55, 56, 5, 7, 0, 0, 56, 58, 3, 24, 12, 0, 57, 55, 1, 0, 0, 0, 57, 58, 1, 0, 0, 0, 58, 3, 1, 0, 0, 0, 59, 60, 5, 9, 0, 0, 60, 61, 5, 20, 0, 0, 61, 5, 1, 0, 0, 0, 62, 63, 5, 10, 0, 0, 63, 69, 5, 20, 0, 0, 64, 66, 5, 7, 0, 0, 65, 67, 3, 8, 4, 0, 66, 65, 1, 0, 0, 0, 66, 67, 1, 0, 0, 0, 67, 68, 1, 0, 0, 0, 68, 70, 3, 24, 12, 0, 69, 64, 1, 0, 0, 0, 69, 70, 1, 0, 0, 0, 70, 71, 1, 0, 0, 0, 71, 72, 5, 11, 0, 0, 72, 75, 3, 26, 13, 0, 73, 74, 5, 8, 0, 0, 74, 76, 3, 24, 12, 0, 75, 73, 1, 0, 0, 0, 75, 76, 1, 0, 0, 0, 76, 7, 1, 0, 0, 0, 77, 78, 7, 0, 0, 0, 78, 9, 1, 0, 0, 0, 79, 80, 6, 5, -1, 0, 80, 81, 5, 1, 0, 0, 81, 82, 5, 16, 0, 0, 82, 83, 3, 10, 5, 0, 83, 84, 5, 17, 0, 0, 84, 91, 1, 0, 0, 0, 85, 86, 5, 16, 0, 0, 86, 87, 3, 10, 5, 0, 87, 88, 5, 17, 0, 0, 88, 91, 1, 0, 0, 0, 89, 91, 3, 14, 7, 0, 90, 79, 1, 0, 0, 0, 90, 85, 1, 0, 0, 0, 90, 89, 1, 0, 0, 0, 91, 100, 1, 0, 0, 0, 92, 93, 10, 4, 0, 0, 93, 94, 5, 2, 0, 0, 94, 99, 3, 10, 5, 5, 95, 96, 10, 3, 0, 0, 96, 97, 5, 3, 0, 0, 97, 99, 3, 10, 5, 4, 98, 92, 1, 0, 0, 0, 98, 95, 1, 0, 0, 0, 99, 102, 1, 0, 0, 0, 100, 98, 1, 0, 0, 0, 100, 101, 1, 0, 0, 0, 101, 11, 1, 0, 0, 0, 102, 100, 1, 0, 0, 0, 103, 104, 5, 12, 0, 0, 104, 105, 3, 10, 5, 0, 105, 106, 5, 8, 0, 0, 106, 107, 3, 24, 12, 0, 107, 13, 1, 0, 0, 0, 108, 109, 5, 18, 0, 0, 109, 115, 3, 24, 12, 0, 110, 111, 3, 16, 8, 0, 111, 112, 5, 4, 0, 0, 112, 113, 3, 18, 9, 0, 113, 115, 1, 0, 0, 0, 114, 108, 1, 0, 0, 0, 114, 110, 1, 0, 0, 0, 115, 15, 1, 0, 0, 0, 116, 119, 3, 24, 12, 0, 117, 119, 5, 22, 0, 0, 118, 116, 1, 0, 0, 0, 118, 117, 1, 0, 0, 0, 119, 17, 1, 0, 0, 0, 120, 124, 3, 24, 12, 0, 121, 124, 3, 20, 10, 0, 122, 124, 5, 22, 0, 0, 123, 120, 1, 0, 0, 0, 123, 121, 1, 0, 0, 0, 123, 122, 1, 0, 0, 0, 124, 19, 1, 0, 0, 0, 125, 126, 7, 1, 0, 0, 126, 21, 1, 0, 0, 0, 127, 128, 7, 2, 0, 0, 128, 23, 1, 0, 0, 0, 129, 132, 3, 22, 11, 0, 130, 132, 5, 19, 0, 0, 131, 129, 1, 0, 0, 0, 131, 130, 1, 0, 0, 0, 132, 25, 1, 0, 0, 0, 133, 136, 3, 24, 12, 0, 134, 136, 5, 13, 0, 0, 135, 133, 1, 0, 0, 0, 135, 134, 1, 0, 0, 0, 136, 27, 1, 0, 0, 0, 17, 29, 34, 37, 42, 48, 57, 66, 69, 75, 90, 98, 100, 114, 118, 123, 131, 135] \ No newline at end of file +[4, 1, 23, 154, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 1, 0, 3, 0, 32, 8, 0, 1, 0, 4, 0, 35, 8, 0, 11, 0, 12, 0, 36, 1, 0, 3, 0, 40, 8, 0, 1, 0, 5, 0, 43, 8, 0, 10, 0, 12, 0, 46, 9, 0, 1, 0, 5, 0, 49, 8, 0, 10, 0, 12, 0, 52, 9, 0, 1, 0, 1, 0, 1, 1, 3, 1, 57, 8, 1, 1, 1, 3, 1, 60, 8, 1, 1, 1, 5, 1, 63, 8, 1, 10, 1, 12, 1, 66, 9, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 74, 8, 2, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 83, 8, 4, 1, 4, 3, 4, 86, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 92, 8, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 107, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 115, 8, 6, 10, 6, 12, 6, 118, 9, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 3, 8, 131, 8, 8, 1, 9, 1, 9, 3, 9, 135, 8, 9, 1, 10, 1, 10, 1, 10, 3, 10, 140, 8, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 3, 13, 148, 8, 13, 1, 14, 1, 14, 3, 14, 152, 8, 14, 1, 14, 0, 1, 12, 15, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 0, 3, 1, 0, 14, 15, 1, 0, 20, 21, 2, 0, 6, 8, 10, 12, 160, 0, 31, 1, 0, 0, 0, 2, 56, 1, 0, 0, 0, 4, 69, 1, 0, 0, 0, 6, 75, 1, 0, 0, 0, 8, 78, 1, 0, 0, 0, 10, 93, 1, 0, 0, 0, 12, 106, 1, 0, 0, 0, 14, 119, 1, 0, 0, 0, 16, 130, 1, 0, 0, 0, 18, 134, 1, 0, 0, 0, 20, 139, 1, 0, 0, 0, 22, 141, 1, 0, 0, 0, 24, 143, 1, 0, 0, 0, 26, 147, 1, 0, 0, 0, 28, 151, 1, 0, 0, 0, 30, 32, 5, 5, 0, 0, 31, 30, 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 34, 1, 0, 0, 0, 33, 35, 3, 4, 2, 0, 34, 33, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 34, 1, 0, 0, 0, 36, 37, 1, 0, 0, 0, 37, 39, 1, 0, 0, 0, 38, 40, 3, 6, 3, 0, 39, 38, 1, 0, 0, 0, 39, 40, 1, 0, 0, 0, 40, 44, 1, 0, 0, 0, 41, 43, 3, 8, 4, 0, 42, 41, 1, 0, 0, 0, 43, 46, 1, 0, 0, 0, 44, 42, 1, 0, 0, 0, 44, 45, 1, 0, 0, 0, 45, 50, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 47, 49, 3, 14, 7, 0, 48, 47, 1, 0, 0, 0, 49, 52, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 50, 51, 1, 0, 0, 0, 51, 53, 1, 0, 0, 0, 52, 50, 1, 0, 0, 0, 53, 54, 5, 0, 0, 1, 54, 1, 1, 0, 0, 0, 55, 57, 3, 6, 3, 0, 56, 55, 1, 0, 0, 0, 56, 57, 1, 0, 0, 0, 57, 59, 1, 0, 0, 0, 58, 60, 3, 8, 4, 0, 59, 58, 1, 0, 0, 0, 59, 60, 1, 0, 0, 0, 60, 64, 1, 0, 0, 0, 61, 63, 3, 14, 7, 0, 62, 61, 1, 0, 0, 0, 63, 66, 1, 0, 0, 0, 64, 62, 1, 0, 0, 0, 64, 65, 1, 0, 0, 0, 65, 67, 1, 0, 0, 0, 66, 64, 1, 0, 0, 0, 67, 68, 5, 0, 0, 1, 68, 3, 1, 0, 0, 0, 69, 70, 5, 6, 0, 0, 70, 73, 5, 20, 0, 0, 71, 72, 5, 7, 0, 0, 72, 74, 3, 26, 13, 0, 73, 71, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 5, 1, 0, 0, 0, 75, 76, 5, 9, 0, 0, 76, 77, 5, 20, 0, 0, 77, 7, 1, 0, 0, 0, 78, 79, 5, 10, 0, 0, 79, 85, 5, 20, 0, 0, 80, 82, 5, 7, 0, 0, 81, 83, 3, 10, 5, 0, 82, 81, 1, 0, 0, 0, 82, 83, 1, 0, 0, 0, 83, 84, 1, 0, 0, 0, 84, 86, 3, 26, 13, 0, 85, 80, 1, 0, 0, 0, 85, 86, 1, 0, 0, 0, 86, 87, 1, 0, 0, 0, 87, 88, 5, 11, 0, 0, 88, 91, 3, 28, 14, 0, 89, 90, 5, 8, 0, 0, 90, 92, 3, 26, 13, 0, 91, 89, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 9, 1, 0, 0, 0, 93, 94, 7, 0, 0, 0, 94, 11, 1, 0, 0, 0, 95, 96, 6, 6, -1, 0, 96, 97, 5, 1, 0, 0, 97, 98, 5, 16, 0, 0, 98, 99, 3, 12, 6, 0, 99, 100, 5, 17, 0, 0, 100, 107, 1, 0, 0, 0, 101, 102, 5, 16, 0, 0, 102, 103, 3, 12, 6, 0, 103, 104, 5, 17, 0, 0, 104, 107, 1, 0, 0, 0, 105, 107, 3, 16, 8, 0, 106, 95, 1, 0, 0, 0, 106, 101, 1, 0, 0, 0, 106, 105, 1, 0, 0, 0, 107, 116, 1, 0, 0, 0, 108, 109, 10, 4, 0, 0, 109, 110, 5, 2, 0, 0, 110, 115, 3, 12, 6, 5, 111, 112, 10, 3, 0, 0, 112, 113, 5, 3, 0, 0, 113, 115, 3, 12, 6, 4, 114, 108, 1, 0, 0, 0, 114, 111, 1, 0, 0, 0, 115, 118, 1, 0, 0, 0, 116, 114, 1, 0, 0, 0, 116, 117, 1, 0, 0, 0, 117, 13, 1, 0, 0, 0, 118, 116, 1, 0, 0, 0, 119, 120, 5, 12, 0, 0, 120, 121, 3, 12, 6, 0, 121, 122, 5, 8, 0, 0, 122, 123, 3, 26, 13, 0, 123, 15, 1, 0, 0, 0, 124, 125, 5, 18, 0, 0, 125, 131, 3, 26, 13, 0, 126, 127, 3, 18, 9, 0, 127, 128, 5, 4, 0, 0, 128, 129, 3, 20, 10, 0, 129, 131, 1, 0, 0, 0, 130, 124, 1, 0, 0, 0, 130, 126, 1, 0, 0, 0, 131, 17, 1, 0, 0, 0, 132, 135, 3, 26, 13, 0, 133, 135, 5, 22, 0, 0, 134, 132, 1, 0, 0, 0, 134, 133, 1, 0, 0, 0, 135, 19, 1, 0, 0, 0, 136, 140, 3, 26, 13, 0, 137, 140, 3, 22, 11, 0, 138, 140, 5, 22, 0, 0, 139, 136, 1, 0, 0, 0, 139, 137, 1, 0, 0, 0, 139, 138, 1, 0, 0, 0, 140, 21, 1, 0, 0, 0, 141, 142, 7, 1, 0, 0, 142, 23, 1, 0, 0, 0, 143, 144, 7, 2, 0, 0, 144, 25, 1, 0, 0, 0, 145, 148, 3, 24, 12, 0, 146, 148, 5, 19, 0, 0, 147, 145, 1, 0, 0, 0, 147, 146, 1, 0, 0, 0, 148, 27, 1, 0, 0, 0, 149, 152, 3, 26, 13, 0, 150, 152, 5, 13, 0, 0, 151, 149, 1, 0, 0, 0, 151, 150, 1, 0, 0, 0, 152, 29, 1, 0, 0, 0, 20, 31, 36, 39, 44, 50, 56, 59, 64, 73, 82, 85, 91, 106, 114, 116, 130, 134, 139, 147, 151] \ No newline at end of file diff --git a/netmap/parser/query_base_visitor.go b/netmap/parser/query_base_visitor.go index 4badbceb..981106f5 100644 --- a/netmap/parser/query_base_visitor.go +++ b/netmap/parser/query_base_visitor.go @@ -12,6 +12,10 @@ func (v *BaseQueryVisitor) VisitPolicy(ctx *PolicyContext) interface{} { return v.VisitChildren(ctx) } +func (v *BaseQueryVisitor) VisitSelectFilterExpr(ctx *SelectFilterExprContext) interface{} { + return v.VisitChildren(ctx) +} + func (v *BaseQueryVisitor) VisitRepStmt(ctx *RepStmtContext) interface{} { return v.VisitChildren(ctx) } diff --git a/netmap/parser/query_parser.go b/netmap/parser/query_parser.go index 63577271..db19c937 100644 --- a/netmap/parser/query_parser.go +++ b/netmap/parser/query_parser.go @@ -44,70 +44,77 @@ func queryParserInit() { "STRING", "WS", } staticData.RuleNames = []string{ - "policy", "repStmt", "cbfStmt", "selectStmt", "clause", "filterExpr", - "filterStmt", "expr", "filterKey", "filterValue", "number", "keyword", - "ident", "identWC", + "policy", "selectFilterExpr", "repStmt", "cbfStmt", "selectStmt", "clause", + "filterExpr", "filterStmt", "expr", "filterKey", "filterValue", "number", + "keyword", "ident", "identWC", } staticData.PredictionContextCache = antlr.NewPredictionContextCache() staticData.serializedATN = []int32{ - 4, 1, 23, 138, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, + 4, 1, 23, 154, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, - 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 1, 0, 3, 0, 30, 8, 0, 1, - 0, 4, 0, 33, 8, 0, 11, 0, 12, 0, 34, 1, 0, 3, 0, 38, 8, 0, 1, 0, 5, 0, - 41, 8, 0, 10, 0, 12, 0, 44, 9, 0, 1, 0, 5, 0, 47, 8, 0, 10, 0, 12, 0, 50, - 9, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 58, 8, 1, 1, 2, 1, 2, 1, - 2, 1, 3, 1, 3, 1, 3, 1, 3, 3, 3, 67, 8, 3, 1, 3, 3, 3, 70, 8, 3, 1, 3, - 1, 3, 1, 3, 1, 3, 3, 3, 76, 8, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, - 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 91, 8, 5, 1, 5, 1, 5, 1, 5, - 1, 5, 1, 5, 1, 5, 5, 5, 99, 8, 5, 10, 5, 12, 5, 102, 9, 5, 1, 6, 1, 6, - 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 3, 7, 115, 8, 7, - 1, 8, 1, 8, 3, 8, 119, 8, 8, 1, 9, 1, 9, 1, 9, 3, 9, 124, 8, 9, 1, 10, - 1, 10, 1, 11, 1, 11, 1, 12, 1, 12, 3, 12, 132, 8, 12, 1, 13, 1, 13, 3, - 13, 136, 8, 13, 1, 13, 0, 1, 10, 14, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, - 20, 22, 24, 26, 0, 3, 1, 0, 14, 15, 1, 0, 20, 21, 2, 0, 6, 8, 10, 12, 142, - 0, 29, 1, 0, 0, 0, 2, 53, 1, 0, 0, 0, 4, 59, 1, 0, 0, 0, 6, 62, 1, 0, 0, - 0, 8, 77, 1, 0, 0, 0, 10, 90, 1, 0, 0, 0, 12, 103, 1, 0, 0, 0, 14, 114, - 1, 0, 0, 0, 16, 118, 1, 0, 0, 0, 18, 123, 1, 0, 0, 0, 20, 125, 1, 0, 0, - 0, 22, 127, 1, 0, 0, 0, 24, 131, 1, 0, 0, 0, 26, 135, 1, 0, 0, 0, 28, 30, - 5, 5, 0, 0, 29, 28, 1, 0, 0, 0, 29, 30, 1, 0, 0, 0, 30, 32, 1, 0, 0, 0, - 31, 33, 3, 2, 1, 0, 32, 31, 1, 0, 0, 0, 33, 34, 1, 0, 0, 0, 34, 32, 1, - 0, 0, 0, 34, 35, 1, 0, 0, 0, 35, 37, 1, 0, 0, 0, 36, 38, 3, 4, 2, 0, 37, - 36, 1, 0, 0, 0, 37, 38, 1, 0, 0, 0, 38, 42, 1, 0, 0, 0, 39, 41, 3, 6, 3, - 0, 40, 39, 1, 0, 0, 0, 41, 44, 1, 0, 0, 0, 42, 40, 1, 0, 0, 0, 42, 43, - 1, 0, 0, 0, 43, 48, 1, 0, 0, 0, 44, 42, 1, 0, 0, 0, 45, 47, 3, 12, 6, 0, - 46, 45, 1, 0, 0, 0, 47, 50, 1, 0, 0, 0, 48, 46, 1, 0, 0, 0, 48, 49, 1, - 0, 0, 0, 49, 51, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 51, 52, 5, 0, 0, 1, 52, - 1, 1, 0, 0, 0, 53, 54, 5, 6, 0, 0, 54, 57, 5, 20, 0, 0, 55, 56, 5, 7, 0, - 0, 56, 58, 3, 24, 12, 0, 57, 55, 1, 0, 0, 0, 57, 58, 1, 0, 0, 0, 58, 3, - 1, 0, 0, 0, 59, 60, 5, 9, 0, 0, 60, 61, 5, 20, 0, 0, 61, 5, 1, 0, 0, 0, - 62, 63, 5, 10, 0, 0, 63, 69, 5, 20, 0, 0, 64, 66, 5, 7, 0, 0, 65, 67, 3, - 8, 4, 0, 66, 65, 1, 0, 0, 0, 66, 67, 1, 0, 0, 0, 67, 68, 1, 0, 0, 0, 68, - 70, 3, 24, 12, 0, 69, 64, 1, 0, 0, 0, 69, 70, 1, 0, 0, 0, 70, 71, 1, 0, - 0, 0, 71, 72, 5, 11, 0, 0, 72, 75, 3, 26, 13, 0, 73, 74, 5, 8, 0, 0, 74, - 76, 3, 24, 12, 0, 75, 73, 1, 0, 0, 0, 75, 76, 1, 0, 0, 0, 76, 7, 1, 0, - 0, 0, 77, 78, 7, 0, 0, 0, 78, 9, 1, 0, 0, 0, 79, 80, 6, 5, -1, 0, 80, 81, - 5, 1, 0, 0, 81, 82, 5, 16, 0, 0, 82, 83, 3, 10, 5, 0, 83, 84, 5, 17, 0, - 0, 84, 91, 1, 0, 0, 0, 85, 86, 5, 16, 0, 0, 86, 87, 3, 10, 5, 0, 87, 88, - 5, 17, 0, 0, 88, 91, 1, 0, 0, 0, 89, 91, 3, 14, 7, 0, 90, 79, 1, 0, 0, - 0, 90, 85, 1, 0, 0, 0, 90, 89, 1, 0, 0, 0, 91, 100, 1, 0, 0, 0, 92, 93, - 10, 4, 0, 0, 93, 94, 5, 2, 0, 0, 94, 99, 3, 10, 5, 5, 95, 96, 10, 3, 0, - 0, 96, 97, 5, 3, 0, 0, 97, 99, 3, 10, 5, 4, 98, 92, 1, 0, 0, 0, 98, 95, - 1, 0, 0, 0, 99, 102, 1, 0, 0, 0, 100, 98, 1, 0, 0, 0, 100, 101, 1, 0, 0, - 0, 101, 11, 1, 0, 0, 0, 102, 100, 1, 0, 0, 0, 103, 104, 5, 12, 0, 0, 104, - 105, 3, 10, 5, 0, 105, 106, 5, 8, 0, 0, 106, 107, 3, 24, 12, 0, 107, 13, - 1, 0, 0, 0, 108, 109, 5, 18, 0, 0, 109, 115, 3, 24, 12, 0, 110, 111, 3, - 16, 8, 0, 111, 112, 5, 4, 0, 0, 112, 113, 3, 18, 9, 0, 113, 115, 1, 0, - 0, 0, 114, 108, 1, 0, 0, 0, 114, 110, 1, 0, 0, 0, 115, 15, 1, 0, 0, 0, - 116, 119, 3, 24, 12, 0, 117, 119, 5, 22, 0, 0, 118, 116, 1, 0, 0, 0, 118, - 117, 1, 0, 0, 0, 119, 17, 1, 0, 0, 0, 120, 124, 3, 24, 12, 0, 121, 124, - 3, 20, 10, 0, 122, 124, 5, 22, 0, 0, 123, 120, 1, 0, 0, 0, 123, 121, 1, - 0, 0, 0, 123, 122, 1, 0, 0, 0, 124, 19, 1, 0, 0, 0, 125, 126, 7, 1, 0, - 0, 126, 21, 1, 0, 0, 0, 127, 128, 7, 2, 0, 0, 128, 23, 1, 0, 0, 0, 129, - 132, 3, 22, 11, 0, 130, 132, 5, 19, 0, 0, 131, 129, 1, 0, 0, 0, 131, 130, - 1, 0, 0, 0, 132, 25, 1, 0, 0, 0, 133, 136, 3, 24, 12, 0, 134, 136, 5, 13, - 0, 0, 135, 133, 1, 0, 0, 0, 135, 134, 1, 0, 0, 0, 136, 27, 1, 0, 0, 0, - 17, 29, 34, 37, 42, 48, 57, 66, 69, 75, 90, 98, 100, 114, 118, 123, 131, - 135, + 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 1, 0, 3, 0, + 32, 8, 0, 1, 0, 4, 0, 35, 8, 0, 11, 0, 12, 0, 36, 1, 0, 3, 0, 40, 8, 0, + 1, 0, 5, 0, 43, 8, 0, 10, 0, 12, 0, 46, 9, 0, 1, 0, 5, 0, 49, 8, 0, 10, + 0, 12, 0, 52, 9, 0, 1, 0, 1, 0, 1, 1, 3, 1, 57, 8, 1, 1, 1, 3, 1, 60, 8, + 1, 1, 1, 5, 1, 63, 8, 1, 10, 1, 12, 1, 66, 9, 1, 1, 1, 1, 1, 1, 2, 1, 2, + 1, 2, 1, 2, 3, 2, 74, 8, 2, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 3, + 4, 83, 8, 4, 1, 4, 3, 4, 86, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 92, 8, + 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, + 6, 1, 6, 3, 6, 107, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 115, + 8, 6, 10, 6, 12, 6, 118, 9, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, + 1, 8, 1, 8, 1, 8, 1, 8, 3, 8, 131, 8, 8, 1, 9, 1, 9, 3, 9, 135, 8, 9, 1, + 10, 1, 10, 1, 10, 3, 10, 140, 8, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, + 1, 13, 3, 13, 148, 8, 13, 1, 14, 1, 14, 3, 14, 152, 8, 14, 1, 14, 0, 1, + 12, 15, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 0, 3, 1, + 0, 14, 15, 1, 0, 20, 21, 2, 0, 6, 8, 10, 12, 160, 0, 31, 1, 0, 0, 0, 2, + 56, 1, 0, 0, 0, 4, 69, 1, 0, 0, 0, 6, 75, 1, 0, 0, 0, 8, 78, 1, 0, 0, 0, + 10, 93, 1, 0, 0, 0, 12, 106, 1, 0, 0, 0, 14, 119, 1, 0, 0, 0, 16, 130, + 1, 0, 0, 0, 18, 134, 1, 0, 0, 0, 20, 139, 1, 0, 0, 0, 22, 141, 1, 0, 0, + 0, 24, 143, 1, 0, 0, 0, 26, 147, 1, 0, 0, 0, 28, 151, 1, 0, 0, 0, 30, 32, + 5, 5, 0, 0, 31, 30, 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 34, 1, 0, 0, 0, + 33, 35, 3, 4, 2, 0, 34, 33, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 34, 1, + 0, 0, 0, 36, 37, 1, 0, 0, 0, 37, 39, 1, 0, 0, 0, 38, 40, 3, 6, 3, 0, 39, + 38, 1, 0, 0, 0, 39, 40, 1, 0, 0, 0, 40, 44, 1, 0, 0, 0, 41, 43, 3, 8, 4, + 0, 42, 41, 1, 0, 0, 0, 43, 46, 1, 0, 0, 0, 44, 42, 1, 0, 0, 0, 44, 45, + 1, 0, 0, 0, 45, 50, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 47, 49, 3, 14, 7, 0, + 48, 47, 1, 0, 0, 0, 49, 52, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 50, 51, 1, + 0, 0, 0, 51, 53, 1, 0, 0, 0, 52, 50, 1, 0, 0, 0, 53, 54, 5, 0, 0, 1, 54, + 1, 1, 0, 0, 0, 55, 57, 3, 6, 3, 0, 56, 55, 1, 0, 0, 0, 56, 57, 1, 0, 0, + 0, 57, 59, 1, 0, 0, 0, 58, 60, 3, 8, 4, 0, 59, 58, 1, 0, 0, 0, 59, 60, + 1, 0, 0, 0, 60, 64, 1, 0, 0, 0, 61, 63, 3, 14, 7, 0, 62, 61, 1, 0, 0, 0, + 63, 66, 1, 0, 0, 0, 64, 62, 1, 0, 0, 0, 64, 65, 1, 0, 0, 0, 65, 67, 1, + 0, 0, 0, 66, 64, 1, 0, 0, 0, 67, 68, 5, 0, 0, 1, 68, 3, 1, 0, 0, 0, 69, + 70, 5, 6, 0, 0, 70, 73, 5, 20, 0, 0, 71, 72, 5, 7, 0, 0, 72, 74, 3, 26, + 13, 0, 73, 71, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 5, 1, 0, 0, 0, 75, 76, + 5, 9, 0, 0, 76, 77, 5, 20, 0, 0, 77, 7, 1, 0, 0, 0, 78, 79, 5, 10, 0, 0, + 79, 85, 5, 20, 0, 0, 80, 82, 5, 7, 0, 0, 81, 83, 3, 10, 5, 0, 82, 81, 1, + 0, 0, 0, 82, 83, 1, 0, 0, 0, 83, 84, 1, 0, 0, 0, 84, 86, 3, 26, 13, 0, + 85, 80, 1, 0, 0, 0, 85, 86, 1, 0, 0, 0, 86, 87, 1, 0, 0, 0, 87, 88, 5, + 11, 0, 0, 88, 91, 3, 28, 14, 0, 89, 90, 5, 8, 0, 0, 90, 92, 3, 26, 13, + 0, 91, 89, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 9, 1, 0, 0, 0, 93, 94, 7, + 0, 0, 0, 94, 11, 1, 0, 0, 0, 95, 96, 6, 6, -1, 0, 96, 97, 5, 1, 0, 0, 97, + 98, 5, 16, 0, 0, 98, 99, 3, 12, 6, 0, 99, 100, 5, 17, 0, 0, 100, 107, 1, + 0, 0, 0, 101, 102, 5, 16, 0, 0, 102, 103, 3, 12, 6, 0, 103, 104, 5, 17, + 0, 0, 104, 107, 1, 0, 0, 0, 105, 107, 3, 16, 8, 0, 106, 95, 1, 0, 0, 0, + 106, 101, 1, 0, 0, 0, 106, 105, 1, 0, 0, 0, 107, 116, 1, 0, 0, 0, 108, + 109, 10, 4, 0, 0, 109, 110, 5, 2, 0, 0, 110, 115, 3, 12, 6, 5, 111, 112, + 10, 3, 0, 0, 112, 113, 5, 3, 0, 0, 113, 115, 3, 12, 6, 4, 114, 108, 1, + 0, 0, 0, 114, 111, 1, 0, 0, 0, 115, 118, 1, 0, 0, 0, 116, 114, 1, 0, 0, + 0, 116, 117, 1, 0, 0, 0, 117, 13, 1, 0, 0, 0, 118, 116, 1, 0, 0, 0, 119, + 120, 5, 12, 0, 0, 120, 121, 3, 12, 6, 0, 121, 122, 5, 8, 0, 0, 122, 123, + 3, 26, 13, 0, 123, 15, 1, 0, 0, 0, 124, 125, 5, 18, 0, 0, 125, 131, 3, + 26, 13, 0, 126, 127, 3, 18, 9, 0, 127, 128, 5, 4, 0, 0, 128, 129, 3, 20, + 10, 0, 129, 131, 1, 0, 0, 0, 130, 124, 1, 0, 0, 0, 130, 126, 1, 0, 0, 0, + 131, 17, 1, 0, 0, 0, 132, 135, 3, 26, 13, 0, 133, 135, 5, 22, 0, 0, 134, + 132, 1, 0, 0, 0, 134, 133, 1, 0, 0, 0, 135, 19, 1, 0, 0, 0, 136, 140, 3, + 26, 13, 0, 137, 140, 3, 22, 11, 0, 138, 140, 5, 22, 0, 0, 139, 136, 1, + 0, 0, 0, 139, 137, 1, 0, 0, 0, 139, 138, 1, 0, 0, 0, 140, 21, 1, 0, 0, + 0, 141, 142, 7, 1, 0, 0, 142, 23, 1, 0, 0, 0, 143, 144, 7, 2, 0, 0, 144, + 25, 1, 0, 0, 0, 145, 148, 3, 24, 12, 0, 146, 148, 5, 19, 0, 0, 147, 145, + 1, 0, 0, 0, 147, 146, 1, 0, 0, 0, 148, 27, 1, 0, 0, 0, 149, 152, 3, 26, + 13, 0, 150, 152, 5, 13, 0, 0, 151, 149, 1, 0, 0, 0, 151, 150, 1, 0, 0, + 0, 152, 29, 1, 0, 0, 0, 20, 31, 36, 39, 44, 50, 56, 59, 64, 73, 82, 85, + 91, 106, 114, 116, 130, 134, 139, 147, 151, } deserializer := antlr.NewATNDeserializer(nil) staticData.atn = deserializer.Deserialize(staticData.serializedATN) @@ -173,20 +180,21 @@ const ( // Query rules. const ( - QueryRULE_policy = 0 - QueryRULE_repStmt = 1 - QueryRULE_cbfStmt = 2 - QueryRULE_selectStmt = 3 - QueryRULE_clause = 4 - QueryRULE_filterExpr = 5 - QueryRULE_filterStmt = 6 - QueryRULE_expr = 7 - QueryRULE_filterKey = 8 - QueryRULE_filterValue = 9 - QueryRULE_number = 10 - QueryRULE_keyword = 11 - QueryRULE_ident = 12 - QueryRULE_identWC = 13 + QueryRULE_policy = 0 + QueryRULE_selectFilterExpr = 1 + QueryRULE_repStmt = 2 + QueryRULE_cbfStmt = 3 + QueryRULE_selectStmt = 4 + QueryRULE_clause = 5 + QueryRULE_filterExpr = 6 + QueryRULE_filterStmt = 7 + QueryRULE_expr = 8 + QueryRULE_filterKey = 9 + QueryRULE_filterValue = 10 + QueryRULE_number = 11 + QueryRULE_keyword = 12 + QueryRULE_ident = 13 + QueryRULE_identWC = 14 ) // IPolicyContext is an interface to support dynamic dispatch. @@ -414,7 +422,7 @@ func (p *Query) Policy() (localctx IPolicyContext) { var _la int p.EnterOuterAlt(localctx, 1) - p.SetState(29) + p.SetState(31) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -423,7 +431,7 @@ func (p *Query) Policy() (localctx IPolicyContext) { if _la == QueryUNIQUE { { - p.SetState(28) + p.SetState(30) p.Match(QueryUNIQUE) if p.HasError() { // Recognition error - abort rule @@ -432,7 +440,7 @@ func (p *Query) Policy() (localctx IPolicyContext) { } } - p.SetState(32) + p.SetState(34) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -441,18 +449,18 @@ func (p *Query) Policy() (localctx IPolicyContext) { for ok := true; ok; ok = _la == QueryREP { { - p.SetState(31) + p.SetState(33) p.RepStmt() } - p.SetState(34) + p.SetState(36) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit } _la = p.GetTokenStream().LA(1) } - p.SetState(37) + p.SetState(39) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -461,12 +469,12 @@ func (p *Query) Policy() (localctx IPolicyContext) { if _la == QueryCBF { { - p.SetState(36) + p.SetState(38) p.CbfStmt() } } - p.SetState(42) + p.SetState(44) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -475,18 +483,18 @@ func (p *Query) Policy() (localctx IPolicyContext) { for _la == QuerySELECT { { - p.SetState(39) + p.SetState(41) p.SelectStmt() } - p.SetState(44) + p.SetState(46) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit } _la = p.GetTokenStream().LA(1) } - p.SetState(48) + p.SetState(50) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -495,11 +503,11 @@ func (p *Query) Policy() (localctx IPolicyContext) { for _la == QueryFILTER { { - p.SetState(45) + p.SetState(47) p.FilterStmt() } - p.SetState(50) + p.SetState(52) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -507,7 +515,228 @@ func (p *Query) Policy() (localctx IPolicyContext) { _la = p.GetTokenStream().LA(1) } { - p.SetState(51) + p.SetState(53) + p.Match(QueryEOF) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISelectFilterExprContext is an interface to support dynamic dispatch. +type ISelectFilterExprContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + EOF() antlr.TerminalNode + CbfStmt() ICbfStmtContext + SelectStmt() ISelectStmtContext + AllFilterStmt() []IFilterStmtContext + FilterStmt(i int) IFilterStmtContext + + // IsSelectFilterExprContext differentiates from other interfaces. + IsSelectFilterExprContext() +} + +type SelectFilterExprContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySelectFilterExprContext() *SelectFilterExprContext { + var p = new(SelectFilterExprContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = QueryRULE_selectFilterExpr + return p +} + +func InitEmptySelectFilterExprContext(p *SelectFilterExprContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = QueryRULE_selectFilterExpr +} + +func (*SelectFilterExprContext) IsSelectFilterExprContext() {} + +func NewSelectFilterExprContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SelectFilterExprContext { + var p = new(SelectFilterExprContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = QueryRULE_selectFilterExpr + + return p +} + +func (s *SelectFilterExprContext) GetParser() antlr.Parser { return s.parser } + +func (s *SelectFilterExprContext) EOF() antlr.TerminalNode { + return s.GetToken(QueryEOF, 0) +} + +func (s *SelectFilterExprContext) CbfStmt() ICbfStmtContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ICbfStmtContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ICbfStmtContext) +} + +func (s *SelectFilterExprContext) SelectStmt() ISelectStmtContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISelectStmtContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISelectStmtContext) +} + +func (s *SelectFilterExprContext) AllFilterStmt() []IFilterStmtContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IFilterStmtContext); ok { + len++ + } + } + + tst := make([]IFilterStmtContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IFilterStmtContext); ok { + tst[i] = t.(IFilterStmtContext) + i++ + } + } + + return tst +} + +func (s *SelectFilterExprContext) FilterStmt(i int) IFilterStmtContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IFilterStmtContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IFilterStmtContext) +} + +func (s *SelectFilterExprContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SelectFilterExprContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SelectFilterExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case QueryVisitor: + return t.VisitSelectFilterExpr(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *Query) SelectFilterExpr() (localctx ISelectFilterExprContext) { + localctx = NewSelectFilterExprContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 2, QueryRULE_selectFilterExpr) + var _la int + + p.EnterOuterAlt(localctx, 1) + p.SetState(56) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == QueryCBF { + { + p.SetState(55) + p.CbfStmt() + } + + } + p.SetState(59) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == QuerySELECT { + { + p.SetState(58) + p.SelectStmt() + } + + } + p.SetState(64) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + for _la == QueryFILTER { + { + p.SetState(61) + p.FilterStmt() + } + + p.SetState(66) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + } + { + p.SetState(67) p.Match(QueryEOF) if p.HasError() { // Recognition error - abort rule @@ -647,12 +876,12 @@ func (s *RepStmtContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { func (p *Query) RepStmt() (localctx IRepStmtContext) { localctx = NewRepStmtContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 2, QueryRULE_repStmt) + p.EnterRule(localctx, 4, QueryRULE_repStmt) var _la int p.EnterOuterAlt(localctx, 1) { - p.SetState(53) + p.SetState(69) p.Match(QueryREP) if p.HasError() { // Recognition error - abort rule @@ -660,7 +889,7 @@ func (p *Query) RepStmt() (localctx IRepStmtContext) { } } { - p.SetState(54) + p.SetState(70) var _m = p.Match(QueryNUMBER1) @@ -670,7 +899,7 @@ func (p *Query) RepStmt() (localctx IRepStmtContext) { goto errorExit } } - p.SetState(57) + p.SetState(73) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -679,7 +908,7 @@ func (p *Query) RepStmt() (localctx IRepStmtContext) { if _la == QueryIN { { - p.SetState(55) + p.SetState(71) p.Match(QueryIN) if p.HasError() { // Recognition error - abort rule @@ -687,7 +916,7 @@ func (p *Query) RepStmt() (localctx IRepStmtContext) { } } { - p.SetState(56) + p.SetState(72) var _x = p.Ident() @@ -795,10 +1024,10 @@ func (s *CbfStmtContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { func (p *Query) CbfStmt() (localctx ICbfStmtContext) { localctx = NewCbfStmtContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 4, QueryRULE_cbfStmt) + p.EnterRule(localctx, 6, QueryRULE_cbfStmt) p.EnterOuterAlt(localctx, 1) { - p.SetState(59) + p.SetState(75) p.Match(QueryCBF) if p.HasError() { // Recognition error - abort rule @@ -806,7 +1035,7 @@ func (p *Query) CbfStmt() (localctx ICbfStmtContext) { } } { - p.SetState(60) + p.SetState(76) var _m = p.Match(QueryNUMBER1) @@ -1041,12 +1270,12 @@ func (s *SelectStmtContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { func (p *Query) SelectStmt() (localctx ISelectStmtContext) { localctx = NewSelectStmtContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 6, QueryRULE_selectStmt) + p.EnterRule(localctx, 8, QueryRULE_selectStmt) var _la int p.EnterOuterAlt(localctx, 1) { - p.SetState(62) + p.SetState(78) p.Match(QuerySELECT) if p.HasError() { // Recognition error - abort rule @@ -1054,7 +1283,7 @@ func (p *Query) SelectStmt() (localctx ISelectStmtContext) { } } { - p.SetState(63) + p.SetState(79) var _m = p.Match(QueryNUMBER1) @@ -1064,7 +1293,7 @@ func (p *Query) SelectStmt() (localctx ISelectStmtContext) { goto errorExit } } - p.SetState(69) + p.SetState(85) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -1073,14 +1302,14 @@ func (p *Query) SelectStmt() (localctx ISelectStmtContext) { if _la == QueryIN { { - p.SetState(64) + p.SetState(80) p.Match(QueryIN) if p.HasError() { // Recognition error - abort rule goto errorExit } } - p.SetState(66) + p.SetState(82) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -1089,13 +1318,13 @@ func (p *Query) SelectStmt() (localctx ISelectStmtContext) { if _la == QueryCLAUSE_SAME || _la == QueryCLAUSE_DISTINCT { { - p.SetState(65) + p.SetState(81) p.Clause() } } { - p.SetState(68) + p.SetState(84) var _x = p.Ident() @@ -1104,7 +1333,7 @@ func (p *Query) SelectStmt() (localctx ISelectStmtContext) { } { - p.SetState(71) + p.SetState(87) p.Match(QueryFROM) if p.HasError() { // Recognition error - abort rule @@ -1112,13 +1341,13 @@ func (p *Query) SelectStmt() (localctx ISelectStmtContext) { } } { - p.SetState(72) + p.SetState(88) var _x = p.IdentWC() localctx.(*SelectStmtContext).Filter = _x } - p.SetState(75) + p.SetState(91) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -1127,7 +1356,7 @@ func (p *Query) SelectStmt() (localctx ISelectStmtContext) { if _la == QueryAS { { - p.SetState(73) + p.SetState(89) p.Match(QueryAS) if p.HasError() { // Recognition error - abort rule @@ -1135,7 +1364,7 @@ func (p *Query) SelectStmt() (localctx ISelectStmtContext) { } } { - p.SetState(74) + p.SetState(90) var _x = p.Ident() @@ -1232,12 +1461,12 @@ func (s *ClauseContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { func (p *Query) Clause() (localctx IClauseContext) { localctx = NewClauseContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 8, QueryRULE_clause) + p.EnterRule(localctx, 10, QueryRULE_clause) var _la int p.EnterOuterAlt(localctx, 1) { - p.SetState(77) + p.SetState(93) _la = p.GetTokenStream().LA(1) if !(_la == QueryCLAUSE_SAME || _la == QueryCLAUSE_DISTINCT) { @@ -1464,12 +1693,12 @@ func (p *Query) filterExpr(_p int) (localctx IFilterExprContext) { localctx = NewFilterExprContext(p, p.GetParserRuleContext(), _parentState) var _prevctx IFilterExprContext = localctx var _ antlr.ParserRuleContext = _prevctx // TODO: To prevent unused variable warning. - _startState := 10 - p.EnterRecursionRule(localctx, 10, QueryRULE_filterExpr, _p) + _startState := 12 + p.EnterRecursionRule(localctx, 12, QueryRULE_filterExpr, _p) var _alt int p.EnterOuterAlt(localctx, 1) - p.SetState(90) + p.SetState(106) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -1478,7 +1707,7 @@ func (p *Query) filterExpr(_p int) (localctx IFilterExprContext) { switch p.GetTokenStream().LA(1) { case QueryNOT_OP: { - p.SetState(80) + p.SetState(96) var _m = p.Match(QueryNOT_OP) @@ -1489,7 +1718,7 @@ func (p *Query) filterExpr(_p int) (localctx IFilterExprContext) { } } { - p.SetState(81) + p.SetState(97) p.Match(QueryL_PAREN) if p.HasError() { // Recognition error - abort rule @@ -1497,14 +1726,14 @@ func (p *Query) filterExpr(_p int) (localctx IFilterExprContext) { } } { - p.SetState(82) + p.SetState(98) var _x = p.filterExpr(0) localctx.(*FilterExprContext).F1 = _x } { - p.SetState(83) + p.SetState(99) p.Match(QueryR_PAREN) if p.HasError() { // Recognition error - abort rule @@ -1514,7 +1743,7 @@ func (p *Query) filterExpr(_p int) (localctx IFilterExprContext) { case QueryL_PAREN: { - p.SetState(85) + p.SetState(101) p.Match(QueryL_PAREN) if p.HasError() { // Recognition error - abort rule @@ -1522,14 +1751,14 @@ func (p *Query) filterExpr(_p int) (localctx IFilterExprContext) { } } { - p.SetState(86) + p.SetState(102) var _x = p.filterExpr(0) localctx.(*FilterExprContext).Inner = _x } { - p.SetState(87) + p.SetState(103) p.Match(QueryR_PAREN) if p.HasError() { // Recognition error - abort rule @@ -1539,7 +1768,7 @@ func (p *Query) filterExpr(_p int) (localctx IFilterExprContext) { case QueryREP, QueryIN, QueryAS, QuerySELECT, QueryFROM, QueryFILTER, QueryAT, QueryIDENT, QuerySTRING: { - p.SetState(89) + p.SetState(105) p.Expr() } @@ -1548,12 +1777,12 @@ func (p *Query) filterExpr(_p int) (localctx IFilterExprContext) { goto errorExit } p.GetParserRuleContext().SetStop(p.GetTokenStream().LT(-1)) - p.SetState(100) + p.SetState(116) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit } - _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 11, p.GetParserRuleContext()) + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 14, p.GetParserRuleContext()) if p.HasError() { goto errorExit } @@ -1563,25 +1792,25 @@ func (p *Query) filterExpr(_p int) (localctx IFilterExprContext) { p.TriggerExitRuleEvent() } _prevctx = localctx - p.SetState(98) + p.SetState(114) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit } - switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 10, p.GetParserRuleContext()) { + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 13, p.GetParserRuleContext()) { case 1: localctx = NewFilterExprContext(p, _parentctx, _parentState) localctx.(*FilterExprContext).F1 = _prevctx p.PushNewRecursionContext(localctx, _startState, QueryRULE_filterExpr) - p.SetState(92) + p.SetState(108) if !(p.Precpred(p.GetParserRuleContext(), 4)) { p.SetError(antlr.NewFailedPredicateException(p, "p.Precpred(p.GetParserRuleContext(), 4)", "")) goto errorExit } { - p.SetState(93) + p.SetState(109) var _m = p.Match(QueryAND_OP) @@ -1592,7 +1821,7 @@ func (p *Query) filterExpr(_p int) (localctx IFilterExprContext) { } } { - p.SetState(94) + p.SetState(110) var _x = p.filterExpr(5) @@ -1603,14 +1832,14 @@ func (p *Query) filterExpr(_p int) (localctx IFilterExprContext) { localctx = NewFilterExprContext(p, _parentctx, _parentState) localctx.(*FilterExprContext).F1 = _prevctx p.PushNewRecursionContext(localctx, _startState, QueryRULE_filterExpr) - p.SetState(95) + p.SetState(111) if !(p.Precpred(p.GetParserRuleContext(), 3)) { p.SetError(antlr.NewFailedPredicateException(p, "p.Precpred(p.GetParserRuleContext(), 3)", "")) goto errorExit } { - p.SetState(96) + p.SetState(112) var _m = p.Match(QueryOR_OP) @@ -1621,7 +1850,7 @@ func (p *Query) filterExpr(_p int) (localctx IFilterExprContext) { } } { - p.SetState(97) + p.SetState(113) var _x = p.filterExpr(4) @@ -1633,12 +1862,12 @@ func (p *Query) filterExpr(_p int) (localctx IFilterExprContext) { } } - p.SetState(102) + p.SetState(118) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit } - _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 11, p.GetParserRuleContext()) + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 14, p.GetParserRuleContext()) if p.HasError() { goto errorExit } @@ -1788,10 +2017,10 @@ func (s *FilterStmtContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { func (p *Query) FilterStmt() (localctx IFilterStmtContext) { localctx = NewFilterStmtContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 12, QueryRULE_filterStmt) + p.EnterRule(localctx, 14, QueryRULE_filterStmt) p.EnterOuterAlt(localctx, 1) { - p.SetState(103) + p.SetState(119) p.Match(QueryFILTER) if p.HasError() { // Recognition error - abort rule @@ -1799,14 +2028,14 @@ func (p *Query) FilterStmt() (localctx IFilterStmtContext) { } } { - p.SetState(104) + p.SetState(120) var _x = p.filterExpr(0) localctx.(*FilterStmtContext).Expr = _x } { - p.SetState(105) + p.SetState(121) p.Match(QueryAS) if p.HasError() { // Recognition error - abort rule @@ -1814,7 +2043,7 @@ func (p *Query) FilterStmt() (localctx IFilterStmtContext) { } } { - p.SetState(106) + p.SetState(122) var _x = p.Ident() @@ -1993,8 +2222,8 @@ func (s *ExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { func (p *Query) Expr() (localctx IExprContext) { localctx = NewExprContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 14, QueryRULE_expr) - p.SetState(114) + p.EnterRule(localctx, 16, QueryRULE_expr) + p.SetState(130) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -2004,7 +2233,7 @@ func (p *Query) Expr() (localctx IExprContext) { case QueryAT: p.EnterOuterAlt(localctx, 1) { - p.SetState(108) + p.SetState(124) p.Match(QueryAT) if p.HasError() { // Recognition error - abort rule @@ -2012,7 +2241,7 @@ func (p *Query) Expr() (localctx IExprContext) { } } { - p.SetState(109) + p.SetState(125) var _x = p.Ident() @@ -2022,14 +2251,14 @@ func (p *Query) Expr() (localctx IExprContext) { case QueryREP, QueryIN, QueryAS, QuerySELECT, QueryFROM, QueryFILTER, QueryIDENT, QuerySTRING: p.EnterOuterAlt(localctx, 2) { - p.SetState(110) + p.SetState(126) var _x = p.FilterKey() localctx.(*ExprContext).Key = _x } { - p.SetState(111) + p.SetState(127) p.Match(QuerySIMPLE_OP) if p.HasError() { // Recognition error - abort rule @@ -2037,7 +2266,7 @@ func (p *Query) Expr() (localctx IExprContext) { } } { - p.SetState(112) + p.SetState(128) var _x = p.FilterValue() @@ -2149,8 +2378,8 @@ func (s *FilterKeyContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { func (p *Query) FilterKey() (localctx IFilterKeyContext) { localctx = NewFilterKeyContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 16, QueryRULE_filterKey) - p.SetState(118) + p.EnterRule(localctx, 18, QueryRULE_filterKey) + p.SetState(134) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -2160,14 +2389,14 @@ func (p *Query) FilterKey() (localctx IFilterKeyContext) { case QueryREP, QueryIN, QueryAS, QuerySELECT, QueryFROM, QueryFILTER, QueryIDENT: p.EnterOuterAlt(localctx, 1) { - p.SetState(116) + p.SetState(132) p.Ident() } case QuerySTRING: p.EnterOuterAlt(localctx, 2) { - p.SetState(117) + p.SetState(133) p.Match(QuerySTRING) if p.HasError() { // Recognition error - abort rule @@ -2297,8 +2526,8 @@ func (s *FilterValueContext) Accept(visitor antlr.ParseTreeVisitor) interface{} func (p *Query) FilterValue() (localctx IFilterValueContext) { localctx = NewFilterValueContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 18, QueryRULE_filterValue) - p.SetState(123) + p.EnterRule(localctx, 20, QueryRULE_filterValue) + p.SetState(139) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -2308,21 +2537,21 @@ func (p *Query) FilterValue() (localctx IFilterValueContext) { case QueryREP, QueryIN, QueryAS, QuerySELECT, QueryFROM, QueryFILTER, QueryIDENT: p.EnterOuterAlt(localctx, 1) { - p.SetState(120) + p.SetState(136) p.Ident() } case QueryNUMBER1, QueryZERO: p.EnterOuterAlt(localctx, 2) { - p.SetState(121) + p.SetState(137) p.Number() } case QuerySTRING: p.EnterOuterAlt(localctx, 3) { - p.SetState(122) + p.SetState(138) p.Match(QuerySTRING) if p.HasError() { // Recognition error - abort rule @@ -2423,12 +2652,12 @@ func (s *NumberContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { func (p *Query) Number() (localctx INumberContext) { localctx = NewNumberContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 20, QueryRULE_number) + p.EnterRule(localctx, 22, QueryRULE_number) var _la int p.EnterOuterAlt(localctx, 1) { - p.SetState(125) + p.SetState(141) _la = p.GetTokenStream().LA(1) if !(_la == QueryNUMBER1 || _la == QueryZERO) { @@ -2547,12 +2776,12 @@ func (s *KeywordContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { func (p *Query) Keyword() (localctx IKeywordContext) { localctx = NewKeywordContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 22, QueryRULE_keyword) + p.EnterRule(localctx, 24, QueryRULE_keyword) var _la int p.EnterOuterAlt(localctx, 1) { - p.SetState(127) + p.SetState(143) _la = p.GetTokenStream().LA(1) if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&7616) != 0) { @@ -2663,8 +2892,8 @@ func (s *IdentContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { func (p *Query) Ident() (localctx IIdentContext) { localctx = NewIdentContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 24, QueryRULE_ident) - p.SetState(131) + p.EnterRule(localctx, 26, QueryRULE_ident) + p.SetState(147) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -2674,14 +2903,14 @@ func (p *Query) Ident() (localctx IIdentContext) { case QueryREP, QueryIN, QueryAS, QuerySELECT, QueryFROM, QueryFILTER: p.EnterOuterAlt(localctx, 1) { - p.SetState(129) + p.SetState(145) p.Keyword() } case QueryIDENT: p.EnterOuterAlt(localctx, 2) { - p.SetState(130) + p.SetState(146) p.Match(QueryIDENT) if p.HasError() { // Recognition error - abort rule @@ -2794,8 +3023,8 @@ func (s *IdentWCContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { func (p *Query) IdentWC() (localctx IIdentWCContext) { localctx = NewIdentWCContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 26, QueryRULE_identWC) - p.SetState(135) + p.EnterRule(localctx, 28, QueryRULE_identWC) + p.SetState(151) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -2805,14 +3034,14 @@ func (p *Query) IdentWC() (localctx IIdentWCContext) { case QueryREP, QueryIN, QueryAS, QuerySELECT, QueryFROM, QueryFILTER, QueryIDENT: p.EnterOuterAlt(localctx, 1) { - p.SetState(133) + p.SetState(149) p.Ident() } case QueryWILDCARD: p.EnterOuterAlt(localctx, 2) { - p.SetState(134) + p.SetState(150) p.Match(QueryWILDCARD) if p.HasError() { // Recognition error - abort rule @@ -2840,7 +3069,7 @@ errorExit: func (p *Query) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool { switch ruleIndex { - case 5: + case 6: var t *FilterExprContext = nil if localctx != nil { t = localctx.(*FilterExprContext) diff --git a/netmap/parser/query_visitor.go b/netmap/parser/query_visitor.go index 960dc2fb..7550d99e 100644 --- a/netmap/parser/query_visitor.go +++ b/netmap/parser/query_visitor.go @@ -11,6 +11,9 @@ type QueryVisitor interface { // Visit a parse tree produced by Query#policy. VisitPolicy(ctx *PolicyContext) interface{} + // Visit a parse tree produced by Query#selectFilterExpr. + VisitSelectFilterExpr(ctx *SelectFilterExprContext) interface{} + // Visit a parse tree produced by Query#repStmt. VisitRepStmt(ctx *RepStmtContext) interface{} diff --git a/netmap/policy.go b/netmap/policy.go index 323050eb..d7065561 100644 --- a/netmap/policy.go +++ b/netmap/policy.go @@ -560,6 +560,44 @@ func (p *PlacementPolicy) DecodeString(s string) error { return nil } +// SelectFilterExpr is an expression containing only selectors and filters. +// It's useful to evaluate their effect before being used in a policy. +type SelectFilterExpr struct { + cbf uint32 + selector *netmap.Selector + filters []netmap.Filter +} + +// DecodeString decodes a string into a SelectFilterExpr. +// Returns an error if s is malformed. +func DecodeSelectFilterString(s string) (*SelectFilterExpr, error) { + var v policyVisitor + + input := antlr.NewInputStream(s) + lexer := parser.NewQueryLexer(input) + lexer.RemoveErrorListeners() + lexer.AddErrorListener(&v) + stream := antlr.NewCommonTokenStream(lexer, 0) + + pp := parser.NewQuery(stream) + pp.BuildParseTrees = true + + pp.RemoveErrorListeners() + pp.AddErrorListener(&v) + sfExpr := pp.SelectFilterExpr().Accept(&v) + + if len(v.errors) != 0 { + return nil, v.errors[0] + } + + parsed, ok := sfExpr.(*SelectFilterExpr) + if !ok { + return nil, fmt.Errorf("unexpected parsed instance type %T", sfExpr) + } + + return parsed, nil +} + var ( // errUnknownFilter is returned when a value of FROM in a query is unknown. errUnknownFilter = errors.New("filter not found") @@ -636,6 +674,39 @@ func (p *policyVisitor) VisitPolicy(ctx *parser.PolicyContext) any { return pl } +func (p *policyVisitor) VisitSelectFilterExpr(ctx *parser.SelectFilterExprContext) any { + if len(p.errors) != 0 { + return nil + } + + sfExpr := new(SelectFilterExpr) + + if cbfStmt := ctx.CbfStmt(); cbfStmt != nil { + cbf, ok := cbfStmt.(*parser.CbfStmtContext).Accept(p).(uint32) + if !ok { + return nil + } + sfExpr.cbf = cbf + } + + if selStmt := ctx.SelectStmt(); selStmt != nil { + sel, ok := selStmt.Accept(p).(*netmap.Selector) + if !ok { + return nil + } + sfExpr.selector = sel + } + + filtStmts := ctx.AllFilterStmt() + sfExpr.filters = make([]netmap.Filter, 0, len(filtStmts)) + + for _, f := range filtStmts { + sfExpr.filters = append(sfExpr.filters, *f.Accept(p).(*netmap.Filter)) + } + + return sfExpr +} + func (p *policyVisitor) VisitCbfStmt(ctx *parser.CbfStmtContext) any { cbf, err := strconv.ParseUint(ctx.GetBackupFactor().GetText(), 10, 32) if err != nil { diff --git a/netmap/policy_test.go b/netmap/policy_test.go index 98ce5f2b..f954eec0 100644 --- a/netmap/policy_test.go +++ b/netmap/policy_test.go @@ -78,3 +78,28 @@ func TestPlacementPolicyEncoding(t *testing.T) { require.Equal(t, v, v2) }) } + +func TestDecodeSelectFilterExpr(t *testing.T) { + for _, s := range []string{ + "SELECT 1 FROM *", + "FILTER Color EQ 'Red' AS RedNode", + ` + FILTER Color EQ 'Red' AS RedNode + FILTER @RedNode AND Shape EQ 'Cirle' AS RedCircleNode + `, + ` + SELECT 1 FROM RedCircleNode + FILTER Color EQ 'Red' AS RedNode + FILTER @RedNode AND Shape EQ 'Cirle' AS RedCircleNode + `, + ` + CBF 1 + SELECT 1 FROM RedCircleNode + FILTER Color EQ 'Red' AS RedNode + FILTER @RedNode AND Shape EQ 'Cirle' AS RedCircleNode + `, + } { + _, err := DecodeSelectFilterString(s) + require.NoError(t, err) + } +} From fb05f7dc5ea44bc555de97d3cede75dc7f4b6fbd Mon Sep 17 00:00:00 2001 From: Alejandro Lopez Date: Tue, 11 Jul 2023 15:23:35 +0300 Subject: [PATCH 016/288] [#112] Add basic documentation for placement policies Signed-off-by: Alejandro Lopez --- doc/image/filter_illustration.svg | 4 + doc/image/placement_policy.svg | 4 + doc/image/rep_illustration.svg | 4 + doc/image/sample_netmap.svg | 4 + doc/image/select_illustration.svg | 4 + doc/policy.md | 445 ++++++++++++++++++++++++++++++ 6 files changed, 465 insertions(+) create mode 100644 doc/image/filter_illustration.svg create mode 100644 doc/image/placement_policy.svg create mode 100644 doc/image/rep_illustration.svg create mode 100644 doc/image/sample_netmap.svg create mode 100644 doc/image/select_illustration.svg create mode 100644 doc/policy.md diff --git a/doc/image/filter_illustration.svg b/doc/image/filter_illustration.svg new file mode 100644 index 00000000..a57aa688 --- /dev/null +++ b/doc/image/filter_illustration.svg @@ -0,0 +1,4 @@ + + + +
FILTER Color EQ 'Red' AS RedNodes
FILTER Color EQ 'Red' AS RedNodes
FILTER Color EQ 'Blue' AS BlueNodes
FILTER Color EQ 'Blue' AS BlueNodes
FILTER @RedNodes OR @BlueNodes AS MyNodes
FILTER @RedNodes OR @BlueNodes AS MyNodes
*
*
MyNodes
MyNodes
Text is not SVG - cannot display
\ No newline at end of file diff --git a/doc/image/placement_policy.svg b/doc/image/placement_policy.svg new file mode 100644 index 00000000..9cc8a1ab --- /dev/null +++ b/doc/image/placement_policy.svg @@ -0,0 +1,4 @@ + + + +
FILTER
FILTER
FILTER
FILTER
FILTER
FILTER
SELECT
SELECT
SELECT
SELECT
SELECT
SELECT
FILTER
FILTER
FILTER
FILTER
FILTER
FILTER
REP
REP
REP
REP
REP
REP
netmap
netmap
Text is not SVG - cannot display
\ No newline at end of file diff --git a/doc/image/rep_illustration.svg b/doc/image/rep_illustration.svg new file mode 100644 index 00000000..8bcc3272 --- /dev/null +++ b/doc/image/rep_illustration.svg @@ -0,0 +1,4 @@ + + + +
(...)
(...)
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
MyNodes
MyNodes
REP 1 IN MyNodes
REP 1 IN MyNodes
Text is not SVG - cannot display
\ No newline at end of file diff --git a/doc/image/sample_netmap.svg b/doc/image/sample_netmap.svg new file mode 100644 index 00000000..3d0b39f5 --- /dev/null +++ b/doc/image/sample_netmap.svg @@ -0,0 +1,4 @@ + + + +
C
C
A
A
Netmap
Netmap
B
B
D
D
E
E
F
F
G
G
H
H
I
I
Text is not SVG - cannot display
\ No newline at end of file diff --git a/doc/image/select_illustration.svg b/doc/image/select_illustration.svg new file mode 100644 index 00000000..3a0956af --- /dev/null +++ b/doc/image/select_illustration.svg @@ -0,0 +1,4 @@ + + + +
FILTER @RedNodes OR @BlueNodes AS RedOrBlueNodes
FILTER @RedNodes OR @BlueNodes AS RedOrBlueNodes
RedOrBlueNodes
RedOrBlueNodes
(...)
(...)
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
MyNodes
MyNodes
Text is not SVG - cannot display
\ No newline at end of file diff --git a/doc/policy.md b/doc/policy.md new file mode 100644 index 00000000..68184688 --- /dev/null +++ b/doc/policy.md @@ -0,0 +1,445 @@ +# Placement Policy + +This document describes placement policies, their purpose, syntax and semantics. + +## Index + +- [Introduction](#introduction) +- [Operations](#operations) + - [Basic Expressions](#basic-expressions) + - [`FILTER`](#filter) + - [`SELECT`](#select) + - [`REP`](#rep) +- [Policies](#policies) + - [The policy playground](#the-policy-playground) + - [`CBF`](#cbf) + - [`UNIQUE`](#unique) + - [More examples](#more-examples) +- [Appendix 1: Operators](#appendix-1-operators) +- [Appendix 2: Policy playground commands](#appendix-2-policy-playground-commands) + +## Introduction + +The purpose of a **placement policy** is to determine whichs node(s) of a frostfs system will store an object. Namely, given a **netmap** (a set of nodes) and a placement policy, a subset of those nodes is selected to store a given object. An important aspect is that since nodes in a netmap come and go due to distributed nature of the system, this selection must be deterministic and consistent, i.e. different nodes must come to the same conclusion as long as they share the same view of the netmap. + +> ℹ️ Throughout this document, we will consider each node as a dictionary of attributes and a global unique ID. + +One way to think about the placement policy, is as a pipeline of operations which begins with a set of nodes (the entire netmap) and gradually refine it into only the nodes that will be in charge of storing the object. More specifically, each operation in this pipeline takes a set of nodes and transforms it into a subset of those nodes. The transformation is done purely on the basis of the node attributes. + +![Placement policy as a pipeline](./image/placement_policy.svg) + +The three main operations are: +1. `FILTER`: filters a set of nodes based on their attributes. +2. `SELECT`: selects a specific amount of nodes from a set of nodes based on certain conditions. +3. `REP`: specifies how many nodes (and which ones) from a set of nodes are used to store an object. + +In the next sections, we will explore each of them in detail. + +## Operations + +### Basic Expressions + +Before exploring the operations in detail, we must get acquainted with the basic expressions that appear in a placement policy. As mentioned above, the placement policy operates solely on the basis of node attributes, and as such, basic expressions mostly revolve around node attribute comparison. + +A comparison expression expresses whether a node attribute equals a specified value: +``` +AttributeName Operation AttributeValue +``` + +For example, the following expression +```sql +City EQ 'Moscow' +``` +asserts that the node attribute `City` equals the value `Moscow`. + +Comparison expressions can be nested via boolean operators and parentheses. For example, the following expression: +```sql +(City EQ 'Moscow') AND (Disks GT 2) +``` +asserts that the node attribute `City` equals the value `Moscow` and the node attribute `Disks` must be greater than `2`. Note that the arguments can be either a string or a number. + +See [Appendix 1](#appendix-1-operators) for a complete list of supported operators. + +### `FILTER` + +A `FILTER` operation takes as input a set of nodes and returns a subset of those nodes. It's useful for selecting nodes that have (or lack) specific attributes. Its basic syntax is as follows: +```bnf +FILTER AS +``` + +For example, the following filter +```sql +FILTER Color EQ 'Red' AS RedNodes +``` +selects those nodes for which the `Color` attribute equals `Red`, and discards the rest. The filter's identifier is `RedNodes`, which can be used to reference it in other parts of the placement policy. For example, you could reference the above filter in another filter as follows +```sql +FILTER @RedNodes AND (City EQ 'Moscow') AS RedMoscowNodes +``` +which would select those nodes for which the `Color` attribute equals `Red` and the `City` attribute equals `Moscow`. You can think of the `@` operator as embedding the referenced filter expression verbatim where it's used. This makes it easy to compose filters. However, filters can be referenced via `@` only within filter expressions. In other places you can simply use the filter identifier directly. + +> ⚠️ Every filter requires a unique identifier. What would be the use of a filter that you cannot reference? + +The following diagram illustrates the filter operation + +![FILTER](./image/filter_illustration.svg) + +where the nodes are represented as colored circles, with their color representing the value of their `Color` attribute, respectively. + +> ℹ️ A filter referring to all nodes in the netmap always exists and can be referenced by `*`. + +### `SELECT` + +A `SELECT` operation specifies how many and which nodes from a subset previously obtained from a `FILTER` will be available to build replica groups for object storage. It's not that different from a `FILTER` in that it transforms a set of nodes into a subset of those, but while a `FILTER` cannot control the size of the resulting subset and other characteristics, a `SELECT` can. + +Its basic syntax is as follows: +```bnf +SELECT {IN (SAME|DISTINCT) } FROM {AS } +``` + +In a nutshell, a `SELECT` takes a filter result as input and outputs a specific number of nodes, optionally enforcing that all output nodes must either share or differ in a specific attribute. Note that only the output node count and the source filter are required. + +Let's see some examples +```sql +-- Selects exactly one node from the entire netmap +SELECT 1 FROM * + +-- Same as above, but with an identifier for the selection +SELECT 1 FROM * AS ONE + +-- Selects two nodes from the RedOrBlueNodes filter, such that both selected nodes +-- share the same value for the Color attribute, i.e. both red or both blue. +SELECT 2 IN SAME Color FROM RedOrBlueNodes + +-- Selects two nodes from the RedOrBlueNodes filter, such that the selected nodes +-- have distinct values for the Color attribute, i.e. one red and one blue. +-- The selection is also given an identifier. +SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes +``` + +The last example is illustrated in the following diagram: + +![SELECT](./image/select_illustration.svg) + +> ℹ️ At this point, notice that while `FILTER`'s output is always unique (namely, every node in the input is either filtered in or out), that is not always the case for `SELECT`. In the last example above, there is more than one way to select two nodes with distinct `Color` attribute. Because we require the output to be deterministic and consistent (so that all nodes agree on which nodes to store a given object without having to commmunicate with each other), we need a way to reach this consensus efficiently. Internally, the policy engine uses [Rendezvouz Hashing](https://en.wikipedia.org/wiki/Rendezvous_hashing) to ensure this. If you want more control over what nodes are actually selected, you can always use narrower filters/selections to ensure this. + +### `REP` + +A `REP` operation specifies how many copies of an object need to be stored (`REP` stands for "replica"). A placement policy can contain multiple replica operations, with each of them representing a replica group, i.e. a group of objects associated with the same replica. Following our analogy with a pipeline, `REP` operations are the sink or output nodes. + +Its basic syntax is as follows: +```bnf +REP {IN * * +``` + +We begin by stating all our `REP` operations, followed by all the `SELECT` operations and finally all the `FILTER` operations. Note that this is the reverse order in which they are applied. Also note that at least one `REP` operation is required. + +Here's a complete example: +```sql +REP 1 IN MyNodes +SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes +FILTER Color EQ 'Red' AS RedNodes +FILTER Color EQ 'Blue' AS BlueNodes +FILTER @RedNodes OR @BlueNodes AS RedOrBlueNodes +``` + +In additional to this basic syntax, there are a couple of additional useful options to specify which nodes and how many nodes are actually selected to store objects. We explore these in the next sections. + +### The policy playground + +> ℹ️ This section assumes you have an up-to-date version of the `frostfs-cli`. + +While simple placement policies have predictable results that can be understood at a glance, more complex ones need careful consideration before deployment. In order to simplify understanding a policy's outcome and experimenting while learning, a builtin tool is provided as part of the `frostfs-cli` for this purpose: the policy playground. + +For the remainder of this guide, we will use the policy playground to setup a virtual netmap (that is, one that doesn't require any networking or deployment) and test various policies. In order to visualize this netmap easily, each node will have three attributes: a character, a shape and a color + +![Sample Netmap](./image/sample_netmap.svg) + +We can start the policy playground as follows: +```sh +$ frostfs-cli container policy-playground +> +``` + +Since we didn't pass any endpoint, the initial netmap is empty, which we can verify with the `ls` command (to list the nodes in the netmap): +```sh +> ls +> +``` + +Nows let's add virtual nodes to represent our test netmap in the figure above +```sh +> add 01 Char:A Shape:Circle Color:Blue +> add 02 Char:B Shape:Circle Color:Green +> add 03 Char:C Shape:Circle Color:Red +> add 04 Char:D Shape:Square Color:Blue +> add 05 Char:E Shape:Square Color:Green +> add 06 Char:F Shape:Square Color:Red +> add 07 Char:G Shape:Diamond Color:Blue +> add 08 Char:H Shape:Diamond Color:Green +> add 09 Char:I Shape:Diamond Color:Red +``` + +and verify that the netmap now contains what we expect +```sh +> ls + 1: id=06 attrs={Char:F Shape:Square Color:Red} + 2: id=08 attrs={Char:H Shape:Diamond Color:Green} + 3: id=01 attrs={Char:A Shape:Circle Color:Blue} + 4: id=04 attrs={Char:D Shape:Square Color:Blue} + 5: id=05 attrs={Char:E Shape:Square Color:Green} + 6: id=09 attrs={Char:I Shape:Diamond Color:Red} + 7: id=02 attrs={Char:B Shape:Circle Color:Green} + 8: id=03 attrs={Char:C Shape:Circle Color:Red} + 9: id=07 attrs={Char:G Shape:Diamond Color:Blue} +``` + +With our sample netmap setup, we can now continue. + +### `CBF` + +Consider the following policy: + +```sql +REP 1 +``` + +It builds a replica consisting of one copy, selected from the entire netmap. If we evaluate this policy in our sample netmap, we obtain a result which is probably unexpected: + +```sh +> eval REP 1 + 1: [06 05 02] +``` + +The `eval` commands evaluates a policy and lists in a separate line the nodes selected for each `REP` operation, in the order they appear in the policy. We were expecting a single node, but we got three instead. The reason is that there's a policy-wide parameter called **container backup factor** (or CBF). This parameter is a multiplier which controls the maximum number of storage nodes: for example, if a policy requires 10 nodes and the CBF is 3, it means that the policy can store an object in up to 10 × 3 nodes. However, if there are not enough nodes and fewer (but at least 10) are used, this is not considered an error. + +The default value for CBF is `3`, which explains our result above, given than every node in the netmap agrees with the policy. The CBF can be explicitly set in the policy right after the `REP` operations. For example + +```sh +> eval REP 1 CBF 1 + 1: [06] +``` + +results in what we expected in the first example. On the other hand + +```sh +> eval REP 1 IN MyNodes SELECT 1 IN SAME Char FROM * AS MyNodes + 1: [01] +``` + +results in a single node despite the default CBF, because there are not enough nodes compatible with the selection. + +### `UNIQUE` + +Consider the following policy: +```sql +REP 1 +REP 1 +CBF 2 +``` + +If we evaluate it +```sh +> eval REP 1 REP 1 CBF 2 + 1: [06 05] + 2: [06 05] +``` + +we find that each replica gets two nodes, in accordance with the CBF. However, these nodes are exactly the same and this might not be desirable. In order to force the policy engine to select different nodes for each replica, we can use the `UNIQUE` option, which is specified right before the `REP` operations. + +In our example, if we change it to +```sql +UNIQUE +REP 1 +REP 1 +CBF 2 +``` + +and evaluate it + +```sh +> eval UNIQUE REP 1 REP 1 CBF 2 + 1: [06 05] + 2: [02 03] +``` + +we now find that the nodes selected for each replica are now distinct from each other. + +### More examples + +This section presents some more examples of placement policies and their result when applied to the sample netmap. Try to figure out the result before looking at it or evaluating the policy. + +#### Example #1 +```sql +REP 1 IN TwoRedNodes +SELECT 2 FROM RedNodes AS TwoRedNodes +FILTER Color EQ 'Red' AS RedNodes +``` + +
+Result + +```sh +> eval REP 1 IN TwoRedNodes SELECT 2 FROM RedNodes AS TwoRedNodes FILTER Color EQ 'Red' AS RedNodes + 1: [06 09 03] +``` + +
+ +#### Example #2 +```sql +REP 1 IN TwoRedNodes +REP 1 IN TwoRedNodes +SELECT 2 FROM RedNodes AS TwoRedNodes +FILTER Color EQ 'Red' AS RedNodes +``` + +
+Result + +```sh +> eval REP 1 REP 1 IN TwoRedNodes SELECT 2 FROM RedNodes AS TwoRedNodes FILTER Color EQ 'Red' AS RedNodes + 1: [06 09 03] + 2: [06 09 03] +``` + +
+ +#### Example #3 +```sql +REP 2 IN MyNodes +REP 2 IN MyNodes +SELECT 2 FROM RedOrBlueNodes AS MyNodes +FILTER Color EQ 'Red' AS RedNodes +FILTER Color EQ 'Blue' AS BlueNodes +FILTER @RedNodes OR @BlueNodes AS RedOrBlueNodes +``` + +
+Result + +```sh +> eval REP 2 IN MyNodes REP 2 IN MyNodes SELECT 2 FROM RedOrBlueNodes AS MyNodes FILTER Color EQ 'Red' AS RedNodes FILTER Color EQ 'Blue' AS BlueNodes FILTER @RedNodes OR @BlueNodes AS RedOrBlueNodes + 1: [06 01 04 03 09 07] + 2: [06 01 04 03 09 07] +``` + +
+ +#### Example #4 +```sql +REP 2 IN MyRedNodes +REP 2 IN MyBlueNodes +CBF 1 +SELECT 2 FROM RedNodes AS MyRedNodes +SELECT 2 FROM BlueNodes AS MyBlueNodes +FILTER Color EQ 'Red' AS RedNodes +FILTER Color EQ 'Blue' AS BlueNodes +``` + +
+Result + +```sh +> eval REP 2 IN MyRedNodes REP 2 IN MyBlueNodes CBF 1 SELECT 2 FROM RedNodes AS MyRedNodes SELECT 2 FROM BlueNodes AS MyBlueNodes FILTER Color EQ 'Red' AS RedNodes FILTER Color EQ 'Blue' AS BlueNodes + 1: [06 03] + 2: [01 04] +``` + +
+ +#### Example #5 +```sql +UNIQUE +REP 1 IN MyGreenNodes +REP 1 IN MyGreenNodes +REP 1 IN MyGreenNodes +CBF 1 +SELECT 1 FROM GreenNodes AS MyGreenNodes +FILTER Color EQ 'Green' AS GreenNodes +``` + +
+Result + +```sh +> eval UNIQUE REP 1 IN MyGreenNodes REP 1 IN MyGreenNodes REP 1 IN MyGreenNodes CBF 1 SELECT 1 FROM GreenNodes AS MyGreenNodes FILTER Color EQ 'Green' AS GreenNodes + 1: [05] + 2: [02] + 3: [08] +``` + +
+ +#### Example #6 +```sql +REP 1 IN MyNodes +REP 2 +CBF 2 +SELECT 1 FROM CuteNodes AS MyNodes +FILTER (Color EQ 'Blue') AND NOT (Shape EQ 'Circle' OR Shape EQ 'Square') AS CuteNodes +``` + +
+Result + +```sh +eval REP 1 IN MyNodes REP 2 CBF 2 SELECT 1 FROM CuteNodes AS MyNodes FILTER (Color EQ 'Blue') AND NOT (Shape EQ 'Circle' OR Shape EQ 'Square') AS CuteNodes + 1: [07] + 2: [06 05 02 03] +``` + +
+ +## Appendix 1: Operators + +Comparison operators (all binary): +- `EQ`: equals +- `NE`: not equal +- `GE`: greater or equal +- `GT`: greater than +- `LE`: less or equal +- `LT`: less than + +Logical operators: +- `NOT`: negation (unary) +- `AND`: conjunction (binary) +- `OR`: disjunction (binary) + +Others: +- `@`: filter reference +- `(`: left parenthesis +- `)`: right parenthesis + +## Appendix 2: Policy playground commands + +- `ls`: list nodes in the current netmap and their attributes +- `add`: add a node to the current netmap. If it already exists, it will be overwritten. +- `remove`: remove a node from the current netmap. +- `eval`: evaluate a placement policy on the current netmap. \ No newline at end of file From 5defed4ab43591f6a2d3247237382b0ef7829fd7 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Wed, 19 Jul 2023 15:19:04 +0300 Subject: [PATCH 017/288] [#126] go.mod: Update frostfs-api-go package version Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index fc96fa43..5a0836f9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.frostfs.info/TrueCloudLab/frostfs-sdk-go go 1.19 require ( - git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230704092742-285516a94ebe + git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230719100335-582d94c81c74 git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 git.frostfs.info/TrueCloudLab/hrw v1.2.1 diff --git a/go.sum b/go.sum index 11f92d0c..bcf3c822 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230704092742-285516a94ebe h1:SB102RiEg+4h9qcwyG97zHBtwduMRbedbtkwRDVSps8= -git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230704092742-285516a94ebe/go.mod h1:pKJJRLOChW4zDQsAt1e8k/snWKljJtpkiPfxV53ngjI= +git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230719100335-582d94c81c74 h1:xgeSzZP40SbMMVGfG1V7xrC8m7DS6llZ9kkjO9L8+jY= +git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230719100335-582d94c81c74/go.mod h1:pKJJRLOChW4zDQsAt1e8k/snWKljJtpkiPfxV53ngjI= git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb h1:S/TrbOOu9qEXZRZ9/Ddw7crnxbBUQLo68PSzQWYrc9M= git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb/go.mod h1:nkR5gaGeez3Zv2SE7aceP0YwxG2FzIB5cGKpQO2vV2o= git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 h1:FxqFDhQYYgpe41qsIHVOcdzSVCB8JNSfPG7Uk4r2oSk= From ecb1fef78cfc92573f42938cd2ae575f7f49008e Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 26 Jul 2023 14:38:43 +0300 Subject: [PATCH 018/288] [#129] client: Do not override error status WriteObject() Here is a scenario: 1. `resolveFrostFSErrors` is false. 2. The first object part was not written, which was signified in status. 3. The second part was written correctly. Client now thinks that the object is written even though it was not. In theory we could also return only status, but client-side splitting is not a single RPC, so it makes sense. Signed-off-by: Evgenii Stratonikov --- client/object_put_transformer.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/object_put_transformer.go b/client/object_put_transformer.go index ad8165d6..402ad004 100644 --- a/client/object_put_transformer.go +++ b/client/object_put_transformer.go @@ -3,6 +3,7 @@ package client import ( "context" + apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer" "google.golang.org/grpc/codes" @@ -82,6 +83,9 @@ func (it *internalTarget) putAsStream(ctx context.Context, o *object.Object) err wrt.WritePayloadChunk(ctx, o.Payload()) } it.res, err = wrt.Close(ctx) + if err == nil && !it.client.prm.resolveFrostFSErrors && !apistatus.IsSuccessful(it.res.st) { + err = apistatus.ErrFromStatus(it.res.st) + } return err } @@ -106,6 +110,10 @@ func (it *internalTarget) tryPutSingle(ctx context.Context, o *object.Object) (b statusRes: res.statusRes, obj: id, } + if !it.client.prm.resolveFrostFSErrors && !apistatus.IsSuccessful(it.res.st) { + return true, apistatus.ErrFromStatus(it.res.st) + } + return true, nil } return true, err } From 0886d800838fc9877446cffceefeb42cfd31c45a Mon Sep 17 00:00:00 2001 From: Marina Biryukova Date: Fri, 28 Jul 2023 18:35:35 +0300 Subject: [PATCH 019/288] [#69] Add close for nns.Dial Signed-off-by: Marina Biryukova --- ns/nns.go | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/ns/nns.go b/ns/nns.go index 4af72f41..947e8fa7 100644 --- a/ns/nns.go +++ b/ns/nns.go @@ -19,12 +19,25 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) +// multiSchemeClient unites invoker.RPCInvoke and common interface of +// rpcclient.Client and rpcclient.WSClient. +type multiSchemeClient interface { + invoker.RPCInvoke + // Init turns client to "ready-to-work" state. + Init() error + // Close closes connections. + Close() + // GetContractStateByID returns state of the NNS contract on 1 input. + GetContractStateByID(int32) (*state.Contract, error) +} + // NNS looks up FrostFS names using Neo Name Service. // // Instances are created with a variable declaration. Before work, the connection // to the NNS server MUST be established using Dial method. type NNS struct { nnsContract util.Uint160 + client multiSchemeClient invoker interface { Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) @@ -37,47 +50,41 @@ type NNS struct { // If URL address scheme is 'ws' or 'wss', then WebSocket protocol is used, // otherwise HTTP. func (n *NNS) Dial(address string) error { - // multiSchemeClient unites invoker.RPCInvoke and common interface of - // rpcclient.Client and rpcclient.WSClient. Interface is anonymous - // according to assumption that common interface of these client types - // is not required by design and may diverge with changes. - var multiSchemeClient interface { - invoker.RPCInvoke - // Init turns client to "ready-to-work" state. - Init() error - // GetContractStateByID returns state of the NNS contract on 1 input. - GetContractStateByID(int32) (*state.Contract, error) - } var err error uri, err := url.Parse(address) if err == nil && (uri.Scheme == "ws" || uri.Scheme == "wss") { - multiSchemeClient, err = rpcclient.NewWS(context.Background(), address, rpcclient.WSOptions{}) + n.client, err = rpcclient.NewWS(context.Background(), address, rpcclient.WSOptions{}) if err != nil { return fmt.Errorf("create Neo WebSocket client: %w", err) } } else { - multiSchemeClient, err = rpcclient.New(context.Background(), address, rpcclient.Options{}) + n.client, err = rpcclient.New(context.Background(), address, rpcclient.Options{}) if err != nil { return fmt.Errorf("create Neo HTTP client: %w", err) } } - if err = multiSchemeClient.Init(); err != nil { + if err = n.client.Init(); err != nil { return fmt.Errorf("initialize Neo client: %w", err) } - nnsContract, err := multiSchemeClient.GetContractStateByID(1) + nnsContract, err := n.client.GetContractStateByID(1) if err != nil { return fmt.Errorf("get NNS contract state: %w", err) } - n.invoker = invoker.New(multiSchemeClient, nil) + n.invoker = invoker.New(n.client, nil) n.nnsContract = nnsContract.Hash return nil } +// Close closes connections of multiSchemeClient. +func (n *NNS) Close() { + n.client.Close() +} + // ResolveContainerDomain looks up for NNS TXT records for the given container domain // by calling `resolve` method of NNS contract. Returns the first record which represents // valid container ID in a string format. Otherwise, returns an error. From 78d1439b2c71df535ad06f3c6d35c6b72862e6b8 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 27 Jul 2023 19:44:44 +0300 Subject: [PATCH 020/288] [#133] go.mod: Update api-go Signed-off-by: Evgenii Stratonikov --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5a0836f9..c628456b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.frostfs.info/TrueCloudLab/frostfs-sdk-go go 1.19 require ( - git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230719100335-582d94c81c74 + git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230726155259-7a5ee927c8a2 git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 git.frostfs.info/TrueCloudLab/hrw v1.2.1 diff --git a/go.sum b/go.sum index bcf3c822..443bcbd2 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230719100335-582d94c81c74 h1:xgeSzZP40SbMMVGfG1V7xrC8m7DS6llZ9kkjO9L8+jY= -git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230719100335-582d94c81c74/go.mod h1:pKJJRLOChW4zDQsAt1e8k/snWKljJtpkiPfxV53ngjI= +git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230726155259-7a5ee927c8a2 h1:5QUnWafFc0RprHCpQ3d1T4MEo2fvGjL/3GPeB0w54mA= +git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230726155259-7a5ee927c8a2/go.mod h1:pKJJRLOChW4zDQsAt1e8k/snWKljJtpkiPfxV53ngjI= git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb h1:S/TrbOOu9qEXZRZ9/Ddw7crnxbBUQLo68PSzQWYrc9M= git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb/go.mod h1:nkR5gaGeez3Zv2SE7aceP0YwxG2FzIB5cGKpQO2vV2o= git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 h1:FxqFDhQYYgpe41qsIHVOcdzSVCB8JNSfPG7Uk4r2oSk= From 0fe0d716784b4412f2711274f1c379de6bd15c16 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 27 Jul 2023 19:47:18 +0300 Subject: [PATCH 021/288] [#133] .forgejo: Add names to actions Signed-off-by: Evgenii Stratonikov --- .forgejo/workflows/dco.yml | 1 + .forgejo/workflows/tests.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.forgejo/workflows/dco.yml b/.forgejo/workflows/dco.yml index 682855b3..d77461ce 100644 --- a/.forgejo/workflows/dco.yml +++ b/.forgejo/workflows/dco.yml @@ -1,3 +1,4 @@ +name: DCO on: [pull_request] jobs: diff --git a/.forgejo/workflows/tests.yml b/.forgejo/workflows/tests.yml index e457cbaf..664767b0 100644 --- a/.forgejo/workflows/tests.yml +++ b/.forgejo/workflows/tests.yml @@ -1,3 +1,4 @@ +name: Tests and linters on: [pull_request] jobs: From 18a9e4bceb671c2a7235ca1107b10c41695ee840 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Mon, 24 Jul 2023 14:29:31 +0300 Subject: [PATCH 022/288] [#121] client: Make PrmContainerPut struct fields public Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- client/common.go | 1 + client/container_put.go | 35 ++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/client/common.go b/client/common.go index 1d561307..7449288d 100644 --- a/client/common.go +++ b/client/common.go @@ -82,6 +82,7 @@ var ( errorMissingAnnouncements = errors.New("missing announcements") errorZeroRangeLength = errors.New("zero range length") errorMissingRanges = errors.New("missing ranges") + errorInvalidXHeaders = errors.New("xheaders must be presented only as key-value pairs") ) // groups all the details required to send a single request and process a response to it. diff --git a/client/container_put.go b/client/container_put.go index 630d265b..ebf90e87 100644 --- a/client/container_put.go +++ b/client/container_put.go @@ -19,20 +19,20 @@ import ( // PrmContainerPut groups parameters of ContainerPut operation. type PrmContainerPut struct { - prmCommonMeta + // FrostFS request X-Headers + XHeaders []string - cnrSet bool - cnr container.Container + Container *container.Container - sessionSet bool - session session.Container + Session *session.Container } // SetContainer sets structured information about new FrostFS container. // Required parameter. +// +// NOTE: method is deprecated func (x *PrmContainerPut) SetContainer(cnr container.Container) { - x.cnr = cnr - x.cnrSet = true + x.Container = &cnr } // WithinSession specifies session within which container should be saved. @@ -43,23 +43,28 @@ func (x *PrmContainerPut) SetContainer(cnr container.Container) { // Session is optional, if set the following requirements apply: // - session operation MUST be session.VerbContainerPut (ForVerb) // - token MUST be signed using private key of the owner of the container to be saved +// +// NOTE: method is deprecated func (x *PrmContainerPut) WithinSession(s session.Container) { - x.session = s - x.sessionSet = true + x.Session = &s } func (x *PrmContainerPut) buildRequest(c *Client) (*v2container.PutRequest, error) { - if !x.cnrSet { + if x.Container == nil { return nil, errorMissingContainer } + if len(x.XHeaders)%2 != 0 { + return nil, errorInvalidXHeaders + } + // TODO: check private key is set before forming the request var cnr v2container.Container - x.cnr.WriteToV2(&cnr) + x.Container.WriteToV2(&cnr) var sig frostfscrypto.Signature - err := container.CalculateSignature(&sig, x.cnr, c.prm.key) + err := container.CalculateSignature(&sig, *x.Container, c.prm.key) if err != nil { return nil, fmt.Errorf("calculate container signature: %w", err) } @@ -72,11 +77,11 @@ func (x *PrmContainerPut) buildRequest(c *Client) (*v2container.PutRequest, erro reqBody.SetSignature(&sigv2) var meta v2session.RequestMetaHeader - writeXHeadersToMeta(x.prmCommonMeta.xHeaders, &meta) + writeXHeadersToMeta(x.XHeaders, &meta) - if x.sessionSet { + if x.Session != nil { var tokv2 v2session.Token - x.session.WriteToV2(&tokv2) + x.Session.WriteToV2(&tokv2) meta.SetSessionToken(&tokv2) } From 13d0b170d2ad49325b08f2b79a8ef7411561ef16 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Mon, 31 Jul 2023 14:08:50 +0300 Subject: [PATCH 023/288] [#121] client: Make pool PrmContainerPut struct fields public Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- client/container_put.go | 4 ++-- pool/pool.go | 33 ++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/client/container_put.go b/client/container_put.go index ebf90e87..f186abd8 100644 --- a/client/container_put.go +++ b/client/container_put.go @@ -30,7 +30,7 @@ type PrmContainerPut struct { // SetContainer sets structured information about new FrostFS container. // Required parameter. // -// NOTE: method is deprecated +// Deprecated: Use PrmContainerPut.Container instead. func (x *PrmContainerPut) SetContainer(cnr container.Container) { x.Container = &cnr } @@ -44,7 +44,7 @@ func (x *PrmContainerPut) SetContainer(cnr container.Container) { // - session operation MUST be session.VerbContainerPut (ForVerb) // - token MUST be signed using private key of the owner of the container to be saved // -// NOTE: method is deprecated +// Deprecated: Use PrmContainerPut.Session instead. func (x *PrmContainerPut) WithinSession(s session.Container) { x.Session = &s } diff --git a/pool/pool.go b/pool/pool.go index 2f662d36..04b84aa4 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -407,7 +407,7 @@ func (c *clientWrapper) containerPut(ctx context.Context, prm PrmContainerPut) ( } start := time.Now() - res, err := cl.ContainerPut(ctx, prm.prmClient) + res, err := cl.ContainerPut(ctx, prm.ClientParams) c.incRequests(time.Since(start), methodContainerPut) var st apistatus.Status if res != nil { @@ -417,13 +417,13 @@ func (c *clientWrapper) containerPut(ctx context.Context, prm PrmContainerPut) ( return cid.ID{}, fmt.Errorf("container put on client: %w", err) } - if !prm.waitParamsSet { - prm.waitParams.setDefaults() + if prm.WaitParams == nil { + prm.WaitParams = defaultWaitParams() } idCnr := res.ID() - err = waitForContainerPresence(ctx, c, idCnr, &prm.waitParams) + err = waitForContainerPresence(ctx, c, idCnr, prm.WaitParams) if err = c.handleError(ctx, nil, err); err != nil { return cid.ID{}, fmt.Errorf("wait container presence on client: %w", err) } @@ -1221,6 +1221,13 @@ func (x *WaitParams) setDefaults() { x.pollInterval = 5 * time.Second } +func defaultWaitParams() *WaitParams { + return &WaitParams{ + timeout: 120 * time.Second, + pollInterval: 5 * time.Second, + } +} + // checkForPositive panics if any of the wait params isn't positive. func (x *WaitParams) checkForPositive() { if x.timeout <= 0 || x.pollInterval <= 0 { @@ -1400,35 +1407,39 @@ func (x *PrmObjectSearch) SetFilters(filters object.SearchFilters) { // PrmContainerPut groups parameters of PutContainer operation. type PrmContainerPut struct { - prmClient sdkClient.PrmContainerPut + ClientParams sdkClient.PrmContainerPut - waitParams WaitParams - waitParamsSet bool + WaitParams *WaitParams } // SetContainer container structure to be used as a parameter of the base // client's operation. // // See git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client.PrmContainerPut.SetContainer. +// +// Deprecated: Use PrmContainerPut.ClientParams.Container instead. func (x *PrmContainerPut) SetContainer(cnr container.Container) { - x.prmClient.SetContainer(cnr) + x.ClientParams.SetContainer(cnr) } // WithinSession specifies session to be used as a parameter of the base // client's operation. // // See git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client.PrmContainerPut.WithinSession. +// +// Deprecated: Use PrmContainerPut.ClientParams.Session instead. func (x *PrmContainerPut) WithinSession(s session.Container) { - x.prmClient.WithinSession(s) + x.ClientParams.WithinSession(s) } // SetWaitParams specifies timeout params to complete operation. // If not provided the default one will be used. // Panics if any of the wait params isn't positive. +// +// Deprecated: Use PrmContainerPut.ClientParams.WaitParams instead. func (x *PrmContainerPut) SetWaitParams(waitParams WaitParams) { waitParams.checkForPositive() - x.waitParams = waitParams - x.waitParamsSet = true + x.WaitParams = &waitParams } // PrmContainerGet groups parameters of GetContainer operation. From 95b987b818d9af79d01f67f2d0efcf2b3c7f5261 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 2 Aug 2023 11:04:45 +0300 Subject: [PATCH 024/288] [#137] go.mod: Update api-go Signed-off-by: Evgenii Stratonikov --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c628456b..7c1690eb 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.frostfs.info/TrueCloudLab/frostfs-sdk-go go 1.19 require ( - git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230726155259-7a5ee927c8a2 + git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230802075510-964c3edb3f44 git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 git.frostfs.info/TrueCloudLab/hrw v1.2.1 diff --git a/go.sum b/go.sum index 443bcbd2..2f9e78f7 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230726155259-7a5ee927c8a2 h1:5QUnWafFc0RprHCpQ3d1T4MEo2fvGjL/3GPeB0w54mA= -git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230726155259-7a5ee927c8a2/go.mod h1:pKJJRLOChW4zDQsAt1e8k/snWKljJtpkiPfxV53ngjI= +git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230802075510-964c3edb3f44 h1:v6JqBD/VzZx3QSxbaXnUwnnJ1KEYheU4LzLGr3IhsAE= +git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230802075510-964c3edb3f44/go.mod h1:pKJJRLOChW4zDQsAt1e8k/snWKljJtpkiPfxV53ngjI= git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb h1:S/TrbOOu9qEXZRZ9/Ddw7crnxbBUQLo68PSzQWYrc9M= git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb/go.mod h1:nkR5gaGeez3Zv2SE7aceP0YwxG2FzIB5cGKpQO2vV2o= git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 h1:FxqFDhQYYgpe41qsIHVOcdzSVCB8JNSfPG7Uk4r2oSk= From 363f153eafa601c6ac8d560496a3bf21adffe0ce Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 2 Aug 2023 10:54:37 +0300 Subject: [PATCH 025/288] [#136] pool: Set order field to get subtree With new revision of tree service protocol, getSubTree requires to use explicit order field. Signed-off-by: Alex Vanin --- pool/tree/pool.go | 3 + pool/tree/service/service.pb.go | 703 ++++++++++++++++----------- pool/tree/service/service_grpc.pb.go | 2 +- pool/tree/service/types.pb.go | 2 +- syncTree.sh | 2 +- 5 files changed, 423 insertions(+), 289 deletions(-) diff --git a/pool/tree/pool.go b/pool/tree/pool.go index 7fca21be..a9adb016 100644 --- a/pool/tree/pool.go +++ b/pool/tree/pool.go @@ -368,6 +368,9 @@ func (p *Pool) GetSubTree(ctx context.Context, prm GetSubTreeParams) (*SubTreeRe RootId: prm.RootID, Depth: prm.Depth, BearerToken: prm.BearerToken, + OrderBy: &grpcService.GetSubTreeRequest_Body_Order{ + Direction: grpcService.GetSubTreeRequest_Body_Order_Asc, + }, }, } diff --git a/pool/tree/service/service.pb.go b/pool/tree/service/service.pb.go index 08664a6d..63f3e714 100644 --- a/pool/tree/service/service.pb.go +++ b/pool/tree/service/service.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.26.0 -// protoc v3.12.4 +// protoc v3.21.9 // source: pkg/services/tree/service.proto package tree @@ -23,6 +23,52 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type GetSubTreeRequest_Body_Order_Direction int32 + +const ( + GetSubTreeRequest_Body_Order_None GetSubTreeRequest_Body_Order_Direction = 0 + GetSubTreeRequest_Body_Order_Asc GetSubTreeRequest_Body_Order_Direction = 1 +) + +// Enum value maps for GetSubTreeRequest_Body_Order_Direction. +var ( + GetSubTreeRequest_Body_Order_Direction_name = map[int32]string{ + 0: "None", + 1: "Asc", + } + GetSubTreeRequest_Body_Order_Direction_value = map[string]int32{ + "None": 0, + "Asc": 1, + } +) + +func (x GetSubTreeRequest_Body_Order_Direction) Enum() *GetSubTreeRequest_Body_Order_Direction { + p := new(GetSubTreeRequest_Body_Order_Direction) + *p = x + return p +} + +func (x GetSubTreeRequest_Body_Order_Direction) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (GetSubTreeRequest_Body_Order_Direction) Descriptor() protoreflect.EnumDescriptor { + return file_pkg_services_tree_service_proto_enumTypes[0].Descriptor() +} + +func (GetSubTreeRequest_Body_Order_Direction) Type() protoreflect.EnumType { + return &file_pkg_services_tree_service_proto_enumTypes[0] +} + +func (x GetSubTreeRequest_Body_Order_Direction) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use GetSubTreeRequest_Body_Order_Direction.Descriptor instead. +func (GetSubTreeRequest_Body_Order_Direction) EnumDescriptor() ([]byte, []int) { + return file_pkg_services_tree_service_proto_rawDescGZIP(), []int{10, 0, 0, 0} +} + type AddRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1940,6 +1986,8 @@ type GetSubTreeRequest_Body struct { Depth uint32 `protobuf:"varint,4,opt,name=depth,proto3" json:"depth,omitempty"` // Bearer token in V2 format. BearerToken []byte `protobuf:"bytes,5,opt,name=bearer_token,json=bearerToken,proto3" json:"bearer_token,omitempty"` + // Result ordering. + OrderBy *GetSubTreeRequest_Body_Order `protobuf:"bytes,6,opt,name=order_by,json=orderBy,proto3" json:"order_by,omitempty"` } func (x *GetSubTreeRequest_Body) Reset() { @@ -2009,6 +2057,60 @@ func (x *GetSubTreeRequest_Body) GetBearerToken() []byte { return nil } +func (x *GetSubTreeRequest_Body) GetOrderBy() *GetSubTreeRequest_Body_Order { + if x != nil { + return x.OrderBy + } + return nil +} + +type GetSubTreeRequest_Body_Order struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Direction GetSubTreeRequest_Body_Order_Direction `protobuf:"varint,1,opt,name=direction,proto3,enum=tree.GetSubTreeRequest_Body_Order_Direction" json:"direction,omitempty"` +} + +func (x *GetSubTreeRequest_Body_Order) Reset() { + *x = GetSubTreeRequest_Body_Order{} + if protoimpl.UnsafeEnabled { + mi := &file_pkg_services_tree_service_proto_msgTypes[32] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetSubTreeRequest_Body_Order) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetSubTreeRequest_Body_Order) ProtoMessage() {} + +func (x *GetSubTreeRequest_Body_Order) ProtoReflect() protoreflect.Message { + mi := &file_pkg_services_tree_service_proto_msgTypes[32] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetSubTreeRequest_Body_Order.ProtoReflect.Descriptor instead. +func (*GetSubTreeRequest_Body_Order) Descriptor() ([]byte, []int) { + return file_pkg_services_tree_service_proto_rawDescGZIP(), []int{10, 0, 0} +} + +func (x *GetSubTreeRequest_Body_Order) GetDirection() GetSubTreeRequest_Body_Order_Direction { + if x != nil { + return x.Direction + } + return GetSubTreeRequest_Body_Order_None +} + type GetSubTreeResponse_Body struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -2027,7 +2129,7 @@ type GetSubTreeResponse_Body struct { func (x *GetSubTreeResponse_Body) Reset() { *x = GetSubTreeResponse_Body{} if protoimpl.UnsafeEnabled { - mi := &file_pkg_services_tree_service_proto_msgTypes[32] + mi := &file_pkg_services_tree_service_proto_msgTypes[33] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2040,7 +2142,7 @@ func (x *GetSubTreeResponse_Body) String() string { func (*GetSubTreeResponse_Body) ProtoMessage() {} func (x *GetSubTreeResponse_Body) ProtoReflect() protoreflect.Message { - mi := &file_pkg_services_tree_service_proto_msgTypes[32] + mi := &file_pkg_services_tree_service_proto_msgTypes[33] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2096,7 +2198,7 @@ type TreeListRequest_Body struct { func (x *TreeListRequest_Body) Reset() { *x = TreeListRequest_Body{} if protoimpl.UnsafeEnabled { - mi := &file_pkg_services_tree_service_proto_msgTypes[33] + mi := &file_pkg_services_tree_service_proto_msgTypes[34] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2109,7 +2211,7 @@ func (x *TreeListRequest_Body) String() string { func (*TreeListRequest_Body) ProtoMessage() {} func (x *TreeListRequest_Body) ProtoReflect() protoreflect.Message { - mi := &file_pkg_services_tree_service_proto_msgTypes[33] + mi := &file_pkg_services_tree_service_proto_msgTypes[34] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2144,7 +2246,7 @@ type TreeListResponse_Body struct { func (x *TreeListResponse_Body) Reset() { *x = TreeListResponse_Body{} if protoimpl.UnsafeEnabled { - mi := &file_pkg_services_tree_service_proto_msgTypes[34] + mi := &file_pkg_services_tree_service_proto_msgTypes[35] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2157,7 +2259,7 @@ func (x *TreeListResponse_Body) String() string { func (*TreeListResponse_Body) ProtoMessage() {} func (x *TreeListResponse_Body) ProtoReflect() protoreflect.Message { - mi := &file_pkg_services_tree_service_proto_msgTypes[34] + mi := &file_pkg_services_tree_service_proto_msgTypes[35] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2196,7 +2298,7 @@ type ApplyRequest_Body struct { func (x *ApplyRequest_Body) Reset() { *x = ApplyRequest_Body{} if protoimpl.UnsafeEnabled { - mi := &file_pkg_services_tree_service_proto_msgTypes[35] + mi := &file_pkg_services_tree_service_proto_msgTypes[36] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2209,7 +2311,7 @@ func (x *ApplyRequest_Body) String() string { func (*ApplyRequest_Body) ProtoMessage() {} func (x *ApplyRequest_Body) ProtoReflect() protoreflect.Message { - mi := &file_pkg_services_tree_service_proto_msgTypes[35] + mi := &file_pkg_services_tree_service_proto_msgTypes[36] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2255,7 +2357,7 @@ type ApplyResponse_Body struct { func (x *ApplyResponse_Body) Reset() { *x = ApplyResponse_Body{} if protoimpl.UnsafeEnabled { - mi := &file_pkg_services_tree_service_proto_msgTypes[36] + mi := &file_pkg_services_tree_service_proto_msgTypes[37] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2268,7 +2370,7 @@ func (x *ApplyResponse_Body) String() string { func (*ApplyResponse_Body) ProtoMessage() {} func (x *ApplyResponse_Body) ProtoReflect() protoreflect.Message { - mi := &file_pkg_services_tree_service_proto_msgTypes[36] + mi := &file_pkg_services_tree_service_proto_msgTypes[37] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2302,7 +2404,7 @@ type GetOpLogRequest_Body struct { func (x *GetOpLogRequest_Body) Reset() { *x = GetOpLogRequest_Body{} if protoimpl.UnsafeEnabled { - mi := &file_pkg_services_tree_service_proto_msgTypes[37] + mi := &file_pkg_services_tree_service_proto_msgTypes[38] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2315,7 +2417,7 @@ func (x *GetOpLogRequest_Body) String() string { func (*GetOpLogRequest_Body) ProtoMessage() {} func (x *GetOpLogRequest_Body) ProtoReflect() protoreflect.Message { - mi := &file_pkg_services_tree_service_proto_msgTypes[37] + mi := &file_pkg_services_tree_service_proto_msgTypes[38] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2371,7 +2473,7 @@ type GetOpLogResponse_Body struct { func (x *GetOpLogResponse_Body) Reset() { *x = GetOpLogResponse_Body{} if protoimpl.UnsafeEnabled { - mi := &file_pkg_services_tree_service_proto_msgTypes[38] + mi := &file_pkg_services_tree_service_proto_msgTypes[39] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2384,7 +2486,7 @@ func (x *GetOpLogResponse_Body) String() string { func (*GetOpLogResponse_Body) ProtoMessage() {} func (x *GetOpLogResponse_Body) ProtoReflect() protoreflect.Message { - mi := &file_pkg_services_tree_service_proto_msgTypes[38] + mi := &file_pkg_services_tree_service_proto_msgTypes[39] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2416,7 +2518,7 @@ type HealthcheckResponse_Body struct { func (x *HealthcheckResponse_Body) Reset() { *x = HealthcheckResponse_Body{} if protoimpl.UnsafeEnabled { - mi := &file_pkg_services_tree_service_proto_msgTypes[39] + mi := &file_pkg_services_tree_service_proto_msgTypes[40] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2429,7 +2531,7 @@ func (x *HealthcheckResponse_Body) String() string { func (*HealthcheckResponse_Body) ProtoMessage() {} func (x *HealthcheckResponse_Body) ProtoReflect() protoreflect.Message { - mi := &file_pkg_services_tree_service_proto_msgTypes[39] + mi := &file_pkg_services_tree_service_proto_msgTypes[40] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2454,7 +2556,7 @@ type HealthcheckRequest_Body struct { func (x *HealthcheckRequest_Body) Reset() { *x = HealthcheckRequest_Body{} if protoimpl.UnsafeEnabled { - mi := &file_pkg_services_tree_service_proto_msgTypes[40] + mi := &file_pkg_services_tree_service_proto_msgTypes[41] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2467,7 +2569,7 @@ func (x *HealthcheckRequest_Body) String() string { func (*HealthcheckRequest_Body) ProtoMessage() {} func (x *HealthcheckRequest_Body) ProtoReflect() protoreflect.Message { - mi := &file_pkg_services_tree_service_proto_msgTypes[40] + mi := &file_pkg_services_tree_service_proto_msgTypes[41] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2640,14 +2742,14 @@ var file_pkg_services_tree_service_proto_rawDesc = []byte{ 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x42, 0x79, 0x50, 0x61, 0x74, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x6e, 0x6f, 0x64, 0x65, - 0x73, 0x22, 0x8b, 0x02, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x54, 0x72, 0x65, 0x65, + 0x73, 0x22, 0xbf, 0x03, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x54, 0x72, 0x65, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x30, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x54, 0x72, 0x65, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, - 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x94, 0x01, 0x0a, 0x04, 0x42, 0x6f, 0x64, + 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0xc8, 0x02, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x74, 0x72, 0x65, 0x65, 0x5f, 0x69, 0x64, 0x18, @@ -2656,146 +2758,157 @@ var file_pkg_services_tree_service_proto_rawDesc = []byte{ 0x72, 0x6f, 0x6f, 0x74, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x65, 0x70, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x64, 0x65, 0x70, 0x74, 0x68, 0x12, 0x21, 0x0a, 0x0c, 0x62, 0x65, 0x61, 0x72, 0x65, 0x72, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x05, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x0b, 0x62, 0x65, 0x61, 0x72, 0x65, 0x72, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, - 0xf6, 0x01, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x54, 0x72, 0x65, 0x65, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x31, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x53, - 0x75, 0x62, 0x54, 0x72, 0x65, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x42, - 0x6f, 0x64, 0x79, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, - 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, - 0x72, 0x65, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, - 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x7e, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, - 0x12, 0x17, 0x0a, 0x07, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x04, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x61, 0x72, - 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x70, 0x61, - 0x72, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, - 0x61, 0x6d, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, - 0x74, 0x61, 0x6d, 0x70, 0x12, 0x22, 0x0a, 0x04, 0x6d, 0x65, 0x74, 0x61, 0x18, 0x04, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, - 0x75, 0x65, 0x52, 0x04, 0x6d, 0x65, 0x74, 0x61, 0x22, 0x9b, 0x01, 0x0a, 0x0f, 0x54, 0x72, 0x65, - 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2e, 0x0a, 0x04, - 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x74, 0x72, 0x65, - 0x65, 0x2e, 0x54, 0x72, 0x65, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, - 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x0f, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, - 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x29, 0x0a, 0x04, 0x42, - 0x6f, 0x64, 0x79, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, - 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, - 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x22, 0x8c, 0x01, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4c, - 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x62, - 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x74, 0x72, 0x65, 0x65, - 0x2e, 0x54, 0x72, 0x65, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, - 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x0f, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, - 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x18, 0x0a, 0x04, 0x42, - 0x6f, 0x64, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, - 0x52, 0x03, 0x69, 0x64, 0x73, 0x22, 0xdb, 0x01, 0x0a, 0x0c, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2b, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x6c, - 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, 0x62, - 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x53, 0x69, - 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, - 0x72, 0x65, 0x1a, 0x6f, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x17, 0x0a, - 0x07, 0x74, 0x72, 0x65, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, - 0x74, 0x72, 0x65, 0x65, 0x49, 0x64, 0x12, 0x2b, 0x0a, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x74, 0x72, 0x65, 0x65, - 0x2e, 0x4c, 0x6f, 0x67, 0x4d, 0x6f, 0x76, 0x65, 0x52, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x22, 0x74, 0x0a, 0x0d, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, 0x62, 0x6f, - 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x53, 0x69, 0x67, - 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, - 0x65, 0x1a, 0x06, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x22, 0xe2, 0x01, 0x0a, 0x0f, 0x47, 0x65, - 0x74, 0x4f, 0x70, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2e, 0x0a, - 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x74, 0x72, - 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x70, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, + 0x28, 0x0c, 0x52, 0x0b, 0x62, 0x65, 0x61, 0x72, 0x65, 0x72, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, + 0x3d, 0x0a, 0x08, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x62, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x22, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x54, + 0x72, 0x65, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x2e, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x79, 0x1a, 0x73, + 0x0a, 0x05, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x4a, 0x0a, 0x09, 0x64, 0x69, 0x72, 0x65, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x2c, 0x2e, 0x74, 0x72, 0x65, + 0x65, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x54, 0x72, 0x65, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x44, + 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x09, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x22, 0x1e, 0x0a, 0x09, 0x44, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x6f, 0x6e, 0x65, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x73, + 0x63, 0x10, 0x01, 0x22, 0xf6, 0x01, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x54, 0x72, + 0x65, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x31, 0x0a, 0x04, 0x62, 0x6f, + 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, + 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x54, 0x72, 0x65, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, - 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x70, 0x0a, 0x04, - 0x42, 0x6f, 0x64, 0x79, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, - 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, - 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x74, 0x72, 0x65, 0x65, 0x5f, - 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x72, 0x65, 0x65, 0x49, 0x64, - 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, - 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0xa7, - 0x01, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x4f, 0x70, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x1b, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x70, 0x4c, 0x6f, - 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, - 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x53, - 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, - 0x75, 0x72, 0x65, 0x1a, 0x33, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x2b, 0x0a, 0x09, 0x6f, - 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, - 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x4c, 0x6f, 0x67, 0x4d, 0x6f, 0x76, 0x65, 0x52, 0x09, 0x6f, - 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x80, 0x01, 0x0a, 0x13, 0x48, 0x65, 0x61, - 0x6c, 0x74, 0x68, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x32, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, - 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x63, 0x68, 0x65, 0x63, - 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, - 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x53, - 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, - 0x75, 0x72, 0x65, 0x1a, 0x06, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x22, 0x7e, 0x0a, 0x12, 0x48, - 0x65, 0x61, 0x6c, 0x74, 0x68, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x31, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x1d, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x63, 0x68, 0x65, - 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, - 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x53, - 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, - 0x75, 0x72, 0x65, 0x1a, 0x06, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x32, 0xd6, 0x04, 0x0a, 0x0b, - 0x54, 0x72, 0x65, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2a, 0x0a, 0x03, 0x41, - 0x64, 0x64, 0x12, 0x10, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3c, 0x0a, 0x09, 0x41, 0x64, 0x64, 0x42, 0x79, - 0x50, 0x61, 0x74, 0x68, 0x12, 0x16, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x42, - 0x79, 0x50, 0x61, 0x74, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x74, - 0x72, 0x65, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x42, 0x79, 0x50, 0x61, 0x74, 0x68, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x33, 0x0a, 0x06, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x12, - 0x13, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x52, 0x65, 0x6d, 0x6f, - 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2d, 0x0a, 0x04, 0x4d, 0x6f, - 0x76, 0x65, 0x12, 0x11, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x4d, 0x6f, 0x76, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x4d, 0x6f, 0x76, - 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x48, 0x0a, 0x0d, 0x47, 0x65, 0x74, - 0x4e, 0x6f, 0x64, 0x65, 0x42, 0x79, 0x50, 0x61, 0x74, 0x68, 0x12, 0x1a, 0x2e, 0x74, 0x72, 0x65, + 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x7e, 0x0a, 0x04, + 0x42, 0x6f, 0x64, 0x79, 0x12, 0x17, 0x0a, 0x07, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x12, 0x1b, 0x0a, + 0x09, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, + 0x52, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, + 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x74, + 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x22, 0x0a, 0x04, 0x6d, 0x65, 0x74, 0x61, + 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x4b, 0x65, + 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x04, 0x6d, 0x65, 0x74, 0x61, 0x22, 0x9b, 0x01, 0x0a, + 0x0f, 0x54, 0x72, 0x65, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x2e, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, + 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x54, 0x72, 0x65, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, + 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, + 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, + 0x29, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x22, 0x8c, 0x01, 0x0a, 0x10, 0x54, + 0x72, 0x65, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x2f, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, + 0x74, 0x72, 0x65, 0x65, 0x2e, 0x54, 0x72, 0x65, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, + 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, + 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, + 0x18, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x64, 0x73, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x09, 0x52, 0x03, 0x69, 0x64, 0x73, 0x22, 0xdb, 0x01, 0x0a, 0x0c, 0x41, 0x70, + 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2b, 0x0a, 0x04, 0x62, 0x6f, + 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, + 0x41, 0x70, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x42, 0x6f, 0x64, + 0x79, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, + 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, 0x65, + 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, + 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x6f, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x21, + 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, + 0x64, 0x12, 0x17, 0x0a, 0x07, 0x74, 0x72, 0x65, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x74, 0x72, 0x65, 0x65, 0x49, 0x64, 0x12, 0x2b, 0x0a, 0x09, 0x6f, 0x70, + 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, + 0x74, 0x72, 0x65, 0x65, 0x2e, 0x4c, 0x6f, 0x67, 0x4d, 0x6f, 0x76, 0x65, 0x52, 0x09, 0x6f, 0x70, + 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x74, 0x0a, 0x0d, 0x41, 0x70, 0x70, 0x6c, 0x79, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x41, 0x70, + 0x70, 0x6c, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x42, 0x6f, 0x64, 0x79, + 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, + 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, 0x65, 0x65, + 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, + 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x06, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x22, 0xe2, 0x01, + 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x4f, 0x70, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x2e, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x1a, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x70, 0x4c, 0x6f, 0x67, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, 0x62, 0x6f, 0x64, + 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, + 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, + 0x1a, 0x70, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, + 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x74, + 0x72, 0x65, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x72, + 0x65, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x14, 0x0a, 0x05, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x63, 0x6f, 0x75, + 0x6e, 0x74, 0x22, 0xa7, 0x01, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x4f, 0x70, 0x4c, 0x6f, 0x67, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, + 0x4f, 0x70, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x42, 0x6f, + 0x64, 0x79, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, + 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, + 0x65, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, + 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x33, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x12, + 0x2b, 0x0a, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x4c, 0x6f, 0x67, 0x4d, 0x6f, 0x76, + 0x65, 0x52, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x80, 0x01, 0x0a, + 0x13, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x32, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, + 0x63, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x42, 0x6f, + 0x64, 0x79, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, + 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, + 0x65, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, + 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x06, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x22, + 0x7e, 0x0a, 0x12, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x31, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, + 0x68, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x42, 0x6f, + 0x64, 0x79, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, + 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x72, + 0x65, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, + 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x06, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x32, + 0xd6, 0x04, 0x0a, 0x0b, 0x54, 0x72, 0x65, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, + 0x2a, 0x0a, 0x03, 0x41, 0x64, 0x64, 0x12, 0x10, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x41, 0x64, + 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, + 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3c, 0x0a, 0x09, 0x41, + 0x64, 0x64, 0x42, 0x79, 0x50, 0x61, 0x74, 0x68, 0x12, 0x16, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, + 0x41, 0x64, 0x64, 0x42, 0x79, 0x50, 0x61, 0x74, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x17, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x42, 0x79, 0x50, 0x61, 0x74, + 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x33, 0x0a, 0x06, 0x52, 0x65, 0x6d, + 0x6f, 0x76, 0x65, 0x12, 0x13, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, + 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2d, + 0x0a, 0x04, 0x4d, 0x6f, 0x76, 0x65, 0x12, 0x11, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x4d, 0x6f, + 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x74, 0x72, 0x65, 0x65, + 0x2e, 0x4d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x48, 0x0a, + 0x0d, 0x47, 0x65, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x42, 0x79, 0x50, 0x61, 0x74, 0x68, 0x12, 0x1a, + 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x42, 0x79, 0x50, + 0x61, 0x74, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x42, 0x79, 0x50, 0x61, 0x74, 0x68, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, - 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x42, 0x79, 0x50, 0x61, 0x74, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x54, 0x72, 0x65, - 0x65, 0x12, 0x17, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x54, - 0x72, 0x65, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x74, 0x72, 0x65, - 0x65, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x54, 0x72, 0x65, 0x65, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x39, 0x0a, 0x08, 0x54, 0x72, 0x65, 0x65, 0x4c, 0x69, - 0x73, 0x74, 0x12, 0x15, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x54, 0x72, 0x65, 0x65, 0x4c, 0x69, - 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x74, 0x72, 0x65, 0x65, - 0x2e, 0x54, 0x72, 0x65, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x30, 0x0a, 0x05, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x2e, 0x74, 0x72, 0x65, - 0x65, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, - 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x4f, 0x70, 0x4c, 0x6f, 0x67, 0x12, - 0x15, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x70, 0x4c, 0x6f, 0x67, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, - 0x74, 0x4f, 0x70, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, - 0x12, 0x42, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x12, - 0x18, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x63, 0x68, 0x65, - 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x74, 0x72, 0x65, 0x65, - 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3e, 0x5a, 0x3c, 0x67, 0x69, 0x74, 0x2e, 0x66, 0x72, 0x6f, 0x73, - 0x74, 0x66, 0x73, 0x2e, 0x69, 0x6e, 0x66, 0x6f, 0x2f, 0x54, 0x72, 0x75, 0x65, 0x43, 0x6c, 0x6f, - 0x75, 0x64, 0x4c, 0x61, 0x62, 0x2f, 0x66, 0x72, 0x6f, 0x73, 0x74, 0x66, 0x73, 0x2d, 0x6e, 0x6f, - 0x64, 0x65, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, - 0x74, 0x72, 0x65, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x53, 0x75, + 0x62, 0x54, 0x72, 0x65, 0x65, 0x12, 0x17, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, + 0x53, 0x75, 0x62, 0x54, 0x72, 0x65, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, + 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x54, 0x72, 0x65, 0x65, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x39, 0x0a, 0x08, 0x54, 0x72, + 0x65, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x15, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x54, 0x72, + 0x65, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, + 0x74, 0x72, 0x65, 0x65, 0x2e, 0x54, 0x72, 0x65, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x30, 0x0a, 0x05, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x12, 0x12, + 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x4f, 0x70, + 0x4c, 0x6f, 0x67, 0x12, 0x15, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x70, + 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x74, 0x72, 0x65, + 0x65, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x70, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x30, 0x01, 0x12, 0x42, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x63, 0x68, + 0x65, 0x63, 0x6b, 0x12, 0x18, 0x2e, 0x74, 0x72, 0x65, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, + 0x68, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, + 0x74, 0x72, 0x65, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x63, 0x68, 0x65, 0x63, 0x6b, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3e, 0x5a, 0x3c, 0x67, 0x69, 0x74, 0x2e, + 0x66, 0x72, 0x6f, 0x73, 0x74, 0x66, 0x73, 0x2e, 0x69, 0x6e, 0x66, 0x6f, 0x2f, 0x54, 0x72, 0x75, + 0x65, 0x43, 0x6c, 0x6f, 0x75, 0x64, 0x4c, 0x61, 0x62, 0x2f, 0x66, 0x72, 0x6f, 0x73, 0x74, 0x66, + 0x73, 0x2d, 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x73, 0x2f, 0x74, 0x72, 0x65, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -2810,127 +2923,132 @@ func file_pkg_services_tree_service_proto_rawDescGZIP() []byte { return file_pkg_services_tree_service_proto_rawDescData } -var file_pkg_services_tree_service_proto_msgTypes = make([]protoimpl.MessageInfo, 41) +var file_pkg_services_tree_service_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_pkg_services_tree_service_proto_msgTypes = make([]protoimpl.MessageInfo, 42) var file_pkg_services_tree_service_proto_goTypes = []interface{}{ - (*AddRequest)(nil), // 0: tree.AddRequest - (*AddResponse)(nil), // 1: tree.AddResponse - (*AddByPathRequest)(nil), // 2: tree.AddByPathRequest - (*AddByPathResponse)(nil), // 3: tree.AddByPathResponse - (*RemoveRequest)(nil), // 4: tree.RemoveRequest - (*RemoveResponse)(nil), // 5: tree.RemoveResponse - (*MoveRequest)(nil), // 6: tree.MoveRequest - (*MoveResponse)(nil), // 7: tree.MoveResponse - (*GetNodeByPathRequest)(nil), // 8: tree.GetNodeByPathRequest - (*GetNodeByPathResponse)(nil), // 9: tree.GetNodeByPathResponse - (*GetSubTreeRequest)(nil), // 10: tree.GetSubTreeRequest - (*GetSubTreeResponse)(nil), // 11: tree.GetSubTreeResponse - (*TreeListRequest)(nil), // 12: tree.TreeListRequest - (*TreeListResponse)(nil), // 13: tree.TreeListResponse - (*ApplyRequest)(nil), // 14: tree.ApplyRequest - (*ApplyResponse)(nil), // 15: tree.ApplyResponse - (*GetOpLogRequest)(nil), // 16: tree.GetOpLogRequest - (*GetOpLogResponse)(nil), // 17: tree.GetOpLogResponse - (*HealthcheckResponse)(nil), // 18: tree.HealthcheckResponse - (*HealthcheckRequest)(nil), // 19: tree.HealthcheckRequest - (*AddRequest_Body)(nil), // 20: tree.AddRequest.Body - (*AddResponse_Body)(nil), // 21: tree.AddResponse.Body - (*AddByPathRequest_Body)(nil), // 22: tree.AddByPathRequest.Body - (*AddByPathResponse_Body)(nil), // 23: tree.AddByPathResponse.Body - (*RemoveRequest_Body)(nil), // 24: tree.RemoveRequest.Body - (*RemoveResponse_Body)(nil), // 25: tree.RemoveResponse.Body - (*MoveRequest_Body)(nil), // 26: tree.MoveRequest.Body - (*MoveResponse_Body)(nil), // 27: tree.MoveResponse.Body - (*GetNodeByPathRequest_Body)(nil), // 28: tree.GetNodeByPathRequest.Body - (*GetNodeByPathResponse_Info)(nil), // 29: tree.GetNodeByPathResponse.Info - (*GetNodeByPathResponse_Body)(nil), // 30: tree.GetNodeByPathResponse.Body - (*GetSubTreeRequest_Body)(nil), // 31: tree.GetSubTreeRequest.Body - (*GetSubTreeResponse_Body)(nil), // 32: tree.GetSubTreeResponse.Body - (*TreeListRequest_Body)(nil), // 33: tree.TreeListRequest.Body - (*TreeListResponse_Body)(nil), // 34: tree.TreeListResponse.Body - (*ApplyRequest_Body)(nil), // 35: tree.ApplyRequest.Body - (*ApplyResponse_Body)(nil), // 36: tree.ApplyResponse.Body - (*GetOpLogRequest_Body)(nil), // 37: tree.GetOpLogRequest.Body - (*GetOpLogResponse_Body)(nil), // 38: tree.GetOpLogResponse.Body - (*HealthcheckResponse_Body)(nil), // 39: tree.HealthcheckResponse.Body - (*HealthcheckRequest_Body)(nil), // 40: tree.HealthcheckRequest.Body - (*Signature)(nil), // 41: tree.Signature - (*KeyValue)(nil), // 42: tree.KeyValue - (*LogMove)(nil), // 43: tree.LogMove + (GetSubTreeRequest_Body_Order_Direction)(0), // 0: tree.GetSubTreeRequest.Body.Order.Direction + (*AddRequest)(nil), // 1: tree.AddRequest + (*AddResponse)(nil), // 2: tree.AddResponse + (*AddByPathRequest)(nil), // 3: tree.AddByPathRequest + (*AddByPathResponse)(nil), // 4: tree.AddByPathResponse + (*RemoveRequest)(nil), // 5: tree.RemoveRequest + (*RemoveResponse)(nil), // 6: tree.RemoveResponse + (*MoveRequest)(nil), // 7: tree.MoveRequest + (*MoveResponse)(nil), // 8: tree.MoveResponse + (*GetNodeByPathRequest)(nil), // 9: tree.GetNodeByPathRequest + (*GetNodeByPathResponse)(nil), // 10: tree.GetNodeByPathResponse + (*GetSubTreeRequest)(nil), // 11: tree.GetSubTreeRequest + (*GetSubTreeResponse)(nil), // 12: tree.GetSubTreeResponse + (*TreeListRequest)(nil), // 13: tree.TreeListRequest + (*TreeListResponse)(nil), // 14: tree.TreeListResponse + (*ApplyRequest)(nil), // 15: tree.ApplyRequest + (*ApplyResponse)(nil), // 16: tree.ApplyResponse + (*GetOpLogRequest)(nil), // 17: tree.GetOpLogRequest + (*GetOpLogResponse)(nil), // 18: tree.GetOpLogResponse + (*HealthcheckResponse)(nil), // 19: tree.HealthcheckResponse + (*HealthcheckRequest)(nil), // 20: tree.HealthcheckRequest + (*AddRequest_Body)(nil), // 21: tree.AddRequest.Body + (*AddResponse_Body)(nil), // 22: tree.AddResponse.Body + (*AddByPathRequest_Body)(nil), // 23: tree.AddByPathRequest.Body + (*AddByPathResponse_Body)(nil), // 24: tree.AddByPathResponse.Body + (*RemoveRequest_Body)(nil), // 25: tree.RemoveRequest.Body + (*RemoveResponse_Body)(nil), // 26: tree.RemoveResponse.Body + (*MoveRequest_Body)(nil), // 27: tree.MoveRequest.Body + (*MoveResponse_Body)(nil), // 28: tree.MoveResponse.Body + (*GetNodeByPathRequest_Body)(nil), // 29: tree.GetNodeByPathRequest.Body + (*GetNodeByPathResponse_Info)(nil), // 30: tree.GetNodeByPathResponse.Info + (*GetNodeByPathResponse_Body)(nil), // 31: tree.GetNodeByPathResponse.Body + (*GetSubTreeRequest_Body)(nil), // 32: tree.GetSubTreeRequest.Body + (*GetSubTreeRequest_Body_Order)(nil), // 33: tree.GetSubTreeRequest.Body.Order + (*GetSubTreeResponse_Body)(nil), // 34: tree.GetSubTreeResponse.Body + (*TreeListRequest_Body)(nil), // 35: tree.TreeListRequest.Body + (*TreeListResponse_Body)(nil), // 36: tree.TreeListResponse.Body + (*ApplyRequest_Body)(nil), // 37: tree.ApplyRequest.Body + (*ApplyResponse_Body)(nil), // 38: tree.ApplyResponse.Body + (*GetOpLogRequest_Body)(nil), // 39: tree.GetOpLogRequest.Body + (*GetOpLogResponse_Body)(nil), // 40: tree.GetOpLogResponse.Body + (*HealthcheckResponse_Body)(nil), // 41: tree.HealthcheckResponse.Body + (*HealthcheckRequest_Body)(nil), // 42: tree.HealthcheckRequest.Body + (*Signature)(nil), // 43: tree.Signature + (*KeyValue)(nil), // 44: tree.KeyValue + (*LogMove)(nil), // 45: tree.LogMove } var file_pkg_services_tree_service_proto_depIdxs = []int32{ - 20, // 0: tree.AddRequest.body:type_name -> tree.AddRequest.Body - 41, // 1: tree.AddRequest.signature:type_name -> tree.Signature - 21, // 2: tree.AddResponse.body:type_name -> tree.AddResponse.Body - 41, // 3: tree.AddResponse.signature:type_name -> tree.Signature - 22, // 4: tree.AddByPathRequest.body:type_name -> tree.AddByPathRequest.Body - 41, // 5: tree.AddByPathRequest.signature:type_name -> tree.Signature - 23, // 6: tree.AddByPathResponse.body:type_name -> tree.AddByPathResponse.Body - 41, // 7: tree.AddByPathResponse.signature:type_name -> tree.Signature - 24, // 8: tree.RemoveRequest.body:type_name -> tree.RemoveRequest.Body - 41, // 9: tree.RemoveRequest.signature:type_name -> tree.Signature - 25, // 10: tree.RemoveResponse.body:type_name -> tree.RemoveResponse.Body - 41, // 11: tree.RemoveResponse.signature:type_name -> tree.Signature - 26, // 12: tree.MoveRequest.body:type_name -> tree.MoveRequest.Body - 41, // 13: tree.MoveRequest.signature:type_name -> tree.Signature - 27, // 14: tree.MoveResponse.body:type_name -> tree.MoveResponse.Body - 41, // 15: tree.MoveResponse.signature:type_name -> tree.Signature - 28, // 16: tree.GetNodeByPathRequest.body:type_name -> tree.GetNodeByPathRequest.Body - 41, // 17: tree.GetNodeByPathRequest.signature:type_name -> tree.Signature - 30, // 18: tree.GetNodeByPathResponse.body:type_name -> tree.GetNodeByPathResponse.Body - 41, // 19: tree.GetNodeByPathResponse.signature:type_name -> tree.Signature - 31, // 20: tree.GetSubTreeRequest.body:type_name -> tree.GetSubTreeRequest.Body - 41, // 21: tree.GetSubTreeRequest.signature:type_name -> tree.Signature - 32, // 22: tree.GetSubTreeResponse.body:type_name -> tree.GetSubTreeResponse.Body - 41, // 23: tree.GetSubTreeResponse.signature:type_name -> tree.Signature - 33, // 24: tree.TreeListRequest.body:type_name -> tree.TreeListRequest.Body - 41, // 25: tree.TreeListRequest.signature:type_name -> tree.Signature - 34, // 26: tree.TreeListResponse.body:type_name -> tree.TreeListResponse.Body - 41, // 27: tree.TreeListResponse.signature:type_name -> tree.Signature - 35, // 28: tree.ApplyRequest.body:type_name -> tree.ApplyRequest.Body - 41, // 29: tree.ApplyRequest.signature:type_name -> tree.Signature - 36, // 30: tree.ApplyResponse.body:type_name -> tree.ApplyResponse.Body - 41, // 31: tree.ApplyResponse.signature:type_name -> tree.Signature - 37, // 32: tree.GetOpLogRequest.body:type_name -> tree.GetOpLogRequest.Body - 41, // 33: tree.GetOpLogRequest.signature:type_name -> tree.Signature - 38, // 34: tree.GetOpLogResponse.body:type_name -> tree.GetOpLogResponse.Body - 41, // 35: tree.GetOpLogResponse.signature:type_name -> tree.Signature - 39, // 36: tree.HealthcheckResponse.body:type_name -> tree.HealthcheckResponse.Body - 41, // 37: tree.HealthcheckResponse.signature:type_name -> tree.Signature - 40, // 38: tree.HealthcheckRequest.body:type_name -> tree.HealthcheckRequest.Body - 41, // 39: tree.HealthcheckRequest.signature:type_name -> tree.Signature - 42, // 40: tree.AddRequest.Body.meta:type_name -> tree.KeyValue - 42, // 41: tree.AddByPathRequest.Body.meta:type_name -> tree.KeyValue - 42, // 42: tree.MoveRequest.Body.meta:type_name -> tree.KeyValue - 42, // 43: tree.GetNodeByPathResponse.Info.meta:type_name -> tree.KeyValue - 29, // 44: tree.GetNodeByPathResponse.Body.nodes:type_name -> tree.GetNodeByPathResponse.Info - 42, // 45: tree.GetSubTreeResponse.Body.meta:type_name -> tree.KeyValue - 43, // 46: tree.ApplyRequest.Body.operation:type_name -> tree.LogMove - 43, // 47: tree.GetOpLogResponse.Body.operation:type_name -> tree.LogMove - 0, // 48: tree.TreeService.Add:input_type -> tree.AddRequest - 2, // 49: tree.TreeService.AddByPath:input_type -> tree.AddByPathRequest - 4, // 50: tree.TreeService.Remove:input_type -> tree.RemoveRequest - 6, // 51: tree.TreeService.Move:input_type -> tree.MoveRequest - 8, // 52: tree.TreeService.GetNodeByPath:input_type -> tree.GetNodeByPathRequest - 10, // 53: tree.TreeService.GetSubTree:input_type -> tree.GetSubTreeRequest - 12, // 54: tree.TreeService.TreeList:input_type -> tree.TreeListRequest - 14, // 55: tree.TreeService.Apply:input_type -> tree.ApplyRequest - 16, // 56: tree.TreeService.GetOpLog:input_type -> tree.GetOpLogRequest - 19, // 57: tree.TreeService.Healthcheck:input_type -> tree.HealthcheckRequest - 1, // 58: tree.TreeService.Add:output_type -> tree.AddResponse - 3, // 59: tree.TreeService.AddByPath:output_type -> tree.AddByPathResponse - 5, // 60: tree.TreeService.Remove:output_type -> tree.RemoveResponse - 7, // 61: tree.TreeService.Move:output_type -> tree.MoveResponse - 9, // 62: tree.TreeService.GetNodeByPath:output_type -> tree.GetNodeByPathResponse - 11, // 63: tree.TreeService.GetSubTree:output_type -> tree.GetSubTreeResponse - 13, // 64: tree.TreeService.TreeList:output_type -> tree.TreeListResponse - 15, // 65: tree.TreeService.Apply:output_type -> tree.ApplyResponse - 17, // 66: tree.TreeService.GetOpLog:output_type -> tree.GetOpLogResponse - 18, // 67: tree.TreeService.Healthcheck:output_type -> tree.HealthcheckResponse - 58, // [58:68] is the sub-list for method output_type - 48, // [48:58] is the sub-list for method input_type - 48, // [48:48] is the sub-list for extension type_name - 48, // [48:48] is the sub-list for extension extendee - 0, // [0:48] is the sub-list for field type_name + 21, // 0: tree.AddRequest.body:type_name -> tree.AddRequest.Body + 43, // 1: tree.AddRequest.signature:type_name -> tree.Signature + 22, // 2: tree.AddResponse.body:type_name -> tree.AddResponse.Body + 43, // 3: tree.AddResponse.signature:type_name -> tree.Signature + 23, // 4: tree.AddByPathRequest.body:type_name -> tree.AddByPathRequest.Body + 43, // 5: tree.AddByPathRequest.signature:type_name -> tree.Signature + 24, // 6: tree.AddByPathResponse.body:type_name -> tree.AddByPathResponse.Body + 43, // 7: tree.AddByPathResponse.signature:type_name -> tree.Signature + 25, // 8: tree.RemoveRequest.body:type_name -> tree.RemoveRequest.Body + 43, // 9: tree.RemoveRequest.signature:type_name -> tree.Signature + 26, // 10: tree.RemoveResponse.body:type_name -> tree.RemoveResponse.Body + 43, // 11: tree.RemoveResponse.signature:type_name -> tree.Signature + 27, // 12: tree.MoveRequest.body:type_name -> tree.MoveRequest.Body + 43, // 13: tree.MoveRequest.signature:type_name -> tree.Signature + 28, // 14: tree.MoveResponse.body:type_name -> tree.MoveResponse.Body + 43, // 15: tree.MoveResponse.signature:type_name -> tree.Signature + 29, // 16: tree.GetNodeByPathRequest.body:type_name -> tree.GetNodeByPathRequest.Body + 43, // 17: tree.GetNodeByPathRequest.signature:type_name -> tree.Signature + 31, // 18: tree.GetNodeByPathResponse.body:type_name -> tree.GetNodeByPathResponse.Body + 43, // 19: tree.GetNodeByPathResponse.signature:type_name -> tree.Signature + 32, // 20: tree.GetSubTreeRequest.body:type_name -> tree.GetSubTreeRequest.Body + 43, // 21: tree.GetSubTreeRequest.signature:type_name -> tree.Signature + 34, // 22: tree.GetSubTreeResponse.body:type_name -> tree.GetSubTreeResponse.Body + 43, // 23: tree.GetSubTreeResponse.signature:type_name -> tree.Signature + 35, // 24: tree.TreeListRequest.body:type_name -> tree.TreeListRequest.Body + 43, // 25: tree.TreeListRequest.signature:type_name -> tree.Signature + 36, // 26: tree.TreeListResponse.body:type_name -> tree.TreeListResponse.Body + 43, // 27: tree.TreeListResponse.signature:type_name -> tree.Signature + 37, // 28: tree.ApplyRequest.body:type_name -> tree.ApplyRequest.Body + 43, // 29: tree.ApplyRequest.signature:type_name -> tree.Signature + 38, // 30: tree.ApplyResponse.body:type_name -> tree.ApplyResponse.Body + 43, // 31: tree.ApplyResponse.signature:type_name -> tree.Signature + 39, // 32: tree.GetOpLogRequest.body:type_name -> tree.GetOpLogRequest.Body + 43, // 33: tree.GetOpLogRequest.signature:type_name -> tree.Signature + 40, // 34: tree.GetOpLogResponse.body:type_name -> tree.GetOpLogResponse.Body + 43, // 35: tree.GetOpLogResponse.signature:type_name -> tree.Signature + 41, // 36: tree.HealthcheckResponse.body:type_name -> tree.HealthcheckResponse.Body + 43, // 37: tree.HealthcheckResponse.signature:type_name -> tree.Signature + 42, // 38: tree.HealthcheckRequest.body:type_name -> tree.HealthcheckRequest.Body + 43, // 39: tree.HealthcheckRequest.signature:type_name -> tree.Signature + 44, // 40: tree.AddRequest.Body.meta:type_name -> tree.KeyValue + 44, // 41: tree.AddByPathRequest.Body.meta:type_name -> tree.KeyValue + 44, // 42: tree.MoveRequest.Body.meta:type_name -> tree.KeyValue + 44, // 43: tree.GetNodeByPathResponse.Info.meta:type_name -> tree.KeyValue + 30, // 44: tree.GetNodeByPathResponse.Body.nodes:type_name -> tree.GetNodeByPathResponse.Info + 33, // 45: tree.GetSubTreeRequest.Body.order_by:type_name -> tree.GetSubTreeRequest.Body.Order + 0, // 46: tree.GetSubTreeRequest.Body.Order.direction:type_name -> tree.GetSubTreeRequest.Body.Order.Direction + 44, // 47: tree.GetSubTreeResponse.Body.meta:type_name -> tree.KeyValue + 45, // 48: tree.ApplyRequest.Body.operation:type_name -> tree.LogMove + 45, // 49: tree.GetOpLogResponse.Body.operation:type_name -> tree.LogMove + 1, // 50: tree.TreeService.Add:input_type -> tree.AddRequest + 3, // 51: tree.TreeService.AddByPath:input_type -> tree.AddByPathRequest + 5, // 52: tree.TreeService.Remove:input_type -> tree.RemoveRequest + 7, // 53: tree.TreeService.Move:input_type -> tree.MoveRequest + 9, // 54: tree.TreeService.GetNodeByPath:input_type -> tree.GetNodeByPathRequest + 11, // 55: tree.TreeService.GetSubTree:input_type -> tree.GetSubTreeRequest + 13, // 56: tree.TreeService.TreeList:input_type -> tree.TreeListRequest + 15, // 57: tree.TreeService.Apply:input_type -> tree.ApplyRequest + 17, // 58: tree.TreeService.GetOpLog:input_type -> tree.GetOpLogRequest + 20, // 59: tree.TreeService.Healthcheck:input_type -> tree.HealthcheckRequest + 2, // 60: tree.TreeService.Add:output_type -> tree.AddResponse + 4, // 61: tree.TreeService.AddByPath:output_type -> tree.AddByPathResponse + 6, // 62: tree.TreeService.Remove:output_type -> tree.RemoveResponse + 8, // 63: tree.TreeService.Move:output_type -> tree.MoveResponse + 10, // 64: tree.TreeService.GetNodeByPath:output_type -> tree.GetNodeByPathResponse + 12, // 65: tree.TreeService.GetSubTree:output_type -> tree.GetSubTreeResponse + 14, // 66: tree.TreeService.TreeList:output_type -> tree.TreeListResponse + 16, // 67: tree.TreeService.Apply:output_type -> tree.ApplyResponse + 18, // 68: tree.TreeService.GetOpLog:output_type -> tree.GetOpLogResponse + 19, // 69: tree.TreeService.Healthcheck:output_type -> tree.HealthcheckResponse + 60, // [60:70] is the sub-list for method output_type + 50, // [50:60] is the sub-list for method input_type + 50, // [50:50] is the sub-list for extension type_name + 50, // [50:50] is the sub-list for extension extendee + 0, // [0:50] is the sub-list for field type_name } func init() { file_pkg_services_tree_service_proto_init() } @@ -3325,7 +3443,7 @@ func file_pkg_services_tree_service_proto_init() { } } file_pkg_services_tree_service_proto_msgTypes[32].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetSubTreeResponse_Body); i { + switch v := v.(*GetSubTreeRequest_Body_Order); i { case 0: return &v.state case 1: @@ -3337,7 +3455,7 @@ func file_pkg_services_tree_service_proto_init() { } } file_pkg_services_tree_service_proto_msgTypes[33].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*TreeListRequest_Body); i { + switch v := v.(*GetSubTreeResponse_Body); i { case 0: return &v.state case 1: @@ -3349,7 +3467,7 @@ func file_pkg_services_tree_service_proto_init() { } } file_pkg_services_tree_service_proto_msgTypes[34].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*TreeListResponse_Body); i { + switch v := v.(*TreeListRequest_Body); i { case 0: return &v.state case 1: @@ -3361,7 +3479,7 @@ func file_pkg_services_tree_service_proto_init() { } } file_pkg_services_tree_service_proto_msgTypes[35].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ApplyRequest_Body); i { + switch v := v.(*TreeListResponse_Body); i { case 0: return &v.state case 1: @@ -3373,7 +3491,7 @@ func file_pkg_services_tree_service_proto_init() { } } file_pkg_services_tree_service_proto_msgTypes[36].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ApplyResponse_Body); i { + switch v := v.(*ApplyRequest_Body); i { case 0: return &v.state case 1: @@ -3385,7 +3503,7 @@ func file_pkg_services_tree_service_proto_init() { } } file_pkg_services_tree_service_proto_msgTypes[37].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetOpLogRequest_Body); i { + switch v := v.(*ApplyResponse_Body); i { case 0: return &v.state case 1: @@ -3397,7 +3515,7 @@ func file_pkg_services_tree_service_proto_init() { } } file_pkg_services_tree_service_proto_msgTypes[38].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetOpLogResponse_Body); i { + switch v := v.(*GetOpLogRequest_Body); i { case 0: return &v.state case 1: @@ -3409,7 +3527,7 @@ func file_pkg_services_tree_service_proto_init() { } } file_pkg_services_tree_service_proto_msgTypes[39].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*HealthcheckResponse_Body); i { + switch v := v.(*GetOpLogResponse_Body); i { case 0: return &v.state case 1: @@ -3421,6 +3539,18 @@ func file_pkg_services_tree_service_proto_init() { } } file_pkg_services_tree_service_proto_msgTypes[40].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HealthcheckResponse_Body); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pkg_services_tree_service_proto_msgTypes[41].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*HealthcheckRequest_Body); i { case 0: return &v.state @@ -3438,13 +3568,14 @@ func file_pkg_services_tree_service_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_pkg_services_tree_service_proto_rawDesc, - NumEnums: 0, - NumMessages: 41, + NumEnums: 1, + NumMessages: 42, NumExtensions: 0, NumServices: 1, }, GoTypes: file_pkg_services_tree_service_proto_goTypes, DependencyIndexes: file_pkg_services_tree_service_proto_depIdxs, + EnumInfos: file_pkg_services_tree_service_proto_enumTypes, MessageInfos: file_pkg_services_tree_service_proto_msgTypes, }.Build() File_pkg_services_tree_service_proto = out.File diff --git a/pool/tree/service/service_grpc.pb.go b/pool/tree/service/service_grpc.pb.go index f981746d..2c082895 100644 --- a/pool/tree/service/service_grpc.pb.go +++ b/pool/tree/service/service_grpc.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v3.12.4 +// - protoc v3.21.9 // source: pkg/services/tree/service.proto package tree diff --git a/pool/tree/service/types.pb.go b/pool/tree/service/types.pb.go index 45d88917..b4d6981e 100644 --- a/pool/tree/service/types.pb.go +++ b/pool/tree/service/types.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.26.0 -// protoc v3.12.4 +// protoc v3.21.9 // source: pkg/services/tree/types.proto package tree diff --git a/syncTree.sh b/syncTree.sh index 9bb758b9..90eeba72 100755 --- a/syncTree.sh +++ b/syncTree.sh @@ -1,6 +1,6 @@ #!/bin/bash -REVISION="f07d4158f50ed5c7f44cc0bc224c3d03edf27f3b" +REVISION="b3695411d907c3c65485bab04f9ff8479a72906b" echo "tree service revision ${REVISION}" From d376302a3bb4a6875b53879ac033e899d76924c8 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Wed, 2 Aug 2023 18:23:32 +0300 Subject: [PATCH 026/288] [#121] client: Make PrmContainerGet fields public Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- client/container_get.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/client/container_get.go b/client/container_get.go index 9e985233..0e2d028e 100644 --- a/client/container_get.go +++ b/client/container_get.go @@ -18,26 +18,31 @@ import ( // PrmContainerGet groups parameters of ContainerGet operation. type PrmContainerGet struct { - prmCommonMeta + // FrostFS request X-Headers + XHeaders []string - idSet bool - id cid.ID + CID *cid.ID } // SetContainer sets identifier of the container to be read. // Required parameter. -func (x *PrmContainerGet) SetContainer(id cid.ID) { - x.id = id - x.idSet = true +// +// Deprecated: Use PrmContainerGet.CID instead. +func (prm *PrmContainerGet) SetContainer(cid cid.ID) { + prm.CID = &cid } -func (x *PrmContainerGet) buildRequest(c *Client) (*v2container.GetRequest, error) { - if !x.idSet { +func (prm *PrmContainerGet) buildRequest(c *Client) (*v2container.GetRequest, error) { + if prm.CID == nil { return nil, errorMissingContainer } + if len(prm.XHeaders)%2 != 0 { + return nil, errorInvalidXHeaders + } + var cidV2 refs.ContainerID - x.id.WriteToV2(&cidV2) + prm.CID.WriteToV2(&cidV2) reqBody := new(v2container.GetRequestBody) reqBody.SetContainerID(&cidV2) From 55c52c8d5d6bf0d5dab97f14649e8709d4ba290a Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Wed, 2 Aug 2023 18:56:41 +0300 Subject: [PATCH 027/288] [#121] pool: Make PrmContainerGet fields public * Also refactor client PrmContainerGet usage Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- client/container_get.go | 12 ++++++------ pool/pool.go | 13 ++++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/client/container_get.go b/client/container_get.go index 0e2d028e..d2ef0fef 100644 --- a/client/container_get.go +++ b/client/container_get.go @@ -18,22 +18,22 @@ import ( // PrmContainerGet groups parameters of ContainerGet operation. type PrmContainerGet struct { - // FrostFS request X-Headers + // FrostFS request X-Headers. XHeaders []string - CID *cid.ID + ContainerID *cid.ID } // SetContainer sets identifier of the container to be read. // Required parameter. // -// Deprecated: Use PrmContainerGet.CID instead. +// Deprecated: Use PrmContainerGet.ContainerID instead. func (prm *PrmContainerGet) SetContainer(cid cid.ID) { - prm.CID = &cid + prm.ContainerID = &cid } func (prm *PrmContainerGet) buildRequest(c *Client) (*v2container.GetRequest, error) { - if prm.CID == nil { + if prm.ContainerID == nil { return nil, errorMissingContainer } @@ -42,7 +42,7 @@ func (prm *PrmContainerGet) buildRequest(c *Client) (*v2container.GetRequest, er } var cidV2 refs.ContainerID - prm.CID.WriteToV2(&cidV2) + prm.ContainerID.WriteToV2(&cidV2) reqBody := new(v2container.GetRequestBody) reqBody.SetContainerID(&cidV2) diff --git a/pool/pool.go b/pool/pool.go index 04b84aa4..833b57e9 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -438,8 +438,9 @@ func (c *clientWrapper) containerGet(ctx context.Context, prm PrmContainerGet) ( return container.Container{}, err } - var cliPrm sdkClient.PrmContainerGet - cliPrm.SetContainer(prm.cnrID) + cliPrm := sdkClient.PrmContainerGet{ + ContainerID: &prm.ContainerID, + } start := time.Now() res, err := cl.ContainerGet(ctx, cliPrm) @@ -1444,12 +1445,14 @@ func (x *PrmContainerPut) SetWaitParams(waitParams WaitParams) { // PrmContainerGet groups parameters of GetContainer operation. type PrmContainerGet struct { - cnrID cid.ID + ContainerID cid.ID } // SetContainerID specifies identifier of the container to be read. -func (x *PrmContainerGet) SetContainerID(cnrID cid.ID) { - x.cnrID = cnrID +// +// Deprecated: Use PrmContainerGet.ContainerID instead. +func (prm *PrmContainerGet) SetContainerID(cnrID cid.ID) { + prm.ContainerID = cnrID } // PrmContainerList groups parameters of ListContainers operation. From 3dc8129ed79406b7f0e523be471f30e3014b9107 Mon Sep 17 00:00:00 2001 From: Alejandro Lopez Date: Wed, 2 Aug 2023 10:01:03 +0300 Subject: [PATCH 028/288] [#135] Make all error status receivers pointers Signed-off-by: Alejandro Lopez --- client/errors.go | 24 +++++------------- client/errors_test.go | 47 +++++++++++------------------------ client/status/common.go | 8 +++--- client/status/container.go | 4 +-- client/status/object.go | 12 ++++----- client/status/session.go | 4 +-- client/status/unrecognized.go | 2 +- pool/pool.go | 8 +++--- pool/pool_test.go | 20 +++++++-------- 9 files changed, 49 insertions(+), 80 deletions(-) diff --git a/client/errors.go b/client/errors.go index bf2b1eab..769b442e 100644 --- a/client/errors.go +++ b/client/errors.go @@ -22,9 +22,7 @@ func IsErrContainerNotFound(err error) bool { switch unwrapErr(err).(type) { default: return false - case - apistatus.ContainerNotFound, - *apistatus.ContainerNotFound: + case *apistatus.ContainerNotFound: return true } } @@ -35,9 +33,7 @@ func IsErrEACLNotFound(err error) bool { switch unwrapErr(err).(type) { default: return false - case - apistatus.EACLNotFound, - *apistatus.EACLNotFound: + case *apistatus.EACLNotFound: return true } } @@ -48,9 +44,7 @@ func IsErrObjectNotFound(err error) bool { switch unwrapErr(err).(type) { default: return false - case - apistatus.ObjectNotFound, - *apistatus.ObjectNotFound: + case *apistatus.ObjectNotFound: return true } } @@ -61,9 +55,7 @@ func IsErrObjectAlreadyRemoved(err error) bool { switch unwrapErr(err).(type) { default: return false - case - apistatus.ObjectAlreadyRemoved, - *apistatus.ObjectAlreadyRemoved: + case *apistatus.ObjectAlreadyRemoved: return true } } @@ -74,9 +66,7 @@ func IsErrSessionExpired(err error) bool { switch unwrapErr(err).(type) { default: return false - case - apistatus.SessionTokenExpired, - *apistatus.SessionTokenExpired: + case *apistatus.SessionTokenExpired: return true } } @@ -87,9 +77,7 @@ func IsErrSessionNotFound(err error) bool { switch unwrapErr(err).(type) { default: return false - case - apistatus.SessionTokenNotFound, - *apistatus.SessionTokenNotFound: + case *apistatus.SessionTokenNotFound: return true } } diff --git a/client/errors_test.go b/client/errors_test.go index 657d0fe3..90114d74 100644 --- a/client/errors_test.go +++ b/client/errors_test.go @@ -10,59 +10,40 @@ import ( ) func TestErrors(t *testing.T) { - for _, tc := range []struct { + errs := []struct { check func(error) bool - errs []error + err error }{ { check: client.IsErrContainerNotFound, - errs: []error{ - apistatus.ContainerNotFound{}, - new(apistatus.ContainerNotFound), - }, + err: new(apistatus.ContainerNotFound), }, { check: client.IsErrEACLNotFound, - errs: []error{ - apistatus.EACLNotFound{}, - new(apistatus.EACLNotFound), - }, + err: new(apistatus.EACLNotFound), }, { check: client.IsErrObjectNotFound, - errs: []error{ - apistatus.ObjectNotFound{}, - new(apistatus.ObjectNotFound), - }, + err: new(apistatus.ObjectNotFound), }, { check: client.IsErrObjectAlreadyRemoved, - errs: []error{ - apistatus.ObjectAlreadyRemoved{}, - new(apistatus.ObjectAlreadyRemoved), - }, + err: new(apistatus.ObjectAlreadyRemoved), }, { check: client.IsErrSessionExpired, - errs: []error{ - apistatus.SessionTokenExpired{}, - new(apistatus.SessionTokenExpired), - }, + err: new(apistatus.SessionTokenExpired), }, { check: client.IsErrSessionNotFound, - errs: []error{ - apistatus.SessionTokenNotFound{}, - new(apistatus.SessionTokenNotFound), - }, + err: new(apistatus.SessionTokenNotFound), }, - } { - require.NotEmpty(t, tc.errs) + } - for i := range tc.errs { - require.True(t, tc.check(tc.errs[i]), tc.errs[i]) - require.True(t, tc.check(fmt.Errorf("top-level context: :%w", - fmt.Errorf("inner context: %w", tc.errs[i])), - ), tc.errs[i]) + for i := range errs { + for j := range errs { + nestedErr := fmt.Errorf("top-level context: :%w", fmt.Errorf("inner context: %w", errs[j].err)) + require.Equal(t, i == j, errs[i].check(errs[j].err)) + require.Equal(t, i == j, errs[i].check(nestedErr)) } } } diff --git a/client/status/common.go b/client/status/common.go index 421d5323..af0dc8ec 100644 --- a/client/status/common.go +++ b/client/status/common.go @@ -14,7 +14,7 @@ type ServerInternal struct { v2 status.Status } -func (x ServerInternal) Error() string { +func (x *ServerInternal) Error() string { return errMessageStatusV2( globalizeCodeV2(status.Internal, status.GlobalizeCommonFail), x.v2.Message(), @@ -62,7 +62,7 @@ type WrongMagicNumber struct { v2 status.Status } -func (x WrongMagicNumber) Error() string { +func (x *WrongMagicNumber) Error() string { return errMessageStatusV2( globalizeCodeV2(status.WrongMagicNumber, status.GlobalizeCommonFail), x.v2.Message(), @@ -132,7 +132,7 @@ type SignatureVerification struct { const defaultSignatureVerificationMsg = "signature verification failed" -func (x SignatureVerification) Error() string { +func (x *SignatureVerification) Error() string { msg := x.v2.Message() if msg == "" { msg = defaultSignatureVerificationMsg @@ -191,7 +191,7 @@ type NodeUnderMaintenance struct { const defaultNodeUnderMaintenanceMsg = "node is under maintenance" // Error implements the error interface. -func (x NodeUnderMaintenance) Error() string { +func (x *NodeUnderMaintenance) Error() string { msg := x.Message() if msg == "" { msg = defaultNodeUnderMaintenanceMsg diff --git a/client/status/container.go b/client/status/container.go index c62aaacf..9f06b27e 100644 --- a/client/status/container.go +++ b/client/status/container.go @@ -13,7 +13,7 @@ type ContainerNotFound struct { const defaultContainerNotFoundMsg = "container not found" -func (x ContainerNotFound) Error() string { +func (x *ContainerNotFound) Error() string { msg := x.v2.Message() if msg == "" { msg = defaultContainerNotFoundMsg @@ -51,7 +51,7 @@ type EACLNotFound struct { const defaultEACLNotFoundMsg = "eACL not found" -func (x EACLNotFound) Error() string { +func (x *EACLNotFound) Error() string { msg := x.v2.Message() if msg == "" { msg = defaultEACLNotFoundMsg diff --git a/client/status/object.go b/client/status/object.go index 579cb930..27ea86cb 100644 --- a/client/status/object.go +++ b/client/status/object.go @@ -13,7 +13,7 @@ type ObjectLocked struct { const defaultObjectLockedMsg = "object is locked" -func (x ObjectLocked) Error() string { +func (x *ObjectLocked) Error() string { msg := x.v2.Message() if msg == "" { msg = defaultObjectLockedMsg @@ -50,7 +50,7 @@ type LockNonRegularObject struct { const defaultLockNonRegularObjectMsg = "locking non-regular object is forbidden" -func (x LockNonRegularObject) Error() string { +func (x *LockNonRegularObject) Error() string { msg := x.v2.Message() if msg == "" { msg = defaultLockNonRegularObjectMsg @@ -87,7 +87,7 @@ type ObjectAccessDenied struct { const defaultObjectAccessDeniedMsg = "access to object operation denied" -func (x ObjectAccessDenied) Error() string { +func (x *ObjectAccessDenied) Error() string { msg := x.v2.Message() if msg == "" { msg = defaultObjectAccessDeniedMsg @@ -135,7 +135,7 @@ type ObjectNotFound struct { const defaultObjectNotFoundMsg = "object not found" -func (x ObjectNotFound) Error() string { +func (x *ObjectNotFound) Error() string { msg := x.v2.Message() if msg == "" { msg = defaultObjectNotFoundMsg @@ -172,7 +172,7 @@ type ObjectAlreadyRemoved struct { const defaultObjectAlreadyRemovedMsg = "object already removed" -func (x ObjectAlreadyRemoved) Error() string { +func (x *ObjectAlreadyRemoved) Error() string { msg := x.v2.Message() if msg == "" { msg = defaultObjectAlreadyRemovedMsg @@ -210,7 +210,7 @@ type ObjectOutOfRange struct { const defaultObjectOutOfRangeMsg = "out of range" -func (x ObjectOutOfRange) Error() string { +func (x *ObjectOutOfRange) Error() string { msg := x.v2.Message() if msg == "" { msg = defaultObjectOutOfRangeMsg diff --git a/client/status/session.go b/client/status/session.go index 6c54965a..6f607581 100644 --- a/client/status/session.go +++ b/client/status/session.go @@ -13,7 +13,7 @@ type SessionTokenNotFound struct { const defaultSessionTokenNotFoundMsg = "session token not found" -func (x SessionTokenNotFound) Error() string { +func (x *SessionTokenNotFound) Error() string { msg := x.v2.Message() if msg == "" { msg = defaultSessionTokenNotFoundMsg @@ -50,7 +50,7 @@ type SessionTokenExpired struct { const defaultSessionTokenExpiredMsg = "expired session token" -func (x SessionTokenExpired) Error() string { +func (x *SessionTokenExpired) Error() string { msg := x.v2.Message() if msg == "" { msg = defaultSessionTokenExpiredMsg diff --git a/client/status/unrecognized.go b/client/status/unrecognized.go index b9a8cdb2..19e481ee 100644 --- a/client/status/unrecognized.go +++ b/client/status/unrecognized.go @@ -8,7 +8,7 @@ type unrecognizedStatusV2 struct { v2 status.Status } -func (x unrecognizedStatusV2) Error() string { +func (x *unrecognizedStatusV2) Error() string { return errMessageStatusV2("unrecognized", x.v2.Message()) } diff --git a/pool/pool.go b/pool/pool.go index 833b57e9..3fb4e9e5 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -1015,10 +1015,10 @@ func (c *clientStatusMonitor) handleError(ctx context.Context, st apistatus.Stat err = apistatus.ErrFromStatus(st) switch err.(type) { - case apistatus.ServerInternal, *apistatus.ServerInternal, - apistatus.WrongMagicNumber, *apistatus.WrongMagicNumber, - apistatus.SignatureVerification, *apistatus.SignatureVerification, - apistatus.NodeUnderMaintenance, *apistatus.NodeUnderMaintenance: + case *apistatus.ServerInternal, + *apistatus.WrongMagicNumber, + *apistatus.SignatureVerification, + *apistatus.NodeUnderMaintenance: c.incErrorRate() } diff --git a/pool/pool_test.go b/pool/pool_test.go index bc0407e7..623d429b 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -271,7 +271,7 @@ func TestSessionCache(t *testing.T) { mockClientBuilder := func(addr string) client { mockCli := newMockClient(addr, *key) - mockCli.statusOnGetObject(apistatus.SessionTokenNotFound{}) + mockCli.statusOnGetObject(new(apistatus.SessionTokenNotFound)) return mockCli } @@ -548,14 +548,14 @@ func TestHandleError(t *testing.T) { }, { ctx: ctx, - status: apistatus.SuccessDefaultV2{}, + status: new(apistatus.SuccessDefaultV2), err: nil, expectedError: false, countError: false, }, { ctx: ctx, - status: apistatus.SuccessDefaultV2{}, + status: new(apistatus.SuccessDefaultV2), err: errors.New("error"), expectedError: true, countError: true, @@ -569,42 +569,42 @@ func TestHandleError(t *testing.T) { }, { ctx: ctx, - status: apistatus.ObjectNotFound{}, + status: new(apistatus.ObjectNotFound), err: nil, expectedError: true, countError: false, }, { ctx: ctx, - status: apistatus.ServerInternal{}, + status: new(apistatus.ServerInternal), err: nil, expectedError: true, countError: true, }, { ctx: ctx, - status: apistatus.WrongMagicNumber{}, + status: new(apistatus.WrongMagicNumber), err: nil, expectedError: true, countError: true, }, { ctx: ctx, - status: apistatus.SignatureVerification{}, + status: new(apistatus.SignatureVerification), err: nil, expectedError: true, countError: true, }, { ctx: ctx, - status: &apistatus.SignatureVerification{}, + status: new(apistatus.SignatureVerification), err: nil, expectedError: true, countError: true, }, { ctx: ctx, - status: apistatus.NodeUnderMaintenance{}, + status: new(apistatus.NodeUnderMaintenance), err: nil, expectedError: true, countError: true, @@ -649,7 +649,7 @@ func TestSwitchAfterErrorThreshold(t *testing.T) { if addr == nodes[0].address { mockCli := newMockClient(addr, *key) mockCli.setThreshold(uint32(errorThreshold)) - mockCli.statusOnGetObject(apistatus.ServerInternal{}) + mockCli.statusOnGetObject(new(apistatus.ServerInternal)) return mockCli } From 9e5faaf8299339198ca4e3ec830f2962617613fa Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Thu, 3 Aug 2023 11:42:54 +0300 Subject: [PATCH 029/288] [#121] client: Make PrmContainerDelete fields public Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- client/container_delete.go | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/client/container_delete.go b/client/container_delete.go index 0059988d..70d5f40a 100644 --- a/client/container_delete.go +++ b/client/container_delete.go @@ -18,29 +18,33 @@ import ( // PrmContainerDelete groups parameters of ContainerDelete operation. type PrmContainerDelete struct { - prmCommonMeta + // FrostFS request X-Headers + XHeaders []string - idSet bool - id cid.ID + ContainerID *cid.ID - tokSet bool - tok session.Container + Session *session.Container } // SetContainer sets identifier of the FrostFS container to be removed. // Required parameter. +// +// Deprecated: Use PrmContainerDelete.Container instead. func (x *PrmContainerDelete) SetContainer(id cid.ID) { - x.id = id - x.idSet = true + x.ContainerID = &id } -func (x *PrmContainerDelete) buildRequest(c *Client) (*v2container.DeleteRequest, error) { - if !x.idSet { +func (prm *PrmContainerDelete) buildRequest(c *Client) (*v2container.DeleteRequest, error) { + if prm.ContainerID == nil { return nil, errorMissingContainer } + if len(prm.XHeaders)%2 != 0 { + return nil, errorInvalidXHeaders + } + var cidV2 refs.ContainerID - x.id.WriteToV2(&cidV2) + prm.ContainerID.WriteToV2(&cidV2) // Container contract expects signature of container ID value, // don't get confused with stable marshaled protobuf container.ID structure. @@ -61,11 +65,11 @@ func (x *PrmContainerDelete) buildRequest(c *Client) (*v2container.DeleteRequest reqBody.SetSignature(&sigv2) var meta v2session.RequestMetaHeader - writeXHeadersToMeta(x.prmCommonMeta.xHeaders, &meta) + writeXHeadersToMeta(prm.XHeaders, &meta) - if x.tokSet { + if prm.Session != nil { var tokv2 v2session.Token - x.tok.WriteToV2(&tokv2) + prm.Session.WriteToV2(&tokv2) meta.SetSessionToken(&tokv2) } @@ -82,9 +86,10 @@ func (x *PrmContainerDelete) buildRequest(c *Client) (*v2container.DeleteRequest // This may affect the execution of an operation (e.g. access control). // // Must be signed. +// +// Deprecated: Use PrmContainerDelete.Session instead. func (x *PrmContainerDelete) WithinSession(tok session.Container) { - x.tok = tok - x.tokSet = true + x.Session = &tok } // ResContainerDelete groups resulting values of ContainerDelete operation. From be28b89312fe7972655e746eef813ce4f20dd797 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Thu, 3 Aug 2023 12:11:14 +0300 Subject: [PATCH 030/288] [#121] pool: Make PrmContainerDelete fields public * Refactor client PrmContainerDelete usage * Introduce WaitParams CheckValidity method Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- pool/pool.go | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/pool/pool.go b/pool/pool.go index 3fb4e9e5..31bf84fc 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -487,10 +487,9 @@ func (c *clientWrapper) containerDelete(ctx context.Context, prm PrmContainerDel return err } - var cliPrm sdkClient.PrmContainerDelete - cliPrm.SetContainer(prm.cnrID) - if prm.stokenSet { - cliPrm.WithinSession(prm.stoken) + cliPrm := sdkClient.PrmContainerDelete{ + ContainerID: &prm.ContainerID, + Session: prm.Session, } start := time.Now() @@ -504,11 +503,14 @@ func (c *clientWrapper) containerDelete(ctx context.Context, prm PrmContainerDel return fmt.Errorf("container delete on client: %w", err) } - if !prm.waitParamsSet { - prm.waitParams.setDefaults() + if prm.WaitParams == nil { + prm.WaitParams = defaultWaitParams() + } + if err := prm.WaitParams.CheckValidity(); err != nil { + return fmt.Errorf("invalid wait parameters: %w", err) } - return waitForContainerRemoved(ctx, c, &prm.cnrID, &prm.waitParams) + return waitForContainerRemoved(ctx, c, &prm.ContainerID, prm.WaitParams) } // containerEACL invokes sdkClient.ContainerEACL parse response status to error and return result as is. @@ -1236,6 +1238,17 @@ func (x *WaitParams) checkForPositive() { } } +// CheckForValid checks if all wait params are non-negative. +func (waitPrm *WaitParams) CheckValidity() error { + if waitPrm.timeout <= 0 { + return errors.New("timeout cannot be negative") + } + if waitPrm.pollInterval <= 0 { + return errors.New("poll interval cannot be negative") + } + return nil +} + type prmContext struct { defaultSession bool verb session.ObjectVerb @@ -1467,33 +1480,35 @@ func (x *PrmContainerList) SetOwnerID(ownerID user.ID) { // PrmContainerDelete groups parameters of DeleteContainer operation. type PrmContainerDelete struct { - cnrID cid.ID + ContainerID cid.ID - stoken session.Container - stokenSet bool + Session *session.Container - waitParams WaitParams - waitParamsSet bool + WaitParams *WaitParams } // SetContainerID specifies identifier of the FrostFS container to be removed. +// +// Deprecated: Use PrmContainerDelete.ContainerID instead. func (x *PrmContainerDelete) SetContainerID(cnrID cid.ID) { - x.cnrID = cnrID + x.ContainerID = cnrID } // SetSessionToken specifies session within which operation should be performed. +// +// Deprecated: Use PrmContainerDelete.Session instead. func (x *PrmContainerDelete) SetSessionToken(token session.Container) { - x.stoken = token - x.stokenSet = true + x.Session = &token } // SetWaitParams specifies timeout params to complete operation. // If not provided the default one will be used. // Panics if any of the wait params isn't positive. +// +// Deprecated: Use PrmContainerDelete.WaitParams instead. func (x *PrmContainerDelete) SetWaitParams(waitParams WaitParams) { waitParams.checkForPositive() - x.waitParams = waitParams - x.waitParamsSet = true + x.WaitParams = &waitParams } // PrmContainerEACL groups parameters of GetEACL operation. From 936e6d230b74a22a060ea89f3810ff7e01320a15 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Thu, 3 Aug 2023 12:14:00 +0300 Subject: [PATCH 031/288] [#121] pool: Add wait params validation for containerPut method * Add WaitParams.CheckValidity() check because SetWaitParams is deprecated, but parameters were checked within this setter with checkForPositive() Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- client/container_delete.go | 8 ++++---- pool/pool.go | 38 +++++++++++++++++++++++--------------- pool/pool_test.go | 12 ++++++------ 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/client/container_delete.go b/client/container_delete.go index 70d5f40a..181c15b5 100644 --- a/client/container_delete.go +++ b/client/container_delete.go @@ -30,8 +30,8 @@ type PrmContainerDelete struct { // Required parameter. // // Deprecated: Use PrmContainerDelete.Container instead. -func (x *PrmContainerDelete) SetContainer(id cid.ID) { - x.ContainerID = &id +func (prm *PrmContainerDelete) SetContainer(id cid.ID) { + prm.ContainerID = &id } func (prm *PrmContainerDelete) buildRequest(c *Client) (*v2container.DeleteRequest, error) { @@ -88,8 +88,8 @@ func (prm *PrmContainerDelete) buildRequest(c *Client) (*v2container.DeleteReque // Must be signed. // // Deprecated: Use PrmContainerDelete.Session instead. -func (x *PrmContainerDelete) WithinSession(tok session.Container) { - x.Session = &tok +func (prm *PrmContainerDelete) WithinSession(tok session.Container) { + prm.Session = &tok } // ResContainerDelete groups resulting values of ContainerDelete operation. diff --git a/pool/pool.go b/pool/pool.go index 31bf84fc..075ba7fc 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -420,6 +420,9 @@ func (c *clientWrapper) containerPut(ctx context.Context, prm PrmContainerPut) ( if prm.WaitParams == nil { prm.WaitParams = defaultWaitParams() } + if err = prm.WaitParams.CheckValidity(); err != nil { + return cid.ID{}, fmt.Errorf("invalid wait parameters: %w", err) + } idCnr := res.ID() @@ -1205,45 +1208,50 @@ func (x *NodeParam) Weight() float64 { // WaitParams contains parameters used in polling is a something applied on FrostFS network. type WaitParams struct { - timeout time.Duration - pollInterval time.Duration + Timeout time.Duration + PollInterval time.Duration } // SetTimeout specifies the time to wait for the operation to complete. +// +// Deprecated: Use WaitParams.Timeout instead. func (x *WaitParams) SetTimeout(timeout time.Duration) { - x.timeout = timeout + x.Timeout = timeout } // SetPollInterval specifies the interval, once it will check the completion of the operation. +// +// Deprecated: Use WaitParams.PollInterval instead. func (x *WaitParams) SetPollInterval(tick time.Duration) { - x.pollInterval = tick + x.PollInterval = tick } +// Deprecated: Use defaultWaitParams() instead. func (x *WaitParams) setDefaults() { - x.timeout = 120 * time.Second - x.pollInterval = 5 * time.Second + x.Timeout = 120 * time.Second + x.PollInterval = 5 * time.Second } func defaultWaitParams() *WaitParams { return &WaitParams{ - timeout: 120 * time.Second, - pollInterval: 5 * time.Second, + Timeout: 120 * time.Second, + PollInterval: 5 * time.Second, } } // checkForPositive panics if any of the wait params isn't positive. func (x *WaitParams) checkForPositive() { - if x.timeout <= 0 || x.pollInterval <= 0 { + if x.Timeout <= 0 || x.PollInterval <= 0 { panic("all wait params must be positive") } } // CheckForValid checks if all wait params are non-negative. -func (waitPrm *WaitParams) CheckValidity() error { - if waitPrm.timeout <= 0 { +func (x *WaitParams) CheckValidity() error { + if x.Timeout <= 0 { return errors.New("timeout cannot be negative") } - if waitPrm.pollInterval <= 0 { + if x.PollInterval <= 0 { return errors.New("poll interval cannot be negative") } return nil @@ -2533,9 +2541,9 @@ func waitForContainerRemoved(ctx context.Context, cli client, cnrID *cid.ID, wai // waitFor await that given condition will be met in waitParams time. func waitFor(ctx context.Context, params *WaitParams, condition func(context.Context) bool) error { - wctx, cancel := context.WithTimeout(ctx, params.timeout) + wctx, cancel := context.WithTimeout(ctx, params.Timeout) defer cancel() - ticker := time.NewTimer(params.pollInterval) + ticker := time.NewTimer(params.PollInterval) defer ticker.Stop() wdone := wctx.Done() done := ctx.Done() @@ -2549,7 +2557,7 @@ func waitFor(ctx context.Context, params *WaitParams, condition func(context.Con if condition(ctx) { return nil } - ticker.Reset(params.pollInterval) + ticker.Reset(params.PollInterval) } } } diff --git a/pool/pool_test.go b/pool/pool_test.go index 623d429b..08de667a 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -483,8 +483,8 @@ func TestWaitPresence(t *testing.T) { var idCnr cid.ID err := waitForContainerPresence(ctx, mockCli, idCnr, &WaitParams{ - timeout: 120 * time.Second, - pollInterval: 5 * time.Second, + Timeout: 120 * time.Second, + PollInterval: 5 * time.Second, }) require.Error(t, err) require.Contains(t, err.Error(), "context canceled") @@ -494,8 +494,8 @@ func TestWaitPresence(t *testing.T) { ctx := context.Background() var idCnr cid.ID err := waitForContainerPresence(ctx, mockCli, idCnr, &WaitParams{ - timeout: 500 * time.Millisecond, - pollInterval: 5 * time.Second, + Timeout: 500 * time.Millisecond, + PollInterval: 5 * time.Second, }) require.Error(t, err) require.Contains(t, err.Error(), "context deadline exceeded") @@ -505,8 +505,8 @@ func TestWaitPresence(t *testing.T) { ctx := context.Background() var idCnr cid.ID err := waitForContainerPresence(ctx, mockCli, idCnr, &WaitParams{ - timeout: 10 * time.Second, - pollInterval: 500 * time.Millisecond, + Timeout: 10 * time.Second, + PollInterval: 500 * time.Millisecond, }) require.NoError(t, err) }) From 6353df8bca63075a24ee736ba36055f4e87e334a Mon Sep 17 00:00:00 2001 From: Alejandro Lopez Date: Fri, 4 Aug 2023 11:43:36 +0300 Subject: [PATCH 032/288] [#142] Fix unwrapErr for go 1.20 Signed-off-by: Alejandro Lopez --- client/errors.go | 65 ++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/client/errors.go b/client/errors.go index 769b442e..64144b6e 100644 --- a/client/errors.go +++ b/client/errors.go @@ -1,85 +1,64 @@ package client import ( - "errors" "fmt" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" ) -// unwraps err using errors.Unwrap and returns the result. -func unwrapErr(err error) error { - for e := errors.Unwrap(err); e != nil; e = errors.Unwrap(err) { - err = e +// wrapsErrType returns true if any error in the error tree of err is of type E. +func wrapsErrType[E error](err error) bool { + switch e := err.(type) { + case E: + return true + case interface{ Unwrap() error }: + return wrapsErrType[E](e.Unwrap()) + case interface{ Unwrap() []error }: + for _, ei := range e.Unwrap() { + if wrapsErrType[E](ei) { + return true + } + } + return false + default: + return false } - - return err } // IsErrContainerNotFound checks if err corresponds to FrostFS status // return corresponding to missing container. Supports wrapped errors. func IsErrContainerNotFound(err error) bool { - switch unwrapErr(err).(type) { - default: - return false - case *apistatus.ContainerNotFound: - return true - } + return wrapsErrType[*apistatus.ContainerNotFound](err) } // IsErrEACLNotFound checks if err corresponds to FrostFS status // return corresponding to missing eACL table. Supports wrapped errors. func IsErrEACLNotFound(err error) bool { - switch unwrapErr(err).(type) { - default: - return false - case *apistatus.EACLNotFound: - return true - } + return wrapsErrType[*apistatus.EACLNotFound](err) } // IsErrObjectNotFound checks if err corresponds to FrostFS status // return corresponding to missing object. Supports wrapped errors. func IsErrObjectNotFound(err error) bool { - switch unwrapErr(err).(type) { - default: - return false - case *apistatus.ObjectNotFound: - return true - } + return wrapsErrType[*apistatus.ObjectNotFound](err) } // IsErrObjectAlreadyRemoved checks if err corresponds to FrostFS status // return corresponding to already removed object. Supports wrapped errors. func IsErrObjectAlreadyRemoved(err error) bool { - switch unwrapErr(err).(type) { - default: - return false - case *apistatus.ObjectAlreadyRemoved: - return true - } + return wrapsErrType[*apistatus.ObjectAlreadyRemoved](err) } // IsErrSessionExpired checks if err corresponds to FrostFS status return // corresponding to expired session. Supports wrapped errors. func IsErrSessionExpired(err error) bool { - switch unwrapErr(err).(type) { - default: - return false - case *apistatus.SessionTokenExpired: - return true - } + return wrapsErrType[*apistatus.SessionTokenExpired](err) } // IsErrSessionNotFound checks if err corresponds to FrostFS status return // corresponding to missing session. Supports wrapped errors. func IsErrSessionNotFound(err error) bool { - switch unwrapErr(err).(type) { - default: - return false - case *apistatus.SessionTokenNotFound: - return true - } + return wrapsErrType[*apistatus.SessionTokenNotFound](err) } // returns error describing missing field with the given name. From d48788c7a946895b40d9d6e8a1f91469b5cf2e98 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 9 Aug 2023 09:51:29 +0300 Subject: [PATCH 033/288] [#144] Bump required go version to go1.20 Signed-off-by: Evgenii Stratonikov --- Dockerfile | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index cb6b4205..a4cfb15a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19 +FROM golang:1.21 RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install make openjdk-11-jre -y WORKDIR /work diff --git a/go.mod b/go.mod index 7c1690eb..3ede75c8 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module git.frostfs.info/TrueCloudLab/frostfs-sdk-go -go 1.19 +go 1.20 require ( git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230802075510-964c3edb3f44 From 548a81d3e6aaa4d607b9dc236c3a2bbaa7fec440 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 9 Aug 2023 09:48:05 +0300 Subject: [PATCH 034/288] [#48] client: Refactor accounting.Balance() Signed-off-by: Evgenii Stratonikov --- client/accounting.go | 92 ++++++++--------- client/common.go | 229 ------------------------------------------- 2 files changed, 46 insertions(+), 275 deletions(-) diff --git a/client/accounting.go b/client/accounting.go index 71dd0305..021b26a4 100644 --- a/client/accounting.go +++ b/client/accounting.go @@ -2,12 +2,16 @@ package client import ( "context" + "fmt" v2accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" rpcapi "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" + v2session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/signature" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/accounting" + apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user" ) @@ -26,6 +30,24 @@ func (x *PrmBalanceGet) SetAccount(id user.ID) { x.accountSet = true } +func (x *PrmBalanceGet) buildRequest(c *Client) (*v2accounting.BalanceRequest, error) { + if !x.accountSet { + return nil, errorAccountNotSet + } + + var accountV2 refs.OwnerID + x.account.WriteToV2(&accountV2) + + var body v2accounting.BalanceRequestBody + body.SetOwnerID(&accountV2) + + var req v2accounting.BalanceRequest + req.SetBody(&body) + + c.prepareRequest(&req, new(v2session.RequestMetaHeader)) + return &req, nil +} + // ResBalanceGet groups resulting values of BalanceGet operation. type ResBalanceGet struct { statusRes @@ -52,57 +74,35 @@ func (x ResBalanceGet) Amount() accounting.Decimal { // Return statuses: // - global (see Client docs). func (c *Client) BalanceGet(ctx context.Context, prm PrmBalanceGet) (*ResBalanceGet, error) { - if !prm.accountSet { - return nil, errorAccountNotSet + req, err := prm.buildRequest(c) + if err != nil { + return nil, err } - // form request body - var accountV2 refs.OwnerID - prm.account.WriteToV2(&accountV2) - - var body v2accounting.BalanceRequestBody - body.SetOwnerID(&accountV2) - - // form request - var req v2accounting.BalanceRequest - - req.SetBody(&body) - - // init call context - - var ( - cc contextCall - res ResBalanceGet - ) - - c.initCallContext(&cc) - cc.meta = prm.prmCommonMeta - cc.req = &req - cc.statusRes = &res - cc.call = func() (responseV2, error) { - return rpcapi.Balance(&c.c, &req, client.WithContext(ctx)) - } - cc.result = func(r responseV2) { - resp := r.(*v2accounting.BalanceResponse) - - const fieldBalance = "balance" - - bal := resp.GetBody().GetBalance() - if bal == nil { - cc.err = newErrMissingResponseField(fieldBalance) - return - } - - cc.err = res.amount.ReadFromV2(*bal) - if cc.err != nil { - cc.err = newErrInvalidResponseField(fieldBalance, cc.err) - } + if err := signature.SignServiceMessage(&c.prm.key, req); err != nil { + return nil, fmt.Errorf("sign request: %w", err) } - // process call - if !cc.processCall() { - return nil, cc.err + resp, err := rpcapi.Balance(&c.c, req, client.WithContext(ctx)) + if err != nil { + return nil, err } + var res ResBalanceGet + res.st, err = c.processResponse(resp) + if err != nil || !apistatus.IsSuccessful(res.st) { + return &res, err + } + + const fieldBalance = "balance" + + bal := resp.GetBody().GetBalance() + if bal == nil { + return &res, newErrMissingResponseField(fieldBalance) + } + + if err := res.amount.ReadFromV2(*bal); err != nil { + return &res, newErrInvalidResponseField(fieldBalance, err) + } return &res, nil } diff --git a/client/common.go b/client/common.go index 7449288d..907f6be9 100644 --- a/client/common.go +++ b/client/common.go @@ -1,7 +1,6 @@ package client import ( - "crypto/ecdsa" "errors" "fmt" @@ -13,21 +12,11 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version" ) -// common interface of resulting structures with API status. -type resCommon interface { - setStatus(apistatus.Status) -} - // structure is embedded to all resulting types in order to inherit status-related methods. type statusRes struct { st apistatus.Status } -// setStatus implements resCommon interface method. -func (x *statusRes) setStatus(st apistatus.Status) { - x.st = st -} - // Status returns server's status return. // // Use apistatus package functionality to handle the status. @@ -85,89 +74,12 @@ var ( errorInvalidXHeaders = errors.New("xheaders must be presented only as key-value pairs") ) -// groups all the details required to send a single request and process a response to it. -type contextCall struct { - // ================================================== - // state vars that do not require explicit initialization - - // final error to be returned from client method - err error - - // received response - resp responseV2 - - // ================================================== - // shared parameters which are set uniformly on all calls - - // request signing key - key ecdsa.PrivateKey - - // callback prior to processing the response by the client - callbackResp func(ResponseMetaInfo) error - - // if set, protocol errors will be expanded into a final error - resolveAPIFailures bool - - // FrostFS network magic - netMagic uint64 - - // Meta parameters - meta prmCommonMeta - - // ================================================== - // custom call parameters - - // structure of the call result - statusRes resCommon - - // request to be signed with a key and sent - req request - - // function to send a request (unary) and receive a response - call func() (responseV2, error) - - // function to send the request (req field) - wReq func() error - - // function to recv the response (resp field) - rResp func() error - - // function to close the message stream - closer func() error - - // function of writing response fields to the resulting structure (optional) - result func(v2 responseV2) -} - type request interface { GetMetaHeader() *v2session.RequestMetaHeader SetMetaHeader(*v2session.RequestMetaHeader) SetVerificationHeader(*v2session.RequestVerificationHeader) } -// sets needed fields of the request meta header. -func (x contextCall) prepareRequest() { - meta := x.req.GetMetaHeader() - if meta == nil { - meta = new(v2session.RequestMetaHeader) - x.req.SetMetaHeader(meta) - } - - if meta.GetTTL() == 0 { - meta.SetTTL(2) - } - - if meta.GetVersion() == nil { - var verV2 refs.Version - version.Current().WriteToV2(&verV2) - meta.SetVersion(&verV2) - } - - meta.SetNetworkMagic(x.netMagic) - - writeXHeadersToMeta(x.meta.xHeaders, meta) -} - func (c *Client) prepareRequest(req request, meta *v2session.RequestMetaHeader) { ttl := meta.GetTTL() if ttl == 0 { @@ -187,75 +99,6 @@ func (c *Client) prepareRequest(req request, meta *v2session.RequestMetaHeader) req.SetMetaHeader(meta) } -// prepares, signs and writes the request. Result means success. -// If failed, contextCall.err contains the reason. -func (x *contextCall) writeRequest() bool { - x.prepareRequest() - - x.req.SetVerificationHeader(nil) - - // sign the request - x.err = signature.SignServiceMessage(&x.key, x.req) - if x.err != nil { - x.err = fmt.Errorf("sign request: %w", x.err) - return false - } - - x.err = x.wReq() - if x.err != nil { - x.err = fmt.Errorf("write request: %w", x.err) - return false - } - - return true -} - -// performs common actions of response processing and writes any problem as a result status or client error -// (in both cases returns false). -// -// Actions: -// - verify signature (internal); -// - call response callback (internal); -// - unwrap status error (optional). -func (x *contextCall) processResponse() bool { - // call response callback if set - if x.callbackResp != nil { - x.err = x.callbackResp(ResponseMetaInfo{ - key: x.resp.GetVerificationHeader().GetBodySignature().GetKey(), - epoch: x.resp.GetMetaHeader().GetEpoch(), - }) - if x.err != nil { - x.err = fmt.Errorf("response callback error: %w", x.err) - return false - } - } - - // note that we call response callback before signature check since it is expected more lightweight - // while verification needs marshaling - - // verify response signature - x.err = signature.VerifyServiceMessage(x.resp) - if x.err != nil { - x.err = fmt.Errorf("invalid response signature: %w", x.err) - return false - } - - // get result status - st := apistatus.FromStatusV2(x.resp.GetMetaHeader().GetStatus()) - - // unwrap unsuccessful status and return it - // as error if client has been configured so - successfulStatus := apistatus.IsSuccessful(st) - - if x.resolveAPIFailures { - x.err = apistatus.ErrFromStatus(st) - } else { - x.statusRes.setStatus(st) - } - - return successfulStatus -} - // processResponse verifies response signature and converts status to an error if needed. func (c *Client) processResponse(resp responseV2) (apistatus.Status, error) { if c.prm.cbRespInfo != nil { @@ -280,78 +123,6 @@ func (c *Client) processResponse(resp responseV2) (apistatus.Status, error) { return st, nil } -// reads response (if rResp is set) and processes it. Result means success. -// If failed, contextCall.err (or statusRes if resolveAPIFailures is set) contains the reason. -func (x *contextCall) readResponse() bool { - if x.rResp != nil { - x.err = x.rResp() - if x.err != nil { - x.err = fmt.Errorf("read response: %w", x.err) - return false - } - } - - return x.processResponse() -} - -// closes the message stream (if closer is set) and writes the results (if result is set). -// Return means success. If failed, contextCall.err contains the reason. -func (x *contextCall) close() bool { - if x.closer != nil { - x.err = x.closer() - if x.err != nil { - x.err = fmt.Errorf("close RPC: %w", x.err) - return false - } - } - - // write response to resulting structure - if x.result != nil { - x.result(x.resp) - } - - return x.err == nil -} - -// goes through all stages of sending a request and processing a response. Returns true if successful. -// If failed, contextCall.err contains the reason. -func (x *contextCall) processCall() bool { - // set request writer - x.wReq = func() error { - var err error - x.resp, err = x.call() - return err - } - - // write request - ok := x.writeRequest() - if !ok { - return false - } - - // read response - ok = x.readResponse() - if !ok { - return x.err == nil - } - - // close and write response to resulting structure - ok = x.close() - if !ok { - return false - } - - return x.err == nil -} - -// initializes static cross-call parameters inherited from client. -func (c *Client) initCallContext(ctx *contextCall) { - ctx.key = c.prm.key - ctx.resolveAPIFailures = c.prm.resolveFrostFSErrors - ctx.callbackResp = c.prm.cbRespInfo - ctx.netMagic = c.prm.netMagic -} - // ExecRaw executes f with underlying git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client.Client // instance. Communicate over the Protocol Buffers protocol in a more flexible way: // most often used to transmit data over a fixed version of the FrostFS protocol, as well From 03827857639916df3f998a91d647eb284b7d8026 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 11 Aug 2023 12:32:11 +0300 Subject: [PATCH 035/288] [#146] .forgejo: Update DCO action Signed-off-by: Evgenii Stratonikov --- .forgejo/workflows/dco.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.forgejo/workflows/dco.yml b/.forgejo/workflows/dco.yml index d77461ce..a5614a5a 100644 --- a/.forgejo/workflows/dco.yml +++ b/.forgejo/workflows/dco.yml @@ -13,9 +13,9 @@ jobs: - name: Setup Go uses: actions/setup-go@v3 with: - go-version: '1.20' + go-version: '1.21' - name: Run commit format checker - uses: https://git.alexvan.in/alexvanin/dco-go@v1 + uses: https://git.frostfs.info/TrueCloudLab/dco-go@v2 with: - from: 406c2324 + from: 'origin/${{ github.event.pull_request.base.ref }}' From 0314b326d31eb19d41bcb1dc59bc9215780ff654 Mon Sep 17 00:00:00 2001 From: Artem Tataurov Date: Tue, 15 Aug 2023 09:51:13 +0300 Subject: [PATCH 036/288] [#51] Add current nodes as external statistics Signed-off-by: Artem Tataurov --- pool/pool.go | 7 +++++++ pool/statistic.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/pool/pool.go b/pool/pool.go index 075ba7fc..db3b298d 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -2482,8 +2482,12 @@ func (p *Pool) Balance(ctx context.Context, prm PrmBalanceGet) (accounting.Decim func (p Pool) Statistic() Statistic { stat := Statistic{} for _, inner := range p.innerPools { + nodes := make([]string, 0, len(inner.clients)) inner.lock.RLock() for _, cl := range inner.clients { + if cl.isHealthy() { + nodes = append(nodes, cl.address()) + } node := NodeStatistic{ address: cl.address(), methods: cl.methodsStatus(), @@ -2494,6 +2498,9 @@ func (p Pool) Statistic() Statistic { stat.overallErrors += node.overallErrors } inner.lock.RUnlock() + if len(stat.currentNodes) == 0 { + stat.currentNodes = nodes + } } return stat diff --git a/pool/statistic.go b/pool/statistic.go index 3a4f4242..5f1cfad9 100644 --- a/pool/statistic.go +++ b/pool/statistic.go @@ -9,6 +9,7 @@ import ( type Statistic struct { overallErrors uint64 nodes []NodeStatistic + currentNodes []string } // OverallErrors returns sum of errors on all connections. It doesn't decrease. @@ -21,6 +22,12 @@ func (s Statistic) Nodes() []NodeStatistic { return s.nodes } +// CurrentNodes returns list of nodes of inner pool that has at least one healthy node. +// These nodes have the same and the highest priority among the other healthy nodes. +func (s Statistic) CurrentNodes() []string { + return s.currentNodes +} + // ErrUnknownNode indicate that node with current address is not found in list. var ErrUnknownNode = errors.New("unknown node") From a3b5d4d4f5c990605aba56b7bdbacb41ec671671 Mon Sep 17 00:00:00 2001 From: Artem Tataurov Date: Tue, 15 Aug 2023 09:51:40 +0300 Subject: [PATCH 037/288] [#51] Add node addresses as debug information Signed-off-by: Artem Tataurov --- pool/pool.go | 80 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 14 deletions(-) diff --git a/pool/pool.go b/pool/pool.go index db3b298d..901545c3 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -2150,7 +2150,7 @@ func (p *Pool) PutObject(ctx context.Context, prm PrmObjectPut) (oid.ID, error) if err != nil { // removes session token from cache in case of token error p.checkSessionTokenErr(err, ctxCall.endpoint) - return id, fmt.Errorf("init writing on API client: %w", err) + return id, fmt.Errorf("init writing on API client %s: %w", ctxCall.endpoint, err) } return id, nil @@ -2193,7 +2193,7 @@ func (p *Pool) DeleteObject(ctx context.Context, prm PrmObjectDelete) error { return p.call(ctx, &cc, func() error { if err = cc.client.objectDelete(ctx, prm); err != nil { - return fmt.Errorf("remove object via client: %w", err) + return fmt.Errorf("remove object via client %s: %w", cc.endpoint, err) } return nil @@ -2244,7 +2244,10 @@ func (p *Pool) GetObject(ctx context.Context, prm PrmObjectGet) (ResGetObject, e return res, p.call(ctx, &cc, func() error { res, err = cc.client.objectGet(ctx, prm) - return err + if err != nil { + return fmt.Errorf("get object via client %s: %w", cc.endpoint, err) + } + return nil }) } @@ -2266,7 +2269,10 @@ func (p *Pool) HeadObject(ctx context.Context, prm PrmObjectHead) (object.Object return obj, p.call(ctx, &cc, func() error { obj, err = cc.client.objectHead(ctx, prm) - return err + if err != nil { + return fmt.Errorf("head object via client %s: %w", cc.endpoint, err) + } + return nil }) } @@ -2314,7 +2320,10 @@ func (p *Pool) ObjectRange(ctx context.Context, prm PrmObjectRange) (ResObjectRa return res, p.call(ctx, &cc, func() error { res, err = cc.client.objectRange(ctx, prm) - return err + if err != nil { + return fmt.Errorf("object range via client %s: %w", cc.endpoint, err) + } + return nil }) } @@ -2375,7 +2384,10 @@ func (p *Pool) SearchObjects(ctx context.Context, prm PrmObjectSearch) (ResObjec return res, p.call(ctx, &cc, func() error { res, err = cc.client.objectSearch(ctx, prm) - return err + if err != nil { + return fmt.Errorf("search object via client %s: %w", cc.endpoint, err) + } + return nil }) } @@ -2395,7 +2407,12 @@ func (p *Pool) PutContainer(ctx context.Context, prm PrmContainerPut) (cid.ID, e return cid.ID{}, err } - return cp.containerPut(ctx, prm) + cnrID, err := cp.containerPut(ctx, prm) + if err != nil { + return cid.ID{}, fmt.Errorf("put container via client '%s': %w", cp.address(), err) + } + + return cnrID, nil } // GetContainer reads FrostFS container by ID. @@ -2407,7 +2424,12 @@ func (p *Pool) GetContainer(ctx context.Context, prm PrmContainerGet) (container return container.Container{}, err } - return cp.containerGet(ctx, prm) + cnrs, err := cp.containerGet(ctx, prm) + if err != nil { + return container.Container{}, fmt.Errorf("get container via client '%s': %w", cp.address(), err) + } + + return cnrs, nil } // ListContainers requests identifiers of the account-owned containers. @@ -2417,7 +2439,12 @@ func (p *Pool) ListContainers(ctx context.Context, prm PrmContainerList) ([]cid. return nil, err } - return cp.containerList(ctx, prm) + cnrIDs, err := cp.containerList(ctx, prm) + if err != nil { + return []cid.ID{}, fmt.Errorf("list containers via client '%s': %w", cp.address(), err) + } + + return cnrIDs, nil } // DeleteContainer sends request to remove the FrostFS container and waits for the operation to complete. @@ -2434,7 +2461,12 @@ func (p *Pool) DeleteContainer(ctx context.Context, prm PrmContainerDelete) erro return err } - return cp.containerDelete(ctx, prm) + err = cp.containerDelete(ctx, prm) + if err != nil { + return fmt.Errorf("delete container via client '%s': %w", cp.address(), err) + } + + return nil } // GetEACL reads eACL table of the FrostFS container. @@ -2446,7 +2478,12 @@ func (p *Pool) GetEACL(ctx context.Context, prm PrmContainerEACL) (eacl.Table, e return eacl.Table{}, err } - return cp.containerEACL(ctx, prm) + eaclResult, err := cp.containerEACL(ctx, prm) + if err != nil { + return eacl.Table{}, fmt.Errorf("get EACL via client '%s': %w", cp.address(), err) + } + + return eaclResult, nil } // SetEACL sends request to update eACL table of the FrostFS container and waits for the operation to complete. @@ -2463,7 +2500,12 @@ func (p *Pool) SetEACL(ctx context.Context, prm PrmContainerSetEACL) error { return err } - return cp.containerSetEACL(ctx, prm) + err = cp.containerSetEACL(ctx, prm) + if err != nil { + return fmt.Errorf("set EACL via client '%s': %w", cp.address(), err) + } + + return nil } // Balance requests current balance of the FrostFS account. @@ -2475,7 +2517,12 @@ func (p *Pool) Balance(ctx context.Context, prm PrmBalanceGet) (accounting.Decim return accounting.Decimal{}, err } - return cp.balanceGet(ctx, prm) + balance, err := cp.balanceGet(ctx, prm) + if err != nil { + return accounting.Decimal{}, fmt.Errorf("get balance via client '%s': %w", cp.address(), err) + } + + return balance, nil } // Statistic returns connection statistics. @@ -2578,7 +2625,12 @@ func (p *Pool) NetworkInfo(ctx context.Context) (netmap.NetworkInfo, error) { return netmap.NetworkInfo{}, err } - return cp.networkInfo(ctx, prmNetworkInfo{}) + netInfo, err := cp.networkInfo(ctx, prmNetworkInfo{}) + if err != nil { + return netmap.NetworkInfo{}, fmt.Errorf("get network info via client '%s': %w", cp.address(), err) + } + + return netInfo, nil } // Close closes the Pool and releases all the associated resources. From 3353940554526899f502868b456a0549dc25132c Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Fri, 11 Aug 2023 10:33:06 +0300 Subject: [PATCH 038/288] [#121] client: Make PrmContainerEACL fields public Signed-off-by: Airat Arifullin --- client/container_eacl.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/client/container_eacl.go b/client/container_eacl.go index 8f8e6513..2acde860 100644 --- a/client/container_eacl.go +++ b/client/container_eacl.go @@ -17,26 +17,31 @@ import ( // PrmContainerEACL groups parameters of ContainerEACL operation. type PrmContainerEACL struct { - prmCommonMeta + // FrostFS request X-Headers. + XHeaders []string - idSet bool - id cid.ID + ContainerID *cid.ID } // SetContainer sets identifier of the FrostFS container to read the eACL table. // Required parameter. +// +// Deprecated: Use PrmContainerEACL.ContainerID instead. func (x *PrmContainerEACL) SetContainer(id cid.ID) { - x.id = id - x.idSet = true + x.ContainerID = &id } func (x *PrmContainerEACL) buildRequest(c *Client) (*v2container.GetExtendedACLRequest, error) { - if !x.idSet { + if x.ContainerID == nil { return nil, errorMissingContainer } + if len(x.XHeaders)%2 != 0 { + return nil, errorInvalidXHeaders + } + var cidV2 refs.ContainerID - x.id.WriteToV2(&cidV2) + x.ContainerID.WriteToV2(&cidV2) reqBody := new(v2container.GetExtendedACLRequestBody) reqBody.SetContainerID(&cidV2) From 6fdbe755179efb5fc5cdf5f1abc78cb4e982c3c8 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Fri, 11 Aug 2023 11:06:45 +0300 Subject: [PATCH 039/288] [#121] pool: Make PrmContainerEACL fields public Signed-off-by: Airat Arifullin --- pool/pool.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pool/pool.go b/pool/pool.go index 901545c3..b603951c 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -523,8 +523,9 @@ func (c *clientWrapper) containerEACL(ctx context.Context, prm PrmContainerEACL) return eacl.Table{}, err } - var cliPrm sdkClient.PrmContainerEACL - cliPrm.SetContainer(prm.cnrID) + cliPrm := sdkClient.PrmContainerEACL{ + ContainerID: &prm.ContainerID, + } start := time.Now() res, err := cl.ContainerEACL(ctx, cliPrm) @@ -1521,12 +1522,12 @@ func (x *PrmContainerDelete) SetWaitParams(waitParams WaitParams) { // PrmContainerEACL groups parameters of GetEACL operation. type PrmContainerEACL struct { - cnrID cid.ID + ContainerID cid.ID } // SetContainerID specifies identifier of the FrostFS container to read the eACL table. func (x *PrmContainerEACL) SetContainerID(cnrID cid.ID) { - x.cnrID = cnrID + x.ContainerID = cnrID } // PrmContainerSetEACL groups parameters of SetEACL operation. @@ -2568,7 +2569,7 @@ func waitForContainerPresence(ctx context.Context, cli client, cnrID cid.ID, wai func waitForEACLPresence(ctx context.Context, cli client, cnrID *cid.ID, table *eacl.Table, waitParams *WaitParams) error { var prm PrmContainerEACL if cnrID != nil { - prm.SetContainerID(*cnrID) + prm.ContainerID = *cnrID } return waitFor(ctx, waitParams, func(ctx context.Context) bool { From 22978303f8b7e4123a54a87966caa2d7aceb25a1 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Fri, 18 Aug 2023 17:54:51 +0300 Subject: [PATCH 040/288] [#121] clientt: Make PrmContainerSetEACL fields public Signed-off-by: Airat Arifullin --- client/container_set_eacl.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/client/container_set_eacl.go b/client/container_set_eacl.go index 19173733..0ea89aa8 100644 --- a/client/container_set_eacl.go +++ b/client/container_set_eacl.go @@ -18,20 +18,20 @@ import ( // PrmContainerSetEACL groups parameters of ContainerSetEACL operation. type PrmContainerSetEACL struct { - prmCommonMeta + // FrostFS request X-Headers. + XHeaders []string - tableSet bool - table eacl.Table + Table *eacl.Table - sessionSet bool - session session.Container + Session *session.Container } // SetTable sets eACL table structure to be set for the container. // Required parameter. +// +// Deprecated: Use PrmContainerSetEACL.Table instead. func (x *PrmContainerSetEACL) SetTable(table eacl.Table) { - x.table = table - x.tableSet = true + x.Table = &table } // WithinSession specifies session within which extended ACL of the container @@ -45,17 +45,22 @@ func (x *PrmContainerSetEACL) SetTable(table eacl.Table) { // for which extended ACL is going to be set // - session operation MUST be session.VerbContainerSetEACL (ForVerb) // - token MUST be signed using private key of the owner of the container to be saved +// +// Deprecated: Use PrmContainerSetEACL.Session instead. func (x *PrmContainerSetEACL) WithinSession(s session.Container) { - x.session = s - x.sessionSet = true + x.Session = &s } func (x *PrmContainerSetEACL) buildRequest(c *Client) (*v2container.SetExtendedACLRequest, error) { - if !x.tableSet { + if x.Table == nil { return nil, errorEACLTableNotSet } - eaclV2 := x.table.ToV2() + if len(x.XHeaders)%2 != 0 { + return nil, errorInvalidXHeaders + } + + eaclV2 := x.Table.ToV2() var sig frostfscrypto.Signature @@ -72,11 +77,11 @@ func (x *PrmContainerSetEACL) buildRequest(c *Client) (*v2container.SetExtendedA reqBody.SetSignature(&sigv2) var meta v2session.RequestMetaHeader - writeXHeadersToMeta(x.prmCommonMeta.xHeaders, &meta) + writeXHeadersToMeta(x.XHeaders, &meta) - if x.sessionSet { + if x.Session != nil { var tokv2 v2session.Token - x.session.WriteToV2(&tokv2) + x.Session.WriteToV2(&tokv2) meta.SetSessionToken(&tokv2) } From 342524159ac33b9bc01df3696ebb151538acd581 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Fri, 18 Aug 2023 18:07:51 +0300 Subject: [PATCH 041/288] [#121] pool: Make PrmContainerSetEACL fields public Signed-off-by: Airat Arifullin --- pool/pool.go | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/pool/pool.go b/pool/pool.go index b603951c..06c317cb 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -549,11 +549,9 @@ func (c *clientWrapper) containerSetEACL(ctx context.Context, prm PrmContainerSe return err } - var cliPrm sdkClient.PrmContainerSetEACL - cliPrm.SetTable(prm.table) - - if prm.sessionSet { - cliPrm.WithinSession(prm.session) + cliPrm := sdkClient.PrmContainerSetEACL{ + Table: &prm.Table, + Session: prm.Session, } start := time.Now() @@ -567,16 +565,19 @@ func (c *clientWrapper) containerSetEACL(ctx context.Context, prm PrmContainerSe return fmt.Errorf("set eacl on client: %w", err) } - if !prm.waitParamsSet { - prm.waitParams.setDefaults() + if prm.WaitParams == nil { + prm.WaitParams = defaultWaitParams() + } + if err := prm.WaitParams.CheckValidity(); err != nil { + return fmt.Errorf("invalid wait parameters: %w", err) } var cIDp *cid.ID - if cID, set := prm.table.CID(); set { + if cID, set := prm.Table.CID(); set { cIDp = &cID } - err = waitForEACLPresence(ctx, c, cIDp, &prm.table, &prm.waitParams) + err = waitForEACLPresence(ctx, c, cIDp, &prm.Table, prm.WaitParams) if err = c.handleError(ctx, nil, err); err != nil { return fmt.Errorf("wait eacl presence on client: %w", err) } @@ -1227,12 +1228,6 @@ func (x *WaitParams) SetPollInterval(tick time.Duration) { x.PollInterval = tick } -// Deprecated: Use defaultWaitParams() instead. -func (x *WaitParams) setDefaults() { - x.Timeout = 120 * time.Second - x.PollInterval = 5 * time.Second -} - func defaultWaitParams() *WaitParams { return &WaitParams{ Timeout: 120 * time.Second, @@ -1532,39 +1527,41 @@ func (x *PrmContainerEACL) SetContainerID(cnrID cid.ID) { // PrmContainerSetEACL groups parameters of SetEACL operation. type PrmContainerSetEACL struct { - table eacl.Table + Table eacl.Table - sessionSet bool - session session.Container + Session *session.Container - waitParams WaitParams - waitParamsSet bool + WaitParams *WaitParams } // SetTable sets structure of container's extended ACL to be used as a // parameter of the base client's operation. // // See git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client.PrmContainerSetEACL.SetTable. +// +// Deprecated: Use PrmContainerSetEACL.Table instead. func (x *PrmContainerSetEACL) SetTable(table eacl.Table) { - x.table = table + x.Table = table } // WithinSession specifies session to be used as a parameter of the base // client's operation. // // See git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client.PrmContainerSetEACL.WithinSession. +// +// Deprecated: Use PrmContainerSetEACL.Session instead. func (x *PrmContainerSetEACL) WithinSession(s session.Container) { - x.session = s - x.sessionSet = true + x.Session = &s } // SetWaitParams specifies timeout params to complete operation. // If not provided the default one will be used. // Panics if any of the wait params isn't positive. +// +// Deprecated: Use PrmContainerSetEACL.WaitParams instead. func (x *PrmContainerSetEACL) SetWaitParams(waitParams WaitParams) { waitParams.checkForPositive() - x.waitParams = waitParams - x.waitParamsSet = true + x.WaitParams = &waitParams } // PrmBalanceGet groups parameters of Balance operation. From 518fb79bc0b7e801d30f430bd955dbed88c1f148 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 11 Jul 2023 12:02:23 +0300 Subject: [PATCH 042/288] [#114] pool: Support client cut with memory limiter Signed-off-by: Denis Kirillov --- pool/cache.go | 4 + pool/object_put_transformer.go | 107 +++++++++++++++++ pool/parts_buffer_pool.go | 64 ++++++++++ pool/pool.go | 207 +++++++++++++++++++++++++++++---- pool/pool_test.go | 22 ++-- 5 files changed, 370 insertions(+), 34 deletions(-) create mode 100644 pool/object_put_transformer.go create mode 100644 pool/parts_buffer_pool.go diff --git a/pool/cache.go b/pool/cache.go index 1614e8a4..5c398882 100644 --- a/pool/cache.go +++ b/pool/cache.go @@ -69,3 +69,7 @@ func (c *sessionCache) expired(val *cacheValue) bool { // use epoch+1 (clear cache beforehand) to prevent 'expired session token' error right after epoch tick return val.token.ExpiredAt(epoch + 1) } + +func (c *sessionCache) Epoch() uint64 { + return c.currentEpoch.Load() +} diff --git a/pool/object_put_transformer.go b/pool/object_put_transformer.go new file mode 100644 index 00000000..74c88c39 --- /dev/null +++ b/pool/object_put_transformer.go @@ -0,0 +1,107 @@ +package pool + +import ( + "context" + "crypto/ecdsa" + + sdkClient "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" + apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" + oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session" +) + +type PrmObjectPutClientCutInit struct { + sdkClient.PrmObjectPutInit + key *ecdsa.PrivateKey + maxSize uint64 + epochSource transformer.EpochSource + withoutHomomorphicHash bool + stoken *session.Object +} + +func (c *clientWrapper) objectPutInitTransformer(prm PrmObjectPutClientCutInit) (*objectWriterTransformer, error) { + var w objectWriterTransformer + w.it = internalTarget{ + client: c.client, + prm: prm, + } + key := &c.prm.key + if prm.key != nil { + key = prm.key + } + + w.ot = transformer.NewPayloadSizeLimiter(transformer.Params{ + Key: key, + NextTargetInit: func() transformer.ObjectWriter { return &w.it }, + MaxSize: prm.maxSize, + WithoutHomomorphicHash: prm.withoutHomomorphicHash, + NetworkState: prm.epochSource, + SessionToken: prm.stoken, + }) + return &w, nil +} + +type objectWriterTransformer struct { + ot transformer.ChunkedObjectWriter + it internalTarget + err error +} + +func (x *objectWriterTransformer) WriteHeader(ctx context.Context, hdr object.Object) bool { + x.err = x.ot.WriteHeader(ctx, &hdr) + return x.err == nil +} + +func (x *objectWriterTransformer) WritePayloadChunk(ctx context.Context, chunk []byte) bool { + _, x.err = x.ot.Write(ctx, chunk) + return x.err == nil +} + +// ResObjectPut groups the final result values of ObjectPutInit operation. +type ResObjectPut struct { + Status apistatus.Status + OID oid.ID +} + +func (x *objectWriterTransformer) Close(ctx context.Context) (*ResObjectPut, error) { + ai, err := x.ot.Close(ctx) + if err != nil { + return nil, err + } + + if ai != nil && ai.ParentID != nil { + x.it.res.OID = *ai.ParentID + } + return &x.it.res, nil +} + +type internalTarget struct { + client *sdkClient.Client + res ResObjectPut + prm PrmObjectPutClientCutInit + useStream bool +} + +func (it *internalTarget) WriteObject(ctx context.Context, o *object.Object) error { + // todo support PutSingle + it.useStream = true + return it.putAsStream(ctx, o) +} + +func (it *internalTarget) putAsStream(ctx context.Context, o *object.Object) error { + wrt, err := it.client.ObjectPutInit(ctx, it.prm.PrmObjectPutInit) + if err != nil { + return err + } + if wrt.WriteHeader(ctx, *o) { + wrt.WritePayloadChunk(ctx, o.Payload()) + } + res, err := wrt.Close(ctx) + if res != nil { + it.res.Status = res.Status() + it.res.OID = res.StoredObjectID() + } + return err +} diff --git a/pool/parts_buffer_pool.go b/pool/parts_buffer_pool.go new file mode 100644 index 00000000..b204f50d --- /dev/null +++ b/pool/parts_buffer_pool.go @@ -0,0 +1,64 @@ +package pool + +import ( + "fmt" + "sync" +) + +type PartBuffer struct { + Buffer []byte + len uint64 +} + +type PartsBufferPool struct { + syncPool *sync.Pool + limit uint64 + maxObjectSize uint64 + + mu sync.Mutex + available uint64 +} + +func NewPartBufferPool(limit uint64, maxObjectSize uint64) *PartsBufferPool { + return &PartsBufferPool{ + limit: limit, + maxObjectSize: maxObjectSize, + available: limit, + syncPool: &sync.Pool{New: func() any { return make([]byte, maxObjectSize) }}, + } +} + +func (p *PartsBufferPool) ParBufferSize() uint64 { + return p.maxObjectSize +} + +func (p *PartsBufferPool) GetBuffer() (*PartBuffer, error) { + p.mu.Lock() + defer p.mu.Unlock() + + if p.maxObjectSize > p.available { + return nil, fmt.Errorf("requested buffer size %d is greater than available: %d", p.maxObjectSize, p.available) + } + + p.available -= p.maxObjectSize + + return &PartBuffer{ + Buffer: p.syncPool.Get().([]byte), + len: p.maxObjectSize, + }, nil +} + +func (p *PartsBufferPool) FreeBuffer(buff *PartBuffer) error { + p.mu.Lock() + defer p.mu.Unlock() + + used := p.limit - p.available + if buff.len > used { + return fmt.Errorf("buffer size %d to free is greater than used: %d", buff.len, used) + } + + p.available += buff.len + p.syncPool.Put(buff.Buffer) + + return nil +} diff --git a/pool/pool.go b/pool/pool.go index 06c317cb..550c1fc5 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -629,6 +629,14 @@ func (c *clientWrapper) networkInfo(ctx context.Context, _ prmNetworkInfo) (netm // objectPut writes object to FrostFS. func (c *clientWrapper) objectPut(ctx context.Context, prm PrmObjectPut) (oid.ID, error) { + if prm.clientCut { + return c.objectPutClientCut(ctx, prm) + } + + return c.objectPutServerCut(ctx, prm) +} + +func (c *clientWrapper) objectPutServerCut(ctx context.Context, prm PrmObjectPut) (oid.ID, error) { cl, err := c.getClient() if err != nil { return oid.ID{}, err @@ -710,6 +718,80 @@ func (c *clientWrapper) objectPut(ctx context.Context, prm PrmObjectPut) (oid.ID return res.StoredObjectID(), nil } +func (c *clientWrapper) objectPutClientCut(ctx context.Context, prm PrmObjectPut) (oid.ID, error) { + var cliPrm sdkClient.PrmObjectPutInit + cliPrm.SetCopiesNumberByVectors(prm.copiesNumber) + if prm.stoken != nil { + cliPrm.WithinSession(*prm.stoken) + } + if prm.key != nil { + cliPrm.UseKey(*prm.key) + } + if prm.btoken != nil { + cliPrm.WithBearerToken(*prm.btoken) + } + + putInitPrm := PrmObjectPutClientCutInit{ + PrmObjectPutInit: cliPrm, + key: prm.key, + maxSize: prm.networkInfo.MaxObjectSize(), + epochSource: prm.networkInfo, + stoken: prm.stoken, + } + + start := time.Now() + wObj, err := c.objectPutInitTransformer(putInitPrm) + c.incRequests(time.Since(start), methodObjectPut) + if err = c.handleError(ctx, nil, err); err != nil { + return oid.ID{}, fmt.Errorf("init writing on API client: %w", err) + } + + if wObj.WriteHeader(ctx, prm.hdr) { + if data := prm.hdr.Payload(); len(data) > 0 { + if prm.payload != nil { + prm.payload = io.MultiReader(bytes.NewReader(data), prm.payload) + } else { + prm.payload = bytes.NewReader(data) + } + } + + if prm.payload != nil { + var n int + + for { + n, err = prm.payload.Read(prm.partBuffer) + if n > 0 { + start = time.Now() + successWrite := wObj.WritePayloadChunk(ctx, prm.partBuffer[:n]) + c.incRequests(time.Since(start), methodObjectPut) + if !successWrite { + break + } + + continue + } + + if errors.Is(err, io.EOF) { + break + } + + return oid.ID{}, fmt.Errorf("read payload: %w", c.handleError(ctx, nil, err)) + } + } + } + + res, err := wObj.Close(ctx) + var st apistatus.Status + if res != nil { + st = res.Status + } + if err = c.handleError(ctx, st, err); err != nil { // here err already carries both status and client errors + return oid.ID{}, fmt.Errorf("client failure: %w", err) + } + + return res.OID, nil +} + // objectDelete invokes sdkClient.ObjectDelete parse response status to error. func (c *clientWrapper) objectDelete(ctx context.Context, prm PrmObjectDelete) error { cl, err := c.getClient() @@ -1072,6 +1154,7 @@ type InitParameters struct { nodeParams []NodeParam requestCallback func(RequestInfo) dialOptions []grpc.DialOption + maxClientCutMemory uint64 clientBuilder clientBuilder } @@ -1136,6 +1219,14 @@ func (x *InitParameters) SetGRPCDialOptions(opts ...grpc.DialOption) { x.dialOptions = opts } +// SetMaxClientCutMemory sets the max amount of bytes that can be used during client cut (see PrmObjectPut.SetClientCut). +// Default value is 1gb (that should be enough for 200 concurrent PUT request for MaxObjectSize 50mb). +// If the MaxObjectSize network param is greater than limit is set by this method +// Pool.PutObject operations with PrmObjectPut.SetClientCut will fail. +func (x *InitParameters) SetMaxClientCutMemory(size uint64) { + x.maxClientCutMemory = size +} + // setClientBuilder sets clientBuilder used for client construction. // Wraps setClientBuilderContext without a context. func (x *InitParameters) setClientBuilder(builder clientBuilder) { @@ -1316,6 +1407,10 @@ type PrmObjectPut struct { payload io.Reader copiesNumber []uint32 + + clientCut bool + partBuffer []byte + networkInfo netmap.NetworkInfo } // SetHeader specifies header of the object. @@ -1340,6 +1435,24 @@ func (x *PrmObjectPut) SetCopiesNumberVector(copiesNumber []uint32) { x.copiesNumber = copiesNumber } +// SetClientCut enables client cut for objects. It means that full object is prepared on client side +// and retrying is possible. But this leads to additional memory using for buffering object parts. +// Buffer size for every put is MaxObjectSize value from FrostFS network. +// There is limit for total memory allocation for in-flight request and +// can be set by InitParameters.SetMaxClientCutMemory (default value is 1gb). +// Put requests will fail if this limit be reached. +func (x *PrmObjectPut) SetClientCut(clientCut bool) { + x.clientCut = clientCut +} + +func (x *PrmObjectPut) setPartBuffer(partBuffer []byte) { + x.partBuffer = partBuffer +} + +func (x *PrmObjectPut) setNetworkInfo(ni netmap.NetworkInfo) { + x.networkInfo = ni +} + // PrmObjectDelete groups parameters of DeleteObject operation. type PrmObjectDelete struct { prmCommon @@ -1635,6 +1748,11 @@ type Pool struct { rebalanceParams rebalanceParameters clientBuilder clientBuilder logger *zap.Logger + + // we cannot initialize partBufferPool in NewPool function, + // so we have to save maxClientCutMemory param for further initialization in Dial. + maxClientCutMemory uint64 + partsBufferPool *PartsBufferPool } type innerPool struct { @@ -1646,6 +1764,7 @@ type innerPool struct { const ( defaultSessionTokenExpirationDuration = 100 // in blocks defaultErrorThreshold = 100 + defaultMaxClientCutMemory = 1024 * 1024 * 1024 // 1gb defaultRebalanceInterval = 15 * time.Second defaultHealthcheckTimeout = 4 * time.Second @@ -1682,7 +1801,8 @@ func NewPool(options InitParameters) (*Pool, error) { clientRebalanceInterval: options.clientRebalanceInterval, sessionExpirationDuration: options.sessionExpirationDuration, }, - clientBuilder: options.clientBuilder, + clientBuilder: options.clientBuilder, + maxClientCutMemory: options.maxClientCutMemory, } return pool, nil @@ -1710,7 +1830,7 @@ func (p *Pool) Dial(ctx context.Context) error { } var st session.Object - err := initSessionForDuration(ctx, &st, clients[j], p.rebalanceParams.sessionExpirationDuration, *p.key) + err := initSessionForDuration(ctx, &st, clients[j], p.rebalanceParams.sessionExpirationDuration, *p.key, false) if err != nil { clients[j].setUnhealthy() p.log(zap.WarnLevel, "failed to create frostfs session token for client", @@ -1718,7 +1838,7 @@ func (p *Pool) Dial(ctx context.Context) error { continue } - _ = p.cache.Put(formCacheKey(addr, p.key), st) + _ = p.cache.Put(formCacheKey(addr, p.key, false), st) atLeastOneHealthy = true } source := rand.NewSource(time.Now().UnixNano()) @@ -1739,6 +1859,12 @@ func (p *Pool) Dial(ctx context.Context) error { p.closedCh = make(chan struct{}) p.innerPools = inner + ni, err := p.NetworkInfo(ctx) + if err != nil { + return fmt.Errorf("get network info for max object size: %w", err) + } + p.partsBufferPool = NewPartBufferPool(p.maxClientCutMemory, ni.MaxObjectSize()) + go p.startRebalance(ctx) return nil } @@ -1760,6 +1886,10 @@ func fillDefaultInitParams(params *InitParameters, cache *sessionCache) { params.errorThreshold = defaultErrorThreshold } + if params.maxClientCutMemory == 0 { + params.maxClientCutMemory = defaultMaxClientCutMemory + } + if params.clientRebalanceInterval <= 0 { params.clientRebalanceInterval = defaultRebalanceInterval } @@ -1949,9 +2079,15 @@ func (p *innerPool) connection() (client, error) { return nil, errors.New("no healthy client") } -func formCacheKey(address string, key *ecdsa.PrivateKey) string { +func formCacheKey(address string, key *ecdsa.PrivateKey, clientCut bool) string { k := keys.PrivateKey{PrivateKey: *key} - return address + k.String() + + stype := "server" + if clientCut { + stype = "client" + } + + return address + stype + k.String() } func (p *Pool) checkSessionTokenErr(err error, address string) bool { @@ -1967,7 +2103,7 @@ func (p *Pool) checkSessionTokenErr(err error, address string) bool { return false } -func initSessionForDuration(ctx context.Context, dst *session.Object, c client, dur uint64, ownerKey ecdsa.PrivateKey) error { +func initSessionForDuration(ctx context.Context, dst *session.Object, c client, dur uint64, ownerKey ecdsa.PrivateKey, clientCut bool) error { ni, err := c.networkInfo(ctx, prmNetworkInfo{}) if err != nil { return err @@ -1985,23 +2121,26 @@ func initSessionForDuration(ctx context.Context, dst *session.Object, c client, prm.setExp(exp) prm.useKey(ownerKey) - res, err := c.sessionCreate(ctx, prm) - if err != nil { - return err - } + var ( + id uuid.UUID + key frostfsecdsa.PublicKey + ) - var id uuid.UUID + if clientCut { + id = uuid.New() + key = frostfsecdsa.PublicKey(ownerKey.PublicKey) - err = id.UnmarshalBinary(res.id) - if err != nil { - return fmt.Errorf("invalid session token ID: %w", err) - } - - var key frostfsecdsa.PublicKey - - err = key.Decode(res.sessionKey) - if err != nil { - return fmt.Errorf("invalid public session key: %w", err) + } else { + res, err := c.sessionCreate(ctx, prm) + if err != nil { + return err + } + if err = id.UnmarshalBinary(res.id); err != nil { + return fmt.Errorf("invalid session token ID: %w", err) + } + if err = key.Decode(res.sessionKey); err != nil { + return fmt.Errorf("invalid public session key: %w", err) + } } dst.SetID(id) @@ -2027,6 +2166,8 @@ type callContext struct { sessionCnr cid.ID sessionObjSet bool sessionObjs []oid.ID + + sessionClientCut bool } func (p *Pool) initCallContext(ctx *callContext, cfg prmCommon, prmCtx prmContext) error { @@ -2063,12 +2204,12 @@ func (p *Pool) initCallContext(ctx *callContext, cfg prmCommon, prmCtx prmContex // opens new session or uses cached one. // Must be called only on initialized callContext with set sessionTarget. func (p *Pool) openDefaultSession(ctx context.Context, cc *callContext) error { - cacheKey := formCacheKey(cc.endpoint, cc.key) + cacheKey := formCacheKey(cc.endpoint, cc.key, cc.sessionClientCut) tok, ok := p.cache.Get(cacheKey) if !ok { // init new session - err := initSessionForDuration(ctx, &tok, cc.client, p.stokenDuration, *cc.key) + err := initSessionForDuration(ctx, &tok, cc.client, p.stokenDuration, *cc.key, cc.sessionClientCut) if err != nil { return fmt.Errorf("session API client: %w", err) } @@ -2133,6 +2274,7 @@ func (p *Pool) PutObject(ctx context.Context, prm PrmObjectPut) (oid.ID, error) p.fillAppropriateKey(&prm.prmCommon) var ctxCall callContext + ctxCall.sessionClientCut = prm.clientCut if err := p.initCallContext(&ctxCall, prm.prmCommon, prmCtx); err != nil { return oid.ID{}, fmt.Errorf("init call context: %w", err) } @@ -2144,6 +2286,25 @@ func (p *Pool) PutObject(ctx context.Context, prm PrmObjectPut) (oid.ID, error) } } + buff, err := p.partsBufferPool.GetBuffer() + if err != nil { + return oid.ID{}, fmt.Errorf("cannot get buffer for put operations: %w", err) + } + + defer func() { + if errFree := p.partsBufferPool.FreeBuffer(buff); errFree != nil { + p.log(zap.WarnLevel, "failed to free part buffer", zap.Error(err)) + } + }() + + prm.setPartBuffer(buff.Buffer) + + var ni netmap.NetworkInfo + ni.SetCurrentEpoch(p.cache.Epoch()) + ni.SetMaxObjectSize(p.partsBufferPool.ParBufferSize()) // we want to use initial max object size in PayloadSizeLimiter + + prm.setNetworkInfo(ni) + id, err := ctxCall.client.objectPut(ctx, prm) if err != nil { // removes session token from cache in case of token error diff --git a/pool/pool_test.go b/pool/pool_test.go index 08de667a..bd1c1eb4 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -106,7 +106,7 @@ func TestBuildPoolOneNodeFailed(t *testing.T) { if err != nil { return false } - st, _ := clientPool.cache.Get(formCacheKey(cp.address(), clientPool.key)) + st, _ := clientPool.cache.Get(formCacheKey(cp.address(), clientPool.key, false)) return st.AssertAuthKey(&expectedAuthKey) } require.Never(t, condition, 900*time.Millisecond, 100*time.Millisecond) @@ -141,7 +141,7 @@ func TestOneNode(t *testing.T) { cp, err := pool.connection() require.NoError(t, err) - st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key)) + st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key, false)) expectedAuthKey := frostfsecdsa.PublicKey(key1.PublicKey) require.True(t, st.AssertAuthKey(&expectedAuthKey)) } @@ -171,7 +171,7 @@ func TestTwoNodes(t *testing.T) { cp, err := pool.connection() require.NoError(t, err) - st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key)) + st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key, false)) require.True(t, assertAuthKeyForAny(st, clientKeys)) } @@ -226,7 +226,7 @@ func TestOneOfTwoFailed(t *testing.T) { for i := 0; i < 5; i++ { cp, err := pool.connection() require.NoError(t, err) - st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key)) + st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key, false)) require.True(t, assertAuthKeyForAny(st, clientKeys)) } } @@ -296,7 +296,7 @@ func TestSessionCache(t *testing.T) { // cache must contain session token cp, err := pool.connection() require.NoError(t, err) - st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key)) + st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key, false)) require.True(t, st.AssertAuthKey(&expectedAuthKey)) var prm PrmObjectGet @@ -309,7 +309,7 @@ func TestSessionCache(t *testing.T) { // cache must not contain session token cp, err = pool.connection() require.NoError(t, err) - _, ok := pool.cache.Get(formCacheKey(cp.address(), pool.key)) + _, ok := pool.cache.Get(formCacheKey(cp.address(), pool.key, false)) require.False(t, ok) var prm2 PrmObjectPut @@ -321,7 +321,7 @@ func TestSessionCache(t *testing.T) { // cache must contain session token cp, err = pool.connection() require.NoError(t, err) - st, _ = pool.cache.Get(formCacheKey(cp.address(), pool.key)) + st, _ = pool.cache.Get(formCacheKey(cp.address(), pool.key, false)) require.True(t, st.AssertAuthKey(&expectedAuthKey)) } @@ -365,7 +365,7 @@ func TestPriority(t *testing.T) { firstNode := func() bool { cp, err := pool.connection() require.NoError(t, err) - st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key)) + st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key, false)) return st.AssertAuthKey(&expectedAuthKey1) } @@ -373,7 +373,7 @@ func TestPriority(t *testing.T) { secondNode := func() bool { cp, err := pool.connection() require.NoError(t, err) - st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key)) + st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key, false)) return st.AssertAuthKey(&expectedAuthKey2) } require.Never(t, secondNode, time.Second, 200*time.Millisecond) @@ -410,7 +410,7 @@ func TestSessionCacheWithKey(t *testing.T) { // cache must contain session token cp, err := pool.connection() require.NoError(t, err) - st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key)) + st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key, false)) require.True(t, st.AssertAuthKey(&expectedAuthKey)) var prm PrmObjectDelete @@ -420,7 +420,7 @@ func TestSessionCacheWithKey(t *testing.T) { err = pool.DeleteObject(ctx, prm) require.NoError(t, err) - st, _ = pool.cache.Get(formCacheKey(cp.address(), anonKey)) + st, _ = pool.cache.Get(formCacheKey(cp.address(), anonKey, false)) require.True(t, st.AssertAuthKey(&expectedAuthKey)) } From cae215534fcaea04992c2f6eb9d4a744f5f14e94 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 14 Jul 2023 12:24:49 +0300 Subject: [PATCH 043/288] [#114] pool: Fix linter errors Signed-off-by: Denis Kirillov --- pool/parts_buffer_pool.go | 12 +++++++++--- pool/pool.go | 1 - 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pool/parts_buffer_pool.go b/pool/parts_buffer_pool.go index b204f50d..d02de668 100644 --- a/pool/parts_buffer_pool.go +++ b/pool/parts_buffer_pool.go @@ -24,7 +24,13 @@ func NewPartBufferPool(limit uint64, maxObjectSize uint64) *PartsBufferPool { limit: limit, maxObjectSize: maxObjectSize, available: limit, - syncPool: &sync.Pool{New: func() any { return make([]byte, maxObjectSize) }}, + syncPool: &sync.Pool{New: func() any { + // We have to use pointer (even for slices), see https://staticcheck.dev/docs/checks/#SA6002 + // It's based on interfaces implementation in 2016, so maybe something has changed since then. + // We can use no pointer for multi-kilobyte slices though https://github.com/golang/go/issues/16323#issuecomment-254401036 + buff := make([]byte, maxObjectSize) + return &buff + }}, } } @@ -43,7 +49,7 @@ func (p *PartsBufferPool) GetBuffer() (*PartBuffer, error) { p.available -= p.maxObjectSize return &PartBuffer{ - Buffer: p.syncPool.Get().([]byte), + Buffer: *p.syncPool.Get().(*[]byte), len: p.maxObjectSize, }, nil } @@ -58,7 +64,7 @@ func (p *PartsBufferPool) FreeBuffer(buff *PartBuffer) error { } p.available += buff.len - p.syncPool.Put(buff.Buffer) + p.syncPool.Put(&buff.Buffer) return nil } diff --git a/pool/pool.go b/pool/pool.go index 550c1fc5..8c0530c1 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -2129,7 +2129,6 @@ func initSessionForDuration(ctx context.Context, dst *session.Object, c client, if clientCut { id = uuid.New() key = frostfsecdsa.PublicKey(ownerKey.PublicKey) - } else { res, err := c.sessionCreate(ctx, prm) if err != nil { From faeeeab87a1ee734297ef81ee8e1ffa701fff1ae Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 14 Jul 2023 15:23:28 +0300 Subject: [PATCH 044/288] [#114] pool: Don't use part buffers when client cut is off Signed-off-by: Denis Kirillov --- pool/parts_buffer_pool.go | 5 ++--- pool/pool.go | 30 ++++++++++++++++-------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pool/parts_buffer_pool.go b/pool/parts_buffer_pool.go index d02de668..828d859f 100644 --- a/pool/parts_buffer_pool.go +++ b/pool/parts_buffer_pool.go @@ -58,9 +58,8 @@ func (p *PartsBufferPool) FreeBuffer(buff *PartBuffer) error { p.mu.Lock() defer p.mu.Unlock() - used := p.limit - p.available - if buff.len > used { - return fmt.Errorf("buffer size %d to free is greater than used: %d", buff.len, used) + if buff.len+p.available > p.limit { + return fmt.Errorf("buffer size %d to free is too large, available: %d, limit: %d", buff.len, p.available, p.limit) } p.available += buff.len diff --git a/pool/pool.go b/pool/pool.go index 8c0530c1..a3f3b45a 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -2285,24 +2285,26 @@ func (p *Pool) PutObject(ctx context.Context, prm PrmObjectPut) (oid.ID, error) } } - buff, err := p.partsBufferPool.GetBuffer() - if err != nil { - return oid.ID{}, fmt.Errorf("cannot get buffer for put operations: %w", err) - } - - defer func() { - if errFree := p.partsBufferPool.FreeBuffer(buff); errFree != nil { - p.log(zap.WarnLevel, "failed to free part buffer", zap.Error(err)) + if prm.clientCut { + buff, err := p.partsBufferPool.GetBuffer() + if err != nil { + return oid.ID{}, fmt.Errorf("cannot get buffer for put operations: %w", err) } - }() - prm.setPartBuffer(buff.Buffer) + prm.setPartBuffer(buff.Buffer) - var ni netmap.NetworkInfo - ni.SetCurrentEpoch(p.cache.Epoch()) - ni.SetMaxObjectSize(p.partsBufferPool.ParBufferSize()) // we want to use initial max object size in PayloadSizeLimiter + var ni netmap.NetworkInfo + ni.SetCurrentEpoch(p.cache.Epoch()) + ni.SetMaxObjectSize(p.partsBufferPool.ParBufferSize()) // we want to use initial max object size in PayloadSizeLimiter - prm.setNetworkInfo(ni) + prm.setNetworkInfo(ni) + + defer func() { + if errFree := p.partsBufferPool.FreeBuffer(buff); errFree != nil { + p.log(zap.WarnLevel, "failed to free part buffer", zap.Error(err)) + } + }() + } id, err := ctxCall.client.objectPut(ctx, prm) if err != nil { From 3cb38410737aedaaa77554129901c07cef0eb817 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 1 Aug 2023 11:50:18 +0300 Subject: [PATCH 045/288] [#115] pool: Try putSingle if possible Signed-off-by: Denis Kirillov --- pool/object_put_transformer.go | 98 ++++++++++++++++++++++++++++------ pool/pool.go | 36 ++++++------- 2 files changed, 98 insertions(+), 36 deletions(-) diff --git a/pool/object_put_transformer.go b/pool/object_put_transformer.go index 74c88c39..08d41dde 100644 --- a/pool/object_put_transformer.go +++ b/pool/object_put_transformer.go @@ -2,30 +2,39 @@ package pool import ( "context" - "crypto/ecdsa" sdkClient "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer" - "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) +type logger interface { + log(level zapcore.Level, msg string, fields ...zap.Field) +} + type PrmObjectPutClientCutInit struct { - sdkClient.PrmObjectPutInit - key *ecdsa.PrivateKey - maxSize uint64 - epochSource transformer.EpochSource + PrmObjectPut withoutHomomorphicHash bool - stoken *session.Object } func (c *clientWrapper) objectPutInitTransformer(prm PrmObjectPutClientCutInit) (*objectWriterTransformer, error) { + cl, err := c.getClient() + if err != nil { + return nil, err + } var w objectWriterTransformer + w.it = internalTarget{ - client: c.client, - prm: prm, + client: cl, + prm: prm, + address: c.address(), + logger: &c.clientStatusMonitor, } key := &c.prm.key if prm.key != nil { @@ -35,9 +44,9 @@ func (c *clientWrapper) objectPutInitTransformer(prm PrmObjectPutClientCutInit) w.ot = transformer.NewPayloadSizeLimiter(transformer.Params{ Key: key, NextTargetInit: func() transformer.ObjectWriter { return &w.it }, - MaxSize: prm.maxSize, + MaxSize: prm.networkInfo.MaxObjectSize(), WithoutHomomorphicHash: prm.withoutHomomorphicHash, - NetworkState: prm.epochSource, + NetworkState: prm.networkInfo, SessionToken: prm.stoken, }) return &w, nil @@ -78,20 +87,41 @@ func (x *objectWriterTransformer) Close(ctx context.Context) (*ResObjectPut, err } type internalTarget struct { - client *sdkClient.Client - res ResObjectPut - prm PrmObjectPutClientCutInit - useStream bool + client *sdkClient.Client + res ResObjectPut + prm PrmObjectPutClientCutInit + useStream bool + address string + logger logger + resolveFrostFSErrors bool } func (it *internalTarget) WriteObject(ctx context.Context, o *object.Object) error { - // todo support PutSingle + putSingleImplemented, err := it.tryPutSingle(ctx, o) + if putSingleImplemented { + return err + } + + it.logger.log(zapcore.DebugLevel, "putSingle not implemented, trying put as stream", zap.String("address", it.address)) + it.useStream = true return it.putAsStream(ctx, o) } func (it *internalTarget) putAsStream(ctx context.Context, o *object.Object) error { - wrt, err := it.client.ObjectPutInit(ctx, it.prm.PrmObjectPutInit) + var cliPrm sdkClient.PrmObjectPutInit + cliPrm.SetCopiesNumberByVectors(it.prm.copiesNumber) + if it.prm.stoken != nil { + cliPrm.WithinSession(*it.prm.stoken) + } + if it.prm.key != nil { + cliPrm.UseKey(*it.prm.key) + } + if it.prm.btoken != nil { + cliPrm.WithBearerToken(*it.prm.btoken) + } + + wrt, err := it.client.ObjectPutInit(ctx, cliPrm) if err != nil { return err } @@ -105,3 +135,37 @@ func (it *internalTarget) putAsStream(ctx context.Context, o *object.Object) err } return err } + +func (it *internalTarget) tryPutSingle(ctx context.Context, o *object.Object) (bool, error) { + if it.useStream { + return false, nil + } + var cliPrm sdkClient.PrmObjectPutSingle + cliPrm.SetCopiesNumber(it.prm.copiesNumber) + cliPrm.UseKey(it.prm.key) + if it.prm.stoken != nil { + cliPrm.WithinSession(*it.prm.stoken) + } + if it.prm.btoken != nil { + cliPrm.WithBearerToken(*it.prm.btoken) + } + cliPrm.SetObject(o.ToV2()) + + res, err := it.client.ObjectPutSingle(ctx, cliPrm) + if err != nil && status.Code(err) == codes.Unimplemented { + return false, err + } + + if err == nil { + id, _ := o.ID() + it.res = ResObjectPut{ + Status: res.Status(), + OID: id, + } + if !it.resolveFrostFSErrors && !apistatus.IsSuccessful(it.res.Status) { + return true, apistatus.ErrFromStatus(it.res.Status) + } + return true, nil + } + return true, err +} diff --git a/pool/pool.go b/pool/pool.go index a3f3b45a..94c08134 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -252,6 +252,11 @@ func (x *wrapperPrm) setKey(key ecdsa.PrivateKey) { x.key = key } +// setLogger sets sdkClient.Client logger. +func (x *wrapperPrm) setLogger(logger *zap.Logger) { + x.logger = logger +} + // setDialTimeout sets the timeout for connection to be established. func (x *wrapperPrm) setDialTimeout(timeout time.Duration) { x.dialTimeout = timeout @@ -719,24 +724,8 @@ func (c *clientWrapper) objectPutServerCut(ctx context.Context, prm PrmObjectPut } func (c *clientWrapper) objectPutClientCut(ctx context.Context, prm PrmObjectPut) (oid.ID, error) { - var cliPrm sdkClient.PrmObjectPutInit - cliPrm.SetCopiesNumberByVectors(prm.copiesNumber) - if prm.stoken != nil { - cliPrm.WithinSession(*prm.stoken) - } - if prm.key != nil { - cliPrm.UseKey(*prm.key) - } - if prm.btoken != nil { - cliPrm.WithBearerToken(*prm.btoken) - } - putInitPrm := PrmObjectPutClientCutInit{ - PrmObjectPutInit: cliPrm, - key: prm.key, - maxSize: prm.networkInfo.MaxObjectSize(), - epochSource: prm.networkInfo, - stoken: prm.stoken, + PrmObjectPut: prm, } start := time.Now() @@ -1054,12 +1043,20 @@ func (c *clientStatusMonitor) incErrorRate() { } c.mu.Unlock() - if thresholdReached && c.logger != nil { - c.logger.Warn("error threshold reached", + if thresholdReached { + c.log(zapcore.WarnLevel, "error threshold reached", zap.String("address", c.addr), zap.Uint32("threshold", c.errorThreshold)) } } +func (c *clientStatusMonitor) log(level zapcore.Level, msg string, fields ...zap.Field) { + if c.logger == nil { + return + } + + c.logger.Log(level, msg, fields...) +} + func (c *clientStatusMonitor) currentErrorRate() uint32 { c.mu.RLock() defer c.mu.RUnlock() @@ -1911,6 +1908,7 @@ func fillDefaultInitParams(params *InitParameters, cache *sessionCache) { var prm wrapperPrm prm.setAddress(addr) prm.setKey(*params.key) + prm.setLogger(params.logger) prm.setDialTimeout(params.nodeDialTimeout) prm.setStreamTimeout(params.nodeStreamTimeout) prm.setErrorThreshold(params.errorThreshold) From 202412230a05d2f91acabdb59cc9f934ded6d2bb Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 1 Aug 2023 12:52:18 +0300 Subject: [PATCH 046/288] [#115] pool: Drop part buffer pool Tests showed that using part buffer pool doesn't save memory a lot. Especially on big parts. Probably we can use pool only for small parts after adding buffer in payloadSizeLimiter Signed-off-by: Denis Kirillov --- ...rmer.go => object_put_pool_transformer.go} | 2 + pool/parts_buffer_pool.go | 69 ------------------- pool/pool.go | 62 +++++------------ 3 files changed, 20 insertions(+), 113 deletions(-) rename pool/{object_put_transformer.go => object_put_pool_transformer.go} (97%) delete mode 100644 pool/parts_buffer_pool.go diff --git a/pool/object_put_transformer.go b/pool/object_put_pool_transformer.go similarity index 97% rename from pool/object_put_transformer.go rename to pool/object_put_pool_transformer.go index 08d41dde..c6add151 100644 --- a/pool/object_put_transformer.go +++ b/pool/object_put_pool_transformer.go @@ -36,6 +36,7 @@ func (c *clientWrapper) objectPutInitTransformer(prm PrmObjectPutClientCutInit) address: c.address(), logger: &c.clientStatusMonitor, } + key := &c.prm.key if prm.key != nil { key = prm.key @@ -74,6 +75,7 @@ type ResObjectPut struct { OID oid.ID } +// Close return non nil result in any case. If error occurred, the result contains only buffer for further reusing. func (x *objectWriterTransformer) Close(ctx context.Context) (*ResObjectPut, error) { ai, err := x.ot.Close(ctx) if err != nil { diff --git a/pool/parts_buffer_pool.go b/pool/parts_buffer_pool.go deleted file mode 100644 index 828d859f..00000000 --- a/pool/parts_buffer_pool.go +++ /dev/null @@ -1,69 +0,0 @@ -package pool - -import ( - "fmt" - "sync" -) - -type PartBuffer struct { - Buffer []byte - len uint64 -} - -type PartsBufferPool struct { - syncPool *sync.Pool - limit uint64 - maxObjectSize uint64 - - mu sync.Mutex - available uint64 -} - -func NewPartBufferPool(limit uint64, maxObjectSize uint64) *PartsBufferPool { - return &PartsBufferPool{ - limit: limit, - maxObjectSize: maxObjectSize, - available: limit, - syncPool: &sync.Pool{New: func() any { - // We have to use pointer (even for slices), see https://staticcheck.dev/docs/checks/#SA6002 - // It's based on interfaces implementation in 2016, so maybe something has changed since then. - // We can use no pointer for multi-kilobyte slices though https://github.com/golang/go/issues/16323#issuecomment-254401036 - buff := make([]byte, maxObjectSize) - return &buff - }}, - } -} - -func (p *PartsBufferPool) ParBufferSize() uint64 { - return p.maxObjectSize -} - -func (p *PartsBufferPool) GetBuffer() (*PartBuffer, error) { - p.mu.Lock() - defer p.mu.Unlock() - - if p.maxObjectSize > p.available { - return nil, fmt.Errorf("requested buffer size %d is greater than available: %d", p.maxObjectSize, p.available) - } - - p.available -= p.maxObjectSize - - return &PartBuffer{ - Buffer: *p.syncPool.Get().(*[]byte), - len: p.maxObjectSize, - }, nil -} - -func (p *PartsBufferPool) FreeBuffer(buff *PartBuffer) error { - p.mu.Lock() - defer p.mu.Unlock() - - if buff.len+p.available > p.limit { - return fmt.Errorf("buffer size %d to free is too large, available: %d, limit: %d", buff.len, p.available, p.limit) - } - - p.available += buff.len - p.syncPool.Put(&buff.Buffer) - - return nil -} diff --git a/pool/pool.go b/pool/pool.go index 94c08134..70f789ea 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -679,7 +679,7 @@ func (c *clientWrapper) objectPutServerCut(ctx context.Context, prm PrmObjectPut } if prm.payload != nil { - const defaultBufferSizePut = 3 << 20 // configure? + const defaultBufferSizePut = 3 << 20 // default grpc message size, configure? if sz == 0 || sz > defaultBufferSizePut { sz = defaultBufferSizePut @@ -736,22 +736,33 @@ func (c *clientWrapper) objectPutClientCut(ctx context.Context, prm PrmObjectPut } if wObj.WriteHeader(ctx, prm.hdr) { + sz := prm.hdr.PayloadSize() + if data := prm.hdr.Payload(); len(data) > 0 { if prm.payload != nil { prm.payload = io.MultiReader(bytes.NewReader(data), prm.payload) } else { prm.payload = bytes.NewReader(data) + sz = uint64(len(data)) } } if prm.payload != nil { + const defaultBufferSizePut = 64 * 1024 // it's buffer size in s3-gw, configure? + + if sz == 0 || sz > defaultBufferSizePut { + sz = defaultBufferSizePut + } + + buf := make([]byte, sz) + var n int for { - n, err = prm.payload.Read(prm.partBuffer) + n, err = prm.payload.Read(buf) if n > 0 { start = time.Now() - successWrite := wObj.WritePayloadChunk(ctx, prm.partBuffer[:n]) + successWrite := wObj.WritePayloadChunk(ctx, buf[:n]) c.incRequests(time.Since(start), methodObjectPut) if !successWrite { break @@ -1151,7 +1162,6 @@ type InitParameters struct { nodeParams []NodeParam requestCallback func(RequestInfo) dialOptions []grpc.DialOption - maxClientCutMemory uint64 clientBuilder clientBuilder } @@ -1216,14 +1226,6 @@ func (x *InitParameters) SetGRPCDialOptions(opts ...grpc.DialOption) { x.dialOptions = opts } -// SetMaxClientCutMemory sets the max amount of bytes that can be used during client cut (see PrmObjectPut.SetClientCut). -// Default value is 1gb (that should be enough for 200 concurrent PUT request for MaxObjectSize 50mb). -// If the MaxObjectSize network param is greater than limit is set by this method -// Pool.PutObject operations with PrmObjectPut.SetClientCut will fail. -func (x *InitParameters) SetMaxClientCutMemory(size uint64) { - x.maxClientCutMemory = size -} - // setClientBuilder sets clientBuilder used for client construction. // Wraps setClientBuilderContext without a context. func (x *InitParameters) setClientBuilder(builder clientBuilder) { @@ -1406,7 +1408,6 @@ type PrmObjectPut struct { copiesNumber []uint32 clientCut bool - partBuffer []byte networkInfo netmap.NetworkInfo } @@ -1442,10 +1443,6 @@ func (x *PrmObjectPut) SetClientCut(clientCut bool) { x.clientCut = clientCut } -func (x *PrmObjectPut) setPartBuffer(partBuffer []byte) { - x.partBuffer = partBuffer -} - func (x *PrmObjectPut) setNetworkInfo(ni netmap.NetworkInfo) { x.networkInfo = ni } @@ -1746,10 +1743,7 @@ type Pool struct { clientBuilder clientBuilder logger *zap.Logger - // we cannot initialize partBufferPool in NewPool function, - // so we have to save maxClientCutMemory param for further initialization in Dial. - maxClientCutMemory uint64 - partsBufferPool *PartsBufferPool + maxObjectSize uint64 } type innerPool struct { @@ -1761,7 +1755,6 @@ type innerPool struct { const ( defaultSessionTokenExpirationDuration = 100 // in blocks defaultErrorThreshold = 100 - defaultMaxClientCutMemory = 1024 * 1024 * 1024 // 1gb defaultRebalanceInterval = 15 * time.Second defaultHealthcheckTimeout = 4 * time.Second @@ -1798,8 +1791,7 @@ func NewPool(options InitParameters) (*Pool, error) { clientRebalanceInterval: options.clientRebalanceInterval, sessionExpirationDuration: options.sessionExpirationDuration, }, - clientBuilder: options.clientBuilder, - maxClientCutMemory: options.maxClientCutMemory, + clientBuilder: options.clientBuilder, } return pool, nil @@ -1860,7 +1852,7 @@ func (p *Pool) Dial(ctx context.Context) error { if err != nil { return fmt.Errorf("get network info for max object size: %w", err) } - p.partsBufferPool = NewPartBufferPool(p.maxClientCutMemory, ni.MaxObjectSize()) + p.maxObjectSize = ni.MaxObjectSize() go p.startRebalance(ctx) return nil @@ -1883,10 +1875,6 @@ func fillDefaultInitParams(params *InitParameters, cache *sessionCache) { params.errorThreshold = defaultErrorThreshold } - if params.maxClientCutMemory == 0 { - params.maxClientCutMemory = defaultMaxClientCutMemory - } - if params.clientRebalanceInterval <= 0 { params.clientRebalanceInterval = defaultRebalanceInterval } @@ -2284,24 +2272,10 @@ func (p *Pool) PutObject(ctx context.Context, prm PrmObjectPut) (oid.ID, error) } if prm.clientCut { - buff, err := p.partsBufferPool.GetBuffer() - if err != nil { - return oid.ID{}, fmt.Errorf("cannot get buffer for put operations: %w", err) - } - - prm.setPartBuffer(buff.Buffer) - var ni netmap.NetworkInfo ni.SetCurrentEpoch(p.cache.Epoch()) - ni.SetMaxObjectSize(p.partsBufferPool.ParBufferSize()) // we want to use initial max object size in PayloadSizeLimiter - + ni.SetMaxObjectSize(p.maxObjectSize) // we want to use initial max object size in PayloadSizeLimiter prm.setNetworkInfo(ni) - - defer func() { - if errFree := p.partsBufferPool.FreeBuffer(buff); errFree != nil { - p.log(zap.WarnLevel, "failed to free part buffer", zap.Error(err)) - } - }() } id, err := ctxCall.client.objectPut(ctx, prm) From 46a214d065f872f31f68cd147619490ea3d9fd9a Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 25 Aug 2023 09:36:08 +0300 Subject: [PATCH 047/288] [#149] pool: Configure homomorphic hash and buffer size Signed-off-by: Denis Kirillov --- pool/object_put_pool_transformer.go | 1 - pool/pool.go | 34 ++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/pool/object_put_pool_transformer.go b/pool/object_put_pool_transformer.go index c6add151..52c6813b 100644 --- a/pool/object_put_pool_transformer.go +++ b/pool/object_put_pool_transformer.go @@ -20,7 +20,6 @@ type logger interface { type PrmObjectPutClientCutInit struct { PrmObjectPut - withoutHomomorphicHash bool } func (c *clientWrapper) objectPutInitTransformer(prm PrmObjectPutClientCutInit) (*objectWriterTransformer, error) { diff --git a/pool/pool.go b/pool/pool.go index 70f789ea..4f8a42a8 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -634,6 +634,10 @@ func (c *clientWrapper) networkInfo(ctx context.Context, _ prmNetworkInfo) (netm // objectPut writes object to FrostFS. func (c *clientWrapper) objectPut(ctx context.Context, prm PrmObjectPut) (oid.ID, error) { + if prm.bufferMaxSize == 0 { + prm.bufferMaxSize = defaultBufferMaxSizeForPut + } + if prm.clientCut { return c.objectPutClientCut(ctx, prm) } @@ -679,10 +683,8 @@ func (c *clientWrapper) objectPutServerCut(ctx context.Context, prm PrmObjectPut } if prm.payload != nil { - const defaultBufferSizePut = 3 << 20 // default grpc message size, configure? - - if sz == 0 || sz > defaultBufferSizePut { - sz = defaultBufferSizePut + if sz == 0 || sz > prm.bufferMaxSize { + sz = prm.bufferMaxSize } buf := make([]byte, sz) @@ -748,10 +750,8 @@ func (c *clientWrapper) objectPutClientCut(ctx context.Context, prm PrmObjectPut } if prm.payload != nil { - const defaultBufferSizePut = 64 * 1024 // it's buffer size in s3-gw, configure? - - if sz == 0 || sz > defaultBufferSizePut { - sz = defaultBufferSizePut + if sz == 0 || sz > prm.bufferMaxSize { + sz = prm.bufferMaxSize } buf := make([]byte, sz) @@ -1409,6 +1409,10 @@ type PrmObjectPut struct { clientCut bool networkInfo netmap.NetworkInfo + + withoutHomomorphicHash bool + + bufferMaxSize uint64 } // SetHeader specifies header of the object. @@ -1443,6 +1447,18 @@ func (x *PrmObjectPut) SetClientCut(clientCut bool) { x.clientCut = clientCut } +// WithoutHomomorphicHash if set to true do not use Tillich-Zémor hash for payload. +func (x *PrmObjectPut) WithoutHomomorphicHash(v bool) { + x.withoutHomomorphicHash = v +} + +// SetBufferMaxSize sets max buffer size to read payload. +// This value isn't used if object size is set explicitly and less than this value. +// Default value 3MB. +func (x *PrmObjectPut) SetBufferMaxSize(size uint64) { + x.bufferMaxSize = size +} + func (x *PrmObjectPut) setNetworkInfo(ni netmap.NetworkInfo) { x.networkInfo = ni } @@ -1760,6 +1776,8 @@ const ( defaultHealthcheckTimeout = 4 * time.Second defaultDialTimeout = 5 * time.Second defaultStreamTimeout = 10 * time.Second + + defaultBufferMaxSizeForPut = 3 * 1024 * 1024 // 3 MB ) // NewPool creates connection pool using parameters. From 84e7e69f98ac8c0d6ef09fb90bb60ba035aade17 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Mon, 28 Aug 2023 11:07:18 +0300 Subject: [PATCH 048/288] [#121] client: Make PrmObjectGet/Head/GetRange fields public * Remove common PrmObjectRead structure * Introduce buildRequest for PrmObjectGet/Head/GetRange * Refactor the usage of these params in pool Signed-off-by: Airat Arifullin --- client/common.go | 2 + client/object_get.go | 397 ++++++++++++++++++++++++++----------------- pool/pool.go | 71 +++----- 3 files changed, 272 insertions(+), 198 deletions(-) diff --git a/client/common.go b/client/common.go index 907f6be9..3895b002 100644 --- a/client/common.go +++ b/client/common.go @@ -47,6 +47,8 @@ func writeXHeadersToMeta(xHeaders []string, h *v2session.RequestMetaHeader) { return } + // TODO (aarifullin): remove the panic when all client parameters will check XHeaders + // within buildRequest invocation. if len(xHeaders)%2 != 0 { panic("slice of X-Headers with odd length") } diff --git a/client/object_get.go b/client/object_get.go index 02de74af..56cbfda8 100644 --- a/client/object_get.go +++ b/client/object_get.go @@ -22,77 +22,76 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session" ) -// shared parameters of GET/HEAD/RANGE. -type prmObjectRead struct { - meta v2session.RequestMetaHeader - - raw bool - - addr v2refs.Address -} - -// WithXHeaders specifies list of extended headers (string key-value pairs) -// to be attached to the request. Must have an even length. -// -// Slice must not be mutated until the operation completes. -func (x *prmObjectRead) WithXHeaders(hs ...string) { - writeXHeadersToMeta(hs, &x.meta) -} - -// MarkRaw marks an intent to read physically stored object. -func (x *prmObjectRead) MarkRaw() { - x.raw = true -} - -// MarkLocal tells the server to execute the operation locally. -func (x *prmObjectRead) MarkLocal() { - x.meta.SetTTL(1) -} - -// WithinSession specifies session within which object should be read. -// -// Creator of the session acquires the authorship of the request. -// This may affect the execution of an operation (e.g. access control). -// -// Must be signed. -func (x *prmObjectRead) WithinSession(t session.Object) { - var tokv2 v2session.Token - t.WriteToV2(&tokv2) - x.meta.SetSessionToken(&tokv2) -} - -// WithBearerToken attaches bearer token to be used for the operation. -// -// If set, underlying eACL rules will be used in access control. -// -// Must be signed. -func (x *prmObjectRead) WithBearerToken(t bearer.Token) { - var v2token acl.BearerToken - t.WriteToV2(&v2token) - x.meta.SetBearerToken(&v2token) -} - -// FromContainer specifies FrostFS container of the object. -// Required parameter. -func (x *prmObjectRead) FromContainer(id cid.ID) { - var cnrV2 v2refs.ContainerID - id.WriteToV2(&cnrV2) - x.addr.SetContainerID(&cnrV2) -} - -// ByID specifies identifier of the requested object. -// Required parameter. -func (x *prmObjectRead) ByID(id oid.ID) { - var objV2 v2refs.ObjectID - id.WriteToV2(&objV2) - x.addr.SetObjectID(&objV2) -} - // PrmObjectGet groups parameters of ObjectGetInit operation. type PrmObjectGet struct { - prmObjectRead + XHeaders []string - key *ecdsa.PrivateKey + BearerToken *bearer.Token + + Session *session.Object + + Raw bool + + Local bool + + ContainerID *cid.ID + + ObjectID *oid.ID + + Key *ecdsa.PrivateKey +} + +func (prm *PrmObjectGet) buildRequest(c *Client) (*v2object.GetRequest, error) { + if prm.ContainerID == nil { + return nil, errorMissingContainer + } + + if prm.ObjectID == nil { + return nil, errorMissingObject + } + + if len(prm.XHeaders)%2 != 0 { + return nil, errorInvalidXHeaders + } + + meta := new(v2session.RequestMetaHeader) + writeXHeadersToMeta(prm.XHeaders, meta) + + if prm.BearerToken != nil { + v2BearerToken := new(acl.BearerToken) + prm.BearerToken.WriteToV2(v2BearerToken) + meta.SetBearerToken(v2BearerToken) + } + + if prm.Session != nil { + v2SessionToken := new(v2session.Token) + prm.Session.WriteToV2(v2SessionToken) + meta.SetSessionToken(v2SessionToken) + } + + if prm.Local { + meta.SetTTL(1) + } + + addr := new(v2refs.Address) + + cnrV2 := new(v2refs.ContainerID) + prm.ContainerID.WriteToV2(cnrV2) + addr.SetContainerID(cnrV2) + + objV2 := new(v2refs.ObjectID) + prm.ObjectID.WriteToV2(objV2) + addr.SetObjectID(objV2) + + body := new(v2object.GetRequestBody) + body.SetRaw(prm.Raw) + body.SetAddress(addr) + + req := new(v2object.GetRequest) + req.SetBody(body) + c.prepareRequest(req, meta) + + return req, nil } // ResObjectGet groups the final result values of ObjectGetInit operation. @@ -122,8 +121,10 @@ type ObjectReader struct { // UseKey specifies private key to sign the requests. // If key is not provided, then Client default key is used. -func (x *PrmObjectGet) UseKey(key ecdsa.PrivateKey) { - x.key = &key +// +// Deprecated: Use PrmObjectGet.Key instead. +func (prm *PrmObjectGet) UseKey(key ecdsa.PrivateKey) { + prm.Key = &key } // ReadHeader reads header of the object. Result means success. @@ -299,39 +300,24 @@ func (x *ObjectReader) Read(p []byte) (int, error) { // Returns an error if parameters are set incorrectly (see PrmObjectGet docs). // Context is required and must not be nil. It is used for network communication. func (c *Client) ObjectGetInit(ctx context.Context, prm PrmObjectGet) (*ObjectReader, error) { - // check parameters - switch { - case prm.addr.GetContainerID() == nil: - return nil, errorMissingContainer - case prm.addr.GetObjectID() == nil: - return nil, errorMissingObject + req, err := prm.buildRequest(c) + if err != nil { + return nil, err } - // form request body - var body v2object.GetRequestBody - - body.SetRaw(prm.raw) - body.SetAddress(&prm.addr) - - // form request - var req v2object.GetRequest - - req.SetBody(&body) - c.prepareRequest(&req, &prm.meta) - - key := prm.key + key := prm.Key if key == nil { key = &c.prm.key } - err := signature.SignServiceMessage(key, &req) + err = signature.SignServiceMessage(key, req) if err != nil { return nil, fmt.Errorf("sign request: %w", err) } ctx, cancel := context.WithCancel(ctx) - stream, err := rpcapi.GetObject(&c.c, &req, client.WithContext(ctx)) + stream, err := rpcapi.GetObject(&c.c, req, client.WithContext(ctx)) if err != nil { cancel() return nil, fmt.Errorf("open stream: %w", err) @@ -347,17 +333,29 @@ func (c *Client) ObjectGetInit(ctx context.Context, prm PrmObjectGet) (*ObjectRe // PrmObjectHead groups parameters of ObjectHead operation. type PrmObjectHead struct { - prmObjectRead + XHeaders []string - keySet bool - key ecdsa.PrivateKey + BearerToken *bearer.Token + + Session *session.Object + + Raw bool + + Local bool + + ContainerID *cid.ID + + ObjectID *oid.ID + + Key *ecdsa.PrivateKey } // UseKey specifies private key to sign the requests. // If key is not provided, then Client default key is used. -func (x *PrmObjectHead) UseKey(key ecdsa.PrivateKey) { - x.keySet = true - x.key = key +// +// Deprecated: Use PrmObjectHead.Key instead. +func (prm *PrmObjectHead) UseKey(key ecdsa.PrivateKey) { + prm.Key = &key } // ResObjectHead groups resulting values of ObjectHead operation. @@ -390,6 +388,58 @@ func (x *ResObjectHead) ReadHeader(dst *object.Object) bool { return true } +func (prm *PrmObjectHead) buildRequest(c *Client) (*v2object.HeadRequest, error) { + if prm.ContainerID == nil { + return nil, errorMissingContainer + } + + if prm.ObjectID == nil { + return nil, errorMissingObject + } + + if len(prm.XHeaders)%2 != 0 { + return nil, errorInvalidXHeaders + } + + meta := new(v2session.RequestMetaHeader) + writeXHeadersToMeta(prm.XHeaders, meta) + + if prm.BearerToken != nil { + v2BearerToken := new(acl.BearerToken) + prm.BearerToken.WriteToV2(v2BearerToken) + meta.SetBearerToken(v2BearerToken) + } + + if prm.Session != nil { + v2SessionToken := new(v2session.Token) + prm.Session.WriteToV2(v2SessionToken) + meta.SetSessionToken(v2SessionToken) + } + + if prm.Local { + meta.SetTTL(1) + } + + addr := new(v2refs.Address) + + cnrV2 := new(v2refs.ContainerID) + prm.ContainerID.WriteToV2(cnrV2) + addr.SetContainerID(cnrV2) + + objV2 := new(v2refs.ObjectID) + prm.ObjectID.WriteToV2(objV2) + addr.SetObjectID(objV2) + body := new(v2object.HeadRequestBody) + body.SetRaw(prm.Raw) + body.SetAddress(addr) + + req := new(v2object.HeadRequest) + req.SetBody(body) + c.prepareRequest(req, meta) + + return req, nil +} + // ObjectHead reads object header through a remote server using FrostFS API protocol. // // Exactly one return value is non-nil. By default, server status is returned in res structure. @@ -413,33 +463,24 @@ func (x *ResObjectHead) ReadHeader(dst *object.Object) bool { // - *apistatus.ObjectAlreadyRemoved; // - *apistatus.SessionTokenExpired. func (c *Client) ObjectHead(ctx context.Context, prm PrmObjectHead) (*ResObjectHead, error) { - switch { - case prm.addr.GetContainerID() == nil: - return nil, errorMissingContainer - case prm.addr.GetObjectID() == nil: - return nil, errorMissingObject + req, err := prm.buildRequest(c) + if err != nil { + return nil, err } - var body v2object.HeadRequestBody - body.SetRaw(prm.raw) - body.SetAddress(&prm.addr) - - var req v2object.HeadRequest - req.SetBody(&body) - c.prepareRequest(&req, &prm.meta) - key := c.prm.key - if prm.keySet { - key = prm.key + if prm.Key != nil { + key = *prm.Key } // sign the request - err := signature.SignServiceMessage(&key, &req) + + err = signature.SignServiceMessage(&key, req) if err != nil { return nil, fmt.Errorf("sign request: %w", err) } - resp, err := rpcapi.HeadObject(&c.c, &req, client.WithContext(ctx)) + resp, err := rpcapi.HeadObject(&c.c, req, client.WithContext(ctx)) if err != nil { return nil, fmt.Errorf("write request: %w", err) } @@ -454,7 +495,7 @@ func (c *Client) ObjectHead(ctx context.Context, prm PrmObjectHead) (*ResObjectH return &res, nil } - _ = res.idObj.ReadFromV2(*prm.addr.GetObjectID()) + res.idObj = *prm.ObjectID switch v := resp.GetBody().GetHeaderPart().(type) { default: @@ -470,29 +511,95 @@ func (c *Client) ObjectHead(ctx context.Context, prm PrmObjectHead) (*ResObjectH // PrmObjectRange groups parameters of ObjectRange operation. type PrmObjectRange struct { - prmObjectRead + XHeaders []string - key *ecdsa.PrivateKey + BearerToken *bearer.Token - rng v2object.Range + Session *session.Object + + Raw bool + + Local bool + + ContainerID *cid.ID + + ObjectID *oid.ID + + Key *ecdsa.PrivateKey + + Offset uint64 + + Length uint64 } -// SetOffset sets offset of the payload range to be read. -// Zero by default. -func (x *PrmObjectRange) SetOffset(off uint64) { - x.rng.SetOffset(off) -} +func (prm *PrmObjectRange) buildRequest(c *Client) (*v2object.GetRangeRequest, error) { + if prm.Length == 0 { + return nil, errorZeroRangeLength + } -// SetLength sets length of the payload range to be read. -// Must be positive. -func (x *PrmObjectRange) SetLength(ln uint64) { - x.rng.SetLength(ln) + if prm.ContainerID == nil { + return nil, errorMissingContainer + } + + if prm.ObjectID == nil { + return nil, errorMissingObject + } + + if len(prm.XHeaders)%2 != 0 { + return nil, errorInvalidXHeaders + } + + meta := new(v2session.RequestMetaHeader) + writeXHeadersToMeta(prm.XHeaders, meta) + + if prm.BearerToken != nil { + v2BearerToken := new(acl.BearerToken) + prm.BearerToken.WriteToV2(v2BearerToken) + meta.SetBearerToken(v2BearerToken) + } + + if prm.Session != nil { + v2SessionToken := new(v2session.Token) + prm.Session.WriteToV2(v2SessionToken) + meta.SetSessionToken(v2SessionToken) + } + + if prm.Local { + meta.SetTTL(1) + } + + addr := new(v2refs.Address) + + cnrV2 := new(v2refs.ContainerID) + prm.ContainerID.WriteToV2(cnrV2) + addr.SetContainerID(cnrV2) + + objV2 := new(v2refs.ObjectID) + prm.ObjectID.WriteToV2(objV2) + addr.SetObjectID(objV2) + + rng := new(v2object.Range) + rng.SetLength(prm.Length) + rng.SetOffset(prm.Offset) + + body := new(v2object.GetRangeRequestBody) + body.SetRaw(prm.Raw) + body.SetAddress(addr) + body.SetRange(rng) + + req := new(v2object.GetRangeRequest) + req.SetBody(body) + c.prepareRequest(req, meta) + + return req, nil } // UseKey specifies private key to sign the requests. // If key is not provided, then Client default key is used. -func (x *PrmObjectRange) UseKey(key ecdsa.PrivateKey) { - x.key = &key +// +// Deprecated: Use PrmObjectRange.Key instead. +func (prm *PrmObjectRange) UseKey(key ecdsa.PrivateKey) { + prm.Key = &key } // ResObjectRange groups the final result values of ObjectRange operation. @@ -662,49 +769,31 @@ func (x *ObjectRangeReader) Read(p []byte) (int, error) { // Returns an error if parameters are set incorrectly (see PrmObjectRange docs). // Context is required and must not be nil. It is used for network communication. func (c *Client) ObjectRangeInit(ctx context.Context, prm PrmObjectRange) (*ObjectRangeReader, error) { - // check parameters - switch { - case prm.addr.GetContainerID() == nil: - return nil, errorMissingContainer - case prm.addr.GetObjectID() == nil: - return nil, errorMissingObject - case prm.rng.GetLength() == 0: - return nil, errorZeroRangeLength + req, err := prm.buildRequest(c) + if err != nil { + return nil, err } - // form request body - var body v2object.GetRangeRequestBody - - body.SetRaw(prm.raw) - body.SetAddress(&prm.addr) - body.SetRange(&prm.rng) - - // form request - var req v2object.GetRangeRequest - - req.SetBody(&body) - c.prepareRequest(&req, &prm.meta) - - key := prm.key + key := prm.Key if key == nil { key = &c.prm.key } - err := signature.SignServiceMessage(key, &req) + err = signature.SignServiceMessage(key, req) if err != nil { return nil, fmt.Errorf("sign request: %w", err) } ctx, cancel := context.WithCancel(ctx) - stream, err := rpcapi.GetObjectRange(&c.c, &req, client.WithContext(ctx)) + stream, err := rpcapi.GetObjectRange(&c.c, req, client.WithContext(ctx)) if err != nil { cancel() return nil, fmt.Errorf("open stream: %w", err) } var r ObjectRangeReader - r.remainingPayloadLen = int(prm.rng.GetLength()) + r.remainingPayloadLen = int(prm.Length) r.cancelCtxStream = cancel r.stream = stream r.client = c diff --git a/pool/pool.go b/pool/pool.go index 4f8a42a8..b4cc8879 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -835,20 +835,15 @@ func (c *clientWrapper) objectGet(ctx context.Context, prm PrmObjectGet) (ResGet return ResGetObject{}, err } - var cliPrm sdkClient.PrmObjectGet - cliPrm.FromContainer(prm.addr.Container()) - cliPrm.ByID(prm.addr.Object()) + prmCnr := prm.addr.Container() + prmObj := prm.addr.Object() - if prm.stoken != nil { - cliPrm.WithinSession(*prm.stoken) - } - - if prm.btoken != nil { - cliPrm.WithBearerToken(*prm.btoken) - } - - if prm.key != nil { - cliPrm.UseKey(*prm.key) + cliPrm := sdkClient.PrmObjectGet{ + BearerToken: prm.btoken, + Session: prm.stoken, + ContainerID: &prmCnr, + ObjectID: &prmObj, + Key: prm.key, } var res ResGetObject @@ -888,23 +883,16 @@ func (c *clientWrapper) objectHead(ctx context.Context, prm PrmObjectHead) (obje return object.Object{}, err } - var cliPrm sdkClient.PrmObjectHead - cliPrm.FromContainer(prm.addr.Container()) - cliPrm.ByID(prm.addr.Object()) - if prm.raw { - cliPrm.MarkRaw() - } + prmCnr := prm.addr.Container() + prmObj := prm.addr.Object() - if prm.stoken != nil { - cliPrm.WithinSession(*prm.stoken) - } - - if prm.btoken != nil { - cliPrm.WithBearerToken(*prm.btoken) - } - - if prm.key != nil { - cliPrm.UseKey(*prm.key) + cliPrm := sdkClient.PrmObjectHead{ + BearerToken: prm.btoken, + Session: prm.stoken, + Raw: prm.raw, + ContainerID: &prmCnr, + ObjectID: &prmObj, + Key: prm.key, } var obj object.Object @@ -933,22 +921,17 @@ func (c *clientWrapper) objectRange(ctx context.Context, prm PrmObjectRange) (Re return ResObjectRange{}, err } - var cliPrm sdkClient.PrmObjectRange - cliPrm.FromContainer(prm.addr.Container()) - cliPrm.ByID(prm.addr.Object()) - cliPrm.SetOffset(prm.off) - cliPrm.SetLength(prm.ln) + prmCnr := prm.addr.Container() + prmObj := prm.addr.Object() - if prm.stoken != nil { - cliPrm.WithinSession(*prm.stoken) - } - - if prm.btoken != nil { - cliPrm.WithBearerToken(*prm.btoken) - } - - if prm.key != nil { - cliPrm.UseKey(*prm.key) + cliPrm := sdkClient.PrmObjectRange{ + BearerToken: prm.btoken, + Session: prm.stoken, + ContainerID: &prmCnr, + ObjectID: &prmObj, + Offset: prm.off, + Length: prm.ln, + Key: prm.key, } start := time.Now() From b5fe52d6bd2dccae43dc6cdd5d2e0d998e3dd9fb Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Tue, 29 Aug 2023 08:41:59 +0300 Subject: [PATCH 049/288] [#150] policy: Check for redundant selectors and filters Signed-off-by: Anton Nikiforov --- netmap/policy.go | 59 ++++++++++++++++++++++++++-------- netmap/policy_decode_test.go | 61 ++++++++++++++++++++++++++++++++++++ netmap/policy_test.go | 50 ----------------------------- 3 files changed, 107 insertions(+), 63 deletions(-) create mode 100644 netmap/policy_decode_test.go diff --git a/netmap/policy.go b/netmap/policy.go index d7065561..df84a8f6 100644 --- a/netmap/policy.go +++ b/netmap/policy.go @@ -551,7 +551,7 @@ func (p *PlacementPolicy) DecodeString(s string) error { return errors.New("parsed nil value") } - if err := validatePolicy(*p); err != nil { + if err := validatePolicy(*parsed); err != nil { return fmt.Errorf("invalid policy: %w", err) } @@ -605,6 +605,13 @@ var ( errUnknownSelector = errors.New("policy: selector not found") // errSyntaxError is returned for errors found by ANTLR parser. errSyntaxError = errors.New("policy: syntax error") + // errRedundantSelector is returned for errors found by selectors policy validator. + errRedundantSelector = errors.New("policy: found redundant selector") + // errUnnamedSelector is returned for errors found by selectors policy validator. + errUnnamedSelector = errors.New("policy: unnamed selectors are useless, " + + "make sure to pair REP and SELECT clauses: \"REP .. IN X\" + \"SELECT ... AS X\"") + // errRedundantSelector is returned for errors found by filters policy validator. + errRedundantFilter = errors.New("policy: found redundant filter") ) type policyVisitor struct { @@ -846,24 +853,50 @@ func (p *policyVisitor) VisitExpr(ctx *parser.ExprContext) any { // being actually defined in FILTER section. func validatePolicy(p PlacementPolicy) error { seenFilters := map[string]bool{} - + expectedFilters := map[string]struct{}{} for i := range p.filters { seenFilters[p.filters[i].GetName()] = true - } - - seenSelectors := map[string]bool{} - - for i := range p.selectors { - if flt := p.selectors[i].GetFilter(); flt != mainFilterName && !seenFilters[flt] { - return fmt.Errorf("%w: '%s'", errUnknownFilter, flt) + for _, f := range p.filters[i].GetFilters() { + if f.GetName() != "" { + expectedFilters[f.GetName()] = struct{}{} + } } - - seenSelectors[p.selectors[i].GetName()] = true } + seenSelectors := map[string]*netmap.Selector{} + for i := range p.selectors { + if p.selectors[i].GetName() == "" { + return errUnnamedSelector + } + if flt := p.selectors[i].GetFilter(); flt != mainFilterName { + expectedFilters[flt] = struct{}{} + if !seenFilters[flt] { + return fmt.Errorf("%w: '%s'", errUnknownFilter, flt) + } + } + seenSelectors[p.selectors[i].GetName()] = &p.selectors[i] + } + + for _, f := range p.filters { + if _, ok := expectedFilters[f.GetName()]; !ok { + return fmt.Errorf("%w: '%s'", errRedundantFilter, f.GetName()) + } + } + + expectedSelectors := map[string]struct{}{} for i := range p.replicas { - if sel := p.replicas[i].GetSelector(); sel != "" && !seenSelectors[sel] { - return fmt.Errorf("%w: '%s'", errUnknownSelector, sel) + selName := p.replicas[i].GetSelector() + if selName != "" { + expectedSelectors[selName] = struct{}{} + if seenSelectors[selName] == nil { + return fmt.Errorf("%w: '%s'", errUnknownSelector, selName) + } + } + } + + for _, s := range p.selectors { + if _, ok := expectedSelectors[s.GetName()]; !ok { + return fmt.Errorf("%w: to use selector '%s' use keyword IN", errRedundantSelector, s.GetName()) } } diff --git a/netmap/policy_decode_test.go b/netmap/policy_decode_test.go new file mode 100644 index 00000000..d1e3cb66 --- /dev/null +++ b/netmap/policy_decode_test.go @@ -0,0 +1,61 @@ +package netmap + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestDecodeString(t *testing.T) { + testCases := []string{ + `REP 1 IN X +CBF 1 +SELECT 2 IN SAME Location FROM * AS X`, + + `REP 1 IN X +REP 2 IN Y +CBF 1 +SELECT 2 FROM * AS X +SELECT 3 FROM * AS Y`, + + `REP 1 IN X +SELECT 2 IN City FROM Good AS X +FILTER Country EQ RU AS FromRU +FILTER Country EQ EN AS FromEN +FILTER @FromRU AND @FromEN AND Rating GT 7 AS Good`, + + `REP 7 IN SPB +SELECT 1 IN City FROM SPBSSD AS SPB +FILTER City EQ SPB AND SSD EQ true OR City EQ SPB AND Rating GE 5 AS SPBSSD`, + + `REP 7 IN SPB +SELECT 1 IN City FROM SPBSSD AS SPB +FILTER NOT (NOT (City EQ SPB) AND SSD EQ true OR City EQ SPB AND Rating GE 5) AS SPBSSD`, + + `UNIQUE +REP 1 +REP 1`, + } + + var p PlacementPolicy + + for _, testCase := range testCases { + require.NoError(t, p.DecodeString(testCase), "unable parse %s", testCase) + var b strings.Builder + require.NoError(t, p.WriteStringTo(&b)) + require.Equal(t, testCase, b.String()) + } + + invalidTestCases := map[string]error{ + `?REP 1`: errSyntaxError, + `REP 1 trailing garbage`: errSyntaxError, + `REP 1 SELECT 4 FROM * `: errUnnamedSelector, + `REP 1 SELECT 4 FROM * AS X`: errRedundantSelector, + `REP 1 IN X REP 2 SELECT 4 FROM * AS X FILTER 'UN-LOCODE' EQ 'RU LED' AS F`: errRedundantFilter, + } + + for i := range invalidTestCases { + require.ErrorIs(t, p.DecodeString(i), invalidTestCases[i], "#%s", i) + } +} diff --git a/netmap/policy_test.go b/netmap/policy_test.go index f954eec0..05b0c98d 100644 --- a/netmap/policy_test.go +++ b/netmap/policy_test.go @@ -1,7 +1,6 @@ package netmap_test import ( - "strings" "testing" . "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap" @@ -9,55 +8,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestEncode(t *testing.T) { - testCases := []string{ - `REP 1 IN X -CBF 1 -SELECT 2 IN SAME Location FROM * AS X`, - - `REP 1 -SELECT 2 IN City FROM Good -FILTER Country EQ RU AS FromRU -FILTER @FromRU AND Rating GT 7 AS Good`, - - `REP 7 IN SPB -SELECT 1 IN City FROM SPBSSD AS SPB -FILTER City EQ SPB AND SSD EQ true OR City EQ SPB AND Rating GE 5 AS SPBSSD`, - - `REP 7 IN SPB -SELECT 1 IN City FROM SPBSSD AS SPB -FILTER NOT (NOT (City EQ SPB) AND SSD EQ true OR City EQ SPB AND Rating GE 5) AS SPBSSD`, - - `UNIQUE -REP 1 -REP 1`, - - `REP 1 IN X -SELECT 1 FROM F AS X -FILTER 'UN-LOCODE' EQ 'RU LED' AS F`, - } - - var p PlacementPolicy - - for _, testCase := range testCases { - require.NoError(t, p.DecodeString(testCase)) - - var b strings.Builder - require.NoError(t, p.WriteStringTo(&b)) - - require.Equal(t, testCase, b.String()) - } - - invalidTestCases := []string{ - `?REP 1`, - `REP 1 trailing garbage`, - } - - for i := range invalidTestCases { - require.Error(t, p.DecodeString(invalidTestCases[i]), "#%d", i) - } -} - func TestPlacementPolicyEncoding(t *testing.T) { v := netmaptest.PlacementPolicy() From 5a471e5002a77b8425215bcf8760b2a6f7ed1316 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Mon, 4 Sep 2023 13:23:10 +0300 Subject: [PATCH 050/288] [#121] client: Make PrmObjectDelete fields public * Introduce buildRequest for PrmObjectDelete * Refactor the usage of these params in pool Signed-off-by: Airat Arifullin --- client/object_delete.go | 136 +++++++++++++++++++--------------------- pool/pool.go | 21 +++---- 2 files changed, 72 insertions(+), 85 deletions(-) diff --git a/client/object_delete.go b/client/object_delete.go index 873cf3df..993cd5d9 100644 --- a/client/object_delete.go +++ b/client/object_delete.go @@ -21,71 +21,25 @@ import ( // PrmObjectDelete groups parameters of ObjectDelete operation. type PrmObjectDelete struct { - meta v2session.RequestMetaHeader + XHeaders []string - body v2object.DeleteRequestBody + BearerToken *bearer.Token - addr v2refs.Address + Session *session.Object - keySet bool - key ecdsa.PrivateKey -} + ContainerID *cid.ID -// WithinSession specifies session within which object should be read. -// -// Creator of the session acquires the authorship of the request. -// This may affect the execution of an operation (e.g. access control). -// -// Must be signed. -func (x *PrmObjectDelete) WithinSession(t session.Object) { - var tv2 v2session.Token - t.WriteToV2(&tv2) + ObjectID *oid.ID - x.meta.SetSessionToken(&tv2) -} - -// WithBearerToken attaches bearer token to be used for the operation. -// -// If set, underlying eACL rules will be used in access control. -// -// Must be signed. -func (x *PrmObjectDelete) WithBearerToken(t bearer.Token) { - var v2token acl.BearerToken - t.WriteToV2(&v2token) - x.meta.SetBearerToken(&v2token) -} - -// FromContainer specifies FrostFS container of the object. -// Required parameter. -func (x *PrmObjectDelete) FromContainer(id cid.ID) { - var cidV2 v2refs.ContainerID - id.WriteToV2(&cidV2) - - x.addr.SetContainerID(&cidV2) -} - -// ByID specifies identifier of the requested object. -// Required parameter. -func (x *PrmObjectDelete) ByID(id oid.ID) { - var idV2 v2refs.ObjectID - id.WriteToV2(&idV2) - - x.addr.SetObjectID(&idV2) + Key *ecdsa.PrivateKey } // UseKey specifies private key to sign the requests. // If key is not provided, then Client default key is used. -func (x *PrmObjectDelete) UseKey(key ecdsa.PrivateKey) { - x.keySet = true - x.key = key -} - -// WithXHeaders specifies list of extended headers (string key-value pairs) -// to be attached to the request. Must have an even length. // -// Slice must not be mutated until the operation completes. -func (x *PrmObjectDelete) WithXHeaders(hs ...string) { - writeXHeadersToMeta(hs, &x.meta) +// Deprecated: Use PrmObjectDelete.Key instead. +func (prm *PrmObjectDelete) UseKey(key ecdsa.PrivateKey) { + prm.Key = &key } // ResObjectDelete groups resulting values of ObjectDelete operation. @@ -100,6 +54,54 @@ func (x ResObjectDelete) Tombstone() oid.ID { return x.tomb } +func (prm *PrmObjectDelete) buildRequest(c *Client) (*v2object.DeleteRequest, error) { + if prm.ContainerID == nil { + return nil, errorMissingContainer + } + + if prm.ObjectID == nil { + return nil, errorMissingObject + } + + if len(prm.XHeaders)%2 != 0 { + return nil, errorInvalidXHeaders + } + + meta := new(v2session.RequestMetaHeader) + writeXHeadersToMeta(prm.XHeaders, meta) + + if prm.BearerToken != nil { + v2BearerToken := new(acl.BearerToken) + prm.BearerToken.WriteToV2(v2BearerToken) + meta.SetBearerToken(v2BearerToken) + } + + if prm.Session != nil { + v2SessionToken := new(v2session.Token) + prm.Session.WriteToV2(v2SessionToken) + meta.SetSessionToken(v2SessionToken) + } + + addr := new(v2refs.Address) + + cnrV2 := new(v2refs.ContainerID) + prm.ContainerID.WriteToV2(cnrV2) + addr.SetContainerID(cnrV2) + + objV2 := new(v2refs.ObjectID) + prm.ObjectID.WriteToV2(objV2) + addr.SetObjectID(objV2) + + body := new(v2object.DeleteRequestBody) + body.SetAddress(addr) + + req := new(v2object.DeleteRequest) + req.SetBody(body) + c.prepareRequest(req, meta) + + return req, nil +} + // ObjectDelete marks an object for deletion from the container using FrostFS API protocol. // As a marker, a special unit called a tombstone is placed in the container. // It confirms the user's intent to delete the object, and is itself a container object. @@ -124,32 +126,22 @@ func (x ResObjectDelete) Tombstone() oid.ID { // - *apistatus.ObjectLocked; // - *apistatus.SessionTokenExpired. func (c *Client) ObjectDelete(ctx context.Context, prm PrmObjectDelete) (*ResObjectDelete, error) { - switch { - case prm.addr.GetContainerID() == nil: - return nil, errorMissingContainer - case prm.addr.GetObjectID() == nil: - return nil, errorMissingObject + req, err := prm.buildRequest(c) + if err != nil { + return nil, err } - // form request body - prm.body.SetAddress(&prm.addr) - - // form request - var req v2object.DeleteRequest - req.SetBody(&prm.body) - c.prepareRequest(&req, &prm.meta) - key := c.prm.key - if prm.keySet { - key = prm.key + if prm.Key != nil { + key = *prm.Key } - err := signature.SignServiceMessage(&key, &req) + err = signature.SignServiceMessage(&key, req) if err != nil { return nil, fmt.Errorf("sign request: %w", err) } - resp, err := rpcapi.DeleteObject(&c.c, &req, client.WithContext(ctx)) + resp, err := rpcapi.DeleteObject(&c.c, req, client.WithContext(ctx)) if err != nil { return nil, err } diff --git a/pool/pool.go b/pool/pool.go index b4cc8879..6dc8fb99 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -799,20 +799,15 @@ func (c *clientWrapper) objectDelete(ctx context.Context, prm PrmObjectDelete) e return err } - var cliPrm sdkClient.PrmObjectDelete - cliPrm.FromContainer(prm.addr.Container()) - cliPrm.ByID(prm.addr.Object()) + cnr := prm.addr.Container() + obj := prm.addr.Object() - if prm.stoken != nil { - cliPrm.WithinSession(*prm.stoken) - } - - if prm.btoken != nil { - cliPrm.WithBearerToken(*prm.btoken) - } - - if prm.key != nil { - cliPrm.UseKey(*prm.key) + cliPrm := sdkClient.PrmObjectDelete{ + BearerToken: prm.btoken, + Session: prm.stoken, + ContainerID: &cnr, + ObjectID: &obj, + Key: prm.key, } start := time.Now() From 291a71ba84a0b7b2af9208e782369111f018b95b Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Mon, 4 Sep 2023 19:53:34 +0300 Subject: [PATCH 051/288] [#121] client: Make PrmAnnounceSpace fields public Signed-off-by: Airat Arifullin --- client/container_space.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/client/container_space.go b/client/container_space.go index af984e5e..c066c0aa 100644 --- a/client/container_space.go +++ b/client/container_space.go @@ -14,27 +14,29 @@ import ( // PrmAnnounceSpace groups parameters of ContainerAnnounceUsedSpace operation. type PrmAnnounceSpace struct { - prmCommonMeta + XHeaders []string - announcements []container.SizeEstimation + Announcements []container.SizeEstimation } // SetValues sets values describing volume of space that is used for the container objects. // Required parameter. Must not be empty. // // Must not be mutated before the end of the operation. +// +// Deprecated: Use PrmAnnounceSpace.Announcements instead. func (x *PrmAnnounceSpace) SetValues(vs []container.SizeEstimation) { - x.announcements = vs + x.Announcements = vs } func (x *PrmAnnounceSpace) buildRequest(c *Client) (*v2container.AnnounceUsedSpaceRequest, error) { - if len(x.announcements) == 0 { + if len(x.Announcements) == 0 { return nil, errorMissingAnnouncements } - v2announce := make([]v2container.UsedSpaceAnnouncement, len(x.announcements)) - for i := range x.announcements { - x.announcements[i].WriteToV2(&v2announce[i]) + v2announce := make([]v2container.UsedSpaceAnnouncement, len(x.Announcements)) + for i := range x.Announcements { + x.Announcements[i].WriteToV2(&v2announce[i]) } reqBody := new(v2container.AnnounceUsedSpaceRequestBody) From 55a1f23e7170a14ee2ba3b7203a5fb79bca713bd Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Mon, 4 Sep 2023 19:55:23 +0300 Subject: [PATCH 052/288] [#121] client: Make PrmEndpointInfo, PrmNetworkInfo fields public Signed-off-by: Airat Arifullin --- client/netmap.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/netmap.go b/client/netmap.go index b63ba653..80d1dedf 100644 --- a/client/netmap.go +++ b/client/netmap.go @@ -16,12 +16,12 @@ import ( // PrmEndpointInfo groups parameters of EndpointInfo operation. type PrmEndpointInfo struct { - prmCommonMeta + XHeaders []string } func (x *PrmEndpointInfo) buildRequest(c *Client) (*v2netmap.LocalNodeInfoRequest, error) { meta := new(v2session.RequestMetaHeader) - writeXHeadersToMeta(x.xHeaders, meta) + writeXHeadersToMeta(x.XHeaders, meta) req := new(v2netmap.LocalNodeInfoRequest) req.SetBody(new(v2netmap.LocalNodeInfoRequestBody)) @@ -112,12 +112,12 @@ func (c *Client) EndpointInfo(ctx context.Context, prm PrmEndpointInfo) (*ResEnd // PrmNetworkInfo groups parameters of NetworkInfo operation. type PrmNetworkInfo struct { - prmCommonMeta + XHeaders []string } func (x PrmNetworkInfo) buildRequest(c *Client) (*v2netmap.NetworkInfoRequest, error) { meta := new(v2session.RequestMetaHeader) - writeXHeadersToMeta(x.xHeaders, meta) + writeXHeadersToMeta(x.XHeaders, meta) var req v2netmap.NetworkInfoRequest req.SetBody(new(v2netmap.NetworkInfoRequestBody)) From 55699d14807b7dbf5e801ddd55302019632898cb Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Tue, 5 Sep 2023 17:30:42 +0300 Subject: [PATCH 053/288] [#121] client: Make PrmSessionCreate fields public Signed-off-by: Airat Arifullin --- client/session.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/client/session.go b/client/session.go index 3e1180e3..b3ec7229 100644 --- a/client/session.go +++ b/client/session.go @@ -16,30 +16,32 @@ import ( // PrmSessionCreate groups parameters of SessionCreate operation. type PrmSessionCreate struct { - prmCommonMeta + XHeaders []string - exp uint64 + Expiration uint64 - keySet bool - key ecdsa.PrivateKey + Key *ecdsa.PrivateKey } // SetExp sets number of the last NepFS epoch in the lifetime of the session after which it will be expired. +// +// Deprecated: Use PrmSessionCreate.Expiration instead. func (x *PrmSessionCreate) SetExp(exp uint64) { - x.exp = exp + x.Expiration = exp } // UseKey specifies private key to sign the requests and compute token owner. // If key is not provided, then Client default key is used. +// +// Deprecated: Use PrmSessionCreate.Key instead. func (x *PrmSessionCreate) UseKey(key ecdsa.PrivateKey) { - x.keySet = true - x.key = key + x.Key = &key } func (x *PrmSessionCreate) buildRequest(c *Client) (*v2session.CreateRequest, error) { ownerKey := c.prm.key.PublicKey - if x.keySet { - ownerKey = x.key.PublicKey + if x.Key != nil { + ownerKey = x.Key.PublicKey } var ownerID user.ID user.IDFromKey(&ownerID, ownerKey) @@ -49,10 +51,10 @@ func (x *PrmSessionCreate) buildRequest(c *Client) (*v2session.CreateRequest, er reqBody := new(v2session.CreateRequestBody) reqBody.SetOwnerID(&ownerIDV2) - reqBody.SetExpiration(x.exp) + reqBody.SetExpiration(x.Expiration) var meta v2session.RequestMetaHeader - writeXHeadersToMeta(x.xHeaders, &meta) + writeXHeadersToMeta(x.XHeaders, &meta) var req v2session.CreateRequest req.SetBody(reqBody) From 303508328a1ce578c0512067797f742f821e5b10 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Tue, 5 Sep 2023 17:32:03 +0300 Subject: [PATCH 054/288] [#121] pool: Refactor PrmSessionCreate usage Signed-off-by: Airat Arifullin --- pool/pool.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pool/pool.go b/pool/pool.go index 6dc8fb99..aebd5d14 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -983,9 +983,10 @@ func (c *clientWrapper) sessionCreate(ctx context.Context, prm prmCreateSession) return resCreateSession{}, err } - var cliPrm sdkClient.PrmSessionCreate - cliPrm.SetExp(prm.exp) - cliPrm.UseKey(prm.key) + cliPrm := sdkClient.PrmSessionCreate{ + Expiration: prm.exp, + Key: &prm.key, + } start := time.Now() res, err := cl.SessionCreate(ctx, cliPrm) From aa12d8c6a6dc42f5fe0049b3cdeb1993297145a9 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Mon, 4 Sep 2023 12:42:55 +0300 Subject: [PATCH 055/288] [#121] client: Make PrmObjectHash fields public * Introduce buildRequest for PrmObjectHash Signed-off-by: Airat Arifullin --- client/object_hash.go | 215 ++++++++++++++++++++---------------------- 1 file changed, 101 insertions(+), 114 deletions(-) diff --git a/client/object_hash.go b/client/object_hash.go index 6df0d7a7..7fdf335c 100644 --- a/client/object_hash.go +++ b/client/object_hash.go @@ -13,121 +13,53 @@ import ( v2session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/signature" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/checksum" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session" ) // PrmObjectHash groups parameters of ObjectHash operation. type PrmObjectHash struct { - meta v2session.RequestMetaHeader + XHeaders []string - body v2object.GetRangeHashRequestBody + BearerToken *bearer.Token - csAlgo v2refs.ChecksumType + Session *session.Object - addr v2refs.Address + Local bool - keySet bool - key ecdsa.PrivateKey + Ranges []object.Range + + Salt []byte + + ChecksumType checksum.Type + + ContainerID *cid.ID + + ObjectID *oid.ID + + Key *ecdsa.PrivateKey } // UseKey specifies private key to sign the requests. // If key is not provided, then Client default key is used. -func (x *PrmObjectHash) UseKey(key ecdsa.PrivateKey) { - x.keySet = true - x.key = key -} - -// MarkLocal tells the server to execute the operation locally. -func (x *PrmObjectHash) MarkLocal() { - x.meta.SetTTL(1) -} - -// WithinSession specifies session within which object should be read. // -// Creator of the session acquires the authorship of the request. -// This may affect the execution of an operation (e.g. access control). -// -// Must be signed. -func (x *PrmObjectHash) WithinSession(t session.Object) { - var tv2 v2session.Token - t.WriteToV2(&tv2) - - x.meta.SetSessionToken(&tv2) -} - -// WithBearerToken attaches bearer token to be used for the operation. -// -// If set, underlying eACL rules will be used in access control. -// -// Must be signed. -func (x *PrmObjectHash) WithBearerToken(t bearer.Token) { - var v2token acl.BearerToken - t.WriteToV2(&v2token) - x.meta.SetBearerToken(&v2token) -} - -// FromContainer specifies FrostFS container of the object. -// Required parameter. -func (x *PrmObjectHash) FromContainer(id cid.ID) { - var cidV2 v2refs.ContainerID - id.WriteToV2(&cidV2) - - x.addr.SetContainerID(&cidV2) -} - -// ByID specifies identifier of the requested object. -// Required parameter. -func (x *PrmObjectHash) ByID(id oid.ID) { - var idV2 v2refs.ObjectID - id.WriteToV2(&idV2) - - x.addr.SetObjectID(&idV2) -} - -// SetRangeList sets list of ranges in (offset, length) pair format. -// Required parameter. -// -// If passed as slice, then it must not be mutated before the operation completes. -func (x *PrmObjectHash) SetRangeList(r ...uint64) { - ln := len(r) - if ln%2 != 0 { - panic("odd number of range parameters") - } - - rs := make([]v2object.Range, ln/2) - - for i := 0; i < ln/2; i++ { - rs[i].SetOffset(r[2*i]) - rs[i].SetLength(r[2*i+1]) - } - - x.body.SetRanges(rs) +// Deprecated: Use PrmObjectHash.Key instead. +func (prm *PrmObjectHash) UseKey(key ecdsa.PrivateKey) { + prm.Key = &key } // TillichZemorAlgo changes the hash function to Tillich-Zemor // (https://link.springer.com/content/pdf/10.1007/3-540-48658-5_5.pdf). // -// By default, SHA256 hash function is used. -func (x *PrmObjectHash) TillichZemorAlgo() { - x.csAlgo = v2refs.TillichZemor -} - -// UseSalt sets the salt to XOR the data range before hashing. +// By default, SHA256 hash function is used/. // -// Must not be mutated before the operation completes. -func (x *PrmObjectHash) UseSalt(salt []byte) { - x.body.SetSalt(salt) -} - -// WithXHeaders specifies list of extended headers (string key-value pairs) -// to be attached to the request. Must have an even length. -// -// Slice must not be mutated until the operation completes. -func (x *PrmObjectHash) WithXHeaders(hs ...string) { - writeXHeadersToMeta(hs, &x.meta) +// Deprecated: Use PrmObjectHash.ChecksumType instead. +func (prm *PrmObjectHash) TillichZemorAlgo() { + prm.ChecksumType = checksum.TZ } // ResObjectHash groups resulting values of ObjectHash operation. @@ -142,6 +74,76 @@ func (x ResObjectHash) Checksums() [][]byte { return x.checksums } +func (prm *PrmObjectHash) buildRequest(c *Client) (*v2object.GetRangeHashRequest, error) { + if prm.ContainerID == nil { + return nil, errorMissingContainer + } + + if prm.ObjectID == nil { + return nil, errorMissingObject + } + + if len(prm.XHeaders)%2 != 0 { + return nil, errorInvalidXHeaders + } + + if len(prm.Ranges) == 0 { + return nil, errorMissingRanges + } + + meta := new(v2session.RequestMetaHeader) + writeXHeadersToMeta(prm.XHeaders, meta) + + if prm.BearerToken != nil { + v2BearerToken := new(acl.BearerToken) + prm.BearerToken.WriteToV2(v2BearerToken) + meta.SetBearerToken(v2BearerToken) + } + + if prm.Session != nil { + v2SessionToken := new(v2session.Token) + prm.Session.WriteToV2(v2SessionToken) + meta.SetSessionToken(v2SessionToken) + } + + if prm.Local { + meta.SetTTL(1) + } + + addr := new(v2refs.Address) + + cnrV2 := new(v2refs.ContainerID) + prm.ContainerID.WriteToV2(cnrV2) + addr.SetContainerID(cnrV2) + + objV2 := new(v2refs.ObjectID) + prm.ObjectID.WriteToV2(objV2) + addr.SetObjectID(objV2) + + rs := make([]v2object.Range, len(prm.Ranges)) + for i := range prm.Ranges { + rs[i].SetOffset(prm.Ranges[i].GetOffset()) + rs[i].SetLength(prm.Ranges[i].GetLength()) + } + + body := new(v2object.GetRangeHashRequestBody) + body.SetAddress(addr) + body.SetRanges(rs) + body.SetSalt(prm.Salt) + + if prm.ChecksumType == checksum.Unknown { + body.SetType(v2refs.SHA256) + } else { + body.SetType(v2refs.ChecksumType(prm.ChecksumType)) + } + + req := new(v2object.GetRangeHashRequest) + req.SetBody(body) + c.prepareRequest(req, meta) + + return req, nil +} + // ObjectHash requests checksum of the range list of the object payload using // FrostFS API protocol. // @@ -165,37 +167,22 @@ func (x ResObjectHash) Checksums() [][]byte { // - *apistatus.ObjectOutOfRange; // - *apistatus.SessionTokenExpired. func (c *Client) ObjectHash(ctx context.Context, prm PrmObjectHash) (*ResObjectHash, error) { - switch { - case prm.addr.GetContainerID() == nil: - return nil, errorMissingContainer - case prm.addr.GetObjectID() == nil: - return nil, errorMissingObject - case len(prm.body.GetRanges()) == 0: - return nil, errorMissingRanges + req, err := prm.buildRequest(c) + if err != nil { + return nil, err } - prm.body.SetAddress(&prm.addr) - if prm.csAlgo == v2refs.UnknownChecksum { - prm.body.SetType(v2refs.SHA256) - } else { - prm.body.SetType(prm.csAlgo) - } - - var req v2object.GetRangeHashRequest - c.prepareRequest(&req, &prm.meta) - req.SetBody(&prm.body) - key := c.prm.key - if prm.keySet { - key = prm.key + if prm.Key != nil { + key = *prm.Key } - err := signature.SignServiceMessage(&key, &req) + err = signature.SignServiceMessage(&key, req) if err != nil { return nil, fmt.Errorf("sign request: %w", err) } - resp, err := rpcapi.HashObjectRange(&c.c, &req, client.WithContext(ctx)) + resp, err := rpcapi.HashObjectRange(&c.c, req, client.WithContext(ctx)) if err != nil { return nil, fmt.Errorf("write request: %w", err) } From 49ad985cadd2a86955aae557e5ab43f1a1af5e02 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 8 Sep 2023 17:15:08 +0300 Subject: [PATCH 056/288] [#161] *: Do not use math/rand.Read() Signed-off-by: Evgenii Stratonikov --- checksum/example_test.go | 2 +- checksum/test/generate.go | 4 ++-- container/id/id_test.go | 2 +- container/id/test/id.go | 4 ++-- crypto/crypto_test.go | 2 +- eacl/test/benchmark_test.go | 2 +- eacl/validator_test.go | 2 +- netmap/selector_test.go | 7 ++++--- netmap/test/generate.go | 4 ++-- ns/nns_test.go | 2 +- object/id/test/generate.go | 4 ++-- object/search_test.go | 2 +- object/tombstone_test.go | 2 +- session/container_test.go | 5 +++-- user/id_test.go | 2 +- 15 files changed, 24 insertions(+), 22 deletions(-) diff --git a/checksum/example_test.go b/checksum/example_test.go index d98c9921..337767ab 100644 --- a/checksum/example_test.go +++ b/checksum/example_test.go @@ -2,9 +2,9 @@ package checksum import ( "bytes" + "crypto/rand" "crypto/sha256" "fmt" - "math/rand" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" ) diff --git a/checksum/test/generate.go b/checksum/test/generate.go index d8c6b0bd..06c90599 100644 --- a/checksum/test/generate.go +++ b/checksum/test/generate.go @@ -1,8 +1,8 @@ package checksumtest import ( + "crypto/rand" "crypto/sha256" - "math/rand" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/checksum" ) @@ -11,7 +11,7 @@ import ( func Checksum() checksum.Checksum { var cs [sha256.Size]byte - rand.Read(cs[:]) + _, _ = rand.Read(cs[:]) var x checksum.Checksum diff --git a/container/id/id_test.go b/container/id/id_test.go index ad122958..ded74572 100644 --- a/container/id/id_test.go +++ b/container/id/id_test.go @@ -1,8 +1,8 @@ package cid_test import ( + "crypto/rand" "crypto/sha256" - "math/rand" "testing" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" diff --git a/container/id/test/id.go b/container/id/test/id.go index 2ebcf091..6790b226 100644 --- a/container/id/test/id.go +++ b/container/id/test/id.go @@ -1,8 +1,8 @@ package cidtest import ( + "crypto/rand" "crypto/sha256" - "math/rand" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" ) @@ -11,7 +11,7 @@ import ( func ID() cid.ID { checksum := [sha256.Size]byte{} - rand.Read(checksum[:]) + _, _ = rand.Read(checksum[:]) return IDWithChecksum(checksum) } diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go index 095cdd9b..7d1ad526 100644 --- a/crypto/crypto_test.go +++ b/crypto/crypto_test.go @@ -1,7 +1,7 @@ package frostfscrypto_test import ( - "math/rand" + "crypto/rand" "testing" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" diff --git a/eacl/test/benchmark_test.go b/eacl/test/benchmark_test.go index cc2c3d00..865789b5 100644 --- a/eacl/test/benchmark_test.go +++ b/eacl/test/benchmark_test.go @@ -2,7 +2,7 @@ package eacltest import ( "bytes" - "math/rand" + "crypto/rand" "testing" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" diff --git a/eacl/validator_test.go b/eacl/validator_test.go index 3b8d9f18..582a6bc3 100644 --- a/eacl/validator_test.go +++ b/eacl/validator_test.go @@ -1,7 +1,7 @@ package eacl import ( - "math/rand" + "crypto/rand" "testing" "github.com/stretchr/testify/require" diff --git a/netmap/selector_test.go b/netmap/selector_test.go index ccb5eb2c..759e7eea 100644 --- a/netmap/selector_test.go +++ b/netmap/selector_test.go @@ -1,9 +1,10 @@ package netmap import ( + "crypto/rand" "encoding/binary" "fmt" - "math/rand" + mrand "math/rand" "sort" "strconv" "testing" @@ -28,10 +29,10 @@ func BenchmarkHRWSort(b *testing.B) { node.SetPublicKey(key) vectors[i] = nodes{node} - weights[i] = float64(rand.Uint32()%10) / 10.0 + weights[i] = float64(mrand.Uint32()%10) / 10.0 } - pivot := rand.Uint64() + pivot := mrand.Uint64() b.Run("sort by index, no weight", func(b *testing.B) { realNodes := make([]nodes, netmapSize) b.ResetTimer() diff --git a/netmap/test/generate.go b/netmap/test/generate.go index 3f5f26b8..19c3514b 100644 --- a/netmap/test/generate.go +++ b/netmap/test/generate.go @@ -1,7 +1,7 @@ package netmaptest import ( - "math/rand" + "crypto/rand" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap" ) @@ -70,7 +70,7 @@ func NetworkInfo() (x netmap.NetworkInfo) { // NodeInfo returns random netmap.NodeInfo. func NodeInfo() (x netmap.NodeInfo) { key := make([]byte, 33) - rand.Read(key) + _, _ = rand.Read(key) x.SetPublicKey(key) x.SetNetworkEndpoints("1", "2", "3") diff --git a/ns/nns_test.go b/ns/nns_test.go index 9970b885..669f4af8 100644 --- a/ns/nns_test.go +++ b/ns/nns_test.go @@ -1,10 +1,10 @@ package ns import ( + "crypto/rand" "errors" "fmt" "math/big" - "math/rand" "strings" "testing" diff --git a/object/id/test/generate.go b/object/id/test/generate.go index e51405d6..0da41199 100644 --- a/object/id/test/generate.go +++ b/object/id/test/generate.go @@ -1,8 +1,8 @@ package oidtest import ( + "crypto/rand" "crypto/sha256" - "math/rand" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -12,7 +12,7 @@ import ( func ID() oid.ID { checksum := [sha256.Size]byte{} - rand.Read(checksum[:]) + _, _ = rand.Read(checksum[:]) return idWithChecksum(checksum) } diff --git a/object/search_test.go b/object/search_test.go index d0f36de5..40df23b5 100644 --- a/object/search_test.go +++ b/object/search_test.go @@ -1,8 +1,8 @@ package object_test import ( + "crypto/rand" "crypto/sha256" - "math/rand" "testing" v2object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" diff --git a/object/tombstone_test.go b/object/tombstone_test.go index cd74e456..98251333 100644 --- a/object/tombstone_test.go +++ b/object/tombstone_test.go @@ -1,8 +1,8 @@ package object import ( + "crypto/rand" "crypto/sha256" - "math/rand" "testing" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone" diff --git a/session/container_test.go b/session/container_test.go index a152e316..d3d46626 100644 --- a/session/container_test.go +++ b/session/container_test.go @@ -1,9 +1,10 @@ package session_test import ( + "crypto/rand" "fmt" "math" - "math/rand" + mrand "math/rand" "testing" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" @@ -396,7 +397,7 @@ func TestContainer_AppliedTo(t *testing.T) { func TestContainer_InvalidAt(t *testing.T) { var x session.Container - nbf := rand.Uint64() + nbf := mrand.Uint64() if nbf == math.MaxUint64 { nbf-- } diff --git a/user/id_test.go b/user/id_test.go index 27d93dc8..30e19db4 100644 --- a/user/id_test.go +++ b/user/id_test.go @@ -1,7 +1,7 @@ package user_test import ( - "math/rand" + "crypto/rand" "testing" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" From 8bc64e088ec04801f5128893d5ce30c9ff3fc48a Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 8 Sep 2023 17:15:53 +0300 Subject: [PATCH 057/288] [#161] .golangci.yml: Reenable deprecated usage warnings Signed-off-by: Evgenii Stratonikov --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index fae355a3..aca07466 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -25,7 +25,7 @@ linters-settings: # report about shadowed variables check-shadowing: false staticcheck: - checks: ["all", "-SA1019"] # TODO Enable SA1019 after deprecated warning are fixed. + checks: ["all"] funlen: lines: 80 # default 60 statements: 60 # default 40 From 4df642e94119afbadcdca5142ad05ea2af6230d1 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 11 Sep 2023 15:12:55 +0300 Subject: [PATCH 058/288] [#162] netmap: Fix possible panic Placement policy is unvalidated external input. Under no circumstances should we panic here. Signed-off-by: Evgenii Stratonikov --- netmap/netmap.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/netmap/netmap.go b/netmap/netmap.go index 3e8d680d..37f5caba 100644 --- a/netmap/netmap.go +++ b/netmap/netmap.go @@ -258,6 +258,9 @@ func (m NetMap) ContainerNodes(p PlacementPolicy, pivot []byte) ([][]NodeInfo, e } if p.unique { + if c.processedSelectors[sName] == nil { + return nil, fmt.Errorf("selector not found: '%s'", sName) + } nodes, err := c.getSelection(*c.processedSelectors[sName]) if err != nil { return nil, err From 0a0b590df38aa9af77ecc89cbda7b75818e97bfb Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 11 Sep 2023 15:21:35 +0300 Subject: [PATCH 059/288] [#162] Fix pre-commit warnings Signed-off-by: Evgenii Stratonikov --- doc/image/filter_illustration.svg | 2 +- doc/image/placement_policy.svg | 2 +- doc/image/rep_illustration.svg | 2 +- doc/image/sample_netmap.svg | 2 +- doc/image/select_illustration.svg | 2 +- doc/policy.md | 20 ++++++++++---------- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/doc/image/filter_illustration.svg b/doc/image/filter_illustration.svg index a57aa688..7eedf3d6 100644 --- a/doc/image/filter_illustration.svg +++ b/doc/image/filter_illustration.svg @@ -1,4 +1,4 @@ -
FILTER Color EQ 'Red' AS RedNodes
FILTER Color EQ 'Red' AS RedNodes
FILTER Color EQ 'Blue' AS BlueNodes
FILTER Color EQ 'Blue' AS BlueNodes
FILTER @RedNodes OR @BlueNodes AS MyNodes
FILTER @RedNodes OR @BlueNodes AS MyNodes
*
*
MyNodes
MyNodes
Text is not SVG - cannot display
\ No newline at end of file +
FILTER Color EQ 'Red' AS RedNodes
FILTER Color EQ 'Red' AS RedNodes
FILTER Color EQ 'Blue' AS BlueNodes
FILTER Color EQ 'Blue' AS BlueNodes
FILTER @RedNodes OR @BlueNodes AS MyNodes
FILTER @RedNodes OR @BlueNodes AS MyNodes
*
*
MyNodes
MyNodes
Text is not SVG - cannot display
diff --git a/doc/image/placement_policy.svg b/doc/image/placement_policy.svg index 9cc8a1ab..2820c64f 100644 --- a/doc/image/placement_policy.svg +++ b/doc/image/placement_policy.svg @@ -1,4 +1,4 @@ -
FILTER
FILTER
FILTER
FILTER
FILTER
FILTER
SELECT
SELECT
SELECT
SELECT
SELECT
SELECT
FILTER
FILTER
FILTER
FILTER
FILTER
FILTER
REP
REP
REP
REP
REP
REP
netmap
netmap
Text is not SVG - cannot display
\ No newline at end of file +
FILTER
FILTER
FILTER
FILTER
FILTER
FILTER
SELECT
SELECT
SELECT
SELECT
SELECT
SELECT
FILTER
FILTER
FILTER
FILTER
FILTER
FILTER
REP
REP
REP
REP
REP
REP
netmap
netmap
Text is not SVG - cannot display
diff --git a/doc/image/rep_illustration.svg b/doc/image/rep_illustration.svg index 8bcc3272..6955499d 100644 --- a/doc/image/rep_illustration.svg +++ b/doc/image/rep_illustration.svg @@ -1,4 +1,4 @@ -
(...)
(...)
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
MyNodes
MyNodes
REP 1 IN MyNodes
REP 1 IN MyNodes
Text is not SVG - cannot display
\ No newline at end of file +
(...)
(...)
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
MyNodes
MyNodes
REP 1 IN MyNodes
REP 1 IN MyNodes
Text is not SVG - cannot display
diff --git a/doc/image/sample_netmap.svg b/doc/image/sample_netmap.svg index 3d0b39f5..ea4928ea 100644 --- a/doc/image/sample_netmap.svg +++ b/doc/image/sample_netmap.svg @@ -1,4 +1,4 @@ -
C
C
A
A
Netmap
Netmap
B
B
D
D
E
E
F
F
G
G
H
H
I
I
Text is not SVG - cannot display
\ No newline at end of file +
C
C
A
A
Netmap
Netmap
B
B
D
D
E
E
F
F
G
G
H
H
I
I
Text is not SVG - cannot display
diff --git a/doc/image/select_illustration.svg b/doc/image/select_illustration.svg index 3a0956af..83ee7838 100644 --- a/doc/image/select_illustration.svg +++ b/doc/image/select_illustration.svg @@ -1,4 +1,4 @@ -
FILTER @RedNodes OR @BlueNodes AS RedOrBlueNodes
FILTER @RedNodes OR @BlueNodes AS RedOrBlueNodes
RedOrBlueNodes
RedOrBlueNodes
(...)
(...)
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
MyNodes
MyNodes
Text is not SVG - cannot display
\ No newline at end of file +
FILTER @RedNodes OR @BlueNodes AS RedOrBlueNodes
FILTER @RedNodes OR @BlueNodes AS RedOrBlueNodes
RedOrBlueNodes
RedOrBlueNodes
(...)
(...)
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
MyNodes
MyNodes
Text is not SVG - cannot display
diff --git a/doc/policy.md b/doc/policy.md index 68184688..c7597eac 100644 --- a/doc/policy.md +++ b/doc/policy.md @@ -101,16 +101,16 @@ In a nutshell, a `SELECT` takes a filter result as input and outputs a specific Let's see some examples ```sql -- Selects exactly one node from the entire netmap -SELECT 1 FROM * +SELECT 1 FROM * -- Same as above, but with an identifier for the selection -SELECT 1 FROM * AS ONE +SELECT 1 FROM * AS ONE --- Selects two nodes from the RedOrBlueNodes filter, such that both selected nodes +-- Selects two nodes from the RedOrBlueNodes filter, such that both selected nodes -- share the same value for the Color attribute, i.e. both red or both blue. -SELECT 2 IN SAME Color FROM RedOrBlueNodes +SELECT 2 IN SAME Color FROM RedOrBlueNodes --- Selects two nodes from the RedOrBlueNodes filter, such that the selected nodes +-- Selects two nodes from the RedOrBlueNodes filter, such that the selected nodes -- have distinct values for the Color attribute, i.e. one red and one blue. -- The selection is also given an identifier. SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes @@ -173,18 +173,18 @@ In additional to this basic syntax, there are a couple of additional useful opti ### The policy playground -> ℹ️ This section assumes you have an up-to-date version of the `frostfs-cli`. +> ℹ️ This section assumes you have an up-to-date version of the `frostfs-cli`. While simple placement policies have predictable results that can be understood at a glance, more complex ones need careful consideration before deployment. In order to simplify understanding a policy's outcome and experimenting while learning, a builtin tool is provided as part of the `frostfs-cli` for this purpose: the policy playground. -For the remainder of this guide, we will use the policy playground to setup a virtual netmap (that is, one that doesn't require any networking or deployment) and test various policies. In order to visualize this netmap easily, each node will have three attributes: a character, a shape and a color +For the remainder of this guide, we will use the policy playground to setup a virtual netmap (that is, one that doesn't require any networking or deployment) and test various policies. In order to visualize this netmap easily, each node will have three attributes: a character, a shape and a color ![Sample Netmap](./image/sample_netmap.svg) We can start the policy playground as follows: ```sh $ frostfs-cli container policy-playground -> +> ``` Since we didn't pass any endpoint, the initial netmap is empty, which we can verify with the `ls` command (to list the nodes in the netmap): @@ -400,7 +400,7 @@ FILTER Color EQ 'Green' AS GreenNodes #### Example #6 ```sql REP 1 IN MyNodes -REP 2 +REP 2 CBF 2 SELECT 1 FROM CuteNodes AS MyNodes FILTER (Color EQ 'Blue') AND NOT (Shape EQ 'Circle' OR Shape EQ 'Square') AS CuteNodes @@ -442,4 +442,4 @@ Others: - `ls`: list nodes in the current netmap and their attributes - `add`: add a node to the current netmap. If it already exists, it will be overwritten. - `remove`: remove a node from the current netmap. -- `eval`: evaluate a placement policy on the current netmap. \ No newline at end of file +- `eval`: evaluate a placement policy on the current netmap. From ac8fc6d4400c4b842fc77d993d2a13598c51970d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 8 Sep 2023 16:57:41 +0300 Subject: [PATCH 060/288] [#162] netmap: Allow to parse single unnamed selectors Signed-off-by: Evgenii Stratonikov --- doc/policy.md | 3 ++- netmap/netmap.go | 2 +- netmap/policy.go | 5 ++-- netmap/policy_decode_test.go | 12 ++++++--- netmap/selector_test.go | 49 ++++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 8 deletions(-) diff --git a/doc/policy.md b/doc/policy.md index c7597eac..28744efc 100644 --- a/doc/policy.md +++ b/doc/policy.md @@ -131,7 +131,8 @@ Its basic syntax is as follows: REP {IN