-
Notifications
You must be signed in to change notification settings - Fork 197
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
Bug fixes elastic search indexer #1997
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"encoding/json" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"net/http" | ||
|
||
"github.com/elastic/go-elasticsearch/v7" | ||
|
@@ -158,8 +159,18 @@ func (dc *databaseClient) DoMultiGet(obj object, index string) (object, error) { | |
return nil, fmt.Errorf("do multi get %s", res.String()) | ||
} | ||
|
||
var responseBody []byte | ||
responseBody, err = ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
log.Warn("indexer: response body", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should delete this Warn, as responeBody should be nil if err != nil. Did you want to log res.Body? If you want to keep this warn you can add it in the next warn as additional info: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
"body", string(responseBody)) | ||
log.Warn("indexer:cannot read from response body", "error", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return nil, err here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
} | ||
|
||
var decodedBody object | ||
if err := json.NewDecoder(res.Body).Decode(&decodedBody); err != nil { | ||
if err := json.Unmarshal(responseBody, &decodedBody); err != nil { | ||
log.Warn("indexer: response body", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete this warn and add it in the next Warn as additional info, like suggested above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. body |
||
"body", string(responseBody)) | ||
log.Warn("indexer cannot decode body", "error", err) | ||
return nil, err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import ( | |
"strconv" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
logger "github.com/ElrondNetwork/elrond-go-logger" | ||
"github.com/ElrondNetwork/elrond-go/core" | ||
|
@@ -601,32 +602,36 @@ func TestDoBulkRequestLimit(t *testing.T) { | |
esDatabase, _ := newElasticSearchDatabase(args) | ||
|
||
//Generate transaction and hashes | ||
numTransactions := 1000 | ||
dataSize := 12345 | ||
txs, hashes := generateTransactions(numTransactions, dataSize) | ||
|
||
header := &dataBlock.Header{} | ||
txsPool := make(map[string]data.TransactionHandler) | ||
for i := 0; i < numTransactions; i++ { | ||
txsPool[hashes[i]] = &txs[i] | ||
} | ||
for i := 0; i < 1000; i++ { | ||
numTransactions := 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move these two lines outside the for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
dataSize := 900001 | ||
txs, hashes := generateTransactions(numTransactions, dataSize) | ||
|
||
miniblock := &dataBlock.MiniBlock{ | ||
TxHashes: make([][]byte, numTransactions), | ||
Type: dataBlock.TxBlock, | ||
} | ||
for i := 0; i < numTransactions; i++ { | ||
miniblock.TxHashes[i] = []byte(hashes[i]) | ||
} | ||
header := &dataBlock.Header{} | ||
txsPool := make(map[string]data.TransactionHandler) | ||
for i := 0; i < numTransactions; i++ { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use j instead i. The outer for uses also i for iteration There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
txsPool[hashes[i]] = &txs[i] | ||
} | ||
|
||
body := &dataBlock.Body{ | ||
MiniBlocks: []*dataBlock.MiniBlock{ | ||
miniblock, | ||
}, | ||
miniblock := &dataBlock.MiniBlock{ | ||
TxHashes: make([][]byte, numTransactions), | ||
Type: dataBlock.TxBlock, | ||
} | ||
for i := 0; i < numTransactions; i++ { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use j instead i. The outer for uses also i for iteration There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
miniblock.TxHashes[i] = []byte(hashes[i]) | ||
} | ||
|
||
body := &dataBlock.Body{ | ||
MiniBlocks: []*dataBlock.MiniBlock{ | ||
miniblock, | ||
}, | ||
} | ||
body.MiniBlocks[0].ReceiverShardID = 2 | ||
body.MiniBlocks[0].SenderShardID = 1 | ||
|
||
esDatabase.SaveTransactions(body, header, txsPool, 2) | ||
} | ||
body.MiniBlocks[0].ReceiverShardID = 2 | ||
body.MiniBlocks[0].SenderShardID = 1 | ||
esDatabase.SaveTransactions(body, header, txsPool, 2) | ||
} | ||
|
||
func generateTransactions(numTxs int, datFieldSize int) ([]transaction.Transaction, []string) { | ||
|
@@ -647,7 +652,7 @@ func generateTransactions(numTxs int, datFieldSize int) ([]transaction.Transacti | |
Data: randomByteArray, | ||
Signature: []byte("443e79a8d99ba093262c1db48c58ab3d59bcfeb313ca5cddf2a9d1d06f9894ec"), | ||
} | ||
hashes[i] = fmt.Sprintf("%d", i) | ||
hashes[i] = fmt.Sprintf("%v", time.Now()) | ||
} | ||
|
||
return txs, hashes | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be leave to go routines - add a go routine throttler ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the moment i will let as it is because method SaveBlock is called on a goroutine and i want the writing of header, miniblocks and transaction to be serial because this write do a lot of requests to elasticsearch database because have to check if miniblocks and transactions exits in database.