Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data loss: named versions are lost from group folder after a while #3095

Closed
sena73 opened this issue Aug 5, 2024 · 11 comments · Fixed by #3213 or #3393
Closed

data loss: named versions are lost from group folder after a while #3095

sena73 opened this issue Aug 5, 2024 · 11 comments · Fixed by #3213 or #3393
Labels
1. to develop Issues that are ready for development bug feature: versions Items related to file versioning

Comments

@sena73
Copy link

sena73 commented Aug 5, 2024

"Versions" extension is not working properly with the "Group folder" extension in NC 29.

If I create named versions of a file in a group folder, they are created, but disappear after a while (noticed after days).

Old versions simply disappear in a group folder without any notice or log message. I would tell it is a severe bug, as I do not see a way to recover deleted versions.

I understand that it gonna take time to fix. But please, make at least this 2 extensions conflicting, so people will not be able to install both of them simultaneously. Or better make "Versions" menu disabled for the files in "Group folder".

I found other bugs that indicate problems when both extensions are working:

#2965 #2343

@sena73 sena73 added 0. Needs triage Issues that need to be triaged bug labels Aug 5, 2024
@joshtrichards joshtrichards added the feature: versions Items related to file versioning label Sep 9, 2024
@joshtrichards
Copy link
Member

If I create named versions of a file in a group folder, they are created, but disappear after a while (noticed after days).

You may be correct. I suspect we're expiring labeled (named) versions within GF. Offhand I don't see the GF Versions handler checking for labeled versions in the same way that the non-GF versions does:

https://github.com/nextcloud/server/blob/2480567005776cc96d543b52992c83a41d75d1a6/apps/files_versions/lib/Storage.php#L569-L570

This may have been lost during the #2543 -> #2857 jump though offhand I don't see it in the former either.

Cc: @artonge

@artonge
Copy link
Contributor

artonge commented Sep 12, 2024

@joshtrichards is right, we do have the check for "normal" versions, but I missed to implement it for groupfolders' versions.

@joshtrichards joshtrichards added 1. to develop Issues that are ready for development and removed 0. Needs triage Issues that need to be triaged labels Sep 12, 2024
@joshtrichards
Copy link
Member

Thanks for reporting this, @sena73. Will be fixed in the next release!

@XueSheng-GIT
Copy link
Contributor

@artonge @joshtrichards I've upgraded groupfolders to 17.0.4 (NC 28.0.7) which includes the backport of #3213 but named versions still expire!

Can you double check and re-open this issue? Or shall I create a new one?

@joshtrichards
Copy link
Member

joshtrichards commented Oct 10, 2024

I believe that API is only applicable to >28. I'm not certain offhand, but you may be right as far as NC 28 goes. I think we'd have to do something unique just for 28 🤔 built on #2543.

Aside: Are you sure you're running 17.0.4? It is only for >=29.

@XueSheng-GIT
Copy link
Contributor

@joshtrichards I'm on NC 29.0.7 (28 was a typo). Sorry for that confusion.

@XueSheng-GIT
Copy link
Contributor

I did some tests on NC 30.0.1 RC2 with groupfolders 18.0.2 and can reproduce the issue (labled versions expire over time). Thus, it seems it's not only related to older NC versions < 28.

@joshtrichards the question still is whether this issue needs to be reopened or a new one created?

@XueSheng-GIT
Copy link
Contributor

@artonge Sorry to bug again. But I lost a lot of labled versions lately which were saved in groupfolders.
Looking at #3213 it seems the main change regarding expiry was done in regards to function getExpiredVersions:

public function getExpiredVersion(array $versions, int $time, bool $quotaExceeded): array {
if ($this->expiration->shouldAutoExpire()) {
$autoExpire = $this->getAutoExpireList($time, $versions);
} else {
$autoExpire = [];
}
$versionsLeft = array_udiff($versions, $autoExpire, function (IVersion $a, IVersion $b) {
return ($a->getRevisionId() <=> $b->getRevisionId()) *
($a->getSourceFile()->getId() <=> $b->getSourceFile()->getId());
});
$expired = array_filter($versionsLeft, function (IVersion $version) use ($quotaExceeded) {
// Do not expire current version.
if ($version->getTimestamp() === $version->getSourceFile()->getMtime()) {
return false;
}
// Do not expire versions with a label.
if ($version instanceof IMetadataVersion && $version->getMetadataValue('label') !== null && $version->getMetadataValue('label') !== '') {
return false;
}
return $this->expiration->isExpired($version->getTimestamp(), $quotaExceeded);
});
return array_merge($autoExpire, $expired);
}

On the first view it returns the versions which shall expire. Those consists of two parts: $autoExpire and $expired

It seems #3213 does only protect labeled versions for $expired (=> quotaExceeded). But regular auto expire done by getAutoExpireList and reflected by $autoExpire does not seem to include any check for labled versions. Thus, I assume it is expected that labled versions are deleted!

I recommend to reopen this issue again until finally fixed.

CC @provokateurin

@XueSheng-GIT
Copy link
Contributor

Just in case somebody stumbles over this, I now changed the following as quick fix to stop auto expiry of labelled versions. Maybe not the cleanest solution but it seems to work.

diff --git a/lib/Versions/ExpireManager.php b/lib/Versions/ExpireManager.php
index e4f63bb29..97012e0eb 100644
--- a/lib/Versions/ExpireManager.php
+++ b/lib/Versions/ExpireManager.php
@@ -66,8 +66,11 @@ protected function getAutoExpireList(int $time, array $versions): array {
 			while ($newInterval) {
 				if ($nextInterval === -1 || $prevTimestamp > $nextInterval) {
 					if ($version->getTimestamp() > $nextVersion) {
-						//distance between two version too small, mark to delete
-						$toDelete[] = $version;
+						// Do not expire versions with a label.
+						if ($version->getMetadataValue('label') === null || $version->getMetadataValue('label') === '') {
+							//distance between two version too small, mark to delete
+							$toDelete[] = $version;
+						}
 					} else {
 						$nextVersion = $version->getTimestamp() - $step;
 						$prevTimestamp = $version->getTimestamp();

@artonge
Copy link
Contributor

artonge commented Oct 29, 2024

@XueSheng-GIT, could you open a PR applying the changes done in #3213 to getAutoExpireList ?

@XueSheng-GIT
Copy link
Contributor

@artonge thanks for reopening the issue. I'm not sure whether I get your request in the right way. The diff mentioned in #3095 (comment) does already change getAutoExpireList in the way #3213 handles it for the out of quota versions.

I created a draft pull accordingly: #3393
If this wasn't your intention, I'll close it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1. to develop Issues that are ready for development bug feature: versions Items related to file versioning
Projects
None yet
4 participants