Files
my-rook-config/pkg/operator/ceph/cluster/osd/config/config.go
T
Shachar Sharon 2a3cfc693b ceph: allow setting primary-affinity to osd
A user with unbalanced system (e.g., some OSDs use a partition which
resides on a device along-side OS partition) may want to have a
fine-grained control on the overall load of specific OSD. While osd
weight affects write-load, primary-affinity affects read-load.

This patch allow user to define osd's primary-affinity (similar to
'DeviceClass' and 'InitialWeight'), which is sent to the osd (via mon)
as part of deployment sequence, using 'ceph osd primary-affinity' command.

Valid values are within the range [0.0, 1.0). If not set, default value
is 1.

ROOK issue: https://github.com/rook/rook/issues/7773

Signed-off-by: Shachar Sharon <ssharon@redhat.com>
2021-05-06 17:46:15 +03:00

110 lines
3.0 KiB
Go

/*
Copyright 2018 The Rook Authors. 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 config for OSD config managed by the operator
package config
import (
"strconv"
)
const (
WalSizeMBKey = "walSizeMB"
DatabaseSizeMBKey = "databaseSizeMB"
JournalSizeMBKey = "journalSizeMB"
OSDsPerDeviceKey = "osdsPerDevice"
EncryptedDeviceKey = "encryptedDevice"
MetadataDeviceKey = "metadataDevice"
DeviceClassKey = "deviceClass"
InitialWeightKey = "initialWeight"
PrimaryAffinityKey = "primaryAffinity"
)
// StoreConfig represents the configuration of an OSD on a device.
type StoreConfig struct {
WalSizeMB int `json:"walSizeMB,omitempty"`
DatabaseSizeMB int `json:"databaseSizeMB,omitempty"`
OSDsPerDevice int `json:"osdsPerDevice,omitempty"`
EncryptedDevice bool `json:"encryptedDevice,omitempty"`
MetadataDevice string `json:"metadataDevice,omitempty"`
DeviceClass string `json:"deviceClass,omitempty"`
InitialWeight string `json:"initialWeight,omitempty"`
PrimaryAffinity string `json:"primaryAffinity,omitempty"`
}
// NewStoreConfig returns a StoreConfig with proper defaults set.
func NewStoreConfig() StoreConfig {
return StoreConfig{
OSDsPerDevice: 1,
}
}
// ToStoreConfig converts a config string-string map to a StoreConfig.
func ToStoreConfig(config map[string]string) StoreConfig {
storeConfig := NewStoreConfig()
for k, v := range config {
switch k {
case WalSizeMBKey:
storeConfig.WalSizeMB = convertToIntIgnoreErr(v)
case DatabaseSizeMBKey:
storeConfig.DatabaseSizeMB = convertToIntIgnoreErr(v)
case OSDsPerDeviceKey:
i := convertToIntIgnoreErr(v)
if i > 0 { // only allow values 1 or more to be set
storeConfig.OSDsPerDevice = i
}
case EncryptedDeviceKey:
storeConfig.EncryptedDevice = (v == "true")
case MetadataDeviceKey:
storeConfig.MetadataDevice = v
case DeviceClassKey:
storeConfig.DeviceClass = v
case InitialWeightKey:
storeConfig.InitialWeight = v
case PrimaryAffinityKey:
storeConfig.PrimaryAffinity = v
}
}
return storeConfig
}
func MetadataDevice(config map[string]string) string {
for k, v := range config {
switch k {
case MetadataDeviceKey:
return v
}
}
return ""
}
func convertToIntIgnoreErr(raw string) int {
val, err := strconv.Atoi(raw)
if err != nil {
val = 0
}
return val
}
// ConfiguredDevice is a device with a corresponding configuration.
type ConfiguredDevice struct {
ID string `json:"id"`
StoreConfig StoreConfig `json:"storeConfig"`
}