server: Sort disk arguments for consistent ordering (#3469)

This is important in a distributed setup, where the server hosting the
first disk formats a fresh setup. Sorting ensures that all servers
arrive at the same 'first' server.

Note: This change doesn't protect against different disk arguments
with some disks being same across servers.
This commit is contained in:
Krishnan Parthasarathi
2016-12-20 06:34:31 +05:30
committed by Harshavardhana
parent 5404dddcea
commit 85c6bb9809
3 changed files with 140 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ import (
"net/url"
"os"
"path"
"sort"
"strings"
"runtime"
@@ -429,6 +430,12 @@ func serverMain(c *cli.Context) {
fatalIf(errInvalidArgument, "None of the disks passed as command line args are local to this server.")
}
// Sort endpoints for consistent ordering across multiple
// nodes in a distributed setup. This is to avoid format.json
// corruption if the disks aren't supplied in the same order
// on all nodes.
sort.Sort(byHostPath(endpoints))
storageDisks, err := initStorageDisks(endpoints)
fatalIf(err, "Unable to initialize storage disk(s).")