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

Save reference ID identical across all versions of a file #15778

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Implement file id provider using reference id of node.
dkocher committed Mar 28, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit d8297da97cc51f9406eb8fc6677aa30a4cc60f9e
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public abstract class CachingFileIdProvider implements FileIdProvider {
public class CachingFileIdProvider implements FileIdProvider {
private static final Logger log = LogManager.getLogger(CachingFileIdProvider.class);

private final LRUCache<SimplePathPredicate, String> cache
Original file line number Diff line number Diff line change
@@ -23,15 +23,15 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public abstract class CachingVersionIdProvider implements VersionIdProvider {
public class CachingVersionIdProvider implements VersionIdProvider {
private static final Logger log = LogManager.getLogger(CachingVersionIdProvider.class);

private final LRUCache<SimplePathPredicate, String> cache
= LRUCache.build(PreferencesFactory.get().getLong("fileid.cache.size"));

private final Protocol.Case sensitivity;

protected CachingVersionIdProvider(final Protocol.Case sensitivity) {
public CachingVersionIdProvider(final Protocol.Case sensitivity) {
this.sensitivity = sensitivity;
}

Original file line number Diff line number Diff line change
@@ -47,6 +47,9 @@ public SDSAttributesAdapter(final SDSSession session) {
@Override
public PathAttributes toAttributes(final Node node) {
final PathAttributes attributes = new PathAttributes();
if(node.getReferenceId() != null) {
attributes.setFileId(String.valueOf(node.getReferenceId()));
}
attributes.setVersionId(String.valueOf(node.getId()));
attributes.setRevision(node.getBranchVersion());
if(node.isIsEncrypted() != null && !node.isIsEncrypted()) {
@@ -109,6 +112,9 @@ public PathAttributes toAttributes(final Node node) {
public PathAttributes toAttributes(final DeletedNode node) {
final PathAttributes attributes = new PathAttributes();
attributes.setDuplicate(true);
if(node.getReferenceId() != null) {
attributes.setVersionId(String.valueOf(node.getReferenceId()));
}
attributes.setVersionId(String.valueOf(node.getId()));
attributes.setCreationDate(node.getCreatedAt() != null ? node.getCreatedAt().getMillis() : -1L);
attributes.setModificationDate(node.getUpdatedAt() != null ? node.getUpdatedAt().getMillis() : -1L);
Original file line number Diff line number Diff line change
@@ -15,11 +15,13 @@
* GNU General Public License for more details.
*/

import ch.cyberduck.core.CachingFileIdProvider;
import ch.cyberduck.core.CachingVersionIdProvider;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.URIEncoder;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.NotfoundException;
import ch.cyberduck.core.features.FileIdProvider;
import ch.cyberduck.core.features.VersionIdProvider;
import ch.cyberduck.core.preferences.HostPreferences;
import ch.cyberduck.core.sds.io.swagger.client.ApiException;
@@ -33,17 +35,26 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class SDSNodeIdProvider extends CachingVersionIdProvider implements VersionIdProvider {
public class SDSNodeIdProvider implements FileIdProvider, VersionIdProvider {
private static final Logger log = LogManager.getLogger(SDSNodeIdProvider.class);

private static final UnicodeNormalizer normalizer = new NFCNormalizer();
private static final String ROOT_NODE_ID = "0";

private final SDSSession session;
/**
* Node id as file version
*/
private final CachingVersionIdProvider versions;
/**
* Reference id that is static across different file versions
*/
private final CachingFileIdProvider references;

public SDSNodeIdProvider(final SDSSession session) {
super(session.getCaseSensitivity());
this.session = session;
this.versions = new CachingVersionIdProvider(session.getCaseSensitivity());
this.references = new CachingFileIdProvider(session.getCaseSensitivity());
}

@Override
@@ -54,20 +65,61 @@ public String getVersionId(final Path file) throws BackgroundException {
}
return file.attributes().getVersionId();
}
final String cached = super.getVersionId(file);
final String cached = versions.getVersionId(file);
if(cached != null) {
if(log.isDebugEnabled()) {
log.debug(String.format("Return cached versionid %s for file %s", cached, file));
}
return cached;
}
return this.getNodeId(file, new HostPreferences(session.getHost()).getInteger("sds.listing.chunksize"));
final Node node = this.getNode(file, new HostPreferences(session.getHost()).getInteger("sds.listing.chunksize"));
if(null == node) {
return ROOT_NODE_ID;
}
if(null != node.getId()) {
return String.valueOf(node.getId());
}
return null;
}

protected String getNodeId(final Path file, final int chunksize) throws BackgroundException {
if(file.isRoot()) {
@Override
public String getFileId(final Path file) throws BackgroundException {
if(file.isDirectory()) {
return null;
}
if(StringUtils.isNotBlank(file.attributes().getFileId())) {
if(log.isDebugEnabled()) {
log.debug(String.format("Return version %s from attributes for file %s", file.attributes().getFileId(), file));
}
return file.attributes().getFileId();
}
final String cached = references.getFileId(file);
if(cached != null) {
if(log.isDebugEnabled()) {
log.debug(String.format("Return cached versionid %s for file %s", cached, file));
}
return cached;
}
final Node node = this.getNode(file, new HostPreferences(session.getHost()).getInteger("sds.listing.chunksize"));
if(null == node) {
return ROOT_NODE_ID;
}
if(null != node.getReferenceId()) {
return String.valueOf(node.getReferenceId());
}
return null;
}

@Override
public void clear() {
versions.clear();
references.clear();
}

protected Node getNode(final Path file, final int chunksize) throws BackgroundException {
if(file.isRoot()) {
return null;
}
try {
final String type;
if(file.isDirectory()) {
@@ -101,7 +153,9 @@ protected String getNodeId(final Path file, final int chunksize) throws Backgrou
if(log.isInfoEnabled()) {
log.info(String.format("Return node %s for file %s", node.getId(), file));
}
return this.cache(file, node.getId().toString());
versions.cache(file, node.getId().toString());
references.cache(file, node.getReferenceId().toString());
return node;
}
}
offset += chunksize;
3 changes: 3 additions & 0 deletions dracoon/src/main/java/ch/cyberduck/core/sds/SDSSession.java
Original file line number Diff line number Diff line change
@@ -569,6 +569,9 @@ public <T> T _getFeature(final Class<T> type) {
if(type == Delete.class) {
return (T) new SDSThresholdDeleteFeature(this, nodeid);
}
if(type == SDSNodeIdProvider.class) {
return (T) nodeid;
}
if(type == VersionIdProvider.class) {
return (T) nodeid;
}
Original file line number Diff line number Diff line change
@@ -91,6 +91,7 @@ public void testWrite() throws Exception {
new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
assertEquals(content.length, out.getStatus().getSize(), 0L);
}
assertNotNull(test.attributes().getFileId());
assertNotNull(test.attributes().getVersionId());
assertTrue(new DefaultFindFeature(session).find(test));
assertTrue(new SDSFindFeature(session, nodeid).find(test));