allow support for parity '0', '1' enabling support for 2,3 drive setups (#15171)

allows for further granular setups

- 2 drives (1 parity, 1 data)
- 3 drives (1 parity, 2 data)

Bonus: allows '0' parity as well.
This commit is contained in:
Harshavardhana
2022-06-27 20:22:18 -07:00
committed by GitHub
parent b7c7e59dac
commit 9c605ad153
17 changed files with 82 additions and 76 deletions

View File

@@ -58,7 +58,7 @@ var (
ErrInvalidErasureSetSize = newErrFn(
"Invalid erasure set size",
"Please check the passed value",
"Erasure set can only accept any of [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] values",
"Erasure set can only accept any of [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] values",
)
ErrInvalidWormValue = newErrFn(
@@ -177,7 +177,7 @@ var (
ErrInvalidNumberOfErasureEndpoints = newErrFn(
"Invalid total number of endpoints for erasure mode",
"Please provide an even number of endpoints greater or equal to 4",
"Please provide number of endpoints greater or equal to 2",
"For more information, please refer to https://docs.min.io/docs/minio-erasure-code-quickstart-guide",
)

View File

@@ -50,10 +50,10 @@ const (
schemePrefix = "EC"
// Min parity disks
minParityDisks = 2
minParityDisks = 0
// Default RRS parity is always minimum parity.
defaultRRSParity = minParityDisks
defaultRRSParity = 1
)
// DefaultKVS - default storage class config
@@ -65,7 +65,7 @@ var (
},
config.KV{
Key: ClassRRS,
Value: "EC:2",
Value: "EC:1",
},
}
)
@@ -76,7 +76,7 @@ type StorageClass struct {
}
// ConfigLock is a global lock for storage-class config
var ConfigLock = sync.RWMutex{}
var ConfigLock sync.RWMutex
// Config storage class configuration
type Config struct {
@@ -154,7 +154,9 @@ func parseStorageClass(storageClassEnv string) (sc StorageClass, err error) {
if err != nil {
return StorageClass{}, config.ErrStorageClassValue(err)
}
if parityDisks < 0 {
return StorageClass{}, config.ErrStorageClassValue(nil).Msg("Unsupported parity value " + s[1] + " provided")
}
return StorageClass{
Parity: parityDisks,
}, nil
@@ -196,7 +198,7 @@ func validateParity(ssParity, rrsParity, setDriveCount int) (err error) {
}
if rrsParity > setDriveCount/2 {
return fmt.Errorf("Reduced redundancy storage class parity %d should be less than or equal to %d", rrsParity, setDriveCount/2)
return fmt.Errorf("Reduced redundancy storage class parity %d should be less than or equal to %d", rrsParity, setDriveCount/2)
}
if ssParity > 0 && rrsParity > 0 {
@@ -223,10 +225,6 @@ func (sCfg Config) GetParityForSC(sc string) (parity int) {
defer ConfigLock.RUnlock()
switch strings.TrimSpace(sc) {
case RRS:
// set the rrs parity if available
if sCfg.RRS.Parity == 0 {
return defaultRRSParity
}
return sCfg.RRS.Parity
default:
return sCfg.Standard.Parity
@@ -248,6 +246,22 @@ func Enabled(kvs config.KVS) bool {
return ssc != "" || rrsc != ""
}
// DefaultParityBlocks returns default parity blocks for 'drive' count
func DefaultParityBlocks(drive int) int {
switch drive {
case 1:
return 0
case 3, 2:
return 1
case 4, 5:
return 2
case 6, 7:
return 3
default:
return 4
}
}
// LookupConfig - lookup storage class config and override with valid environment settings if any.
func LookupConfig(kvs config.KVS, setDriveCount int) (cfg Config, err error) {
cfg = Config{}
@@ -274,10 +288,15 @@ func LookupConfig(kvs config.KVS, setDriveCount int) (cfg Config, err error) {
return Config{}, err
}
}
if cfg.RRS.Parity == 0 {
if cfg.RRS.Parity == 0 && rrsc == "" {
cfg.RRS.Parity = defaultRRSParity
}
if cfg.Standard.Parity == 0 && ssc == "" {
cfg.Standard.Parity = DefaultParityBlocks(setDriveCount)
}
// Validation is done after parsing both the storage classes. This is needed because we need one
// storage class value to deduce the correct value of the other storage class.
if err = validateParity(cfg.Standard.Parity, cfg.RRS.Parity, setDriveCount); err != nil {

View File

@@ -102,7 +102,8 @@ func TestValidateParity(t *testing.T) {
{2, 4, true, 16},
{3, 3, true, 16},
{0, 0, true, 16},
{1, 4, false, 16},
{1, 4, true, 16},
{0, 4, true, 16},
{7, 6, false, 16},
{9, 0, false, 16},
{9, 9, false, 16},
@@ -140,7 +141,7 @@ func TestParityCount(t *testing.T) {
Parity: 8,
},
RRS: StorageClass{
Parity: 0,
Parity: 2,
},
}
// Set env var for test case 4