-
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.
Introduce orderer sharedconfig mechanism
The configtx.Manager supports maintaining configuration updates based on configuration transactions, but today, the only interpretation of these configuration updates is the policies.Manager which handles configuration updates of type Policy. There are other types of configuration, such as Orderer type configuration which are currently ignored. This changeset adds an orderer shared config manager. It is called sharedconfig to make it explicit that this configuration is common to and available to all orderers. This is different from the notion of localconfig which could include things like machine dependent paths and buffer sizes. This changeset also establishes a convention for encoding orderer configuration by creating a proto message with name equal to the Key field which is set in the orderer config. This changeset hooks the shared config into the XXX points of the multichain ChainSupport. In the future, the batchSize and consensusType will be removed from the localconfig once the other consensus plugins have been migrated to the new shared multichain infrastructure. Change-Id: Ia68f5a83bf816317609b7df4c9ad0d1bed1bb800 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
- Loading branch information
Jason Yellick
committed
Dec 2, 2016
1 parent
8e97791
commit e6d3b99
Showing
9 changed files
with
482 additions
and
20 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,141 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package sharedconfig | ||
|
||
import ( | ||
"fmt" | ||
|
||
cb "github.com/hyperledger/fabric/protos/common" | ||
ab "github.com/hyperledger/fabric/protos/orderer" | ||
|
||
"github.com/golang/protobuf/proto" | ||
"github.com/op/go-logging" | ||
) | ||
|
||
// ConsensusTypeKey is the cb.ConfigurationItem type key name for the ConsensusType message | ||
const ConsensusTypeKey = "ConsensusType" | ||
|
||
// BatchSizeKey is the cb.ConfigurationItem type key name for the BatchSize message | ||
const BatchSizeKey = "BatchSize" | ||
|
||
var logger = logging.MustGetLogger("orderer/common/sharedconfig") | ||
|
||
func init() { | ||
logging.SetLevel(logging.DEBUG, "") | ||
} | ||
|
||
// Manager stores the common shared orderer configuration | ||
// It is intended to be the primary accessor of ManagerImpl | ||
// It is intended to discourage use of the other exported ManagerImpl methods | ||
// which are used for updating the orderer configuration by the ConfigManager | ||
type Manager interface { | ||
// ConsensusType returns the configured consensus type | ||
ConsensusType() string | ||
|
||
// BatchSize returns the maximum number of messages to include in a block | ||
BatchSize() int | ||
} | ||
|
||
type ordererConfig struct { | ||
consensusType string | ||
batchSize int | ||
} | ||
|
||
// ManagerImpl is an implementation of Manager and configtx.ConfigHandler | ||
// In general, it should only be referenced as an Impl for the configtx.ConfigManager | ||
type ManagerImpl struct { | ||
pendingConfig *ordererConfig | ||
config *ordererConfig | ||
} | ||
|
||
// NewManagerImpl creates a new ManagerImpl with the given CryptoHelper | ||
func NewManagerImpl() *ManagerImpl { | ||
return &ManagerImpl{ | ||
config: &ordererConfig{}, | ||
} | ||
} | ||
|
||
// ConsensusType returns the configured consensus type | ||
func (pm *ManagerImpl) ConsensusType() string { | ||
return pm.config.consensusType | ||
} | ||
|
||
// BatchSize returns the maximum number of messages to include in a block | ||
func (pm *ManagerImpl) BatchSize() int { | ||
return pm.config.batchSize | ||
} | ||
|
||
// BeginConfig is used to start a new configuration proposal | ||
func (pm *ManagerImpl) BeginConfig() { | ||
if pm.pendingConfig != nil { | ||
logger.Fatalf("Programming error, cannot call begin in the middle of a proposal") | ||
} | ||
pm.pendingConfig = &ordererConfig{} | ||
} | ||
|
||
// RollbackConfig is used to abandon a new configuration proposal | ||
func (pm *ManagerImpl) RollbackConfig() { | ||
pm.pendingConfig = nil | ||
} | ||
|
||
// CommitConfig is used to commit a new configuration proposal | ||
func (pm *ManagerImpl) CommitConfig() { | ||
if pm.pendingConfig == nil { | ||
logger.Fatalf("Programming error, cannot call commit without an existing proposal") | ||
} | ||
pm.config = pm.pendingConfig | ||
pm.pendingConfig = nil | ||
} | ||
|
||
// ProposeConfig is used to add new configuration to the configuration proposal | ||
func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error { | ||
if configItem.Type != cb.ConfigurationItem_Orderer { | ||
return fmt.Errorf("Expected type of ConfigurationItem_Orderer, got %v", configItem.Type) | ||
} | ||
|
||
switch configItem.Key { | ||
case ConsensusTypeKey: | ||
consensusType := &ab.ConsensusType{} | ||
err := proto.Unmarshal(configItem.Value, consensusType) | ||
if err != nil { | ||
return fmt.Errorf("Unmarshaling error for ConsensusType: %s", err) | ||
} | ||
if pm.config.consensusType == "" { | ||
// The first configuration we accept the consensus type regardless | ||
pm.config.consensusType = consensusType.Type | ||
} | ||
if consensusType.Type != pm.config.consensusType { | ||
return fmt.Errorf("Attempted to change the consensus type from %s to %s after init", pm.config.consensusType, consensusType.Type) | ||
} | ||
|
||
pm.pendingConfig.consensusType = consensusType.Type | ||
case BatchSizeKey: | ||
batchSize := &ab.BatchSize{} | ||
err := proto.Unmarshal(configItem.Value, batchSize) | ||
if err != nil { | ||
return fmt.Errorf("Unmarshaling error for BatchSize: %s", err) | ||
} | ||
|
||
if batchSize.Messages <= 0 { | ||
return fmt.Errorf("Attempted to set the batch size to %d which is less than or equal to 0", batchSize.Messages) | ||
} | ||
|
||
pm.pendingConfig.batchSize = int(batchSize.Messages) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.