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

Change thumbnail mounting dir to avoid nested mounts #1076

Closed
Rivers47 opened this issue Sep 10, 2024 · 2 comments
Closed

Change thumbnail mounting dir to avoid nested mounts #1076

Rivers47 opened this issue Sep 10, 2024 · 2 comments

Comments

@Rivers47
Copy link

Please describe your suggestion, and the problem it'd solve.
Currently the docker image mounts thumbnail to content/thumb which is very convoluted and LRRG will try to create a empty directory "thumb/ under content if user creates a thumbnail volume that mounts to content/thumb. Mounting a volume inside another bind mount should be avoided. I suggest either in tools/build/docker/Dockerfile remove

VOLUME [ "/home/koyomi/lanraragi/content/thumb" ]

alltogether and let user decide where thumbnails should be,
or change it to

VOLUME [ "/home/koyomi/lanraragi/thumb" ]

Additional context
none

@Difegue
Copy link
Owner

Difegue commented Oct 12, 2024

hmm, the idea with that mount was to keep the previous behavior where thumbnails were always in the content folder by default, but maybe I should just give up on that and have it in a fully separated folder for good.

@dix0nym
Copy link

dix0nym commented Nov 1, 2024

TL;DR: I think I experienced the following problem because of the nested mount: No thumbnails on container restart.

My content folder is in a NFS mounted directory of the host system.
After each restart of the container, the thumbnails were missing. And it could only be fixed by running Generate missing thumbnails - even though all thumbnail should already exist.

I set up some logging in the serve_thumbnail function:

server_thumbnail with some logging
sub serve_thumbnail {

    my ( $self, $id ) = @_;

    my $logger = get_logger( "Thumbanil Serving", "lanraragi" );

    my $page = $self->req->param('page');
    $page = 0 unless $page;

    my $no_fallback = $self->req->param('no_fallback');
    $no_fallback = ( $no_fallback && $no_fallback eq "true" ) || "0";    # Prevent undef warnings by checking the variable first

    my $thumbdir        = LANraragi::Model::Config->get_thumbdir;
    my $use_jxl         = LANraragi::Model::Config->get_jxlthumbpages;
    my $format          = $use_jxl         ? 'jxl' : 'jpg';
    my $fallback_format = $format eq 'jxl' ? 'jpg' : 'jxl';

    # Thumbnails are stored in the content directory, thumb subfolder.
    # Another subfolder with the first two characters of the id is used for FS optimization.
    my $subfolder = substr( $id, 0, 2 );

    # Check for the page and set the appropriate thumbnail name and fallback thumbnail name
    my $thumbbase          = ( $page - 1 > 0 ) ? "$thumbdir/$subfolder/$id/$page" : "$thumbdir/$subfolder/$id";
    my $thumbname          = "$thumbbase.$format";
    my $fallback_thumbname = "$thumbbase.$fallback_format";

    # Check if the preferred format thumbnail exists, if not, try the alternate format
    unless ( -e $thumbname ) {
        $logger->info("thumbnail (preferred format) for $id: '$thumbname' does not exist! Trying fallback: '$fallback_thumbname'");
        $thumbname = $fallback_thumbname;
    }

    unless ( -e $thumbname ) {
        $logger->info("thumbnail (pf|fallback) for $id: '$thumbname' does not exist!");
        if ($no_fallback) {
            $logger->info("thumbnail fallback disabled for '$thumbname' ($id) - queue minion job");
            # Queue a minion job to generate the thumbnail. Thumbnail jobs have the lowest priority.
            my $job_id = $self->minion->enqueue( thumbnail_task => [ $thumbdir, $id, $page ] => { priority => 0, attempts => 3 } );
            $self->render(
                json => {
                    operation => "serve_thumbnail",
                    success   => 1,
                    job       => $job_id
                },
                status => 202    # 202 Accepted
            );
        } else {
            $logger->info("fallback enabled but no thumb found for '$thumbname' - serving noThumb.png for $id");
            # If the thumbnail doesn't exist, serve the default thumbnail.
            $self->render_file( filepath => "./public/img/noThumb.png" );
        }
        return;
    } else {
        $logger->info("thumbnail (pf|fallback) found for $id: $thumbname - serving");
        # Simply serve the thumbnail.
        $self->render_file( filepath => $thumbname );
    }
}

output:

WindowsTerminal_3br8eGPfWX

As you can see on the screenshot -> the thumbnail actually did not exist! All other thumbnails and folder structure in content/thumb was also missing. But all archives were there in /home/koyomi/lanraragi/content.

I thought it could be a NFS limitation, as I currently have 27k archives in content. But I could not confirm that.

Another option could be a issue with the nested docker mounts. I moved the thumb and tried the following addition to my docker-compose.yaml:

    environment:
      LRR_THUMB_DIRECTORY: "/thumb"
   volumes:
      - /media/nfs-share/lanraragi/content:/home/koyomi/lanraragi/content
      - /media/nfs-share/lanraragi/thumb:/thumb

And all thumbnail were loading from the start! Separating content and thumb actually solved my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants