mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
07.32.2019 21d4ef254deeee8cae5459c6cf4cfb996fb7040b
JProfiler session for optimizing heap space (a big memory leak fixed).
3 files modified
37 ■■■■ changed files
borgbutler-core/src/main/java/de/micromata/borgbutler/BorgCommands.java 21 ●●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/BorgJob.java 6 ●●●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/jobs/AbstractCommandLineJob.java 10 ●●●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/BorgCommands.java
@@ -34,7 +34,7 @@
        BorgCommand command = new BorgCommand()
                .setParams("--version")
                .setDescription("Getting borg version.");
        JobResult<String> jobResult = execute(command).getResult();
        JobResult<String> jobResult = getResult(command);
        if (jobResult == null || jobResult.getStatus() != JobResult.Status.OK) {
            return null;
        }
@@ -55,7 +55,7 @@
                .setCommand("info")
                .setParams("--json") // --progress has no effect.
                .setDescription("Loading info of repo '" + repoConfig.getDisplayName() + "'.");
        JobResult<String> jobResult = execute(command).getResult();
        JobResult<String> jobResult = getResult(command);
        if (jobResult == null || jobResult.getStatus() != JobResult.Status.OK) {
            return null;
        }
@@ -88,7 +88,7 @@
                .setCommand("list")
                .setParams("--json") // --progress has no effect.
                .setDescription("Loading list of archives of repo '" + repoConfig.getDisplayName() + "'.");
        JobResult<String> jobResult = execute(command).getResult();
        JobResult<String> jobResult = getResult(command);
        if (jobResult == null || jobResult.getStatus() != JobResult.Status.OK) {
            log.error("Can't load archives from repo '" + repository.getName() + "'.");
            return;
@@ -130,7 +130,7 @@
                .setArchive(archive.getName())
                .setParams("--json", "--log-json", "--progress")
                .setDescription("Loading info of archive '" + archive.getName() + "' of repo '" + repoConfig.getDisplayName() + "'.");
        JobResult<String> jobResult = execute(command).getResult();
        JobResult<String> jobResult = getResult(command);
        if (jobResult == null || jobResult.getStatus() != JobResult.Status.OK) {
            return;
        }
@@ -193,7 +193,9 @@
        if (jobResult == null ||jobResult.getStatus() != JobResult.Status.OK) {
            return null;
        }
        return job.payload;
        List<BorgFilesystemItem> items = job.payload;
        job.cleanUp(); // payload will be released.
        return items;
    }
    /**
@@ -221,10 +223,17 @@
                .setDescription("Extract content of archive '" + archive.getName()
                        + "' of repo '" + repoConfig.getDisplayName() + "': "
                        + path);
        JobResult<String> jobResult = execute(command).getResult();
        JobResult<String> jobResult = getResult(command);
        return restoreDir;
    }
    private static JobResult<String> getResult(BorgCommand command) {
        BorgJob<Void> job = execute(command);
        JobResult<String> jobResult = job.getResult();
        job.cleanUp();
        return jobResult;
    }
    private static BorgJob<Void> execute(BorgCommand command) {
        Validate.notNull(command);
        return BorgQueueExecutor.getInstance().execute(command);
borgbutler-core/src/main/java/de/micromata/borgbutler/BorgJob.java
@@ -121,4 +121,10 @@
        }
        return clone;
    }
    @Override
    public void cleanUp() {
        super.cleanUp();
        payload = null;
    }
}
borgbutler-core/src/main/java/de/micromata/borgbutler/jobs/AbstractCommandLineJob.java
@@ -139,4 +139,14 @@
            EnvironmentUtils.addVariableToEnvironment(env, name + "=" + value);
        }
    }
    /**
     * Frees the output streams.
     * Should be called after a job was done, failed or cancelled while running.
     */
    public void cleanUp() {
        log.info("Freeing resources of job: " + commandLineAsString);
        outputStream = null;
        errorOutputStream = null;
    }
}