Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02cbc808ff | ||
|
|
9ca0ed5072 | ||
|
|
afa3729b69 | ||
|
|
6785ca843c | ||
|
|
54f5c350c2 |
No files matched your search
@@ -0,0 +1,5 @@
|
||||
Enhancement: Add the upload consistency cli
|
||||
|
||||
Added the cli command checks the consistency of upload sessions and their corresponding target nodes in the decomposedfs.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12039
|
||||
@@ -175,7 +175,7 @@ See also [example server setup]({{< ref "preparing_server" >}})
|
||||
# Minio domain. Defaults to "minio.owncloud.test".
|
||||
MINIO_DOMAIN=
|
||||
|
||||
# Define SMPT settings if you would like to send Infinite Scale email notifications.
|
||||
# Define SMTP settings if you would like to send Infinite Scale email notifications.
|
||||
# For more details see:
|
||||
# https://doc.owncloud.com/ocis/latest/deployment/services/s-list/notifications.html
|
||||
# NOTE: when configuring mail server, these settings have no effect, see mailserver.yml for details.
|
||||
|
||||
@@ -55,7 +55,9 @@ ocis storage-users uploads <command>
|
||||
|
||||
```plaintext
|
||||
COMMANDS:
|
||||
sessions Print a list of upload sessions
|
||||
sessions Print a list of upload sessions
|
||||
delete-stale-nodes Delete (or revert) all nodes in processing state that are not referenced by any upload session
|
||||
consistency Check consistency of uploads
|
||||
```
|
||||
|
||||
#### Sessions command
|
||||
@@ -140,7 +142,6 @@ ocis storage-users uploads sessions --expired=true --clean
|
||||
ocis storage-users uploads sessions --processing=true --has-virus=false --resume
|
||||
```
|
||||
|
||||
|
||||
#### Delete Stale Nodes command
|
||||
|
||||
This command allows to remove (or revert) nodes that are stale, meaning they are in postprocessing but their upload session is gone.
|
||||
@@ -184,6 +185,55 @@ ocis storage-users uploads delete-stale-nodes --dry-run=false --verbose
|
||||
```
|
||||
|
||||
|
||||
#### Consistency command
|
||||
|
||||
This command checks the consistency of upload sessions and their corresponding target nodes in the decomposedfs. It will:
|
||||
|
||||
- **List upload sessions** (optionally filtered by ID).
|
||||
- **Verify the target node hierarchy** for each session.
|
||||
- **Detect missing parent nodes** and **missing parent node metadata files**.
|
||||
- **Detect parents that were moved to the trash**.
|
||||
|
||||
```bash
|
||||
ocis storage-users uploads consistency [command options]
|
||||
```
|
||||
|
||||
```
|
||||
NAME:
|
||||
ocis storage-users uploads consistency - Check consistency of uploads.
|
||||
|
||||
USAGE:
|
||||
ocis storage-users uploads consistency [command options]
|
||||
|
||||
OPTIONS:
|
||||
--id value filter sessions by upload session ID (default: unset)
|
||||
--verbose Enable verbose logging (default: false)
|
||||
--help, -h show help
|
||||
```
|
||||
|
||||
The command prints a summary of the number of upload sessions being checked, and then reports any issues found in the node hierarchy for each session. In verbose mode, it also prints the traversal of parent nodes.
|
||||
|
||||
**Command Examples**
|
||||
|
||||
Check all upload sessions for consistency issues:
|
||||
|
||||
```bash
|
||||
ocis storage-users uploads consistency
|
||||
```
|
||||
|
||||
Check a specific upload session by ID:
|
||||
|
||||
```bash
|
||||
ocis storage-users uploads consistency --id <upload-id>
|
||||
```
|
||||
|
||||
Enable verbose logging to see node traversal details:
|
||||
|
||||
```bash
|
||||
ocis storage-users uploads consistency --verbose
|
||||
```
|
||||
|
||||
|
||||
### Manage Spaces
|
||||
|
||||
This command set provides commands to manage spaces, including purging disabled spaces that exceed the retention period.
|
||||
|
||||
@@ -63,6 +63,7 @@ func Uploads(cfg *config.Config) *cli.Command {
|
||||
Subcommands: []*cli.Command{
|
||||
ListUploadSessions(cfg),
|
||||
DeleteStaleProcessingNodes(cfg),
|
||||
Consistency(cfg),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||
"github.com/owncloud/ocis/v2/services/storage-users/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/storage-users/pkg/config/parser"
|
||||
"github.com/owncloud/ocis/v2/services/storage-users/pkg/revaconfig"
|
||||
"github.com/owncloud/reva/v2/pkg/storage"
|
||||
"github.com/owncloud/reva/v2/pkg/storage/fs/registry"
|
||||
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/lookup"
|
||||
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/metadata"
|
||||
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/metadata/prefixes"
|
||||
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/node"
|
||||
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/options"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Consistency is the entry point for the consistency command
|
||||
func Consistency(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "consistency",
|
||||
Usage: "Check consistency of uploads.",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "id",
|
||||
DefaultText: "unset",
|
||||
Usage: "Filter sessions by upload session ID",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "verbose",
|
||||
Usage: "Enable verbose logging",
|
||||
Value: false,
|
||||
},
|
||||
},
|
||||
Before: func(c *cli.Context) error {
|
||||
return configlog.ReturnFatal(parser.ParseConfig(cfg))
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
f, ok := registry.NewFuncs[cfg.Driver]
|
||||
if !ok {
|
||||
fmt.Fprintf(os.Stderr, "Unknown filesystem driver '%s'\n", cfg.Driver)
|
||||
os.Exit(1)
|
||||
}
|
||||
drivers := revaconfig.StorageProviderDrivers(cfg)
|
||||
fs, err := f(drivers[cfg.Driver].(map[string]interface{}), nil, nil)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to initialize filesystem driver '%s'\n", cfg.Driver)
|
||||
return err
|
||||
}
|
||||
|
||||
managingFS, ok := fs.(storage.UploadSessionLister)
|
||||
if !ok {
|
||||
fmt.Fprintf(os.Stderr, "'%s' storage does not support listing upload sessions\n", cfg.Driver)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
filter := buildFilter(c)
|
||||
uploads, err := managingFS.ListUploadSessions(c.Context, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// We need a lookup to read nodes, but we don't have easy access to the one created inside the driver.
|
||||
// We will recreate a minimal one for read-only access.
|
||||
// This assumes the driver is decomposedfs, which is the only one we really care about for this error.
|
||||
if cfg.Driver != "ocis" { // "ocis" is the driver name for decomposedfs in ocis config
|
||||
fmt.Printf("Warning: driver is '%s', consistency check is optimized for 'ocis' (decomposedfs).\n", cfg.Driver)
|
||||
}
|
||||
|
||||
// Initialize a minimal lookup
|
||||
opts, err := options.New(drivers[cfg.Driver].(map[string]interface{}))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var backend metadata.Backend
|
||||
switch opts.MetadataBackend {
|
||||
case "xattrs":
|
||||
backend = metadata.NewXattrsBackend(opts.Root, opts.FileMetadataCache)
|
||||
case "messagepack":
|
||||
backend = metadata.NewMessagePackBackend(opts.Root, opts.FileMetadataCache)
|
||||
default:
|
||||
return fmt.Errorf("unknown metadata backend %s", opts.MetadataBackend)
|
||||
}
|
||||
lu := lookup.New(backend, opts, nil)
|
||||
|
||||
verbose := c.Bool("verbose")
|
||||
|
||||
fmt.Printf("Checking consistency for %d upload sessions...\n", len(uploads))
|
||||
|
||||
for _, u := range uploads {
|
||||
ref := u.Reference()
|
||||
spaceID := ref.GetResourceId().GetSpaceId()
|
||||
nodeID := ref.GetResourceId().GetOpaqueId()
|
||||
if verbose {
|
||||
fmt.Printf("Checking upload %s (NodeID: %s, SpaceID: %s)\n", u.ID(), nodeID, spaceID)
|
||||
}
|
||||
if nodeID == "" {
|
||||
fmt.Printf("Error: nodeID is epmpty in upload %s\n", u.ID())
|
||||
continue
|
||||
}
|
||||
if spaceID == "" {
|
||||
fmt.Printf("Error: spaceID is epmpty in upload %s\n", u.ID())
|
||||
continue
|
||||
}
|
||||
|
||||
err := checkNodeConsistency(c.Context, lu, spaceID, nodeID, verbose)
|
||||
if err != nil {
|
||||
fmt.Printf("Issue found in upload %s: %v\n", u.ID(), err)
|
||||
} else if verbose {
|
||||
fmt.Printf("Upload %s seems consistent.\n", u.ID())
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func checkNodeConsistency(ctx context.Context, lu *lookup.Lookup, spaceID, nodeID string, verbose bool) error {
|
||||
checkMetadataMsg := "check the node metadata"
|
||||
|
||||
nodePath := lu.InternalPath(spaceID, nodeID)
|
||||
// Check if node exists
|
||||
_, err := os.Stat(nodePath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return fmt.Errorf("Error: node %s does not exist on disk", nodeID)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err = os.Open(lu.MetadataBackend().MetadataPath(nodePath)); err != nil {
|
||||
return fmt.Errorf("Error: failed to read metafile for node %s. %s: %s", nodeID, checkMetadataMsg, lu.MetadataBackend().MetadataPath(nodePath))
|
||||
}
|
||||
|
||||
attrs, err := lu.MetadataBackend().All(ctx, nodePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error: failed to read attributes for node %s: %w. %s", nodeID, err, checkMetadataMsg)
|
||||
}
|
||||
|
||||
if len(attrs) == 0 {
|
||||
return fmt.Errorf("Error: node %s has no attributes. %s", nodeID, checkMetadataMsg)
|
||||
}
|
||||
|
||||
parentID := string(attrs[prefixes.ParentidAttr])
|
||||
|
||||
if verbose {
|
||||
name := string(attrs[prefixes.NameAttr])
|
||||
fmt.Printf("node %s (%s) has parent %s\n", nodeID, name, parentID)
|
||||
}
|
||||
|
||||
if parentID == "" {
|
||||
if nodeID == spaceID {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Error: node %s has no %s attribute. %s", nodeID, prefixes.ParentidAttr, checkMetadataMsg)
|
||||
}
|
||||
|
||||
if parentID == node.RootID {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Traverse upwards
|
||||
currentID := parentID
|
||||
for {
|
||||
if currentID == spaceID || currentID == node.RootID {
|
||||
break
|
||||
}
|
||||
|
||||
parentPath := lu.InternalPath(spaceID, currentID)
|
||||
_, err := os.Stat(parentPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
// Parent is missing. Check trash bin.
|
||||
matches, globErr := filepath.Glob(parentPath + node.TrashIDDelimiter + "*")
|
||||
if globErr == nil && len(matches) > 0 {
|
||||
return fmt.Errorf("Info: node parent %s is in trash bin (found %d trashed versions, e.g. %s)", currentID, len(matches), filepath.Base(matches[0]))
|
||||
}
|
||||
|
||||
return fmt.Errorf("Info: node parent %s is missing from disk", currentID)
|
||||
}
|
||||
return fmt.Errorf("Info: failed to stat parent %s: %w", currentID, err)
|
||||
}
|
||||
|
||||
// Read parent's parent
|
||||
if _, err = os.Open(lu.MetadataBackend().MetadataPath(parentPath)); err != nil {
|
||||
return fmt.Errorf("Error: failed to read metafile for node %s. %s: %s", parentID, checkMetadataMsg, lu.MetadataBackend().MetadataPath(parentPath))
|
||||
}
|
||||
|
||||
pAttrs, pErr := lu.MetadataBackend().All(ctx, parentPath)
|
||||
if pErr != nil {
|
||||
return fmt.Errorf("Error: failed to read attributes for parent %s: %w. %s", parentID, pErr, checkMetadataMsg)
|
||||
}
|
||||
|
||||
if len(pAttrs) == 0 {
|
||||
return fmt.Errorf("Error: parent node %s has no attributes. %s", parentID, checkMetadataMsg)
|
||||
}
|
||||
|
||||
nextParentID := string(pAttrs[prefixes.ParentidAttr])
|
||||
if verbose {
|
||||
pName := string(pAttrs[prefixes.NameAttr])
|
||||
fmt.Printf("parent %s (%s) has parent %s\n", parentID, pName, nextParentID)
|
||||
}
|
||||
|
||||
if nextParentID == "" {
|
||||
return fmt.Errorf("Error: node parent %s has no parentID. %s", parentID, checkMetadataMsg)
|
||||
}
|
||||
currentID = nextParentID
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user