Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Documentation for media_storage_providers #7140

Open

Description

@djschilling

I want to use the s3_storage_provider.S3StorageProviderBackend.

I configured it and when images are send over my synapse server they are also stored in the s3 bucket.
Here is how i configured it:

media_storage_providers:
- module: s3_storage_provider.S3StorageProviderBackend
  store_local: False
  store_remote: True
  store_synchronous: True
  config:
    bucket: synapse1
    endpoint_url: $HIDDEN_ENDPOINT
    access_key_id: $HIDDEN_KEY
    secret_access_key: $HIDDEN_KEY

But the images are still also stored locally on disk at /var/lib/matrix-synapse/media and if i remove the folder /var/lib/matrix-synapse/media the images are not shown anymore although they are still in the s3 bucket. So it seems to me that the s3_storage_provider.S3StorageProviderBackend does nothing but also store the data as a backup option?

I also could not find any documentation about media_storage_providers in this repo.
Can someone explain what they are and how they are supposed to work please.

My use case is that i want only to use the S3 Bucket and no local storage. Is this possible with media_storage_providers?

Activity

  1. added
    A-Docsthings relating to the documentation
    A-Media-RepositoryUploading, downloading images and video, thumbnailing
    on Apr 2, 2020
  2. tristanlins commented on Apr 12, 2020

    @tristanlins
    Contributor

    I'm also interested in what the media storage is for.

    For me too, the file is stored locally in the file system AND on the S3.
    The strange thing is that store_local: False means that the file is only saved in the file system and NOT on the S3!

    But if I delete the local directory, all files are still available to me.

    I use a Minio server as S3 storage.

  3. tristanlins commented on Apr 12, 2020

    @tristanlins
    Contributor

    What I just noticed is that all pre-generated thumbnails are ONLY stored on the S3 as expected. 🤔

  4. clokep commented on Apr 13, 2020

    @clokep
    Member

    I also could not find any documentation about media_storage_providers in this repo.

    The documentation is pretty light, but seems to be at https://github.com/matrix-org/synapse/blob/develop/docs/media_repository.md, the default config could certainly offer a bit more info:

    # Media storage providers allow media to be stored in different
    # locations.
    #
    #media_storage_providers:
    # - module: file_system
    # # Whether to write new local files.
    # store_local: false
    # # Whether to write new remote media
    # store_remote: false
    # # Whether to block upload requests waiting for write to this
    # # provider to complete
    # store_synchronous: false
    # config:
    # directory: /mnt/some/other/directory

    Looking at some of the code it seems that the "local" vs. "remote" in those configurations is whether the media was uploaded directly to this server vs. whether it was received over federation (it does not mean whether the data is stored "locally" on the server vs. "remote on S3", which is how I originally read it). See

    "store_local", # Whether to store newly uploaded local files
    "store_remote", # Whether to store newly downloaded remote files
    "store_synchronous", # Whether to wait for successful storage for local uploads

    What's your configuration for backup_media_store_path? It looks like the file system store might be enabled if backup_media_store_path is set to true, see

    storage_providers = [
    {
    "module": "file_system",
    "store_local": True,
    "store_synchronous": synchronous_backup_media_store,
    "store_remote": True,
    "config": {"directory": backup_media_store_path},
    }
    ]

  5. tristanlins commented on Apr 14, 2020

    @tristanlins
    Contributor

    I have not specified backup_media_store_path, I will take a deeper look into this...

  6. tristanlins commented on Apr 14, 2020

    @tristanlins
    Contributor

    The backup_media_store_path is not the problem, it cannot be used together with media_storage_providers:

    if backup_media_store_path:
    if storage_providers:
    raise ConfigError(
    "Cannot use both 'backup_media_store_path' and 'storage_providers'"
    )

  7. tristanlins commented on Apr 14, 2020

    @tristanlins
    Contributor

    Okay, I think I understand how the media storage providers are meant.
    The bad news: It is not possible to replace the local storage (media_store_path) with the remote storage.

    The storage of the media is primarily managed by the MediaStorage and not the StorageProvider.

    fname = yield self.media_storage.store_file(content, file_info)

    output_path = yield self.media_storage.store_file(

    output_path = yield self.media_storage.store_file(

    output_path = yield self.media_storage.store_file(




    This in turn always saves the file first in the local directory:

    with self.store_into_file(file_info) as (f, fname, finish_cb):
    # Write to the main repository
    yield defer_to_thread(
    self.hs.get_reactor(), _write_file_synchronously, source, f
    )
    yield finish_cb()




    And then this locally stored file is passed on to the StorageProviders:

    @defer.inlineCallbacks
    def finish():
    for provider in self.storage_providers:
    yield provider.store_file(path, file_info)




    I'm slowly beginning to understand what the s3_media_upload.py cleanup job is all about.
    https://github.com/matrix-org/synapse-s3-storage-provider#regular-cleanup-job




    However, it should not be a problem to simply delete the local files from media_store_path at regular intervals. In this case, the file is then delivered by the first StorageProvider who still holds the file.

    path = self._file_info_to_path(file_info)
    local_path = os.path.join(self.local_media_directory, path)
    if os.path.exists(local_path):
    return FileResponder(open(local_path, "rb"))
    for provider in self.storage_providers:
    res = yield provider.fetch(path, file_info)
    if res:
    return res




    I hope I have analyzed it correctly.
    Perhaps a responsible developer can comment again on whether this is correct ?!

  8. babolivier commented on Apr 22, 2020

    @babolivier
    Contributor

    Hey @tristanlins, yes this seems correct to me.

  9. nemani commented on Jul 16, 2020

    @nemani

    Can we add a link to this issue at the relevant place in the sample config file?

    Thanks!

  10. added
    Z-Help-WantedWe know exactly how to fix this issue, and would be grateful for any contribution
    on Aug 4, 2020
  11. ftpmorph commented on Feb 3, 2021

    @ftpmorph

    Note there is an alternative solution which in theory should be easy to config so that the only media directory is an S3 bucket. I'm going to try it myself when I set my server up within the next few days.

    You install and configure Goofys, make sure it mounts an S3 bucket directory on boot, and then you can simply change the media directory in the Matrix config to that one and turn off the S3 storage provider.

    As far as Matrix is concerned it is writing media to the local filesystem but it'll be transparently using your S3 bucket instead.

    This is the S3 config from the popular Ansible Docker deploy.

  12. sorcer1122 commented on Jan 8, 2023

    @sorcer1122

    Note there is an alternative solution which in theory should be easy to config so that the only media directory is an S3 bucket. I'm going to try it myself when I set my server up within the next few days.

    You install and configure Goofys, make sure it mounts an S3 bucket directory on boot, and then you can simply change the media directory in the Matrix config to that one and turn off the S3 storage provider.

    As far as Matrix is concerned it is writing media to the local filesystem but it'll be transparently using your S3 bucket instead.

    This is the S3 config from the popular Ansible Docker deploy.

    Any luck with this? I am looking for the same solution on how to replace local media storage with S3.

  13. djmaze commented on Jan 8, 2023

    @djmaze

    I bet using goofys works worse and is more brittle than just using the s3 storage provider. The local storage even has the advantage of being a cache for recently uploaded files.

    Why not just run the clean-up script regularly? (Or run synapse in ephemeral containers, which, at least for me, is already sufficient?)

  14. sorcer1122 commented on Jan 8, 2023

    @sorcer1122

    I bet using goofys works worse and is more brittle than just using the s3 storage provider. The local storage even has the advantage of being a cache for recently uploaded files.

    Why not just run the clean-up script regularly? (Or run synapse in ephemeral containers, which, at least for me, is already sufficient?)

    Couple of reasons:

    1. I want everything to go into S3 for speed and reliability reasons
    2. Much easier to clean-up S3 bucket for me
  15. added
    T-TaskRefactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.
    on Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-Docsthings relating to the documentationA-Media-RepositoryUploading, downloading images and video, thumbnailingT-TaskRefactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.Z-Help-WantedWe know exactly how to fix this issue, and would be grateful for any contribution

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions