Skip to content

Commit 8b1f60c

Browse files
author
Luis Sanchez
committed
[FAB-1733] Fix blockcutting logic when msg > preferred
Change-Id: If0208e13302ad48d7b420b0d07a31017467976b6 Signed-off-by: Luis Sanchez <[email protected]>
1 parent ab5b2b5 commit 8b1f60c

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

orderer/common/blockcutter/blockcutter.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,15 @@ func (r *receiver) Ordered(msg *cb.Envelope) ([][]*cb.Envelope, [][]filter.Commi
9292
return nil, nil, false
9393
}
9494

95-
if committer.Isolated() {
96-
logger.Debugf("Found message which requested to be isolated, cutting into its own batch")
95+
messageSizeBytes := messageSizeBytes(msg)
96+
97+
if committer.Isolated() || messageSizeBytes > r.sharedConfigManager.BatchSize().PreferredMaxBytes {
98+
99+
if committer.Isolated() {
100+
logger.Debugf("Found message which requested to be isolated, cutting into its own batch")
101+
} else {
102+
logger.Debugf("The current message, with %v bytes, is larger than the preferred batch size of %v bytes and will be isolated.", messageSizeBytes, r.sharedConfigManager.BatchSize().PreferredMaxBytes)
103+
}
97104

98105
messageBatches := [][]*cb.Envelope{}
99106
committerBatches := [][]filter.Committer{}
@@ -115,7 +122,6 @@ func (r *receiver) Ordered(msg *cb.Envelope) ([][]*cb.Envelope, [][]filter.Commi
115122
messageBatches := [][]*cb.Envelope{}
116123
committerBatches := [][]filter.Committer{}
117124

118-
messageSizeBytes := messageSizeBytes(msg)
119125
messageWillOverflowBatchSizeBytes := r.pendingBatchSizeBytes+messageSizeBytes > r.sharedConfigManager.BatchSize().PreferredMaxBytes
120126

121127
if messageWillOverflowBatchSizeBytes {

orderer/common/blockcutter/blockcutter_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func getFilters() *filter.RuleSet {
7474

7575
var badTx = &cb.Envelope{Payload: []byte("BAD")}
7676
var goodTx = &cb.Envelope{Payload: []byte("GOOD")}
77+
var goodTxLarge = &cb.Envelope{Payload: []byte("GOOD"), Signature: make([]byte, 1000)}
7778
var isolatedTx = &cb.Envelope{Payload: []byte("ISOLATED")}
7879
var unmatchedTx = &cb.Envelope{Payload: []byte("UNMATCHED")}
7980

@@ -306,3 +307,36 @@ func TestBatchSizePreferredMaxBytesOverflow(t *testing.T) {
306307
}
307308

308309
}
310+
311+
func TestBatchSizePreferredMaxBytesOverflowNoPending(t *testing.T) {
312+
filters := getFilters()
313+
314+
goodTxLargeBytes := messageSizeBytes(goodTxLarge)
315+
316+
// set preferred max bytes such that 1 goodTxLarge will not fit
317+
preferredMaxBytes := goodTxLargeBytes - 1
318+
319+
// set message count > 1
320+
maxMessageCount := uint32(20)
321+
322+
r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: preferredMaxBytes * 3, PreferredMaxBytes: preferredMaxBytes}}, filters)
323+
324+
// submit large message
325+
batches, committers, ok := r.Ordered(goodTxLarge)
326+
327+
if batches == nil || committers == nil {
328+
t.Fatalf("Should have created batch")
329+
}
330+
331+
if len(batches) != 1 || len(committers) != 1 {
332+
t.Fatalf("Should have created one batch, got %d and %d", len(batches), len(committers))
333+
}
334+
335+
if len(batches[0]) != 1 || len(committers[0]) != 1 {
336+
t.Fatalf("Should have had one normal tx in the batch got %d and %d committers", len(batches[0]), len(committers[0]))
337+
}
338+
if !ok {
339+
t.Fatalf("Should have enqueued the message into batch")
340+
}
341+
342+
}

0 commit comments

Comments
 (0)