Skip to content

Commit

Permalink
[FAB-1733] Fix blockcutting logic when msg > preferred
Browse files Browse the repository at this point in the history
Change-Id: If0208e13302ad48d7b420b0d07a31017467976b6
Signed-off-by: Luis Sanchez <sanchezl@us.ibm.com>
  • Loading branch information
Luis Sanchez committed Jan 18, 2017
1 parent ab5b2b5 commit 8b1f60c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
12 changes: 9 additions & 3 deletions orderer/common/blockcutter/blockcutter.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,15 @@ func (r *receiver) Ordered(msg *cb.Envelope) ([][]*cb.Envelope, [][]filter.Commi
return nil, nil, false
}

if committer.Isolated() {
logger.Debugf("Found message which requested to be isolated, cutting into its own batch")
messageSizeBytes := messageSizeBytes(msg)

if committer.Isolated() || messageSizeBytes > r.sharedConfigManager.BatchSize().PreferredMaxBytes {

if committer.Isolated() {
logger.Debugf("Found message which requested to be isolated, cutting into its own batch")
} else {
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)
}

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

messageSizeBytes := messageSizeBytes(msg)
messageWillOverflowBatchSizeBytes := r.pendingBatchSizeBytes+messageSizeBytes > r.sharedConfigManager.BatchSize().PreferredMaxBytes

if messageWillOverflowBatchSizeBytes {
Expand Down
34 changes: 34 additions & 0 deletions orderer/common/blockcutter/blockcutter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func getFilters() *filter.RuleSet {

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

Expand Down Expand Up @@ -306,3 +307,36 @@ func TestBatchSizePreferredMaxBytesOverflow(t *testing.T) {
}

}

func TestBatchSizePreferredMaxBytesOverflowNoPending(t *testing.T) {
filters := getFilters()

goodTxLargeBytes := messageSizeBytes(goodTxLarge)

// set preferred max bytes such that 1 goodTxLarge will not fit
preferredMaxBytes := goodTxLargeBytes - 1

// set message count > 1
maxMessageCount := uint32(20)

r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: preferredMaxBytes * 3, PreferredMaxBytes: preferredMaxBytes}}, filters)

// submit large message
batches, committers, ok := r.Ordered(goodTxLarge)

if batches == nil || committers == nil {
t.Fatalf("Should have created batch")
}

if len(batches) != 1 || len(committers) != 1 {
t.Fatalf("Should have created one batch, got %d and %d", len(batches), len(committers))
}

if len(batches[0]) != 1 || len(committers[0]) != 1 {
t.Fatalf("Should have had one normal tx in the batch got %d and %d committers", len(batches[0]), len(committers[0]))
}
if !ok {
t.Fatalf("Should have enqueued the message into batch")
}

}

0 comments on commit 8b1f60c

Please sign in to comment.