Skip to content

Commit

Permalink
ISPN-12787 Non-transactional cache needs to be invalidated after comm…
Browse files Browse the repository at this point in the history
…it on JPQL update/delete operation
  • Loading branch information
wburns authored and tristantarrant committed Mar 31, 2021
1 parent d67ee7a commit dea8ab9
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ boolean update(Object session, Object key, Object value, Object currentVersion,
*/
void remove(Object session, Object key) throws CacheException;

/**
* Called just before the delegate will have all entries removed. Any work to prevent concurrent modifications
* while this occurs should happen here
* @throws CacheException if locking had an issue
*/
void lockAll() throws CacheException;

/**
* Called just after the delegate had all entries removed via {@link #removeAll()}. Any work required to allow
* for new modifications to happen should be done here
* @throws CacheException if unlocking had an issue
*/
void unlockAll() throws CacheException;

/**
* Called to evict data from the entire region
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,22 @@ public void remove(Object session, Object key) throws CacheException {
}

@Override
public void removeAll() throws CacheException {
try {
if (!putValidator.beginInvalidatingRegion()) {
log.failedInvalidateRegion(region.getName());
}
Caches.removeAll(cache);
}
finally {
putValidator.endInvalidatingRegion();
public void lockAll() throws CacheException {
if (!putValidator.beginInvalidatingRegion()) {
log.failedInvalidateRegion(region.getName());
}
}

@Override
public void unlockAll() throws CacheException {
putValidator.endInvalidatingRegion();
}

@Override
public void removeAll() throws CacheException {
Caches.removeAll(cache);
}

@Override
public void evict(Object key) throws CacheException {
writeCache.remove( key );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,18 @@ public void remove(Object session, Object key) throws CacheException {
}

@Override
public void removeAll() throws CacheException {
public void lockAll() throws CacheException {
region.beginInvalidation();
try {
Caches.broadcastEvictAll(cache);
}
finally {
region.endInvalidation();
}
}

@Override
public void unlockAll() throws CacheException {
region.endInvalidation();
}

@Override
public void removeAll() throws CacheException {
Caches.broadcastEvictAll(cache);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,7 @@ public boolean afterUpdate(Object session, Object key, Object value, Object curr

@Override
public void removeAll() throws CacheException {
try {
if (!putValidator.beginInvalidatingRegion()) {
log.failedInvalidateRegion(region.getName());
}
cache.clear();
}
finally {
putValidator.endInvalidatingRegion();
}
cache.clear();
}

protected void registerLocalInvalidation(Object session, Object lockOwner, Object key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ public boolean beginInvalidatingRegion() {
// removed from the cache and now the DB is about to be updated).
for (Iterator<PendingPutMap> it = pendingPuts.values().iterator(); it.hasNext(); ) {
PendingPutMap entry = it.next();
it.remove();
if (entry.acquireLock(60, TimeUnit.SECONDS)) {
try {
entry.invalidate(now);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,18 @@ protected void write(Object session, Object key, Object value) {
}

@Override
public void removeAll() throws CacheException {
public void lockAll() throws CacheException {
region.beginInvalidation();
try {
Caches.broadcastEvictAll(cache);
}
finally {
region.endInvalidation();
}
}

@Override
public void unlockAll() throws CacheException {
region.endInvalidation();
}

@Override
public void removeAll() throws CacheException {
Caches.broadcastEvictAll(cache);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @author Radim Vansa &lt;rvansa@redhat.com&gt;
*/
public class InvalidationTest extends SingleNodeTest {
static final InfinispanMessageLogger log = InfinispanMessageLogger.Provider.getLog(ReadOnlyTest.class);
static final InfinispanMessageLogger log = InfinispanMessageLogger.Provider.getLog(InvalidationTest.class);

@Override
public List<Object[]> getParameters() {
Expand Down Expand Up @@ -149,7 +149,12 @@ public void testConcurrentRemoveAndPutFromLoad() throws Exception {
});
}

protected AdvancedCache getPendingPutsCache(Class<Item> entityClazz) {
protected AdvancedCache getSecondLevelCache(Class<?> entityClazz) {
InfinispanBaseRegion region = TEST_SESSION_ACCESS.getRegion(sessionFactory(), entityClazz.getName());
return region.getCache();
}

protected AdvancedCache getPendingPutsCache(Class<?> entityClazz) {
InfinispanBaseRegion region = TEST_SESSION_ACCESS.getRegion(sessionFactory(), entityClazz.getName());
AdvancedCache entityCache = region.getCache();
return entityCache.getCacheManager().getCache(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ public void removeAll() throws CacheException {
}

public SoftLock lockRegion() throws CacheException {
delegate.lockAll();
return null;
}

public void unlockRegion(SoftLock lock) throws CacheException {
delegate.unlockAll();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ public void removeAll(SharedSessionContractImplementor session) throws CacheExce
}

public SoftLock lockRegion() throws CacheException {
delegate.lockAll();
return null;
}

public void unlockRegion(SoftLock lock) throws CacheException {
delegate.unlockAll();
}

public AccessType getAccessType() {
Expand Down

0 comments on commit dea8ab9

Please sign in to comment.