Assume standard storage class if not set in metadata (#5370)

If STANDARD storage class is set before starting up Minio server, 
but x-amz-storage-class metadata field is not set in a PutObject 
request, Minio server defaults to N/2 data and N/2 parity disks.

This PR changes the behaviour to use data and parity disks set in
STANDARD storage class, even if x-amz-storage-class metadata 
field is not present in PutObject requests.
This commit is contained in:
Nitish Tiwari 2018-01-11 14:58:12 +05:30 committed by GitHub
parent f413224b24
commit 1b721d76b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 5 deletions

View File

@ -182,11 +182,13 @@ func validateSSParity(ssParity, rrsParity int) (err error) {
// Returns the data and parity drive count based on storage class // Returns the data and parity drive count based on storage class
// If storage class is set using the env vars MINIO_STORAGE_CLASS_RRS and MINIO_STORAGE_CLASS_STANDARD // If storage class is set using the env vars MINIO_STORAGE_CLASS_RRS and MINIO_STORAGE_CLASS_STANDARD
// or config.json fields
// -- corresponding values are returned // -- corresponding values are returned
// If storage class is not set using environment variables, default values are returned // If storage class is not set during startup, default values are returned
// -- Default for Reduced Redundancy Storage class is, parity = 2 and data = N-Parity // -- Default for Reduced Redundancy Storage class is, parity = 2 and data = N-Parity
// -- Default for Standard Storage class is, parity = N/2, data = N/2 // -- Default for Standard Storage class is, parity = N/2, data = N/2
// If storage class is not present in metadata, default value is data = N/2, parity = N/2 // If storage class is empty
// -- standard storage class is assumed and corresponding data and parity is returned
func getRedundancyCount(sc string, totalDisks int) (data, parity int) { func getRedundancyCount(sc string, totalDisks int) (data, parity int) {
parity = totalDisks / 2 parity = totalDisks / 2
switch sc { switch sc {
@ -198,7 +200,7 @@ func getRedundancyCount(sc string, totalDisks int) (data, parity int) {
// else fall back to default value // else fall back to default value
parity = defaultRRSParity parity = defaultRRSParity
} }
case standardStorageClass: case standardStorageClass, "":
if globalStandardStorageClass.Parity != 0 { if globalStandardStorageClass.Parity != 0 {
// set the standard parity if available // set the standard parity if available
parity = globalStandardStorageClass.Parity parity = globalStandardStorageClass.Parity

View File

@ -173,6 +173,7 @@ func testGetRedundancyCount(obj ObjectLayer, instanceType string, dirs []string,
{3, "", xl.storageDisks, 8, 8}, {3, "", xl.storageDisks, 8, 8},
{4, reducedRedundancyStorageClass, xl.storageDisks, 9, 7}, {4, reducedRedundancyStorageClass, xl.storageDisks, 9, 7},
{5, standardStorageClass, xl.storageDisks, 10, 6}, {5, standardStorageClass, xl.storageDisks, 10, 6},
{6, "", xl.storageDisks, 9, 7},
} }
for _, tt := range tests { for _, tt := range tests {
// Set env var for test case 4 // Set env var for test case 4
@ -183,6 +184,10 @@ func testGetRedundancyCount(obj ObjectLayer, instanceType string, dirs []string,
if tt.name == 5 { if tt.name == 5 {
globalStandardStorageClass.Parity = 6 globalStandardStorageClass.Parity = 6
} }
// Set env var for test case 6
if tt.name == 6 {
globalStandardStorageClass.Parity = 7
}
data, parity := getRedundancyCount(tt.sc, len(tt.disks)) data, parity := getRedundancyCount(tt.sc, len(tt.disks))
if data != tt.expectedData { if data != tt.expectedData {
t.Errorf("Test %d, Expected data disks %d, got %d", tt.name, tt.expectedData, data) t.Errorf("Test %d, Expected data disks %d, got %d", tt.name, tt.expectedData, data)

View File

@ -112,6 +112,8 @@ func TestXLDeleteObjectBasic(t *testing.T) {
} }
func TestXLDeleteObjectDiskNotFound(t *testing.T) { func TestXLDeleteObjectDiskNotFound(t *testing.T) {
// Reset global storage class flags
resetGlobalStorageEnvs()
// Create an instance of xl backend. // Create an instance of xl backend.
obj, fsDirs, err := prepareXL16() obj, fsDirs, err := prepareXL16()
if err != nil { if err != nil {

View File

@ -20,7 +20,7 @@ Parity blocks can not be higher than data blocks, so `STANDARD` storage class pa
Default value for `STANDARD` storage class is `N/2` (N is the total number of drives). Default value for `STANDARD` storage class is `N/2` (N is the total number of drives).
### Reduced redundancy storage class (REDUCED_REDUNDANCY) ### Values for reduced redundancy storage class (REDUCED_REDUNDANCY)
`REDUCED_REDUNDANCY` implies lesser parity than `STANDARD` class. So,`REDUCED_REDUNDANCY` parity disks should be `REDUCED_REDUNDANCY` implies lesser parity than `STANDARD` class. So,`REDUCED_REDUNDANCY` parity disks should be
@ -47,7 +47,15 @@ export MINIO_STORAGE_CLASS_STANDARD=EC:3
export MINIO_STORAGE_CLASS_RRS=EC:2 export MINIO_STORAGE_CLASS_RRS=EC:2
``` ```
If storage class is not defined before starting Minio server, and subsequent PutObject metadata field has `x-amz-storage-class` present Storage class can also be set via `config.json` file. Refer [storage class](https://github.com/minio/minio/tree/master/docs/config#storage-class) for
more details.
*Note*
- If `STANDARD` storage class is set via environment variables or `config.json` files, and `x-amz-storage-class` is not present in request metadata, Minio server will
apply `STANDARD` storage class to the object. This means the data and parity disks will be used as set in `STANDARD` storage class.
- If storage class is not defined before starting Minio server, and subsequent PutObject metadata field has `x-amz-storage-class` present
with values `REDUCED_REDUNDANCY` or `STANDARD`, Minio server uses default parity values. with values `REDUCED_REDUNDANCY` or `STANDARD`, Minio server uses default parity values.
### Set metadata ### Set metadata