You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "David Sitsky (JIRA)" <ji...@apache.org> on 2018/11/05 01:36:00 UTC

[jira] [Resolved] (AMQ-7089) StoreUtil.findParentDirectory does not work correctly on Linux

     [ https://issues.apache.org/jira/browse/AMQ-7089?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

David Sitsky resolved AMQ-7089.
-------------------------------
    Resolution: Not A Bug

My apologies.. my wires were crossed with my initial report in AMQ-7085 and the comment to findParentDirectory which said "Utility method to help find the root directory of the store".  The comment is completely out of sync with the code, which returns the first directory which exists.


> StoreUtil.findParentDirectory does not work correctly on Linux
> --------------------------------------------------------------
>
>                 Key: AMQ-7089
>                 URL: https://issues.apache.org/jira/browse/AMQ-7089
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: Broker
>    Affects Versions: 5.15.7
>            Reporter: David Sitsky
>            Priority: Major
>
> On my Linux machine I have been running ActiveMQ on a filesystem setup like this:
> {noformat}
> Filesystem Size Used Avail Use% Mounted on
> /dev/nvme0n1p1 407G 299G 88G 78% /
> ...
> /dev/nvme1n1p2 477G 443G 35G 93% /media/sits/DATA
> {noformat}
> When I call broker.setDataDirectoryFile("/media/sits/DATA/activemq') after broker initialisation it reports the amount of free temp space usage is the free space on '/', not on '/media/sits/DATA'.
> The culprit is BrokerService.checkTmpStorageUsageLimits() calls checkUsageLimit(tmpDir, usage.getTempUsage(), usage.getTempUsage().getPercentLimit()) which ultimately calls this code:
> {code}
>     protected void checkUsageLimit(File dir, Usage<?> storeUsage, int percentLimit) throws ConfigurationException {
>         if (dir != null) {
>             dir = StoreUtil.findParentDirectory(dir);
>             String storeName = storeUsage instanceof StoreUsage ? "Store" : "Temporary Store";
>             long storeLimit = storeUsage.getLimit();
>             long storeCurrent = storeUsage.getUsage();
>             long totalSpace = dir.getTotalSpace();
> {code}
> The problem is StoreUtil is broken on Linux (and probably other OS's) since you can mount a filesystems in non-root locations.  Even on Windows this is possible.
> {code}
>     public static File findParentDirectory(File dir) {
>         if (dir != null) {
>             String dirPath = dir.getAbsolutePath();
>             if (!dir.isAbsolute()) {
>                 dir = new File(dirPath);
>             }
>             while (dir != null && !dir.isDirectory()) {
>                 dir = dir.getParentFile();
>             }
>         }
>         return dir;
>     }
> {code}
> On Linux this will always go to '/' and use that for reporting free space which is clearly wrong.
> There are only a few usages of this method.  My proposal is to nuke this method and instead update the clients to just call Files.getFileStore(Path path) and then FileStore.getTotalSpace() and FileStore.getUsableSpace.
> I'm happy to submit a PR if people are happy with the approach?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)