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

Bug fix/sync multiple tries #1864

Merged
merged 13 commits into from Jun 5, 2020
Merged

Conversation

sasurobert
Copy link
Contributor

sync multiple tries at the same time - on go routines.

@sasurobert sasurobert changed the base branch from release-candidate to bugFix/recreate-trie-after-shuffle-out June 4, 2020 10:22
@iulianpascalau iulianpascalau self-requested a review June 4, 2020 10:22
@SebastianMarian SebastianMarian self-requested a review June 4, 2020 10:22
iulianpascalau
iulianpascalau previously approved these changes Jun 4, 2020
Base automatically changed from bugFix/recreate-trie-after-shuffle-out to release-candidate June 4, 2020 10:43
@LucianMincu LucianMincu dismissed iulianpascalau’s stale review June 4, 2020 10:43

The base branch was changed.

u.syncerMutex.Lock()
dataTrie, err := trie.NewTrie(u.trieStorageManager, u.marshalizer, u.hasher, u.maxTrieLevelInMemory)
if err != nil {
return err
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}(rootHash)

errMutex.Lock()
Copy link
Contributor

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
}

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trieHashesAcumulator ?

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

  1. If yes, they would be added again in rrh.trieHashAccumulator, and now we have 16, but they are duplicates.
  2. If not, they would be not requested anymore.

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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()
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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() {
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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

Copy link
Contributor Author

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.

errMutex.Lock()
returnErr := errFound
errMutex.Unlock()
errMutex.Lock()
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

SebastianMarian
SebastianMarian previously approved these changes Jun 4, 2020
consensus/mock/cacherMock.go Show resolved Hide resolved
data/mock/cacherMock.go Show resolved Hide resolved
data/mock/cacherMock.go Show resolved Hide resolved
dataRetriever/mock/cacherStub.go Show resolved Hide resolved
data/mock/uint64CacherStub.go Show resolved Hide resolved
storage/txcache/txCache.go Show resolved Hide resolved
log.Error("TxCache.RegisterHandler is not implemented")
}

// RegisterHandler is not implemented
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnRegisterHandler

Copy link
Contributor Author

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 Show resolved Hide resolved
update/mock/cacherMock.go Show resolved Hide resolved
update/mock/cacherStub.go Show resolved Hide resolved
core/common.go Outdated
@@ -12,3 +16,10 @@ func EmptyChannel(ch chan bool) int {
}
}
}

// UniqueIdentifier returns a unique string identifier
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

data/mock/cacherMock.go Show resolved Hide resolved
data/mock/cacherMock.go Show resolved Hide resolved
@@ -140,7 +138,6 @@ func (rrh *resolverRequestHandler) requestHashesWithDataSplit(
"num txs", len(unrequestedHashes),
"max txs to request", rrh.maxTxsToRequest,
)
return err
Copy link
Contributor

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

Copy link
Contributor Author

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.

@iulianpascalau iulianpascalau added the type:bug Something isn't working label Jun 4, 2020
Copy link
Contributor

@LucianMincu LucianMincu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System tests passed.

@LucianMincu LucianMincu merged commit 5f2bb92 into release-candidate Jun 5, 2020
@LucianMincu LucianMincu deleted the bugFix/sync-multiple-tries branch June 5, 2020 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants