-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove requests from BFT memory pool when syncing
When a BFT node commits a block, it goes through the transactions in the block and searches whether they exist in the in-memory pool, and if so, it removes them from the pool. When a follower node syncs blocks from another node, the requests of these blocks still remain in its request pool. They not only take up memory, but also holds the semaphore resources which throttle needlessly the client. This commit goes through the requests of a block that is committed through synchronization and removes them as well. This is needed because the library only sees the last block committed during synchronization and not the entire range. Signed-off-by: Yacov Manevich <yacov.manevich@ibm.com>
- Loading branch information
Showing
3 changed files
with
126 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package smartbft | ||
|
||
import ( | ||
"encoding/binary" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestWorker(t *testing.T) { | ||
work := make([][]byte, 13) | ||
|
||
for i := 0; i < 13; i++ { | ||
work[i] = make([]byte, 2) | ||
binary.BigEndian.PutUint16(work[i], uint16(i)) | ||
} | ||
|
||
workDone := make(map[int]struct{}) | ||
|
||
var lock sync.Mutex | ||
|
||
var workers []worker | ||
for i := 0; i < 7; i++ { | ||
workers = append(workers, worker{ | ||
workerNum: 7, | ||
work: work, | ||
id: i, | ||
f: func(data []byte) { | ||
lock.Lock() | ||
defer lock.Unlock() | ||
|
||
workDone[int(binary.BigEndian.Uint16(data))] = struct{}{} | ||
}, | ||
}) | ||
} | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(7) | ||
|
||
for i := 0; i < len(workers); i++ { | ||
go func(i int, w worker) { | ||
defer wg.Done() | ||
w.doWork() | ||
}(i, workers[i]) | ||
} | ||
|
||
wg.Wait() | ||
|
||
assert.Len(t, workDone, 13) | ||
} |