-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: EDR refresh Synchronization (#1648)
* fix: Synchronize EDR refresh (#1633) * Failing test and added code to make it pass * Created module for EdrLockSql and added statements * alter test to check for correct response * remove debug messages * Introduce InMemoryEdrLock * working version * improve test for two different edrs. * code dup * refactor inmem acquireLock * handle * handle2 * refactor in mem EDR lock * update EdrServiceImpl to enable force refresh * Remove non existing job from verify.yaml * Add ComponentTests * fix failing uts * Removes global lock in inmem variant * inmem release lock should be atomic * retrigger CI * retrigger CI * updates due to edc 0.10.0 * Trigger CI * Trigger CI
- Loading branch information
1 parent
3824629
commit 03df535
Showing
22 changed files
with
1,178 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...src/main/java/org/eclipse/tractusx/edc/edr/core/lock/DefaultEdrLockProviderExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.eclipse.tractusx.edc.edr.core.lock; | ||
|
||
import org.eclipse.edc.edr.spi.store.EndpointDataReferenceEntryIndex; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Extension; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Inject; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Provider; | ||
import org.eclipse.edc.spi.system.ServiceExtension; | ||
import org.eclipse.edc.transaction.spi.TransactionContext; | ||
import org.eclipse.tractusx.edc.edr.spi.index.lock.EndpointDataReferenceLock; | ||
|
||
@Extension("Provides A Default EdrLock Provider") | ||
public class DefaultEdrLockProviderExtension implements ServiceExtension { | ||
|
||
@Inject | ||
EndpointDataReferenceEntryIndex entryIndex; | ||
|
||
@Inject | ||
TransactionContext transactionContext; | ||
|
||
@Provider(isDefault = true) | ||
public EndpointDataReferenceLock createInMemoryEdrLock() { | ||
return new InMemoryEdrLock(entryIndex, transactionContext); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
core/edr-core/src/main/java/org/eclipse/tractusx/edc/edr/core/lock/InMemoryEdrLock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.eclipse.tractusx.edc.edr.core.lock; | ||
|
||
import org.eclipse.edc.edr.spi.store.EndpointDataReferenceEntryIndex; | ||
import org.eclipse.edc.spi.result.StoreResult; | ||
import org.eclipse.edc.spi.types.domain.DataAddress; | ||
import org.eclipse.edc.transaction.spi.TransactionContext; | ||
import org.eclipse.tractusx.edc.edr.spi.index.lock.EndpointDataReferenceLock; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
|
||
|
||
public class InMemoryEdrLock implements EndpointDataReferenceLock { | ||
|
||
private final EndpointDataReferenceEntryIndex entryIndex; | ||
private final TransactionContext transactionContext; | ||
private final Map<String, ReentrantReadWriteLock> lockedEdrs = new ConcurrentHashMap<>(); | ||
|
||
public InMemoryEdrLock(EndpointDataReferenceEntryIndex entryIndex, TransactionContext transactionContext) { | ||
this.entryIndex = entryIndex; | ||
this.transactionContext = transactionContext; | ||
} | ||
|
||
@Override | ||
public StoreResult<Boolean> acquireLock(String edrId, DataAddress edr) { | ||
|
||
var rowLock = lockedEdrs.computeIfAbsent(edrId, k -> new ReentrantReadWriteLock()); | ||
|
||
rowLock.writeLock().lock(); // this lock synchronizes row-level access | ||
|
||
var edrEntry = transactionContext.execute(() -> entryIndex.findById(edrId)); | ||
|
||
return StoreResult.success(isExpired(edr, edrEntry)); | ||
|
||
} | ||
|
||
|
||
@Override | ||
public StoreResult<Void> releaseLock(String edrId) { | ||
|
||
lockedEdrs.computeIfPresent(edrId, (k, rowLock) -> { | ||
if (rowLock.writeLock().isHeldByCurrentThread()) { | ||
rowLock.writeLock().unlock(); | ||
if (!rowLock.hasQueuedThreads()) { | ||
return null; | ||
} | ||
} | ||
return rowLock; | ||
}); | ||
|
||
return StoreResult.success(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
core/edr-core/src/test/java/org/eclipse/tractusx/edc/edr/core/lock/InMemoryEdrLockTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.eclipse.tractusx.edc.edr.core.lock; | ||
|
||
import org.eclipse.edc.edr.store.defaults.InMemoryEndpointDataReferenceEntryIndex; | ||
import org.eclipse.edc.junit.annotations.ComponentTest; | ||
import org.eclipse.edc.query.CriterionOperatorRegistryImpl; | ||
import org.eclipse.edc.transaction.spi.NoopTransactionContext; | ||
import org.eclipse.edc.transaction.spi.TransactionContext; | ||
import org.eclipse.tractusx.edc.edr.spi.index.lock.EndpointDataReferenceLock; | ||
import org.eclipse.tractusx.edc.edr.spi.testfixtures.index.lock.EndpointDataReferenceLockBaseTest; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
|
||
@ComponentTest | ||
class InMemoryEdrLockTest extends EndpointDataReferenceLockBaseTest { | ||
|
||
private InMemoryEdrLock edrLock; | ||
private final TransactionContext transactionContext = new NoopTransactionContext(); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
var entryIndex = new InMemoryEndpointDataReferenceEntryIndex(CriterionOperatorRegistryImpl.ofDefaults()); | ||
edrLock = new InMemoryEdrLock(entryIndex, transactionContext); | ||
entryIndex.save(edrEntry("mock", ACQUIRE_LOCK_TP)); | ||
} | ||
|
||
@Override | ||
protected EndpointDataReferenceLock getStore() { | ||
return edrLock; | ||
} | ||
} |
Oops, something went wrong.