Skip to content

Commit f68a97e

Browse files
author
Luis Sanchez
committed
[FAB-1242] Add BatchSize.AbsoluteMaxBytes config
This changeset just adds the new config property. A subsequent changeset will exploit it. Change-Id: I2c0f46b4036575a8d53d71546335c6480a6618c3 Signed-off-by: Luis Sanchez <[email protected]>
1 parent 9e8fb87 commit f68a97e

File tree

9 files changed

+102
-68
lines changed

9 files changed

+102
-68
lines changed

orderer/common/bootstrap/provisional/provisional.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ func New(conf *config.TopLevel) Generator {
8484
chainID: TestChainID,
8585
consensusType: conf.Genesis.OrdererType,
8686
batchSize: &ab.BatchSize{
87-
MaxMessageCount: conf.Genesis.BatchSize.MaxMessageCount,
87+
MaxMessageCount: conf.Genesis.BatchSize.MaxMessageCount,
88+
AbsoluteMaxBytes: conf.Genesis.BatchSize.AbsoluteMaxBytes,
8889
},
8990
batchTimeout: conf.Genesis.BatchTimeout.String(),
9091
}

orderer/common/sharedconfig/sharedconfig.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,11 @@ func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error {
194194
if err := proto.Unmarshal(configItem.Value, batchSize); err != nil {
195195
return fmt.Errorf("Unmarshaling error for BatchSize: %s", err)
196196
}
197-
if batchSize.MaxMessageCount <= 0 {
198-
return fmt.Errorf("Attempted to set the batch size max message count to %d which is less than or equal to 0", batchSize.MaxMessageCount)
197+
if batchSize.MaxMessageCount == 0 {
198+
return fmt.Errorf("Attempted to set the batch size max message count to an invalid value: 0")
199+
}
200+
if batchSize.AbsoluteMaxBytes == 0 {
201+
return fmt.Errorf("Attempted to set the batch size absolute max bytes to an invalid value: 0")
199202
}
200203
pm.pendingConfig.batchSize = batchSize
201204
case BatchTimeoutKey:

orderer/common/sharedconfig/sharedconfig_test.go

+54-40
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"testing"
2323
"time"
2424

25+
"github.com/stretchr/testify/assert"
26+
2527
cb "github.com/hyperledger/fabric/protos/common"
2628
ab "github.com/hyperledger/fabric/protos/orderer"
2729
"github.com/hyperledger/fabric/protos/utils"
@@ -132,51 +134,63 @@ func TestConsensusType(t *testing.T) {
132134
}
133135

134136
func TestBatchSize(t *testing.T) {
135-
endBatchSize := struct{ MaxMessageCount uint32 }{
136-
MaxMessageCount: uint32(10),
137-
}
138-
invalidMessage := &cb.ConfigurationItem{
139-
Type: cb.ConfigurationItem_Orderer,
140-
Key: BatchSizeKey,
141-
Value: []byte("Garbage Data"),
142-
}
143-
zeroBatchSize := &cb.ConfigurationItem{
144-
Type: cb.ConfigurationItem_Orderer,
145-
Key: BatchSizeKey,
146-
Value: utils.MarshalOrPanic(&ab.BatchSize{MaxMessageCount: 0}),
147-
}
148-
validMessage := &cb.ConfigurationItem{
149-
Type: cb.ConfigurationItem_Orderer,
150-
Key: BatchSizeKey,
151-
Value: utils.MarshalOrPanic(&ab.BatchSize{MaxMessageCount: endBatchSize.MaxMessageCount}),
152-
}
153-
m := NewManagerImpl()
154-
m.BeginConfig()
155137

156-
err := m.ProposeConfig(validMessage)
157-
if err != nil {
158-
t.Fatalf("Error applying valid config: %s", err)
159-
}
138+
validMaxMessageCount := uint32(10)
139+
validAbsoluteMaxBytes := uint32(1000)
160140

161-
err = m.ProposeConfig(invalidMessage)
162-
if err == nil {
163-
t.Fatalf("Should have failed on invalid message")
164-
}
165-
166-
err = m.ProposeConfig(zeroBatchSize)
167-
if err == nil {
168-
t.Fatalf("Should have rejected batch size of 0")
169-
}
141+
t.Run("ValidConfiguration", func(t *testing.T) {
142+
m := NewManagerImpl()
143+
m.BeginConfig()
144+
err := m.ProposeConfig(&cb.ConfigurationItem{
145+
Type: cb.ConfigurationItem_Orderer,
146+
Key: BatchSizeKey,
147+
Value: utils.MarshalOrPanic(&ab.BatchSize{MaxMessageCount: validMaxMessageCount, AbsoluteMaxBytes: validAbsoluteMaxBytes}),
148+
})
149+
assert.Nil(t, err, "Error applying valid config: %s", err)
150+
m.CommitConfig()
151+
if m.BatchSize().MaxMessageCount != validMaxMessageCount {
152+
t.Fatalf("Got batch size max message count of %d. Expected: %d", m.BatchSize().MaxMessageCount, validMaxMessageCount)
153+
}
154+
if m.BatchSize().AbsoluteMaxBytes != validAbsoluteMaxBytes {
155+
t.Fatalf("Got batch size absolute max bytes of %d. Expected: %d", m.BatchSize().AbsoluteMaxBytes, validAbsoluteMaxBytes)
156+
}
157+
})
170158

171-
m.CommitConfig()
159+
t.Run("UnserializableConfiguration", func(t *testing.T) {
160+
m := NewManagerImpl()
161+
m.BeginConfig()
162+
err := m.ProposeConfig(&cb.ConfigurationItem{
163+
Type: cb.ConfigurationItem_Orderer,
164+
Key: BatchSizeKey,
165+
Value: []byte("Garbage Data"),
166+
})
167+
assert.NotNil(t, err, "Should have failed on invalid message")
168+
m.CommitConfig()
169+
})
172170

173-
nowBatchSize := struct{ MaxMessageCount uint32 }{
174-
MaxMessageCount: m.BatchSize().MaxMessageCount,
175-
}
171+
t.Run("ZeroMaxMessageCount", func(t *testing.T) {
172+
m := NewManagerImpl()
173+
m.BeginConfig()
174+
err := m.ProposeConfig(&cb.ConfigurationItem{
175+
Type: cb.ConfigurationItem_Orderer,
176+
Key: BatchSizeKey,
177+
Value: utils.MarshalOrPanic(&ab.BatchSize{MaxMessageCount: 0, AbsoluteMaxBytes: validAbsoluteMaxBytes}),
178+
})
179+
assert.NotNil(t, err, "Should have rejected batch size max message count of 0")
180+
m.CommitConfig()
181+
})
176182

177-
if nowBatchSize.MaxMessageCount != endBatchSize.MaxMessageCount {
178-
t.Fatalf("Got batch size max message count of %d. Expected: %d", nowBatchSize.MaxMessageCount, endBatchSize.MaxMessageCount)
179-
}
183+
t.Run("ZeroAbsoluteMaxBytes", func(t *testing.T) {
184+
m := NewManagerImpl()
185+
m.BeginConfig()
186+
err := m.ProposeConfig(&cb.ConfigurationItem{
187+
Type: cb.ConfigurationItem_Orderer,
188+
Key: BatchSizeKey,
189+
Value: utils.MarshalOrPanic(&ab.BatchSize{MaxMessageCount: validMaxMessageCount, AbsoluteMaxBytes: 0}),
190+
})
191+
assert.NotNil(t, err, "Should have rejected batch size absolute max message bytes of 0")
192+
m.CommitConfig()
193+
})
180194
}
181195

182196
func TestBatchTimeout(t *testing.T) {

orderer/kafka/config_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ var testConf = &config.TopLevel{
5959
OrdererType: "kafka",
6060
BatchTimeout: 500 * time.Millisecond,
6161
BatchSize: config.BatchSize{
62-
MaxMessageCount: 100,
62+
MaxMessageCount: 100,
63+
AbsoluteMaxBytes: 10 * 1024 * 1024,
6364
},
6465
},
6566
}

orderer/localconfig/config.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ type Genesis struct {
5959

6060
// BatchSize contains configuration affecting the size of batches
6161
type BatchSize struct {
62-
MaxMessageCount uint32
62+
MaxMessageCount uint32
63+
AbsoluteMaxBytes uint32
6364
}
6465

6566
// Profile contains configuration for Go pprof profiling
@@ -141,7 +142,8 @@ var defaults = TopLevel{
141142
OrdererType: "solo",
142143
BatchTimeout: 10 * time.Second,
143144
BatchSize: BatchSize{
144-
MaxMessageCount: 10,
145+
MaxMessageCount: 10,
146+
AbsoluteMaxBytes: 100000000,
145147
},
146148
},
147149
}
@@ -197,6 +199,9 @@ func (c *TopLevel) completeInitialization() {
197199
case c.Genesis.BatchSize.MaxMessageCount == 0:
198200
logger.Infof("Genesis.BatchSize.MaxMessageCount unset, setting to %s", defaults.Genesis.BatchSize.MaxMessageCount)
199201
c.Genesis.BatchSize.MaxMessageCount = defaults.Genesis.BatchSize.MaxMessageCount
202+
case c.Genesis.BatchSize.AbsoluteMaxBytes == 0:
203+
logger.Infof("Genesis.BatchSize.AbsoluteMaxBytes unset, setting to %s", defaults.Genesis.BatchSize.AbsoluteMaxBytes)
204+
c.Genesis.BatchSize.AbsoluteMaxBytes = defaults.Genesis.BatchSize.AbsoluteMaxBytes
200205
default:
201206
// A bit hacky, but its type makes it impossible to test for a nil value.
202207
// This may be overwritten by the Kafka orderer upon instantiation.

orderer/orderer.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,6 @@ Genesis:
122122
# Max Message Count: The maximum number of messages to permit in a batch
123123
MaxMessageCount: 10
124124

125+
# Absolute Max Bytes: The absolute maximum number of bytes allowed for
126+
# the serialized messages in a batch.
127+
AbsoluteMaxBytes: 100000000

protos/orderer/configuration.pb.go

+25-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/orderer/configuration.proto

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ message BatchSize {
3737
// Simply specified as number of messages for now, in the future
3838
// we may want to allow this to be specified by size in bytes
3939
uint32 maxMessageCount = 1;
40+
// The byte count of the serialized messages in a batch cannot
41+
// exceed this value.
42+
uint32 absoluteMaxBytes = 2;
4043
}
4144

4245
message BatchTimeout {

protos/utils/blockutils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func CopyBlockMetadata(src *cb.Block, dst *cb.Block) {
8484
InitBlockMetadata(dst)
8585
}
8686

87-
// CopyBlockMetadata copies metadata from one block into another
87+
// InitBlockMetadata copies metadata from one block into another
8888
func InitBlockMetadata(block *cb.Block) {
8989
if block.Metadata == nil {
9090
block.Metadata = &cb.BlockMetadata{Metadata: [][]byte{[]byte{}, []byte{}, []byte{}}}

0 commit comments

Comments
 (0)