Skip to content

Conversation

@icewind1991
Copy link
Member

@icewind1991 icewind1991 commented May 13, 2025

Allow configuring multiple object store backends to allow further load balancing and easier migration.

Configuration

Multiple object stores are configured by setting the objectstore system config to an array of object storage configurations instead of a single configuration. This array can contains both configuration items and references to other configuration keys (which functions as an alias).

When a the configured bucket for a user is an alias, the target of the alias is stored as the users chosen configuration instead to make migrations easier.
The "default" option is required to be an alias to prevent instances from accidentally being setup in a way that makes migration difficult.

By default everything is put in the "default" bucket, objects for the root storage are put in the "root" bucket if it exists ("default" if it doesn't), the backend for users can be set with a user preference option (occ user:setting <user> homeobjectstore objectstore <config key>).

Existing objectstore and objectstore_multibucket configurations are handled transparently.

Migration example

Migrating users to a new s3 server could be done with the following steps:

  • create a new object store configuration
  • update the default reference to the new configuration.

all new users will now be stored on the new s3 server, existing users can now be migrated one-by-one with minimal downtime

  • copy over the objects for a single user to the new s3 server
  • update the objectstore config key for the user

example configuration:

[
  'objectstore' => [
    'default' => 'new',
    'new' => [
      'class' => 'OC\\Files\\ObjectStore\\S3',
      'arguments' => [
        'multibucket' => true,
        'bucket' => 'nextcloud-',
        'hostname' => 'objectstore2',
        ...
      ],
    ],
    'old' => [
      'class' => 'OC\\Files\\ObjectStore\\S3',
      'arguments' => [
        'bucket' => 'nextcloud',
        'hostname' => 'objectstore1',
        ...
      ],
    ],
    'root' => [
      'class' => 'OC\\Files\\ObjectStore\\S3',
      'arguments' => [
        'bucket' => 'nextcloud-root',
        'hostname' => 'objectstore1',
        ...
      ],
    ],
  ],
]

For a use case where all objects in the root storage is put in "objectstore1/nextcloud-root", users created before the objectstore migration have the "homeobjectstore.objectstore" config option set to "old" and have their objects stored in "objectstore1/nextcloud" which all users created afterwards have their objects stored in the "objectstore2/nextcloud-XX" buckets.

todo

  • command to rename configurations
    • create "<new>" objectstore configuration as a copy from "<old>"
    • for all users who are currently using "<old>" set the objectstore config key to "<new>"
  • command to migrate users to a different config
  • command to list users by configuration

@icewind1991 icewind1991 force-pushed the multi-object-store branch 6 times, most recently from cf36e0c to 95a019a Compare May 14, 2025 08:37
@icewind1991 icewind1991 force-pushed the multi-object-store branch from 95a019a to 5c33aec Compare May 14, 2025 13:23
@icewind1991 icewind1991 force-pushed the multi-object-store branch 3 times, most recently from b2923b0 to 77b1e72 Compare June 2, 2025 15:58
@icewind1991 icewind1991 force-pushed the multi-object-store branch 2 times, most recently from 16533d5 to 077003d Compare June 5, 2025 15:42
@icewind1991 icewind1991 force-pushed the multi-object-store branch 7 times, most recently from 14b8f17 to 2acc97c Compare June 12, 2025 15:52
@icewind1991 icewind1991 force-pushed the multi-object-store branch 4 times, most recently from 6440956 to 4a27074 Compare July 31, 2025 15:41
@icewind1991 icewind1991 added the 3. to review Waiting for reviews label Aug 1, 2025
@icewind1991 icewind1991 added this to the Nextcloud 32 milestone Aug 1, 2025
@icewind1991 icewind1991 marked this pull request as ready for review August 1, 2025 14:10
@icewind1991 icewind1991 changed the title [WIP] allow configuring multiple object store backends allow configuring multiple object store backends Aug 1, 2025
$query = $this->connection->getQueryBuilder();
$query->update('preferences')
->set('configvalue', $query->createNamedParameter($target))
->where($query->expr()->eq('appid', $query->createNamedParameter('homeobjectstore')))
Copy link
Contributor

Choose a reason for hiding this comment

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

That’s not an appid ⚠️
What about using core?

Copy link
Member Author

Choose a reason for hiding this comment

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

Having a separate "scope" makes it much easier to work with the values in bulk (see for example the query in the rename command).

Fwiw: homeobjectstore is already used as an appid for storing the bucket for the user.

@icewind1991 icewind1991 force-pushed the multi-object-store branch 2 times, most recently from 53b0d3b to 404bce1 Compare August 5, 2025 17:40
Copy link
Contributor

@salmart-dev salmart-dev left a comment

Choose a reason for hiding this comment

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

I'm not familiar with the object store, but the logic here makes sense in accordance to the PR's description.

@szaimen szaimen removed their request for review August 11, 2025 11:51
@icewind1991 icewind1991 requested a review from CarlSchwan August 13, 2025 17:33
Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Robin Appelman <robin@icewind.nl>
@icewind1991 icewind1991 merged commit b691093 into master Aug 14, 2025
232 of 239 checks passed
@icewind1991 icewind1991 deleted the multi-object-store branch August 14, 2025 13:49
@skjnldsv skjnldsv mentioned this pull request Aug 19, 2025
@skjnldsv skjnldsv modified the milestones: Nextcloud 32, Nextcloud 33 Sep 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants