diff options
author | Edwin Kempin <edwin.kempin@sap.com> | 2012-10-16 16:32:49 +0200 |
---|---|---|
committer | Edwin Kempin <edwin.kempin@sap.com> | 2012-10-16 16:46:14 +0200 |
commit | 3f461de64e73917ef814a407bc5c4a7c35127e67 (patch) | |
tree | c88e6a6b2411fbf22fc99e7058fc2ccea4fe5fa5 /gerrit-cache-h2 | |
parent | f77e9a9109b2bdd21991e5d5c53953434bef5d83 (diff) |
Flush persistent H2 cache if the existing entries are incompatible
Some caches (e.g. 'diff_intraline') are peristent so that the entries
survive a Gerrit restart (e.g. because the entries are expensive to
compute). To persist the cache entries Java serialization is used. If
now a class for a cache entry is changed and its serialVersionUID is
updated, already peristent cache entries cannot be deserialized anymore
since their class is incompatible with the new cache entry class.
Flush the cache if incompatible cache entries are detected.
E.g. commit 2424a8a9d595c87106db51da5867ed417eb8a2f5 changed a cache
entry class and as result the existing entries of the 'diff_intraline'
cache could not be loaded anymore, which caused an exception on each
Gerrit startup and when trying to access one of these cached entries.
To get rid of these exeptions the Gerrit administrator had to manually
flush the cache.
Change-Id: Ia158855d983d51335ae2a4df2b73d6c14fc612f0
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
Diffstat (limited to 'gerrit-cache-h2')
-rw-r--r-- | gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheImpl.java | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheImpl.java b/gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheImpl.java index a5bdacc77b..4a44348167 100644 --- a/gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheImpl.java +++ b/gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheImpl.java @@ -13,10 +13,12 @@ import com.google.common.hash.Funnels; import com.google.common.hash.PrimitiveSink; import com.google.inject.TypeLiteral; +import org.h2.jdbc.JdbcSQLException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; +import java.io.InvalidClassException; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.sql.Connection; @@ -390,6 +392,15 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> { while (r.next()) { b.put(keyType.get(r, 1)); } + } catch (JdbcSQLException e) { + if (e.getCause() instanceof InvalidClassException) { + log.warn("Entries cached for " + url + + " have an incompatible class and can't be deserialized. " + + "Cache is flushed."); + invalidateAll(); + } else { + throw e; + } } finally { r.close(); } |