concurrency

This commit is contained in:
Bill Burke 2016-02-09 22:13:55 -05:00
parent 45e5cfac99
commit 0b54838f31
3 changed files with 20 additions and 22 deletions

View file

@ -211,11 +211,12 @@ public class RevisionedCacheRealmProvider implements CacheRealmProvider {
logger.tracev("by id cache hit: {0}", cached.getName()); logger.tracev("by id cache hit: {0}", cached.getName());
} }
if (cached == null) { if (cached == null) {
Long loaded = cache.getCurrentRevision(id); Long loaded = UpdateCounter.current();
RealmModel model = getDelegate().getRealm(id); RealmModel model = getDelegate().getRealm(id);
if (model == null) return null; if (model == null) return null;
if (realmInvalidations.contains(id)) return model; if (realmInvalidations.contains(id)) return model;
cached = new RevisionedCachedRealm(loaded, cache, this, model); cached = new RevisionedCachedRealm(loaded, cache, this, model);
logger.tracev("try caching realm: {0} {1}", cached.getName(), loaded);
cache.addCachedRealm(cached); cache.addCachedRealm(cached);
} else if (realmInvalidations.contains(id)) { } else if (realmInvalidations.contains(id)) {
return getDelegate().getRealm(id); return getDelegate().getRealm(id);
@ -234,10 +235,12 @@ public class RevisionedCacheRealmProvider implements CacheRealmProvider {
logger.tracev("by name cache hit: {0}", cached.getName()); logger.tracev("by name cache hit: {0}", cached.getName());
} }
if (cached == null) { if (cached == null) {
Long loaded = UpdateCounter.current();
RealmModel model = getDelegate().getRealmByName(name); RealmModel model = getDelegate().getRealmByName(name);
if (model == null) return null; if (model == null) return null;
if (realmInvalidations.contains(model.getId())) return model; if (realmInvalidations.contains(model.getId())) return model;
cached = new RevisionedCachedRealm(null, cache, this, model); cached = new RevisionedCachedRealm(loaded, cache, this, model);
logger.tracev("try caching realm: {0}", cached.getName());
cache.addCachedRealm(cached); cache.addCachedRealm(cached);
} else if (realmInvalidations.contains(cached.getId())) { } else if (realmInvalidations.contains(cached.getId())) {
return getDelegate().getRealmByName(name); return getDelegate().getRealmByName(name);
@ -299,7 +302,7 @@ public class RevisionedCacheRealmProvider implements CacheRealmProvider {
} }
if (cached == null) { if (cached == null) {
Long loaded = cache.getCurrentRevision(id); Long loaded = UpdateCounter.current();
RoleModel model = getDelegate().getRoleById(id, realm); RoleModel model = getDelegate().getRoleById(id, realm);
if (model == null) return null; if (model == null) return null;
if (roleInvalidations.contains(id)) return model; if (roleInvalidations.contains(id)) return model;
@ -328,7 +331,7 @@ public class RevisionedCacheRealmProvider implements CacheRealmProvider {
} }
if (cached == null) { if (cached == null) {
Long loaded = cache.getCurrentRevision(id); Long loaded = UpdateCounter.current();
GroupModel model = getDelegate().getGroupById(id, realm); GroupModel model = getDelegate().getGroupById(id, realm);
if (model == null) return null; if (model == null) return null;
if (groupInvalidations.contains(id)) return model; if (groupInvalidations.contains(id)) return model;
@ -356,7 +359,7 @@ public class RevisionedCacheRealmProvider implements CacheRealmProvider {
} }
if (cached == null) { if (cached == null) {
Long loaded = cache.getCurrentRevision(id); Long loaded = UpdateCounter.current();
ClientModel model = getDelegate().getClientById(id, realm); ClientModel model = getDelegate().getClientById(id, realm);
if (model == null) return null; if (model == null) return null;
if (appInvalidations.contains(id)) return model; if (appInvalidations.contains(id)) return model;
@ -379,7 +382,7 @@ public class RevisionedCacheRealmProvider implements CacheRealmProvider {
} }
if (cached == null) { if (cached == null) {
Long loaded = cache.getCurrentRevision(id); Long loaded = UpdateCounter.current();
ClientTemplateModel model = getDelegate().getClientTemplateById(id, realm); ClientTemplateModel model = getDelegate().getClientTemplateById(id, realm);
if (model == null) return null; if (model == null) return null;
if (clientTemplateInvalidations.contains(id)) return model; if (clientTemplateInvalidations.contains(id)) return model;

View file

@ -51,11 +51,6 @@ public class RevisionedRealmCache implements RealmCache {
return cache; return cache;
} }
public Long getCurrentRevision(String id) {
//return revisions.get(id);
return UpdateCounter.current();
}
private <T> T get(String id, Class<T> type) { private <T> T get(String id, Class<T> type) {
Revisioned o = (Revisioned)cache.get(id); Revisioned o = (Revisioned)cache.get(id);
if (o == null) { if (o == null) {
@ -83,13 +78,13 @@ public class RevisionedRealmCache implements RealmCache {
protected void addRevisioned(String id, Revisioned object) { protected void addRevisioned(String id, Revisioned object) {
Long rev = revisions.get(id); Long rev = revisions.get(id);
if (rev == null) { if (rev == null) {
logger.tracev("rev was null in addRevisioned, adding one");
rev = UpdateCounter.next(); rev = UpdateCounter.next();
revisions.put(id, rev); revisions.put(id, rev);
return;
} }
if (rev.equals(object.getRevision())) {
cache.putForExternalRead(id, object); cache.putForExternalRead(id, object);
} }
}

View file

@ -32,13 +32,6 @@
} }
}, },
"realmCache": {
"provider": "infinispan-revisioned",
"infinispan-locking" : {
"enabled": true
}
},
"timer": { "timer": {
"provider": "basic" "provider": "basic"
}, },
@ -85,8 +78,15 @@
} }
}, },
"realmCache": {
"provider": "infinispan-locking",
"infinispan-locking" : {
"enabled": true
}
},
"connectionsInfinispan": { "connectionsInfinispan": {
"provider": "revisioned", "provider": "locking",
"locking": { "locking": {
"clustered": "${keycloak.connectionsInfinispan.clustered:false}", "clustered": "${keycloak.connectionsInfinispan.clustered:false}",
"async": "${keycloak.connectionsInfinispan.async:true}", "async": "${keycloak.connectionsInfinispan.async:true}",