Skip to content

Commit 39f20f1

Browse files
authored
Merge pull request #11704 from kobergj/FixStaleNodesCommand
[full-ci][OCISDEV-355] Fix delete stale nodes command
2 parents eb469d8 + 5efa32a commit 39f20f1

File tree

19 files changed

+228
-87
lines changed

19 files changed

+228
-87
lines changed

changelog/unreleased/bump-reva.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ bumped reva version
44

55
https://github.com/owncloud/ocis/pull/11669
66
https://github.com/owncloud/ocis/pull/11693
7+
https://github.com/owncloud/ocis/pull/11704
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bugfix: Fix stale nodes command
2+
3+
Fix delete-stale-nodes command to properly remove or roll-back nodes
4+
5+
https://github.com/owncloud/ocis/pull/11704

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ require (
5858
github.com/mna/pigeon v1.3.0
5959
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
6060
github.com/nats-io/nats-server/v2 v2.12.0
61-
github.com/nats-io/nats.go v1.45.0
61+
github.com/nats-io/nats.go v1.46.0
6262
github.com/olekukonko/tablewriter v1.1.0
6363
github.com/onsi/ginkgo v1.16.5
6464
github.com/onsi/ginkgo/v2 v2.25.3
6565
github.com/onsi/gomega v1.38.2
6666
github.com/open-policy-agent/opa v1.6.0
6767
github.com/orcaman/concurrent-map v1.0.0
6868
github.com/owncloud/libre-graph-api-go v1.0.5-0.20250217093259-fa3804be6c27
69-
github.com/owncloud/reva/v2 v2.0.0-20250925134851-02c7681fe2b3
69+
github.com/owncloud/reva/v2 v2.0.0-20251001134122-cb98fe521deb
7070
github.com/pkg/errors v0.9.1
7171
github.com/pkg/xattr v0.4.12
7272
github.com/prometheus/client_golang v1.23.2

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,8 @@ github.com/nats-io/jwt/v2 v2.8.0 h1:K7uzyz50+yGZDO5o772eRE7atlcSEENpL7P+b74JV1g=
666666
github.com/nats-io/jwt/v2 v2.8.0/go.mod h1:me11pOkwObtcBNR8AiMrUbtVOUGkqYjMQZ6jnSdVUIA=
667667
github.com/nats-io/nats-server/v2 v2.12.0 h1:OIwe8jZUqJFrh+hhiyKu8snNib66qsx806OslqJuo74=
668668
github.com/nats-io/nats-server/v2 v2.12.0/go.mod h1:nr8dhzqkP5E/lDwmn+A2CvQPMd1yDKXQI7iGg3lAvww=
669-
github.com/nats-io/nats.go v1.45.0 h1:/wGPbnYXDM0pLKFjZTX+2JOw9TQPoIgTFrUaH97giwA=
670-
github.com/nats-io/nats.go v1.45.0/go.mod h1:iRWIPokVIFbVijxuMQq4y9ttaBTMe0SFdlZfMDd+33g=
669+
github.com/nats-io/nats.go v1.46.0 h1:iUcX+MLT0HHXskGkz+Sg20sXrPtJLsOojMDTDzOHSb8=
670+
github.com/nats-io/nats.go v1.46.0/go.mod h1:iRWIPokVIFbVijxuMQq4y9ttaBTMe0SFdlZfMDd+33g=
671671
github.com/nats-io/nkeys v0.4.11 h1:q44qGV008kYd9W1b1nEBkNzvnWxtRSQ7A8BoqRrcfa0=
672672
github.com/nats-io/nkeys v0.4.11/go.mod h1:szDimtgmfOi9n25JpfIdGw12tZFYXqhGxjhVxsatHVE=
673673
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
@@ -703,8 +703,8 @@ github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HD
703703
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
704704
github.com/owncloud/libre-graph-api-go v1.0.5-0.20250217093259-fa3804be6c27 h1:ID8s5lGBntmrlI6TbDAjTzRyHucn3bVM2wlW+HBplv4=
705705
github.com/owncloud/libre-graph-api-go v1.0.5-0.20250217093259-fa3804be6c27/go.mod h1:+gT+x62AS9u2Farh9wE2uYmgdvTg0MQgsSI62D+xoRg=
706-
github.com/owncloud/reva/v2 v2.0.0-20250925134851-02c7681fe2b3 h1:VL/YicK+o8a2u9IbFM5GlH540C04A0L6Ao3pCgctCXw=
707-
github.com/owncloud/reva/v2 v2.0.0-20250925134851-02c7681fe2b3/go.mod h1:Re3ZSyWo8fgH6hJ3zgLSgZG/jqeo+O8JX3c+AUzKJro=
706+
github.com/owncloud/reva/v2 v2.0.0-20251001134122-cb98fe521deb h1:wIu3AM0Khs+cw3BJjXnPz7tjJyZ3DbMsX2pwWafvyRI=
707+
github.com/owncloud/reva/v2 v2.0.0-20251001134122-cb98fe521deb/go.mod h1:JwGg9zW2BmgMdcjKRwzqyoWtSVhFTMlVa4z6UToQgAA=
708708
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
709709
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
710710
github.com/pablodz/inotifywaitgo v0.0.9 h1:njquRbBU7fuwIe5rEvtaniVBjwWzcpdUVptSgzFqZsw=

services/storage-users/pkg/command/uploads.go

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"io/fs"
8+
"log"
89
"os"
910
"path/filepath"
1011
"strconv"
@@ -16,6 +17,7 @@ import (
1617
"github.com/urfave/cli/v2"
1718

1819
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
20+
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
1921
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
2022
"github.com/owncloud/ocis/v2/services/storage-users/pkg/config"
2123
"github.com/owncloud/ocis/v2/services/storage-users/pkg/config/parser"
@@ -376,9 +378,18 @@ func DeleteStaleProcessingNodes(cfg *config.Config) *cli.Command {
376378
}
377379
}
378380

381+
var stream events.Stream
382+
if !dryRun {
383+
s, err := event.NewStream(cfg)
384+
if err != nil {
385+
log.Fatalf("Failed to create event stream: %v", err)
386+
}
387+
stream = s
388+
}
389+
379390
staleCount := 0
380391
for _, spaceID := range spaceIDs {
381-
staleCount += deleteStaleUploads(cfg, spaceID, dryRun, verbose)
392+
staleCount += deleteStaleUploads(cfg, spaceID, dryRun, verbose, stream)
382393
}
383394

384395
if verbose {
@@ -410,7 +421,7 @@ func globSpaceIDs(cfg *config.Config) []string {
410421
}
411422

412423
// delete stale processing nodes for a given spaceID
413-
func deleteStaleUploads(cfg *config.Config, spaceID string, dryRun bool, verbose bool) int {
424+
func deleteStaleUploads(cfg *config.Config, spaceID string, dryRun bool, verbose bool, stream events.Stream) int {
414425
if verbose {
415426
fmt.Printf("\nDeleting stale processing nodes for space: %s\n", spaceID)
416427
}
@@ -440,7 +451,7 @@ func deleteStaleUploads(cfg *config.Config, spaceID string, dryRun bool, verbose
440451

441452
staleCount := 0
442453
for _, path := range mpkFiles {
443-
staleCount += deleteStaleNode(cfg, path, dryRun, verbose)
454+
staleCount += deleteStaleNode(cfg, path, dryRun, verbose, stream)
444455
}
445456

446457
if verbose {
@@ -452,7 +463,7 @@ func deleteStaleUploads(cfg *config.Config, spaceID string, dryRun bool, verbose
452463

453464
// deleteStaleNode deletes a stale node: if it is not referenced by any upload session
454465
// returns 1 if the node stale node was detected for deletion, 0 otherwise, for counting purposes
455-
func deleteStaleNode(cfg *config.Config, path string, dryRun bool, verbose bool) int {
466+
func deleteStaleNode(cfg *config.Config, path string, dryRun bool, verbose bool, stream events.Stream) int {
456467
nodeDir := filepath.Dir(path)
457468

458469
// Read .mpk file to get processing info
@@ -495,11 +506,20 @@ func deleteStaleNode(cfg *config.Config, path string, dryRun bool, verbose bool)
495506
return 1
496507
}
497508

498-
if err := os.RemoveAll(nodeDir); err != nil {
499-
fmt.Fprintf(os.Stderr, "%sError deleting stale node %s: %v\n", LOG_INDENT_L2, nodeDir, err)
509+
rid := extractResourceID(strings.TrimSuffix(path, ".mpk"))
510+
if rid == nil {
511+
fmt.Fprintf(os.Stderr, "Failed to extract resource ID from path %s\n", path)
500512
return 0
501513
}
502514

515+
if err := events.Publish(context.Background(), stream, events.RevertRevision{
516+
ResourceID: rid,
517+
Timestamp: utils.TSNow(),
518+
}); err != nil {
519+
// if publishing fails there is no need to try publishing other events - they will fail too.
520+
log.Fatalf("Failed to send revert revision event for node '%s'\n", path)
521+
}
522+
503523
if verbose {
504524
fmt.Printf("%sDeleted stale node: %s\n", LOG_INDENT_L2, nodeDir)
505525
}
@@ -518,3 +538,21 @@ func extractProcessingID(mpkData map[string]interface{}) string {
518538
}
519539
return processingID
520540
}
541+
542+
func extractResourceID(path string) *provider.ResourceId {
543+
// path looks like /.../storage/users/spaces/f2/06bccf-0f10-4070-9e63-40943f060667/nodes/5b/ba/1e/a7/-f185-4f31-8342-ed4b5743f096
544+
parts := strings.Split(path, "spaces")
545+
if len(parts) < 2 {
546+
return nil
547+
}
548+
549+
spaceParts := strings.Split(parts[1], "nodes")
550+
if len(spaceParts) < 2 {
551+
return nil
552+
}
553+
554+
return &provider.ResourceId{
555+
SpaceId: strings.ReplaceAll(spaceParts[0], "/", ""),
556+
OpaqueId: strings.ReplaceAll(spaceParts[1], "/", ""),
557+
}
558+
}

vendor/github.com/nats-io/nats.go/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/nats-io/nats.go/README.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/nats-io/nats.go/go_test.mod

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/nats-io/nats.go/go_test.sum

Lines changed: 12 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/nats-io/nats.go/js.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)