Q: ActiveStorage DiskService directory sharding

548 views
Skip to first unread message

Dominik Menke

unread,
Aug 27, 2019, 7:24:02 AM8/27/19
to Ruby on Rails: Talk
Hello list,

I've noticed ActiveStorage::Service::DiskService does two levels of directory sharding for Blob pathnames:

$ tree storage/
storage/
+-- aa/
    +-- bb/
    |   +-- aabb00...
    +-- cc/
        +-- aacc11...

However, when it comes to variants, the sharding is circumvented:

$ tree storage/
storage/
+-- aa/
|   +-- bb/
|   |   +-- aabb00...
|   +-- cc/
|       +-- aacc11...
+-- va/
    +-- ri/
        +-- variants/
            +-- aabb00.../
            |   +-- <encoded variant file name>
            +-- aacc11.../
                +-- <encoded variant file name>


Should sharding exclude variant/ key prefixes? Maybe the directory layout can look like this:

$ tree storage/
storage/
+-- aa/
|   +-- bb/
|   |   +-- aabb00...
|   +-- cc/
|       +-- aacc11...
+-- variants/
    +-- aa/
        +-- bb/
        |   +-- aabb00.../
        |       +-- <encoded variant file name>
        +-- cc/
            +-- aacc11.../
                +-- <encoded variant file name>


This might not actually a problem at all, as the limiting factor on ext4 file systems is the inode index (which allow directories to contain ~10 million entries with 32 character long names (reference); the Base58 blob id is only 24 characters long). I guess with ZFS it's even less of a problem.

I was going to create an issue for this, but this might actually be expected/desired behaviour. I'm also not sure if this is a bug or feature request either. I know changing this will cause some headache. I'm primarily looking for other opinions.

Kind Regards,
Dominik

Josef Strzibny

unread,
Aug 29, 2019, 7:22:11 AM8/29/19
to Ruby on Rails: Talk
On the first look I would like your layout more (as something I would expect or design myself). However, I don't know any background on why is this like it is.

Dne úterý 27. srpna 2019 13:24:02 UTC+2 Dominik Menke napsal(a):
Reply all
Reply to author
Forward
0 new messages