-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store object data natively and metadata in xattr (#683)
The latter remains a JSON-encoded blob but is now stored in file extended attributes, except on Windows where it is a separate file. This reduces memory usage and is much faster by avoiding JSON-encoding large objects. This enables a future commit to avoid reading the entire object, particularly for range requests. Note that this commit changes the on-disk format and is not compatible with previous data sets. Extended attributes have some caveats including lack of tmpfs and Windows support. References pkg/xattr#47. References #669. Fixes #671.
- Loading branch information
Showing
7 changed files
with
119 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2017 Francisco Souza. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build !windows | ||
// +build !windows | ||
|
||
package backend | ||
|
||
import ( | ||
"github.com/pkg/xattr" | ||
) | ||
|
||
const xattrKey = "user.metadata" | ||
|
||
func writeXattr(path string, encoded []byte) error { | ||
return xattr.Set(path, xattrKey, encoded) | ||
} | ||
|
||
func readXattr(path string) ([]byte, error) { | ||
return xattr.Get(path, xattrKey) | ||
} | ||
|
||
func isXattrFile(path string) bool { | ||
return false | ||
} | ||
|
||
func removeXattrFile(path string) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2017 Francisco Souza. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// TODO: this package works around missing Windows support in xattr: | ||
// https://github.com/pkg/xattr/issues/47 | ||
|
||
package backend | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
) | ||
|
||
const xattrKey = ".metadata" | ||
|
||
func writeXattr(path string, encoded []byte) error { | ||
return ioutil.WriteFile(path+xattrKey, encoded, 0o600) | ||
} | ||
|
||
func readXattr(path string) ([]byte, error) { | ||
return ioutil.ReadFile(path + xattrKey) | ||
} | ||
|
||
func isXattrFile(path string) bool { | ||
return strings.HasSuffix(path, xattrKey) | ||
} | ||
|
||
func removeXattrFile(path string) error { | ||
return os.Remove(path + xattrKey) | ||
} |