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

Support resource files tagged by version to reduce initial data requests #4519

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
cb9f0f0
Initial tests
freimair Apr 9, 2020
3296db3
Version helper uses real Bisq version
freimair Apr 15, 2020
e7831d6
Tests use static fixtures
freimair Apr 16, 2020
581286e
Migration test succeeds
freimair Apr 16, 2020
fc7a43d
GetMap test succeeds
freimair Apr 16, 2020
d111d8c
GetMapSinceFilter works
freimair Apr 16, 2020
6eda9a9
updateScenario works
freimair Apr 16, 2020
ff53f51
freshInstall scenario works
freimair Apr 16, 2020
49731f9
put scenario works
freimair Apr 16, 2020
e123a0b
Introduce SplitStore and Service to handle BL
freimair Apr 17, 2020
da5d41b
Moved file handling logic to SplitStoreService
freimair Apr 17, 2020
c7351a0
Activate other split data stores
freimair Apr 17, 2020
e2e80d7
Refactored tests
freimair Apr 20, 2020
10c1ecc
Initial tests for requests
freimair Apr 20, 2020
f6cea15
Requests are smaller
freimair Apr 20, 2020
0d80123
Prevent adding duplicate data
freimair Apr 24, 2020
aad57c3
Enforce version format and filter faulty ones
freimair Apr 24, 2020
faca8e4
Test incoming special keys from the future
freimair Apr 24, 2020
72600b1
Javadoc cosmetics
freimair Apr 24, 2020
3ad395b
Init integration test script
freimair Apr 29, 2020
2589137
Persist live database after split
freimair May 1, 2020
34abad0
Integration test script tests stock
freimair May 1, 2020
62a77e3
Use version history array
freimair May 1, 2020
39fcca5
Integration test script tests new system
freimair May 4, 2020
a3628ff
Use full sync between seednodes
freimair May 4, 2020
a374249
Cleanup integration test script
freimair May 4, 2020
8e55f64
Ignore some tests
freimair May 11, 2020
e927e6d
Adjust P2PDataStorage tests
freimair May 11, 2020
2fb2232
Add another migration test
freimair May 12, 2020
5f8b7cf
Reactivate ignored tests
freimair May 12, 2020
f8320fe
Refactoring and cleaning up
freimair May 20, 2020
017bbfd
Cleanup
freimair May 20, 2020
d2a6655
Refactored test helpers
freimair May 21, 2020
469c374
Fixed a potential issue when loading stores
freimair May 21, 2020
249e185
Fixed wrong filename
freimair May 22, 2020
06ec223
Refactoring
freimair May 22, 2020
eabadc0
Make special key platform-independent
freimair May 26, 2020
755fc03
Fixed persisting wrong data store
freimair Jun 12, 2020
d218f2e
Renamed data stores
freimair Jun 12, 2020
c34bfee
Replace TODO comment
freimair Jun 16, 2020
d6f195d
Fixed a timing issue
freimair Jul 1, 2020
d81bdab
Added 1.3.6 and 1.3.7 data stores
freimair Sep 1, 2020
abbfedc
Update history version list
freimair Sep 1, 2020
5f94406
Removed deprecated test mechanisms
freimair Sep 1, 2020
0eccec7
Cleanup imports
freimair Sep 1, 2020
270f1e7
Included PR feedback
freimair Sep 1, 2020
c8c63ef
Included PR feedback
freimair Sep 1, 2020
76cc37e
Added 1.3.8 data stores
freimair Sep 12, 2020
b4aae51
Use Version.VERSION again
freimair Sep 12, 2020
f83c147
Merge branch 'master_upstream' into chimp-reduce_initial_request_size
chimp1984 Sep 13, 2020
5f8e779
Refactor: Add getStore method to be reused by SplitStoreService
chimp1984 Sep 13, 2020
3100888
Use readStore(); instead of store = readStore(getFileName());
chimp1984 Sep 13, 2020
591c2fb
Apply code inspection suggestions
chimp1984 Sep 13, 2020
d5c6644
Add mapOfHistoricalStores field
chimp1984 Sep 13, 2020
3dac4c4
Revert critical data stores to current version.
chimp1984 Sep 13, 2020
2cef411
Add version field
chimp1984 Sep 13, 2020
8458a88
Remove methods in MapStoreService and do instead instance of check in…
chimp1984 Sep 13, 2020
2ece512
Add current version to version list. Makes it more clear that those a…
chimp1984 Sep 13, 2020
965de7f
Remove file
chimp1984 Sep 13, 2020
cfefae2
Rename SplitStore to PersistableNetworkPayload
chimp1984 Sep 13, 2020
28987f5
Rename for better clarity
chimp1984 Sep 13, 2020
6cf054c
Fix bug with missing replace -> use existing methods in Version for v…
chimp1984 Sep 13, 2020
aadd2e4
Revert version to 1.3.7 to not break build
chimp1984 Sep 13, 2020
7a5ba0b
Fix param in test. Add Ignore to the 2 test classes handling the new …
chimp1984 Sep 13, 2020
224eaab
Fix param in test.
chimp1984 Sep 13, 2020
98877b4
Revert changes at tests from prev version
chimp1984 Sep 13, 2020
32cf32c
Merge branch 'master_upstream' into chimp-reduce_initial_request_size
chimp1984 Sep 15, 2020
8f2e4ca
Change dev mode price
chimp1984 Sep 15, 2020
22fc97d
Remove test files from previous version
chimp1984 Sep 16, 2020
9c873a6
Add getPersisted method
chimp1984 Sep 16, 2020
3252a50
remove test files
chimp1984 Sep 16, 2020
a3ea54a
remove test
chimp1984 Sep 16, 2020
2b61563
Fix issues and refactor
chimp1984 Sep 16, 2020
996364e
Cleanup
chimp1984 Sep 16, 2020
4115c0c
Add data from non-splitStoreService as well
chimp1984 Sep 16, 2020
ad95019
Merge branch 'master_upstream' into chimp-reduce_initial_request_size
chimp1984 Sep 17, 2020
e680c4d
Merge branch 'master_upstream' into chimp-reduce_initial_request_size
chimp1984 Sep 19, 2020
80bf8bf
Merge branch 'master_upstream' into chimp-reduce_initial_request_size
chimp1984 Sep 27, 2020
3a4784e
Merge branch 'chimp-reduce_initial_request_size' of https://github.co…
chimp1984 Sep 27, 2020
c482a1b
Cleanups, renaming, add comments
chimp1984 Sep 27, 2020
ba0dc1b
Fix mock class to reflect real class better.
chimp1984 Sep 28, 2020
f132a35
Fix incorrect test.
chimp1984 Sep 28, 2020
6eb1efb
Remove todo, add system line break
chimp1984 Sep 28, 2020
ee725bc
Add more logs
chimp1984 Sep 28, 2020
82c5b5e
Add isEmpty check
chimp1984 Sep 29, 2020
171be24
Do not call super.readFromResources(postFix); as we do not have a no…
chimp1984 Sep 29, 2020
bd38097
Add more logs
chimp1984 Sep 29, 2020
0feece6
Remove toProtoNetworkEnvelope call used only for debug logs
chimp1984 Sep 29, 2020
e402c8a
Only call pruneStore if we have created a new historical store from r…
chimp1984 Sep 29, 2020
620dfca
Fix wrong param order in log
chimp1984 Sep 29, 2020
90da37f
Remove dev test data
chimp1984 Sep 29, 2020
9240eec
Add more info in log
chimp1984 Sep 29, 2020
ab82286
Rename SplitStoreService to HistoricalDataStoreService
chimp1984 Sep 29, 2020
f2cc5a6
Merge branch 'master_upstream' into wip-merge
chimp1984 Oct 1, 2020
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
10 changes: 9 additions & 1 deletion common/src/main/java/bisq/common/app/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package bisq.common.app;

import java.util.Arrays;
import java.util.List;

import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkArgument;
Expand All @@ -29,6 +32,11 @@ public class Version {
// We use semantic versioning with major, minor and patch
public static final String VERSION = "1.3.9";

/**
* Holds a list of the versions of tagged resource files for optimizing the getData requests.
*/
public static final List<String> HISTORY = Arrays.asList("1.4.0");

public static int getMajorVersion(String version) {
return getSubVersion(version, 0);
}
Expand All @@ -45,7 +53,7 @@ public static boolean isNewVersion(String newVersion) {
return isNewVersion(newVersion, VERSION);
}

static boolean isNewVersion(String newVersion, String currentVersion) {
public static boolean isNewVersion(String newVersion, String currentVersion) {
if (newVersion.equals(currentVersion))
return false;
else if (getMajorVersion(newVersion) > getMajorVersion(currentVersion))
Expand Down
11 changes: 8 additions & 3 deletions common/src/main/java/bisq/common/storage/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@ public Storage(@Named(Config.STORAGE_DIR) File dir,
this.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler;
}

@Nullable
public T getPersisted(String fileName) {
return getPersisted(new File(dir, fileName));
}

@Nullable
public T initAndGetPersistedWithFileName(String fileName, long delay) {
this.fileName = fileName;
storageFile = new File(dir, fileName);
fileManager = new FileManager<>(dir, storageFile, delay, persistenceProtoResolver);
return getPersisted();
return getPersisted(storageFile);
}

@Nullable
Expand All @@ -96,7 +101,7 @@ public T initAndGetPersisted(T persistable, String fileName, long delay) {
this.fileName = fileName;
storageFile = new File(dir, fileName);
fileManager = new FileManager<>(dir, storageFile, delay, persistenceProtoResolver);
return getPersisted();
return getPersisted(storageFile);
}

public void queueUpForSave() {
Expand Down Expand Up @@ -144,7 +149,7 @@ public void remove(String fileName) {
// We do the file read on the UI thread to avoid problems from multi threading.
// Data are small and read is done only at startup, so it is no performance issue.
@Nullable
private T getPersisted() {
private T getPersisted(File storageFile) {
if (storageFile.exists()) {
long now = System.currentTimeMillis();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import bisq.common.config.Config;
import bisq.common.storage.Storage;

import javax.inject.Named;
import javax.inject.Inject;
import javax.inject.Named;

import java.io.File;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@


import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;

import bisq.common.proto.persistable.ThreadedPersistableEnvelope;
import bisq.network.p2p.storage.persistence.PersistableNetworkPayloadStore;

import com.google.protobuf.Message;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;


Expand All @@ -40,9 +35,7 @@
* definition and provide a hashMap for the domain access.
*/
@Slf4j
public class SignedWitnessStore implements ThreadedPersistableEnvelope {
@Getter
private Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = new ConcurrentHashMap<>();
public class SignedWitnessStore extends PersistableNetworkPayloadStore {

SignedWitnessStore() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import bisq.common.config.Config;
import bisq.common.storage.Storage;

import javax.inject.Named;
import javax.inject.Inject;
import javax.inject.Named;

import java.io.File;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
package bisq.core.account.witness;

import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;

import bisq.common.proto.persistable.ThreadedPersistableEnvelope;
import bisq.network.p2p.storage.persistence.PersistableNetworkPayloadStore;

import com.google.protobuf.Message;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;


Expand All @@ -39,9 +34,7 @@
* definition and provide a hashMap for the domain access.
*/
@Slf4j
public class AccountAgeWitnessStore implements ThreadedPersistableEnvelope {
@Getter
private Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = new ConcurrentHashMap<>();
public class AccountAgeWitnessStore extends PersistableNetworkPayloadStore {

AccountAgeWitnessStore() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
package bisq.core.dao.governance.blindvote.storage;

import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;

import bisq.common.proto.persistable.ThreadedPersistableEnvelope;
import bisq.network.p2p.storage.persistence.PersistableNetworkPayloadStore;

import com.google.protobuf.Message;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;


Expand All @@ -39,9 +34,7 @@
* definition and provide a hashMap for the domain access.
*/
@Slf4j
public class BlindVoteStore implements ThreadedPersistableEnvelope {
@Getter
private Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = new ConcurrentHashMap<>();
public class BlindVoteStore extends PersistableNetworkPayloadStore {

BlindVoteStore() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ private void fillListFromProtectedStore() {
p2PService.getDataMap().values().forEach(e -> onProtectedDataAdded(e, false));
}

//todo use proposalStorageService
private void fillListFromAppendOnlyDataStore() {
p2PService.getP2PDataStorage().getAppendOnlyDataStoreMap().values().forEach(e -> onAppendOnlyDataAdded(e, false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
package bisq.core.dao.governance.proposal.storage.appendonly;

import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;

import bisq.common.proto.persistable.ThreadedPersistableEnvelope;
import bisq.network.p2p.storage.persistence.PersistableNetworkPayloadStore;

import com.google.protobuf.Message;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;


Expand All @@ -39,9 +34,7 @@
* definition and provide a hashMap for the domain access.
*/
@Slf4j
public class ProposalStore implements ThreadedPersistableEnvelope {
@Getter
private Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = new ConcurrentHashMap<>();
public class ProposalStore extends PersistableNetworkPayloadStore {

ProposalStore() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ public void applyBannedNodes(@Nullable List<String> bannedNodes) {
fillProviderList();
selectNextProviderBaseUrl();

if (bannedNodes == null)
if (bannedNodes == null) {
log.info("Selected provider baseUrl={}, providerList={}", baseUrl, providerList);
else
} else if (!bannedNodes.isEmpty()) {
log.warn("We have banned provider nodes: bannedNodes={}, selected provider baseUrl={}, providerList={}",
bannedNodes, baseUrl, providerList);
}
}

public void selectNextProviderBaseUrl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ public Map<NodeAddress, T> getDisputeAgents() {
} else {
bannedDisputeAgents = null;
}
if (bannedDisputeAgents != null)

if (bannedDisputeAgents != null && !bannedDisputeAgents.isEmpty()) {
log.warn("bannedDisputeAgents=" + bannedDisputeAgents);
}

Set<T> disputeAgentSet = getDisputeAgentSet(bannedDisputeAgents);

Map<NodeAddress, T> map = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,21 @@

package bisq.core.trade.statistics;

import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;
import bisq.network.p2p.storage.persistence.MapStoreService;
import bisq.network.p2p.storage.persistence.HistoricalDataStoreService;

import bisq.common.config.Config;
import bisq.common.storage.Storage;

import javax.inject.Named;

import javax.inject.Inject;
import javax.inject.Named;

import java.io.File;

import java.util.Map;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TradeStatistics2StorageService extends MapStoreService<TradeStatistics2Store, PersistableNetworkPayload> {
public class TradeStatistics2StorageService extends HistoricalDataStoreService<TradeStatistics2Store> {
private static final String FILE_NAME = "TradeStatistics2Store";


Expand All @@ -59,11 +55,6 @@ public String getFileName() {
return FILE_NAME;
}

@Override
public Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> getMap() {
return store.getMap();
}

@Override
public boolean canHandle(PersistableNetworkPayload payload) {
return payload instanceof TradeStatistics2;
Expand All @@ -78,9 +69,4 @@ public boolean canHandle(PersistableNetworkPayload payload) {
protected TradeStatistics2Store createStore() {
return new TradeStatistics2Store();
}

@Override
protected void readStore() {
super.readStore();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
package bisq.core.trade.statistics;

import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;

import bisq.common.proto.persistable.ThreadedPersistableEnvelope;
import bisq.network.p2p.storage.persistence.PersistableNetworkPayloadStore;

import com.google.protobuf.Message;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
Expand All @@ -38,9 +33,7 @@
* definition and provide a hashMap for the domain access.
*/
@Slf4j
public class TradeStatistics2Store implements ThreadedPersistableEnvelope {
@Getter
private final Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = new ConcurrentHashMap<>();
public class TradeStatistics2Store extends PersistableNetworkPayloadStore {

TradeStatistics2Store() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public void onAllServicesInitialized() {
addToSet((TradeStatistics2) payload);
});

Set<TradeStatistics2> collect = tradeStatistics2StorageService.getMap().values().stream()
Set<TradeStatistics2> set = tradeStatistics2StorageService.getMapOfAllData().values().stream()
.filter(e -> e instanceof TradeStatistics2)
.map(e -> (TradeStatistics2) e)
.map(WrapperTradeStatistics2::new)
.distinct()
.map(WrapperTradeStatistics2::unwrap)
.filter(TradeStatistics2::isValid)
.collect(Collectors.toSet());
observableTradeStatisticsSet.addAll(collect);
observableTradeStatisticsSet.addAll(set);

priceFeedService.applyLatestBisqMarketPrice(observableTradeStatisticsSet);

Expand All @@ -99,7 +99,6 @@ public ObservableSet<TradeStatistics2> getObservableTradeStatisticsSet() {
}

private void addToSet(TradeStatistics2 tradeStatistics) {

if (!observableTradeStatisticsSet.contains(tradeStatistics)) {
Optional<TradeStatistics2> duplicate = observableTradeStatisticsSet.stream().filter(
e -> e.getOfferId().equals(tradeStatistics.getOfferId())).findAny();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ public void handle(GetDataRequest getDataRequest, final Connection connection) {
.map(e -> "node address " + e.getFullAddress())
.orElseGet(() -> "connection UID " + connection.getUid());

AtomicBoolean outPersistableNetworkPayloadOutputTruncated = new AtomicBoolean(false);
AtomicBoolean outProtectedStoragePayloadOutputTruncated = new AtomicBoolean(false);
AtomicBoolean wasPersistableNetworkPayloadsTruncated = new AtomicBoolean(false);
AtomicBoolean wasProtectedStorageEntriesTruncated = new AtomicBoolean(false);
GetDataResponse getDataResponse = dataStorage.buildGetDataResponse(
getDataRequest,
MAX_ENTRIES,
outPersistableNetworkPayloadOutputTruncated,
outProtectedStoragePayloadOutputTruncated,
wasPersistableNetworkPayloadsTruncated,
wasProtectedStorageEntriesTruncated,
connection.getCapabilities());

if (outPersistableNetworkPayloadOutputTruncated.get()) {
if (wasPersistableNetworkPayloadsTruncated.get()) {
log.warn("The getData request from peer with {} caused too much PersistableNetworkPayload " +
"entries to get delivered. We limited the entries for the response to {} entries",
connectionInfo, MAX_ENTRIES);
}

if (outProtectedStoragePayloadOutputTruncated.get()) {
if (wasProtectedStorageEntriesTruncated.get()) {
log.warn("The getData request from peer with {} caused too much ProtectedStorageEntry " +
"entries to get delivered. We limited the entries for the response to {} entries",
connectionInfo, MAX_ENTRIES);
Expand Down
Loading