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

Add retention based backup system #2905

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ private void checkInstanceLock() {
}
}

public CompletableFuture<Void> pruneAllBackups() {
return persistenceService.pruneAllBackups();
}

public CompletableFuture<Boolean> readAllPersisted() {
return persistenceService.readAllPersisted();
}
Expand Down
8 changes: 8 additions & 0 deletions application/src/main/java/bisq/application/Executable.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ public Executable(String[] args) {
}));

applicationService = createApplicationService(args);

long ts = System.currentTimeMillis();
applicationService.pruneAllBackups().join();
log.info("pruneAllBackups took {} ms", System.currentTimeMillis() - ts);

ts = System.currentTimeMillis();
applicationService.readAllPersisted().join();
log.info("readAllPersisted took {} ms", System.currentTimeMillis() - ts);

launchApplication(args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import bisq.desktop.main.content.ContentTabController;
import bisq.desktop.main.content.settings.display.DisplaySettingsController;
import bisq.desktop.main.content.settings.language.LanguageSettingsController;
import bisq.desktop.main.content.settings.network.NetworkSettingsController;
import bisq.desktop.main.content.settings.misc.MiscSettingsController;
import bisq.desktop.main.content.settings.notifications.NotificationsSettingsController;
import bisq.desktop.main.content.settings.trade.TradeSettingsController;
import lombok.Getter;
Expand All @@ -48,7 +48,7 @@ protected Optional<? extends Controller> createController(NavigationTarget navig
case NOTIFICATION_SETTINGS -> Optional.of(new NotificationsSettingsController(serviceProvider));
case DISPLAY_SETTINGS -> Optional.of(new DisplaySettingsController(serviceProvider));
case TRADE_SETTINGS -> Optional.of(new TradeSettingsController(serviceProvider));
case NETWORK_SETTINGS -> Optional.of(new NetworkSettingsController(serviceProvider));
case MISC_SETTINGS -> Optional.of(new MiscSettingsController(serviceProvider));
default -> Optional.empty();
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public SettingsView(SettingsModel model, SettingsController controller) {
addTab(Res.get("settings.notifications"), NavigationTarget.NOTIFICATION_SETTINGS);
addTab(Res.get("settings.trade"), NavigationTarget.TRADE_SETTINGS);
addTab(Res.get("settings.display"), NavigationTarget.DISPLAY_SETTINGS);
addTab(Res.get("settings.network"), NavigationTarget.NETWORK_SETTINGS);
addTab(Res.get("settings.misc"), NavigationTarget.MISC_SETTINGS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.desktop.main.content.settings.network;
package bisq.desktop.main.content.settings.misc;

import bisq.bonded_roles.security_manager.difficulty_adjustment.DifficultyAdjustmentService;
import bisq.common.observable.Pin;
Expand All @@ -31,22 +31,22 @@
import org.fxmisc.easybind.Subscription;

@Slf4j
public class NetworkSettingsController implements Controller {
public class MiscSettingsController implements Controller {
@Getter
private final NetworkSettingsView view;
private final NetworkSettingsModel model;
private final MiscSettingsView view;
private final MiscSettingsModel model;
private final SettingsService settingsService;
private final DifficultyAdjustmentService difficultyAdjustmentService;

private Pin ignoreDiffAdjustmentFromSecManagerPin,
mostRecentDifficultyAdjustmentFactorOrDefaultPin, difficultyAdjustmentFactorPin;
mostRecentDifficultyAdjustmentFactorOrDefaultPin, difficultyAdjustmentFactorPin, totalMaxBackupSizeInMBPin;
private Subscription difficultyAdjustmentFactorDescriptionTextPin;

public NetworkSettingsController(ServiceProvider serviceProvider) {
public MiscSettingsController(ServiceProvider serviceProvider) {
settingsService = serviceProvider.getSettingsService();
difficultyAdjustmentService = serviceProvider.getBondedRolesService().getDifficultyAdjustmentService();
model = new NetworkSettingsModel();
view = new NetworkSettingsView(model, this);
model = new MiscSettingsModel();
view = new MiscSettingsView(model, this);
}

@Override
Expand Down Expand Up @@ -74,13 +74,17 @@ public void onActivate() {
UIThread.run(() -> model.getDifficultyAdjustmentFactor().set(mostRecentValueOrDefault)));
}
});

totalMaxBackupSizeInMBPin = FxBindings.bindBiDir(model.getTotalMaxBackupSizeInMB())
.to(settingsService.getTotalMaxBackupSizeInMB());
}

@Override
public void onDeactivate() {
ignoreDiffAdjustmentFromSecManagerPin.unbind();
model.getDifficultyAdjustmentFactorEditable().unbind();
difficultyAdjustmentFactorDescriptionTextPin.unsubscribe();
totalMaxBackupSizeInMBPin.unbind();
if (difficultyAdjustmentFactorPin != null) {
difficultyAdjustmentFactorPin.unbind();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.desktop.main.content.settings.network;
package bisq.desktop.main.content.settings.misc;

import bisq.desktop.common.view.Model;
import javafx.beans.property.*;
Expand All @@ -24,12 +24,13 @@

@Slf4j
@Getter
public class NetworkSettingsModel implements Model {
public class MiscSettingsModel implements Model {
private final DoubleProperty difficultyAdjustmentFactor = new SimpleDoubleProperty();
private final BooleanProperty difficultyAdjustmentFactorEditable = new SimpleBooleanProperty();
private final StringProperty difficultyAdjustmentFactorDescriptionText = new SimpleStringProperty();
private final BooleanProperty ignoreDiffAdjustmentFromSecManager = new SimpleBooleanProperty();
private final DoubleProperty totalMaxBackupSizeInMB = new SimpleDoubleProperty();

public NetworkSettingsModel() {
public MiscSettingsModel() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.desktop.main.content.settings.network;
package bisq.desktop.main.content.settings.misc;

import bisq.common.util.MathUtils;
import bisq.desktop.common.converters.Converters;
import bisq.desktop.common.converters.DoubleStringConverter;
import bisq.desktop.common.view.View;
import bisq.desktop.components.controls.MaterialTextField;
import bisq.desktop.components.controls.Switch;
Expand All @@ -26,6 +28,8 @@
import bisq.desktop.main.content.settings.SettingsViewUtils;
import bisq.i18n.Res;
import bisq.network.p2p.node.network_load.NetworkLoad;
import bisq.persistence.backup.BackupService;
import de.jensd.fx.fontawesome.AwesomeIcon;
import javafx.beans.binding.Bindings;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
Expand All @@ -36,17 +40,20 @@
import org.fxmisc.easybind.Subscription;

@Slf4j
public class NetworkSettingsView extends View<VBox, NetworkSettingsModel, NetworkSettingsController> {
public class MiscSettingsView extends View<VBox, MiscSettingsModel, MiscSettingsController> {
private static final double TEXT_FIELD_WIDTH = 500;
private static final ValidatorBase DIFFICULTY_ADJUSTMENT_FACTOR_VALIDATOR =
new NumberValidator(Res.get("settings.network.difficultyAdjustmentFactor.invalid", NetworkLoad.MAX_DIFFICULTY_ADJUSTMENT),
0, NetworkLoad.MAX_DIFFICULTY_ADJUSTMENT);
private static final double TEXT_FIELD_WIDTH = 500;
private static final ValidatorBase TOTAL_MAX_BACKUP_SIZE_VALIDATOR =
new NumberValidator(Res.get("settings.backup.totalMaxBackupSizeInMB.invalid", 1, 1000),
1, 1000);

private final Switch ignoreDiffAdjustFromSecManagerSwitch;
private final MaterialTextField difficultyAdjustmentFactor;
private final MaterialTextField difficultyAdjustmentFactor, totalMaxBackupSizeInMB;
private Subscription ignoreDiffAdjustFromSecManagerSwitchPin;

public NetworkSettingsView(NetworkSettingsModel model, NetworkSettingsController controller) {
public MiscSettingsView(MiscSettingsModel model, MiscSettingsController controller) {
super(new VBox(), model, controller);

root.setAlignment(Pos.TOP_LEFT);
Expand All @@ -61,8 +68,20 @@ public NetworkSettingsView(NetworkSettingsModel model, NetworkSettingsController
ignoreDiffAdjustFromSecManagerSwitch = new Switch(Res.get("settings.network.difficultyAdjustmentFactor.ignoreValueFromSecManager"));

VBox networkVBox = new VBox(10, difficultyAdjustmentFactor, ignoreDiffAdjustFromSecManagerSwitch);

Label backupHeadline = new Label(Res.get("settings.backup.headline"));
backupHeadline.getStyleClass().add("large-thin-headline");

totalMaxBackupSizeInMB = new MaterialTextField(Res.get("settings.backup.totalMaxBackupSizeInMB.description"));
totalMaxBackupSizeInMB.setMaxWidth(TEXT_FIELD_WIDTH);
totalMaxBackupSizeInMB.setValidators(TOTAL_MAX_BACKUP_SIZE_VALIDATOR);
totalMaxBackupSizeInMB.setStringConverter(Converters.DOUBLE_STRING_CONVERTER);
totalMaxBackupSizeInMB.setIcon(AwesomeIcon.INFO_SIGN);
totalMaxBackupSizeInMB.setIconTooltip(Res.get("settings.backup.totalMaxBackupSizeInMB.info.tooltip"));

VBox contentBox = new VBox(50);
contentBox.getChildren().addAll(networkHeadline, SettingsViewUtils.getLineAfterHeadline(contentBox.getSpacing()), networkVBox);
contentBox.getChildren().addAll(networkHeadline, SettingsViewUtils.getLineAfterHeadline(contentBox.getSpacing()), networkVBox,
backupHeadline, SettingsViewUtils.getLineAfterHeadline(contentBox.getSpacing()), totalMaxBackupSizeInMB);
contentBox.getStyleClass().add("bisq-common-bg");
root.getChildren().add(contentBox);
root.setPadding(new Insets(0, 40, 20, 40));
Expand All @@ -75,6 +94,20 @@ protected void onViewAttached() {
Converters.DOUBLE_STRING_CONVERTER);
difficultyAdjustmentFactor.getTextInputControl().editableProperty().bind(model.getDifficultyAdjustmentFactorEditable());
difficultyAdjustmentFactor.descriptionProperty().bind(model.getDifficultyAdjustmentFactorDescriptionText());

Bindings.bindBidirectional(totalMaxBackupSizeInMB.textProperty(), model.getTotalMaxBackupSizeInMB(),
new DoubleStringConverter() {
@Override
public Number fromString(String value) {
double result = MathUtils.parseToDouble(value);
if(TOTAL_MAX_BACKUP_SIZE_VALIDATOR.validateAndGet()){
return result;
}else{
return BackupService.TOTAL_MAX_BACKUP_SIZE_IN_MB;
}
}
});

ignoreDiffAdjustFromSecManagerSwitchPin = EasyBind.subscribe(
ignoreDiffAdjustFromSecManagerSwitch.selectedProperty(), s -> difficultyAdjustmentFactor.validate());
}
Expand All @@ -85,7 +118,11 @@ protected void onViewDetached() {
Bindings.unbindBidirectional(difficultyAdjustmentFactor.textProperty(), model.getDifficultyAdjustmentFactor());
difficultyAdjustmentFactor.getTextInputControl().editableProperty().unbind();
difficultyAdjustmentFactor.descriptionProperty().unbind();

Bindings.unbindBidirectional(totalMaxBackupSizeInMB.textProperty(), model.getTotalMaxBackupSizeInMB());

ignoreDiffAdjustFromSecManagerSwitchPin.unsubscribe();
difficultyAdjustmentFactor.resetValidation();
totalMaxBackupSizeInMB.resetValidation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public enum NavigationTarget {
NOTIFICATION_SETTINGS(SETTINGS),
DISPLAY_SETTINGS(SETTINGS),
TRADE_SETTINGS(SETTINGS),
NETWORK_SETTINGS(SETTINGS),
MISC_SETTINGS(SETTINGS),

// WALLET
WALLET(CONTENT),
Expand Down
33 changes: 32 additions & 1 deletion common/src/main/java/bisq/common/file/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e)
}));
}

public static void makeDirs(Path dirPath) throws IOException {
makeDirs(dirPath.toFile());
}

public static void makeDirs(String dirPath) throws IOException {
makeDirs(new File(dirPath));
}
Expand Down Expand Up @@ -288,7 +292,14 @@ public static void copy(InputStream inputStream, OutputStream outputStream) thro
}

public static Set<String> listFiles(String dirPath) {
try (Stream<Path> stream = Files.list(Paths.get(dirPath))) {
return listFiles(Paths.get(dirPath));
}

public static Set<String> listFiles(Path dirPath) {
if (!dirPath.toFile().exists()) {
return new HashSet<>();
}
try (Stream<Path> stream = Files.list(dirPath)) {
return stream
.filter(file -> !Files.isDirectory(file))
.map(Path::getFileName)
Expand All @@ -300,6 +311,26 @@ public static Set<String> listFiles(String dirPath) {
}
}

public static Set<String> listDirectories(String dirPath) {
return listDirectories(Paths.get(dirPath));
}

public static Set<String> listDirectories(Path dirPath) {
if (!dirPath.toFile().exists()) {
return new HashSet<>();
}
try (Stream<Path> stream = Files.list(dirPath)) {
return stream
.filter(Files::isDirectory)
.map(Path::getFileName)
.map(Path::toString)
.collect(Collectors.toSet());
} catch (IOException e) {
log.error(e.toString(), e);
return new HashSet<>();
}
}

public static File createNewFile(Path path) throws IOException {
File file = path.toFile();
if (!file.createNewFile()) {
Expand Down
15 changes: 14 additions & 1 deletion i18n/src/main/resources/settings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ settings.language=Language
settings.notifications=Notifications
settings.trade=Offer and trade
settings.display=Display
settings.network=Network
settings.misc=Miscellaneous

settings.language.headline=Language selection
settings.language.select=Select language
Expand Down Expand Up @@ -44,3 +44,16 @@ settings.network.difficultyAdjustmentFactor.description.fromSecManager=PoW diffi
settings.network.difficultyAdjustmentFactor.invalid=Must be a number between 0 and {0}
settings.network.difficultyAdjustmentFactor.ignoreValueFromSecManager=Ignore value provided by Bisq Security Manager

settings.backup.headline=Backup settings
settings.backup.totalMaxBackupSizeInMB.description=Max. size in MB for automatic backups
settings.backup.totalMaxBackupSizeInMB.info.tooltip=Important data is automatically backed up in the data directory whenever updates are made,\n\
following this retention strategy:\n\t\
- Last Hour: Keep a maximum of one backup per minute.\n\t\
- Last Day: Keep one backup per hour.\n\t\
- Last Week: Keep one backup per day.\n\t\
- Last Month: Keep one backup per week.\n\t\
- Last Year: Keep one backup per month.\n\t\
- Previous Years: Keep one backup per year.\n\n\
Please note, this backup mechanism does not protect against hard disk failures.\n\
For better protection, we strongly recommend creating manual backups on an alternative hard drive.
settings.backup.totalMaxBackupSizeInMB.invalid=Must be a value between {0} MB and {1} MB
2 changes: 1 addition & 1 deletion i18n/src/main/resources/settings_cs.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ settings.language=Jazyk
settings.notifications=Oznámení
settings.trade=Nabídka a obchod
settings.display=Zobrazení
settings.network=Síť
settings.misc=Různé

settings.language.headline=Výběr jazyka
settings.language.select=Vyberte jazyk
Expand Down
2 changes: 1 addition & 1 deletion i18n/src/main/resources/settings_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ settings.language=Sprache
settings.notifications=Benachrichtigungen
settings.trade=Angebot und Handel
settings.display=Anzeige
settings.network=Netzwerk
settings.misc=Verschiedenes

settings.language.headline=Sprachauswahl
settings.language.select=Sprache auswählen
Expand Down
2 changes: 1 addition & 1 deletion i18n/src/main/resources/settings_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ settings.language=Idioma
settings.notifications=Notificaciones
settings.trade=Oferta y compra-venta
settings.display=Visualización
settings.network=Red
settings.misc=Misceláneo

settings.language.headline=Selección de Idioma
settings.language.select=Seleccionar idioma
Expand Down
2 changes: 1 addition & 1 deletion i18n/src/main/resources/settings_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ settings.language=Lingua
settings.notifications=Notifiche
settings.trade=Offerta e scambio
settings.display=Visualizzazione
settings.network=Rete
settings.misc=Misto

settings.language.headline=Selezione della lingua
settings.language.select=Seleziona la lingua
Expand Down
2 changes: 1 addition & 1 deletion i18n/src/main/resources/settings_pcm.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ settings.language=Language
settings.notifications=Notifications
settings.trade=Offer and trade
settings.display=Display
settings.network=Network
settings.misc=Miscellaneous

settings.language.headline=Selek Language
settings.language.select=Chuze Language
Expand Down
2 changes: 1 addition & 1 deletion i18n/src/main/resources/settings_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ settings.language=Idioma
settings.notifications=Notificações
settings.trade=Oferta e negociação
settings.display=Exibição
settings.network=Rede
settings.misc=Diversos

settings.language.headline=Seleção de Idioma
settings.language.select=Selecionar idioma
Expand Down
3 changes: 1 addition & 2 deletions identity/src/main/java/bisq/identity/IdentityService.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ public CompletableFuture<Boolean> shutdown() {

@Override
public CompletableFuture<Boolean> persist() {
return getPersistence().persistAsync(getPersistableStore().getClone())
.handle((nil, throwable) -> throwable == null);
return PersistenceClient.super.persist();
}


Expand Down
Loading
Loading