Adding format.json during FS initialization (#1896)

master
karthic rao 9 years ago committed by Harshavardhana
parent 23c88ffb1d
commit afc3102488
  1. 31
      fs-v1-metadata.go
  2. 25
      fs-v1.go
  3. 1
      object-common.go

@ -7,7 +7,8 @@ import (
)
const (
fsMetaJSONFile = "fs.json"
fsMetaJSONFile = "fs.json"
fsFormatJSONFile = "format.json"
)
// A fsMetaV1 represents a metadata header mapping keys to sets of values.
@ -78,6 +79,34 @@ func newFSMetaV1() (fsMeta fsMetaV1) {
return fsMeta
}
// newFSFormatV1 - initializes new formatConfigV1 with FS format info.
func newFSFormatV1() (format formatConfigV1) {
return formatConfigV1{
Version: "1",
Format: "fs",
FS: &fsFormat{
Version: "1",
},
}
}
// writes FS format (format.json) into minioMetaBucket.
func writeFSFormatData(storage StorageAPI, fsFormat formatConfigV1) error {
metadataBytes, err := json.Marshal(fsFormat)
if err != nil {
return err
}
// fsFormatJSONFile - format.json file stored in minioMetaBucket(.minio) directory.
n, err := storage.AppendFile(minioMetaBucket, fsFormatJSONFile, metadataBytes)
if err != nil {
return err
}
if n != int64(len(metadataBytes)) {
return errUnexpected
}
return nil
}
// writeFSMetadata - writes `fs.json` metadata.
func (fs fsObjects) writeFSMetadata(bucket, prefix string, fsMeta fsMetaV1) error {
metadataBytes, err := json.Marshal(fsMeta)

@ -39,6 +39,16 @@ type fsObjects struct {
listObjectMapMutex *sync.Mutex
}
// creates format.json, the FS format info in minioMetaBucket.
func initFormatFS(storageDisk StorageAPI) error {
return writeFSFormatData(storageDisk, newFSFormatV1())
}
// loads format.json from minioMetaBucket if it exists.
func loadFormatFS(storageDisk StorageAPI) ([]byte, error) {
return readAll(storageDisk, minioMetaBucket, fsFormatJSONFile)
}
// newFSObjects - initialize new fs object layer.
func newFSObjects(disk string) (ObjectLayer, error) {
storage, err := newStorageAPI(disk)
@ -48,7 +58,20 @@ func newFSObjects(disk string) (ObjectLayer, error) {
// Runs house keeping code, like creating minioMetaBucket, cleaning up tmp files etc.
fsHouseKeeping(storage)
// loading format.json from minioMetaBucket.
// Note: The format.json content is ignored, reserved for future use.
_, err = loadFormatFS(storage)
if err != nil {
if err == errFileNotFound {
// format.json doesn't exist, create it inside minioMetaBucket.
err = initFormatFS(storage)
if err != nil {
return nil, err
}
} else {
return nil, err
}
}
// Return successfully initialized object layer.
return fsObjects{
storage: storage,

@ -126,6 +126,7 @@ func cleanupDir(storage StorageAPI, volume, dirPath string) error {
}
for _, entry := range entries {
err = delFunc(pathJoin(entryPath, entry))
if err != nil {
return err
}

Loading…
Cancel
Save