Merge pull request #3150 from wiz/update-datastore

Update data storage on expired data removal
This commit is contained in:
Christoph Atteneder 2019-08-28 09:43:20 +02:00 committed by GitHub
commit cbbd1a0bf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -201,8 +201,10 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
// Batch processing can cause performance issues, so we give listeners a chance to deal with it by notifying
// about start and end of iteration.
hashMapChangedListeners.forEach(HashMapChangedListener::onBatchRemoveExpiredDataStarted);
toRemoveSet.forEach(protectedDataToRemove -> hashMapChangedListeners.forEach(
listener -> listener.onRemoved(protectedDataToRemove)));
toRemoveSet.forEach(protectedStorageEntry -> {
hashMapChangedListeners.forEach(l -> l.onRemoved(protectedStorageEntry));
removeFromProtectedDataStore(protectedStorageEntry);
});
hashMapChangedListeners.forEach(HashMapChangedListener::onBatchRemoveExpiredDataCompleted);
if (sequenceNumberMap.size() > 1000)
@ -483,21 +485,26 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
broadcast(new RemoveDataMessage(protectedStorageEntry), sender, null, isDataOwner);
if (protectedStoragePayload instanceof PersistablePayload) {
ByteArray compactHash = getCompactHashAsByteArray(protectedStoragePayload);
ProtectedStorageEntry previous = protectedDataStoreService.remove(compactHash, protectedStorageEntry);
if (previous != null) {
protectedDataStoreListeners.forEach(e -> e.onRemoved(protectedStorageEntry));
} else {
log.info("We cannot remove the protectedStorageEntry from the persistedEntryMap as it does not exist.");
}
}
removeFromProtectedDataStore(protectedStorageEntry);
} else {
log.debug("remove failed");
}
return result;
}
private void removeFromProtectedDataStore(ProtectedStorageEntry protectedStorageEntry) {
ProtectedStoragePayload protectedStoragePayload = protectedStorageEntry.getProtectedStoragePayload();
if (protectedStoragePayload instanceof PersistablePayload) {
ByteArray compactHash = getCompactHashAsByteArray(protectedStoragePayload);
ProtectedStorageEntry previous = protectedDataStoreService.remove(compactHash, protectedStorageEntry);
if (previous != null) {
protectedDataStoreListeners.forEach(e -> e.onRemoved(protectedStorageEntry));
} else {
log.info("We cannot remove the protectedStorageEntry from the persistedEntryMap as it does not exist.");
}
}
}
@SuppressWarnings("UnusedReturnValue")
public boolean removeMailboxData(ProtectedMailboxStorageEntry protectedMailboxStorageEntry, @Nullable NodeAddress sender, boolean isDataOwner) {
ByteArray hashOfData = get32ByteHashAsByteArray(protectedMailboxStorageEntry.getProtectedStoragePayload());