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 fix/sync multiple tries #1864
Conversation
u.syncerMutex.Lock() | ||
dataTrie, err := trie.NewTrie(u.trieStorageManager, u.marshalizer, u.hasher, u.maxTrieLevelInMemory) | ||
if err != nil { | ||
return err |
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.
u.syncerMutex.Unlock() before return
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.
done
u.dataTries[string(rootHash)] = dataTrie | ||
trieSyncer, err := trie.NewTrieSyncer(u.requestHandler, u.cacher, dataTrie, u.shardId, factory.AccountTrieNodesTopic) | ||
if err != nil { | ||
return err |
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.
u.syncerMutex.Unlock() before return
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.
done
data/syncer/userAccountsSyncer.go
Outdated
} | ||
}(rootHash) | ||
|
||
errMutex.Lock() |
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.
Missing errMutex.Unlock() after line 128. I suggest to replace the code between lines 123-128 with:
errMutex.RLock()
returnErr := errFound
errMutex.RUnlock()
if returnErr != nil {
return returnErr
}
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.
done
@@ -28,6 +31,10 @@ type resolverRequestHandler struct { | |||
sweepTime time.Time | |||
requestInterval time.Duration | |||
mutSweepTime sync.Mutex | |||
|
|||
trieHashAccumulator [][]byte |
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.
trieHashesAcumulator ?
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.
done
|
||
rrh.trieHashAccumulator = append(rrh.trieHashAccumulator, unrequestedHashes...) | ||
elapsedTime := time.Since(rrh.lastTrieRequestTime) | ||
if len(rrh.trieHashAccumulator) < minHashesToRequest && elapsedTime < timeToAccumulateTrieHashes { |
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.
What if the last bulk of trieHashes is smaller than 10? Let say 8. This will make the method to return in this point. It would be called again for the same 8 hashes after a while?
- If yes, they would be added again in rrh.trieHashAccumulator, and now we have 16, but they are duplicates.
- If not, they would be not requested anymore.
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.
I think you should either call: rrh.addRequestedItems(rrh.trieHashAccumulator) before return or better rrh.trieHashAccumulator = rrh.trieHashAccumulator[:0] and add them again in the next call
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.
There are also other exit points below so I think you should put this line: rrh.trieHashAccumulator = rrh.trieHashAccumulator[:0], in a defer method above and remove it from line 400
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.
the request trie hashes method is called in a continuous way at every second. Thus the accumulated hashes will be surely requested.
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.
Then you need only to manage the duplicate hashes added in rrh.trieHashAccumulator after each call
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.
done with MAP.
return | ||
} | ||
|
||
rrh.lastTrieRequestTime = time.Now() |
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.
Move this to line 391 where you are sure that the rrh.requestHashesWithDataSplit(rrh.trieHashAccumulator, trieResolver) would be executed
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.
I would make requestHashesWithDataSplit to return error at least if the SplitDataInChunks call fails. And set the rrh.lastTrieRequestTime = time.Now() only if the request has been done with success.
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.
done.
@@ -18,6 +18,9 @@ var _ epochStart.RequestHandler = (*resolverRequestHandler)(nil) | |||
|
|||
var log = logger.GetOrCreate("dataretriever/requesthandlers") | |||
|
|||
const minHashesToRequest = 10 |
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.
Please replace line 456 from addRequestedItems method with continue instead return. This will fix the situation when the call of rrh.requestedItemsHandler.Add for a key, fails for whatever reason, and because of this the all others keys would not be added in the requested items list.
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.
done
@@ -150,7 +152,10 @@ func (rrh *resolverRequestHandler) requestHashesWithDataSplit( | |||
"batch size", len(batch), | |||
) | |||
} | |||
return err |
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.
Move this return after line 153, or better remove it at all so some of them would be requested
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.
done.
@@ -121,15 +121,17 @@ func (rrh *resolverRequestHandler) requestByHashes(destShardID uint32, hashes [] | |||
|
|||
rrh.whiteList.Add(unrequestedHashes) | |||
|
|||
go rrh.requestHashesWithDataSplit(unrequestedHashes, txResolver) | |||
go func() { |
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.
You can replace 124-126 with:
err = rrh.requestHashesWithDataSplit(unrequestedHashes, txResolver)
if err != nil {
return
}
As all the exported methods from this file, which call requestByHashes method, are called already on go routines
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.
done
index++ | ||
} | ||
|
||
rrh.whiteList.Add(itemsToRequest) |
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.
Move this in line 411 to not add duplicate items if multiple calls are done and all of them exit in line 382, 399 or 405
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.
moved addRequestedItems - whitelisting would leave to the top.
} | ||
|
||
rrh.whiteList.Add(itemsToRequest) | ||
rrh.addRequestedItems(itemsToRequest) |
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.
Move this in line 416 to be done only if the request of these items is done
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.
moved addRequestedItems - whitelisting would leave to the top.
data/syncer/userAccountsSyncer.go
Outdated
errMutex.Lock() | ||
returnErr := errFound | ||
errMutex.Unlock() | ||
errMutex.Lock() |
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.
You can replace 124-132 with:
errMutex.RLock()
defer errMutex.RUnlock()
return errFound
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.
done.
storage/txcache/txCache.go
Outdated
log.Error("TxCache.RegisterHandler is not implemented") | ||
} | ||
|
||
// RegisterHandler is not implemented |
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.
UnRegisterHandler
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.
done.
core/common.go
Outdated
@@ -12,3 +16,10 @@ func EmptyChannel(ch chan bool) int { | |||
} | |||
} | |||
} | |||
|
|||
// UniqueIdentifier returns a unique string identifier |
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.
might add ...of 32 bytes long
Since this will contain unprintable elements, I guess (for the sake of the re usability) to change the return type in []byte
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.
done
@@ -140,7 +138,6 @@ func (rrh *resolverRequestHandler) requestHashesWithDataSplit( | |||
"num txs", len(unrequestedHashes), | |||
"max txs to request", rrh.maxTxsToRequest, | |||
) | |||
return err |
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.
You can call "return" here
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.
would leave as it is - the next for could do nothing as is a range over a nil.
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.
System tests passed.
sync multiple tries at the same time - on go routines.