Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rc/2022 july #172

Merged
merged 97 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
edfee91
implemented count check
miiu96 Apr 14, 2022
b28d0c4
continue the implementation
miiu96 Apr 14, 2022
e8af781
more logs
miiu96 Apr 14, 2022
4125cf5
sort imports
miiu96 Apr 14, 2022
ce206fd
check with interval
miiu96 Apr 15, 2022
662d83f
fix imports
miiu96 Apr 15, 2022
6a2b097
small fix
miiu96 Apr 15, 2022
09abb28
small refactor
miiu96 Apr 15, 2022
416f284
small fix
miiu96 Apr 18, 2022
b904195
fix log
miiu96 Apr 18, 2022
7fecca1
Merge branch 'feat/operations' into clusters-checker
miiu96 Apr 27, 2022
abfc216
cleanup config
miiu96 Apr 27, 2022
604b8c2
fix rating index
miiu96 Apr 27, 2022
7040788
integrate partial execution
miiu96 May 3, 2022
61358d3
fix unit tests
miiu96 May 3, 2022
e724cd0
Merge branch 'feat/operations' into clusters-checker
miiu96 May 10, 2022
b4b4c71
Merge branch 'master' into clusters-checker
miiu96 May 25, 2022
4a44bb8
Merge branch 'master' into prepare-indexer-partial-execution
miiu96 May 30, 2022
1e8de9f
optimeze
miiu96 May 30, 2022
85b2a26
Merge branch 'master' into prepare-indexer-partial-execution
miiu96 Jun 6, 2022
609ca62
Merge pull request #150 from ElrondNetwork/merge-master-in-dev
miiu96 Jun 6, 2022
3cbe17c
Merge branch 'development' into prepare-indexer-partial-execution
miiu96 Jun 6, 2022
028b006
extend github action
miiu96 Jun 6, 2022
87d4fa6
Merge branch 'development' into clusters-checker
miiu96 Jun 6, 2022
6cea394
fixes after review
miiu96 Jun 6, 2022
0ad7e84
Merge pull request #140 from ElrondNetwork/prepare-indexer-partial-ex…
miiu96 Jun 7, 2022
f04d71c
Merge branch 'development' into clusters-checker
miiu96 Jun 7, 2022
8573294
Merge branch 'development' into merge-master-in-dev-j
miiu96 Jun 15, 2022
800c0c2
Merge pull request #152 from ElrondNetwork/merge-master-in-dev-j
miiu96 Jun 15, 2022
7bb96b0
Merge branch 'development' into clusters-checker
miiu96 Jun 15, 2022
db85cef
fix
miiu96 Jun 15, 2022
97e7b45
add operations
miiu96 Jun 16, 2022
e2a10c9
Merge pull request #135 from ElrondNetwork/clusters-checker
miiu96 Jun 17, 2022
3db265a
fix nft processor
miiu96 Jun 23, 2022
a73c8e9
collections index initial impl
miiu96 Jun 23, 2022
c7aa4b1
collections
miiu96 Jun 23, 2022
5de1320
empty
miiu96 Jun 23, 2022
fad0401
Merge branch 'development' into collections-index
miiu96 Jun 23, 2022
97fd229
implement serialize for collections
miiu96 Jun 23, 2022
2b8ce9d
fix unit tests
miiu96 Jun 23, 2022
6a279d9
integration test
miiu96 Jun 24, 2022
7dab841
fix import
miiu96 Jun 24, 2022
a1a5781
small fix
miiu96 Jun 24, 2022
d68de88
delete if empty
miiu96 Jun 24, 2022
a0bd9c9
Merge branch 'development' into merge-master-in-dev-mon
miiu96 Jun 27, 2022
7549f1d
Merge branch 'master' into merge-master-in-dev-mon
miiu96 Jun 27, 2022
009580e
Merge pull request #156 from ElrondNetwork/merge-master-in-dev-mon
miiu96 Jun 27, 2022
8e215b1
remove data field parser
miiu96 Jun 27, 2022
a3b6cc8
small fix
miiu96 Jun 27, 2022
0d0e763
Merge pull request #159 from ElrondNetwork/remove-data-field-parser-3
miiu96 Jun 27, 2022
79adec7
fixes after review
miiu96 Jun 27, 2022
564c5de
Merge branch 'development' into collections-index
miiu96 Jun 27, 2022
e3a7be8
use converters.JsonEscape
miiu96 Jun 27, 2022
e768a55
fix unit tests
miiu96 Jun 27, 2022
6f5d9a3
extra protection JsonEscape
miiu96 Jun 28, 2022
febf6d4
Merge pull request #153 from ElrondNetwork/collections-index
miiu96 Jun 29, 2022
f6f2561
fix gas used operations index
miiu96 Jul 14, 2022
bb02795
fix gas used txs with informative logs and refund
miiu96 Jul 15, 2022
8566b72
Merge pull request #160 from ElrondNetwork/update-refund-also-in-oper…
miiu96 Jul 15, 2022
d9d8ce7
silent retry in case of conflict code
miiu96 Jul 18, 2022
a15f64e
fixes after review
miiu96 Jul 19, 2022
ad21dfb
Merge pull request #161 from ElrondNetwork/silent-retry-if-conflict
miiu96 Jul 19, 2022
7c4e811
extra field block structure
miiu96 Jul 20, 2022
2984885
upgrade version integration tests
miiu96 Jul 20, 2022
7326448
small fix
miiu96 Jul 20, 2022
a7bfb2e
Merge pull request #162 from ElrondNetwork/epoch-start-start-data-meta
miiu96 Jul 20, 2022
1aeab7c
shard id in accounts and accountsesdt index
miiu96 Aug 19, 2022
4734751
delete rewards txs in case of metachain observer and rollback
miiu96 Aug 19, 2022
26a5708
remove comment
miiu96 Aug 19, 2022
2844dab
remove also accounts esdt in case of rollback
miiu96 Aug 19, 2022
be3d256
fix unit tests
miiu96 Aug 19, 2022
e4e11e8
fix integration tests
miiu96 Aug 19, 2022
e17d553
integration test and small refactor
miiu96 Aug 22, 2022
80ea936
empty line
miiu96 Aug 22, 2022
b469c35
small fix
miiu96 Aug 22, 2022
598cd45
use header hash from arg instead of compute it
miiu96 Aug 23, 2022
59067cb
change logic how logs are indexed
miiu96 Aug 24, 2022
d8a9de1
fix integration tests
miiu96 Aug 24, 2022
1bfa2dc
integration tests index logs
miiu96 Aug 24, 2022
f0c615d
fix integration tests
miiu96 Aug 24, 2022
94bfd27
fixes after first review
miiu96 Aug 24, 2022
e614840
Update process/accounts/accountsProcessor.go
miiu96 Aug 24, 2022
0510696
Merge pull request #165 from ElrondNetwork/fix-accounts-esdt
miiu96 Aug 24, 2022
5b666c0
initial paid fee in transaction structure
miiu96 Aug 25, 2022
52b2a95
fix unit and integration tests
miiu96 Aug 25, 2022
882990c
change remove function
miiu96 Aug 25, 2022
39bc4d0
extend unit tests and fixes
miiu96 Aug 26, 2022
67faa54
fixes
miiu96 Aug 26, 2022
2a0b2f1
fixes after review
miiu96 Aug 26, 2022
8f72e25
fixes after second review
miiu96 Aug 26, 2022
f58f648
small rename
miiu96 Aug 26, 2022
6e1ac8c
small rename
miiu96 Aug 26, 2022
2d11d20
Merge pull request #166 from ElrondNetwork/initial-paid-fee
miiu96 Aug 26, 2022
4c645f6
extend block structure
miiu96 Sep 15, 2022
0c41f75
Merge pull request #169 from ElrondNetwork/mb-details-in-block
miiu96 Sep 15, 2022
d4b2b44
delete cross shard scrs at source
miiu96 Sep 20, 2022
78d3e7f
Merge pull request #170 from ElrondNetwork/delete-scrs-at-soruce
miiu96 Sep 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: Go build

on:
push:
branches: [ master, feat/* ]
branches: [ master, development, feat/* ]
pull_request:
branches: [ master, feat/* ]
branches: [ master, development, feat/* ]

jobs:
build:
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/pr-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Integration tests

on:
push:
branches: [ master, feat/* ]
branches: [ master, development, feat/* ]
pull_request:
branches: [ master, feat/* ]
branches: [ master, development, feat/* ]

jobs:
test-1:
Expand All @@ -26,7 +26,7 @@ jobs:
- name: Run integration tests with Elasticsearch `v7.16.2`
run: make integration-tests ES_VERSION=7.16.2
test-2:
name: Elasticsearch v8.1.1
name: Elasticsearch v8.3.2
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
Expand All @@ -41,8 +41,8 @@ jobs:
- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Run integration tests with Elasticsearch `v8.1.1`
run: make integration-tests ES_VERSION=8.1.1
- name: Run integration tests with Elasticsearch `v8.3.2`
run: make integration-tests ES_VERSION=8.3.2
test-3:
name: OpenSearch v1.2.4
runs-on: ubuntu-latest
Expand All @@ -63,7 +63,7 @@ jobs:
run: make integration-tests-open-search OPEN_VERSION=1.2.4

test-4:
name: OpenSearch v1.3.2
name: OpenSearch v2.1.0
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
Expand All @@ -78,5 +78,5 @@ jobs:
- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Run integration tests with OpenSearch `v1.3.2`
run: make integration-tests-open-search OPEN_VERSION=1.3.2
- name: Run integration tests with OpenSearch `v2.1.0`
run: make integration-tests-open-search OPEN_VERSION=2.1.0
4 changes: 2 additions & 2 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Tests

on:
push:
branches: [ master, feat/* ]
branches: [ master, development, feat/* ]
pull_request:
branches: [ master, feat/* ]
branches: [ master, development, feat/* ]

jobs:
test:
Expand Down
69 changes: 39 additions & 30 deletions client/elasticClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
// TODO add more unit tests

const (
esConflictsPolicy = "proceed"
errPolicyAlreadyExists = "document already exists"
)

Expand All @@ -30,7 +31,7 @@ type (

type elasticClient struct {
elasticBaseUrl string
es *elasticsearch.Client
client *elasticsearch.Client

// countScroll is used to be incremented after each scroll so the scroll duration is different each time,
// bypassing any possible caching based on the same request
Expand All @@ -49,7 +50,7 @@ func NewElasticClient(cfg elasticsearch.Config) (*elasticClient, error) {
}

ec := &elasticClient{
es: es,
client: es,
elasticBaseUrl: cfg.Addresses[0],
}

Expand Down Expand Up @@ -94,7 +95,7 @@ func (ec *elasticClient) CheckAndCreateAlias(alias string, indexName string) err

// DoRequest will do a request to elastic server
func (ec *elasticClient) DoRequest(req *esapi.IndexRequest) error {
res, err := req.Do(context.Background(), ec.es)
res, err := req.Do(context.Background(), ec.client)
if err != nil {
return err
}
Expand All @@ -108,10 +109,10 @@ func (ec *elasticClient) DoBulkRequest(buff *bytes.Buffer, index string) error {

options := make([]func(*esapi.BulkRequest), 0)
if index != "" {
options = append(options, ec.es.Bulk.WithIndex(index))
options = append(options, ec.client.Bulk.WithIndex(index))
}

res, err := ec.es.Bulk(
res, err := ec.client.Bulk(
reader,
options...,
)
Expand All @@ -132,9 +133,9 @@ func (ec *elasticClient) DoMultiGet(ids []string, index string, withSource bool,
return err
}

res, err := ec.es.Mget(
res, err := ec.client.Mget(
&body,
ec.es.Mget.WithIndex(index),
ec.client.Mget.WithIndex(index),
)
if err != nil {
log.Warn("elasticClient.DoMultiGet",
Expand All @@ -152,46 +153,54 @@ func (ec *elasticClient) DoMultiGet(ids []string, index string, withSource bool,
return nil
}

// DoBulkRemove will do a bulk remove to elasticsearch server
func (ec *elasticClient) DoBulkRemove(index string, hashes []string) error {
obj := prepareHashesForBulkRemove(hashes)
body, err := encode(obj)
if err != nil {
return err
// DoQueryRemove will do a query remove to elasticsearch server
func (ec *elasticClient) DoQueryRemove(index string, body *bytes.Buffer) error {
if err := ec.doRefresh(index); err != nil {
log.Warn("elasticClient.doRefresh", "cannot to refresh", err.Error())
}

res, err := ec.es.DeleteByQuery(
res, err := ec.client.DeleteByQuery(
[]string{index},
&body,
ec.es.DeleteByQuery.WithIgnoreUnavailable(true),
body,
ec.client.DeleteByQuery.WithIgnoreUnavailable(true),
ec.client.DeleteByQuery.WithConflicts(esConflictsPolicy),
)

if err != nil {
log.Warn("elasticClient.DoBulkRemove",
"cannot do bulk remove", err.Error())
log.Warn("elasticClient.DoQueryRemove", "cannot do query remove", err.Error())
return err
}

var decodedBody objectsMap
err = parseResponse(res, &decodedBody, elasticDefaultErrorResponseHandler)
err = parseResponse(res, nil, elasticDefaultErrorResponseHandler)
if err != nil {
log.Warn("elasticClient.DoBulkRemove",
"error parsing response", err.Error())
log.Warn("elasticClient.DoQueryRemove", "error parsing response", err.Error())
return err
}

return nil
}

func (ec *elasticClient) doRefresh(index string) error {
res, err := ec.client.Indices.Refresh(
ec.client.Indices.Refresh.WithIndex(index),
ec.client.Indices.Refresh.WithIgnoreUnavailable(true),
)
if err != nil {
return err
}

return parseResponse(res, nil, elasticDefaultErrorResponseHandler)
}

// TemplateExists checks weather a template is already created
func (ec *elasticClient) templateExists(index string) bool {
res, err := ec.es.Indices.ExistsTemplate([]string{index})
res, err := ec.client.Indices.ExistsTemplate([]string{index})
return exists(res, err)
}

// IndexExists checks if a given index already exists
func (ec *elasticClient) indexExists(index string) bool {
res, err := ec.es.Indices.Exists([]string{index})
res, err := ec.client.Indices.Exists([]string{index})
return exists(res, err)
}

Expand All @@ -205,7 +214,7 @@ func (ec *elasticClient) PolicyExists(policy string) bool {
)

req := newRequest(http.MethodGet, policyRoute, nil)
res, err := ec.es.Transport.Perform(req)
res, err := ec.client.Transport.Perform(req)
if err != nil {
log.Warn("elasticClient.PolicyExists",
"error performing request", err.Error())
Expand Down Expand Up @@ -237,7 +246,7 @@ func (ec *elasticClient) aliasExists(alias string) bool {
)

req := newRequest(http.MethodHead, aliasRoute, nil)
res, err := ec.es.Transport.Perform(req)
res, err := ec.client.Transport.Perform(req)
if err != nil {
log.Warn("elasticClient.AliasExists",
"error performing request", err.Error())
Expand All @@ -255,7 +264,7 @@ func (ec *elasticClient) aliasExists(alias string) bool {

// CreateIndex creates an elasticsearch index
func (ec *elasticClient) createIndex(index string) error {
res, err := ec.es.Indices.Create(index)
res, err := ec.client.Indices.Create(index)
if err != nil {
return err
}
Expand All @@ -274,7 +283,7 @@ func (ec *elasticClient) createPolicy(policyName string, policy *bytes.Buffer) e
req := newRequest(http.MethodPut, policyRoute, policy)
req.Header[headerContentType] = headerContentTypeJSON
req.Header[headerXSRF] = []string{"false"}
res, err := ec.es.Transport.Perform(req)
res, err := ec.client.Transport.Perform(req)
if err != nil {
return err
}
Expand All @@ -301,7 +310,7 @@ func (ec *elasticClient) createPolicy(policyName string, policy *bytes.Buffer) e

// CreateIndexTemplate creates an elasticsearch index template
func (ec *elasticClient) createIndexTemplate(templateName string, template io.Reader) error {
res, err := ec.es.Indices.PutTemplate(templateName, template)
res, err := ec.client.Indices.PutTemplate(templateName, template)
if err != nil {
return err
}
Expand All @@ -311,7 +320,7 @@ func (ec *elasticClient) createIndexTemplate(templateName string, template io.Re

// CreateAlias creates an index alias
func (ec *elasticClient) createAlias(alias string, index string) error {
res, err := ec.es.Indices.PutAlias([]string{index}, alias)
res, err := ec.client.Indices.PutAlias([]string{index}, alias)
if err != nil {
return err
}
Expand Down
30 changes: 15 additions & 15 deletions client/elasticClientScroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

// DoCountRequest will get the number of elements that correspond with the provided query
func (ec *elasticClient) DoCountRequest(index string, body []byte) (uint64, error) {
res, err := ec.es.Count(
ec.es.Count.WithIndex(index),
ec.es.Count.WithBody(bytes.NewBuffer(body)),
res, err := ec.client.Count(
ec.client.Count.WithIndex(index),
ec.client.Count.WithBody(bytes.NewBuffer(body)),
)
if err != nil {
return 0, err
Expand All @@ -44,13 +44,13 @@ func (ec *elasticClient) DoScrollRequest(
handlerFunc func(responseBytes []byte) error,
) error {
ec.countScroll++
res, err := ec.es.Search(
ec.es.Search.WithSize(9000),
ec.es.Search.WithScroll(10*time.Minute+time.Duration(ec.countScroll)*time.Millisecond),
ec.es.Search.WithContext(context.Background()),
ec.es.Search.WithIndex(index),
ec.es.Search.WithBody(bytes.NewBuffer(body)),
ec.es.Search.WithSource(strconv.FormatBool(withSource)),
res, err := ec.client.Search(
ec.client.Search.WithSize(9000),
ec.client.Search.WithScroll(10*time.Minute+time.Duration(ec.countScroll)*time.Millisecond),
ec.client.Search.WithContext(context.Background()),
ec.client.Search.WithIndex(index),
ec.client.Search.WithBody(bytes.NewBuffer(body)),
ec.client.Search.WithSource(strconv.FormatBool(withSource)),
)
if err != nil {
return err
Expand Down Expand Up @@ -103,9 +103,9 @@ func (ec *elasticClient) iterateScroll(

func (ec *elasticClient) getScrollResponse(scrollID string) ([]byte, error) {
ec.countScroll++
res, err := ec.es.Scroll(
ec.es.Scroll.WithScrollID(scrollID),
ec.es.Scroll.WithScroll(2*time.Minute+time.Duration(ec.countScroll)*time.Millisecond),
res, err := ec.client.Scroll(
ec.client.Scroll.WithScrollID(scrollID),
ec.client.Scroll.WithScroll(2*time.Minute+time.Duration(ec.countScroll)*time.Millisecond),
)
if err != nil {
return nil, err
Expand All @@ -115,8 +115,8 @@ func (ec *elasticClient) getScrollResponse(scrollID string) ([]byte, error) {
}

func (ec *elasticClient) clearScroll(scrollID string) error {
resp, err := ec.es.ClearScroll(
ec.es.ClearScroll.WithScrollID(scrollID),
resp, err := ec.client.ClearScroll(
ec.client.ClearScroll.WithScrollID(scrollID),
)
if err != nil {
return err
Expand Down
10 changes: 0 additions & 10 deletions client/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,3 @@ func getDocumentsByIDsQuery(hashes []string, withSource bool) objectsMap {
"docs": interfaceSlice,
}
}

func prepareHashesForBulkRemove(hashes []string) objectsMap {
return objectsMap{
"query": objectsMap{
"ids": objectsMap{
"values": hashes,
},
},
}
}
2 changes: 2 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (
DelegatorsIndex = "delegators"
// OperationsIndex is the Elasticsearch index for transactions and smart contract results
OperationsIndex = "operations"
// CollectionsIndex is the Elasticsearch index for collections
CollectionsIndex = "collections"

// TransactionsPolicy is the Elasticsearch policy for the transactions
TransactionsPolicy = "transactions_policy"
Expand Down
31 changes: 29 additions & 2 deletions converters/json.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
package converters

import "encoding/json"
import (
"bytes"
"encoding/json"
"fmt"

logger "github.com/ElrondNetwork/elrond-go-logger"
)

const defaultStr = "default"

var log = logger.GetOrCreate("indexer/converters")

// JsonEscape will format the provided string in a json compatible string
func JsonEscape(i string) string {
b, err := json.Marshal(i)
if err != nil {
return ""
log.Warn("converters.JsonEscape something went wrong",
"input", i,
"error", err,
)
return defaultStr
}

// Trim the beginning and trailing " character
return string(b[1 : len(b)-1])
}

// PrepareHashesForQueryRemove will prepare the provided hashes for query remove
func PrepareHashesForQueryRemove(hashes []string) *bytes.Buffer {
if len(hashes) == 0 {
hashes = []string{}
}

serializedHashes, _ := json.Marshal(hashes)
query := `{"query": {"ids": {"values": %s}}}`
deleteQuery := fmt.Sprintf(query, serializedHashes)

return bytes.NewBuffer([]byte(deleteQuery))
}
Loading