Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
bf5e28f
some refactoring changes (#8549)
landreev Nov 1, 2023
9954c5e
checking in some intermediate changes/work in progress (#8549)
landreev Nov 3, 2023
75789e0
current state of the flyway script (work in progress/likely to change…
landreev Nov 14, 2023
06f6222
more intermediate changes to the entity classes #8549
landreev Nov 20, 2023
552e735
get quota command #8549
landreev Nov 20, 2023
2b87779
new classes and instances #8549
landreev Nov 20, 2023
3e004c2
set/delete apis for quotas (#8549)
landreev Nov 20, 2023
fb952a2
more commands (#8549)
landreev Nov 20, 2023
9e80815
another iteration of the flyway script for calculating the initial si…
landreev Nov 25, 2023
1b95665
new object that defines the size limits for the current upload sessio…
landreev Nov 26, 2023
627a7b1
a stub for the release note (#8549)
landreev Nov 26, 2023
a5196df
All the bits and pieces that haven't been committed yet. (#8549)
landreev Nov 26, 2023
03e1860
renaming the flyway script, since there is a 6.0.0.3 in the develop b…
landreev Nov 26, 2023
01e8f94
Merge branch 'develop' into 8549-collection-quotas
landreev Nov 26, 2023
8d49fc4
a quick stab at a restassured test for the collection quotas #8549
landreev Nov 27, 2023
7754c36
Merge branch 'develop' into 8549-collection-quotas
landreev Nov 27, 2023
c9dc155
restassured test/work in progress #8549
landreev Nov 27, 2023
9840f60
Merge branch 'develop' into 8549-collection-quotas
landreev Nov 28, 2023
28cb866
basic restassured test added. #8549
landreev Nov 29, 2023
de84457
missing '/' #8549
landreev Nov 29, 2023
6c67dc2
Update src/main/java/edu/harvard/iq/dataverse/DataFileServiceBean.java
landreev Nov 29, 2023
f9f375c
Update doc/release-notes/8549-collection-quotas.md
landreev Nov 29, 2023
f9b58a1
test fixes #8549
landreev Nov 29, 2023
9b3c277
Merge branch '8549-collection-quotas' of https://github.com/IQSS/data…
landreev Nov 29, 2023
cda06a3
quota tests should be working now #8549
landreev Nov 29, 2023
162f967
Merge branch 'develop' into 8549-collection-quotas
landreev Nov 30, 2023
2644fae
Rearranges the code that updates the Storage Use records to reflect t…
landreev Nov 30, 2023
dc56784
making the set/delete quota commands superuser-only (doh). #8549
landreev Dec 1, 2023
f4eee65
removing the license template stubs (#8549)
landreev Dec 1, 2023
0bfbb10
"manage collections" guide entry. #8549
landreev Dec 1, 2023
1a96c56
the kill switch for the real-time storageuse updates (just in case) a…
landreev Dec 3, 2023
0a536da
a missing ref in the doc. #8549
landreev Dec 4, 2023
3babc5a
moving the StorageUse member to DvObjectContainer from DvObject; movi…
landreev Dec 5, 2023
c78613e
one more refinement for the flyway script. #8549
landreev Dec 5, 2023
c194d74
Clarified the sentence about the initial deployment in the release no…
landreev Dec 5, 2023
cf7e664
moved the entitymanager calls from a command to the service #8549
landreev Dec 5, 2023
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
3 changes: 3 additions & 0 deletions doc/release-notes/8549-collection-quotas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This release adds support for defining storage size quotas for collections. Please see the API guide for details. This is an experimental feature that has not yet been used in production on any real life Dataverse instance, but we are planning to try it out at Harvard/IQSS.
Please note that this release includes a database update (via a Flyway script) that will calculate the storage sizes of all the existing datasets and collections on the first deployment. On a large production database with tens of thousands of datasets this may add a couple of extra minutes to the first, initial deployment of 6.1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have a API changelog we could say something like, "See the API changelog for details: http://preview.guides.gdcc.io/en/develop/api/changelog.html "

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

19 changes: 19 additions & 0 deletions doc/sphinx-guides/source/admin/collectionquotas.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

Storage Quotas for Collections
==============================

Please note that this is a new and still experimental feature (as of Dataverse v6.1 release).

Instance admins can now define storage quota limits for specific collections. These limits can be set, changed and/or deleted via the provided APIs (please see the :ref:`collection-storage-quotas` section of the :doc:`/api/native-api` guide). The Read version of the API is available to the individual collection admins (i.e., a collection owner can check on the quota configured for their collection), but only superusers can set, change or disable storage quotas.

Storage quotas are *inherited* by subcollections. In other words, when storage use limit is set for a specific collection, it applies to all the datasets immediately under it and in its sub-collections, unless different quotas are defined there and so on. Each file added to any dataset in that hierarchy counts for the purposes of the quota limit defined for the top collection. A storage quota defined on a child sub-collection overrides whatever quota that may be defined on the parent, or inherited from an ancestor.

For example, a collection ``A`` has the storage quota set to 10GB. It has 3 sub-collections, ``B``, ``C`` and ``D``. Users can keep uploading files into the datasets anywhere in this hierarchy until the combined size of 10GB is reached between them. However, if an admin has reasons to limit one of the sub-collections, ``B`` to 3GB only, that quota can be explicitly set there. This both limits the growth of ``B`` to 3GB, and also *guarantees* that allocation to it. I.e. the contributors to collection ``B`` will be able to keep adding data until the 3GB limit is reached, even after the parent collection ``A`` reaches the combined 10GB limit (at which point ``A`` and all its subcollections except for ``B`` will become read-only).

We do not yet know whether this is going to be a popular, or needed use case - a child collection quota that is different from the quota it inherits from a parent. It is likely that for many instances it will be sufficient to be able to define quotas for collections and have them apply to all the child objects underneath. We will examine the response to this feature and consider making adjustments to this scheme based on it. We are already considering introducing other types of quotas, such as limits by users or specific storage volumes.

Please note that only the sizes of the main datafiles and the archival tab-delimited format versions, as produced by the ingest process are counted for the purposes of enforcing the limits. Automatically generated "auxiliary" files, such as rescaled image thumbnails and metadata exports for datasets are not.

When quotas are set and enforced, the users will be informed of the remaining storage allocation on the file upload page together with other upload and processing limits.

Part of the new and experimental nature of this feature is that we don't know for the fact yet how well it will function in real life on a very busy production system, despite our best efforts to test it prior to the release. One specific issue is having to update the recorded storage use for every parent collection of the given dataset whenever new files are added. This includes updating the combined size of the root, top collection - which will need to be updated after *every* file upload. In an unlikely case that this will start causing problems with race conditions and database update conflicts, it is possible to disable these updates (and thus disable the storage quotas feature), by setting the :ref:`dataverse.storageuse.disable-storageuse-increments` JVM setting to true.
1 change: 1 addition & 0 deletions doc/sphinx-guides/source/admin/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This guide documents the functionality only available to superusers (such as "da
solr-search-index
ip-groups
mail-groups
collectionquotas
monitoring
reporting-tools-and-queries
maintenance
Expand Down
35 changes: 35 additions & 0 deletions doc/sphinx-guides/source/api/native-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,41 @@ The following attributes are supported:
* ``affiliation`` Affiliation
* ``filePIDsEnabled`` ("true" or "false") Restricted to use by superusers and only when the :ref:`:AllowEnablingFilePIDsPerCollection <:AllowEnablingFilePIDsPerCollection>` setting is true. Enables or disables registration of file-level PIDs in datasets within the collection (overriding the instance-wide setting).

.. _collection-storage-quotas:

Collection Storage Quotas
~~~~~~~~~~~~~~~~~~~~~~~~~
Comment on lines +759 to +760

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any UI impact? Should we add to the long, dynamic list of rules? Or defer until we're off JSF? Screenshot below:

Screenshot 2023-11-28 at 12 02 31 PM

@landreev landreev Nov 29, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the remaining quota info will be shown to the user on the file upload page, above. The code for that is already in the develop branch, it was added in the proof of concept/phase one pr (#9409).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this:
Screen Shot 2023-11-28 at 7 15 51 PM


.. code-block::

curl -H "X-Dataverse-key:$API_TOKEN" "$SERVER_URL/api/dataverses/$ID/storage/quota"

Will output the storage quota allocated (in bytes), or a message indicating that the quota is not defined for the specific collection. The user identified by the API token must have the ``Manage`` permission on the collection.


To set or change the storage allocation quota for a collection:

.. code-block::

curl -X PUT -H "X-Dataverse-key:$API_TOKEN" "$SERVER_URL/api/dataverses/$ID/storage/quota/$SIZE_IN_BYTES"

This is API is superuser-only.


To delete a storage quota configured for a collection:

.. code-block::

curl -X DELETE -H "X-Dataverse-key:$API_TOKEN" "$SERVER_URL/api/dataverses/$ID/storage/quota"

This is API is superuser-only.

Use the ``/settings`` API to enable or disable the enforcement of storage quotas that are defined across the instance via the following setting. For example,

.. code-block::

curl -X PUT -d 'true' http://localhost:8080/api/admin/settings/:UseStorageQuotas


Datasets
--------
Expand Down
7 changes: 7 additions & 0 deletions doc/sphinx-guides/source/installation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,13 @@ This setting was added to keep S3 direct upload lightweight. When that feature i

See also :ref:`s3-direct-upload-features-disabled`.

.. _dataverse.storageuse.disable-storageuse-increments:

dataverse.storageuse.disable-storageuse-increments
++++++++++++++++++++++++++++++++++++++++++++++++++

This setting serves the role of an emergency "kill switch" that will disable maintaining the real time record of storage use for all the datasets and collections in the database. Because of the experimental nature of this feature (see :doc:`/admin/collectionquotas`) that hasn't been used in production setting as of this release, v6.1 this setting is provided in case these updates start causing database race conditions and conflicts on a busy server.

dataverse.auth.oidc.*
+++++++++++++++++++++

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/harvard/iq/dataverse/DataFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public String getFriendlySize() {
return BundleUtil.getStringFromBundle("file.sizeNotAvailable");
}
}

public boolean isRestricted() {
return restricted;
}
Expand Down
93 changes: 37 additions & 56 deletions src/main/java/edu/harvard/iq/dataverse/DataFileServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import edu.harvard.iq.dataverse.ingest.IngestServiceBean;
import edu.harvard.iq.dataverse.search.SolrSearchResult;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.storageuse.StorageQuota;
import edu.harvard.iq.dataverse.storageuse.StorageUseServiceBean;
import edu.harvard.iq.dataverse.storageuse.UploadSessionQuotaLimit;
import edu.harvard.iq.dataverse.util.FileSortFieldAndOrder;
import edu.harvard.iq.dataverse.util.FileUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;
Expand Down Expand Up @@ -41,8 +44,6 @@
*
* @author Leonid Andreev
*
* Basic skeleton of the new DataFile service for DVN 4.0
*
*/

@Stateless
Expand All @@ -66,6 +67,9 @@ public class DataFileServiceBean implements java.io.Serializable {

@EJB SystemConfig systemConfig;

@EJB
StorageUseServiceBean storageUseService;

@PersistenceContext(unitName = "VDCNet-ejbPU")
private EntityManager em;

Expand Down Expand Up @@ -139,39 +143,6 @@ public class DataFileServiceBean implements java.io.Serializable {
*/
public static final String MIME_TYPE_PACKAGE_FILE = "application/vnd.dataverse.file-package";

public class UserStorageQuota {

@landreev landreev Nov 27, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class was used during the phase one/proof of concept development.

private Long totalAllocatedInBytes = 0L;
private Long totalUsageInBytes = 0L;

public UserStorageQuota(Long allocated, Long used) {
this.totalAllocatedInBytes = allocated;
this.totalUsageInBytes = used;
}

public Long getTotalAllocatedInBytes() {
return totalAllocatedInBytes;
}

public void setTotalAllocatedInBytes(Long totalAllocatedInBytes) {
this.totalAllocatedInBytes = totalAllocatedInBytes;
}

public Long getTotalUsageInBytes() {
return totalUsageInBytes;
}

public void setTotalUsageInBytes(Long totalUsageInBytes) {
this.totalUsageInBytes = totalUsageInBytes;
}

public Long getRemainingQuotaInBytes() {
if (totalUsageInBytes > totalAllocatedInBytes) {
return 0L;
}
return totalAllocatedInBytes - totalUsageInBytes;
}
}

public DataFile find(Object pk) {
return em.find(DataFile.class, pk);
}
Expand Down Expand Up @@ -1396,28 +1367,38 @@ public Embargo findEmbargo(Long id) {
return d.getEmbargo();
}

public Long getStorageUsageByCreator(AuthenticatedUser user) {
Query query = em.createQuery("SELECT SUM(o.filesize) FROM DataFile o WHERE o.creator.id=:creatorId");

try {
Long totalSize = (Long)query.setParameter("creatorId", user.getId()).getSingleResult();
logger.info("total size for user: "+totalSize);
return totalSize == null ? 0L : totalSize;
} catch (NoResultException nre) { // ?
logger.info("NoResultException, returning 0L");
return 0L;
/**
* Checks if the supplied DvObjectContainer (Dataset or Collection; although
* only collection-level storage quotas are officially supported as of now)
* has a quota configured, and if not, keeps checking if any of the direct
* ancestor Collections further up have a configured quota. If it finds one,
* it will retrieve the current total content size for that specific ancestor
* dvObjectContainer and use it to define the quota limit for the upload
* session in progress.
*
* @param parent - DvObjectContainer, Dataset or Collection
* @return upload session size limit spec, or null if quota not defined on
* any of the ancestor DvObjectContainers
*/
public UploadSessionQuotaLimit getUploadSessionQuotaLimit(DvObjectContainer parent) {
Comment thread
scolapasta marked this conversation as resolved.
Resolved
DvObjectContainer testDvContainer = parent;
StorageQuota quota = testDvContainer.getStorageQuota();
while (quota == null && testDvContainer.getOwner() != null) {
testDvContainer = testDvContainer.getOwner();
quota = testDvContainer.getStorageQuota();
if (quota != null) {
break;
}
}
if (quota == null || quota.getAllocation() == null) {
return null;
}
}

public UserStorageQuota getUserStorageQuota(AuthenticatedUser user, Dataset dataset) {
// this is for testing only - one pre-set, installation-wide quota limit
// for everybody:
Long totalAllocated = systemConfig.getTestStorageQuotaLimit();
// again, this is for testing only - we are only counting the total size
// of all the files created by this user; it will likely be a much more
// complex calculation in real life applications:
Long totalUsed = getStorageUsageByCreator(user);

return new UserStorageQuota(totalAllocated, totalUsed);
// Note that we are checking the recorded storage use not on the
// immediate parent necessarily, but on the specific ancestor
// DvObjectContainer on which the storage quota is defined:
Long currentSize = storageUseService.findStorageSizeByDvContainerId(testDvContainer.getId());

return new UploadSessionQuotaLimit(quota.getAllocation(), currentSize);
}
}
10 changes: 10 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import jakarta.persistence.TemporalType;

import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.storageuse.StorageUse;
import edu.harvard.iq.dataverse.util.StringUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;

Expand Down Expand Up @@ -189,13 +190,22 @@ public void setTemplate(Template template) {
}

public Dataset() {
this(false);
}

public Dataset(boolean isHarvested) {
DatasetVersion datasetVersion = new DatasetVersion();
datasetVersion.setDataset(this);
datasetVersion.setVersionState(DatasetVersion.VersionState.DRAFT);
datasetVersion.setFileMetadatas(new ArrayList<>());
datasetVersion.setVersionNumber((long) 1);
datasetVersion.setMinorVersionNumber((long) 0);
versions.add(datasetVersion);

if (!isHarvested) {
StorageUse storageUse = new StorageUse(this);
this.setStorageUse(storageUse);
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/Dataverse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import edu.harvard.iq.dataverse.harvest.client.HarvestingClient;
import edu.harvard.iq.dataverse.authorization.DataverseRole;
import edu.harvard.iq.dataverse.search.savedsearch.SavedSearch;
import edu.harvard.iq.dataverse.storageuse.StorageUse;
import edu.harvard.iq.dataverse.util.BundleUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;

Expand Down Expand Up @@ -103,7 +104,11 @@ public enum DataverseType {
* dataverses.
*/
protected boolean permissionRoot;


public Dataverse() {
StorageUse storageUse = new StorageUse(this);
this.setStorageUse(storageUse);
}

public DataverseType getDataverseType() {
return dataverseType;
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DataverseServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import edu.harvard.iq.dataverse.search.IndexServiceBean;
import edu.harvard.iq.dataverse.search.SolrIndexServiceBean;
import edu.harvard.iq.dataverse.search.SolrSearchResult;
import edu.harvard.iq.dataverse.storageuse.StorageQuota;
import edu.harvard.iq.dataverse.util.StringUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;
import java.io.File;
Expand Down Expand Up @@ -919,5 +920,27 @@ public List<Object[]> getDatasetTitlesWithinDataverse(Long dataverseId) {
return em.createNativeQuery(cqString).getResultList();
}

public void saveStorageQuota(Dataverse target, Long allocation) {
StorageQuota storageQuota = target.getStorageQuota();

if (storageQuota != null) {
storageQuota.setAllocation(allocation);
em.merge(storageQuota);
} else {
storageQuota = new StorageQuota();
storageQuota.setDefinitionPoint(target);
storageQuota.setAllocation(allocation);
target.setStorageQuota(storageQuota);
em.persist(storageQuota);
}
em.flush();
}

public void disableStorageQuota(StorageQuota storageQuota) {
if (storageQuota != null && storageQuota.getAllocation() != null) {
storageQuota.setAllocation(null);
em.merge(storageQuota);
em.flush();
}
}
}
15 changes: 14 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DvObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
import edu.harvard.iq.dataverse.pidproviders.PidUtil;
import edu.harvard.iq.dataverse.storageuse.StorageQuota;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -155,7 +156,7 @@ public String visit(DataFile df) {
private String identifier;

private boolean identifierRegistered;

private transient GlobalId globalId = null;

@OneToMany(mappedBy = "dvObject", cascade = CascadeType.ALL, orphanRemoval = true)
Expand All @@ -177,6 +178,9 @@ public void setAlternativePersistentIndentifiers(Set<AlternativePersistentIdenti
*/
private boolean previewImageAvailable;

@OneToOne(mappedBy = "definitionPoint",cascade={ CascadeType.REMOVE, CascadeType.MERGE,CascadeType.PERSIST}, orphanRemoval=true)
private StorageQuota storageQuota;

public boolean isPreviewImageAvailable() {
return previewImageAvailable;
}
Expand Down Expand Up @@ -458,6 +462,14 @@ public void setStorageIdentifier(String storageIdentifier) {
this.storageIdentifier = storageIdentifier;
}

public StorageQuota getStorageQuota() {
return storageQuota;
}

public void setStorageQuota(StorageQuota storageQuota) {
this.storageQuota = storageQuota;
}

/**
*
* @param other
Expand All @@ -467,4 +479,5 @@ public void setStorageIdentifier(String storageIdentifier) {

@OneToMany(mappedBy = "definitionPoint",cascade={ CascadeType.REMOVE, CascadeType.MERGE,CascadeType.PERSIST}, orphanRemoval=true)
List<RoleAssignment> roleAssignments;

}
Loading