Repository navigation
Collection Quotas #10144
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
Collection Quotas #10144
Changes from all commits
bf5e28f
9954c5e
75789e0
06f6222
552e735
2b87779
3e004c2
fb952a2
9e80815
1b95665
627a7b1
a5196df
03e1860
01e8f94
8d49fc4
7754c36
c9dc155
9840f60
28cb866
de84457
6c67dc2
f9f375c
f9b58a1
9b3c277
cda06a3
162f967
2644fae
dc56784
f4eee65
0bfbb10
1a96c56
0a536da
3babc5a
c78613e
c194d74
cf7e664
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
| 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| .. 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 | ||
| -------- | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -41,8 +44,6 @@ | |
| * | ||
| * @author Leonid Andreev | ||
| * | ||
| * Basic skeleton of the new DataFile service for DVN 4.0 | ||
| * | ||
| */ | ||
|
|
||
| @Stateless | ||
|
|
@@ -66,6 +67,9 @@ public class DataFileServiceBean implements java.io.Serializable { | |
|
|
||
| @EJB SystemConfig systemConfig; | ||
|
|
||
| @EJB | ||
| StorageUseServiceBean storageUseService; | ||
|
|
||
| @PersistenceContext(unitName = "VDCNet-ejbPU") | ||
| private EntityManager em; | ||
|
|
||
|
|
@@ -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 { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
|
|
@@ -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) { | ||
|
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); | ||
| } | ||
| } | ||


There was a problem hiding this comment.
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 "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.