Define ETCD Transaction limit (#3094)
Signed-off-by: Bernd Verst <github@bernd.dev>
This commit is contained in:
parent
824ccebe87
commit
fe2b4aa1fb
|
@ -43,6 +43,7 @@ type Etcd struct {
|
||||||
features []state.Feature
|
features []state.Feature
|
||||||
logger logger.Logger
|
logger logger.Logger
|
||||||
schema schemaMarshaller
|
schema schemaMarshaller
|
||||||
|
maxTxnOps int
|
||||||
}
|
}
|
||||||
|
|
||||||
type etcdConfig struct {
|
type etcdConfig struct {
|
||||||
|
@ -53,6 +54,8 @@ type etcdConfig struct {
|
||||||
CA string `json:"ca"`
|
CA string `json:"ca"`
|
||||||
Cert string `json:"cert"`
|
Cert string `json:"cert"`
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
|
// Transaction server options
|
||||||
|
MaxTxnOps int `mapstructure:"maxTxnOps"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEtcdStateStoreV1 returns a new etcd state store for schema V1.
|
// NewEtcdStateStoreV1 returns a new etcd state store for schema V1.
|
||||||
|
@ -93,6 +96,7 @@ func (e *Etcd) Init(_ context.Context, metadata state.Metadata) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
e.keyPrefixPath = etcdConfig.KeyPrefixPath
|
e.keyPrefixPath = etcdConfig.KeyPrefixPath
|
||||||
|
e.maxTxnOps = etcdConfig.MaxTxnOps
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -134,7 +138,10 @@ func (e *Etcd) Features() []state.Feature {
|
||||||
}
|
}
|
||||||
|
|
||||||
func metadataToConfig(connInfo map[string]string) (*etcdConfig, error) {
|
func metadataToConfig(connInfo map[string]string) (*etcdConfig, error) {
|
||||||
m := &etcdConfig{}
|
m := &etcdConfig{
|
||||||
|
// This is the default value for maximum ops per transaction, configurtable via etcd server flag --max-txn-ops.
|
||||||
|
MaxTxnOps: 128,
|
||||||
|
}
|
||||||
err := metadata.DecodeMetadata(connInfo, m)
|
err := metadata.DecodeMetadata(connInfo, m)
|
||||||
return m, err
|
return m, err
|
||||||
}
|
}
|
||||||
|
@ -323,6 +330,13 @@ func (e *Etcd) Ping() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MultiMaxSize returns the maximum number of operations allowed in a transaction.
|
||||||
|
// For Etcd the default is 128, but this can be configured via the server flag --max-txn-ops.
|
||||||
|
// As such we are using the component metadata value maxTxnOps.
|
||||||
|
func (e *Etcd) MultiMaxSize() int {
|
||||||
|
return e.maxTxnOps
|
||||||
|
}
|
||||||
|
|
||||||
// Multi performs a transactional operation. succeeds only if all operations succeed, and fails if one or more operations fail.
|
// Multi performs a transactional operation. succeeds only if all operations succeed, and fails if one or more operations fail.
|
||||||
func (e *Etcd) Multi(ctx context.Context, request *state.TransactionalStateRequest) error {
|
func (e *Etcd) Multi(ctx context.Context, request *state.TransactionalStateRequest) error {
|
||||||
if len(request.Operations) == 0 {
|
if len(request.Operations) == 0 {
|
||||||
|
|
Loading…
Reference in New Issue