From: Simon Brandhof Date: Thu, 18 Apr 2013 09:08:51 +0000 (+0200) Subject: SONAR-3755 use Persistit temporary volume X-Git-Tag: 3.6~641 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=46ccee9163fa252b757a09078e79012b1bf07d5e;p=sonarqube.git SONAR-3755 use Persistit temporary volume --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/Caches.java b/sonar-batch/src/main/java/org/sonar/batch/index/Caches.java index d027e30e1b4..ff747945ad0 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/Caches.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/Caches.java @@ -24,6 +24,7 @@ import com.google.common.collect.Sets; import com.google.common.io.Files; import com.persistit.Exchange; import com.persistit.Persistit; +import com.persistit.Volume; import com.persistit.exception.PersistitException; import com.persistit.logging.Slf4jAdapter; import org.apache.commons.io.FileUtils; @@ -46,12 +47,13 @@ public class Caches implements BatchComponent, Startable { private final Set cacheNames = Sets.newHashSet(); private File tempDir; private Persistit persistit; + private Volume volume; public Cache createCache(String cacheName) { + Preconditions.checkState(volume != null && volume.isOpened(), "Caches are not started"); Preconditions.checkState(!cacheNames.contains(cacheName), "Cache is already created: " + cacheName); - try { - Exchange exchange = persistit.getExchange("sonar-scan", cacheName, true); + Exchange exchange = persistit.getExchange(volume, cacheName, true); Cache cache = new Cache(cacheName, exchange); cacheNames.add(cacheName); return cache; @@ -68,15 +70,15 @@ public class Caches implements BatchComponent, Startable { persistit.setPersistitLogger(new Slf4jAdapter(LoggerFactory.getLogger("PERSISTIT"))); Properties props = new Properties(); props.setProperty("datapath", tempDir.getAbsolutePath()); + props.setProperty("logpath", "${datapath}/log"); + props.setProperty("logfile", "${logpath}/persistit_${timestamp}.log"); props.setProperty("buffer.count.8192", "10"); - props.setProperty("logfile", "${datapath}/persistit.log"); - props.setProperty("volume.1", "${datapath}/sonar-scan,create,pageSize:8192,initialSize:1M,extensionSize:1M,maximumSize:10G"); props.setProperty("journalpath", "${datapath}/journal"); + props.setProperty("tmpvoldir", "${datapath}"); + props.setProperty("volume.1", "${datapath}/persistit,create,pageSize:8192,initialPages:10,extensionPages:100,maximumPages:25000"); persistit.setProperties(props); persistit.initialize(); - - // TODO should use persistit#createTemporaryVolume(), but how ? - // See https://github.com/akiban/persistit/blob/master/doc/Miscellaneous.rst + volume = persistit.createTemporaryVolume(); } catch (Exception e) { throw new IllegalStateException("Fail to start caches", e); @@ -89,6 +91,7 @@ public class Caches implements BatchComponent, Startable { try { persistit.close(false); persistit = null; + volume = null; } catch (PersistitException e) { throw new IllegalStateException("Fail to close caches", e); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/CachesTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/CachesTest.java index 2471bb76c71..75c422c1617 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/CachesTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/CachesTest.java @@ -74,6 +74,16 @@ public class CachesTest { } } + @Test + public void should_not_create_cache_before_starting() { + try { + caches.createCache("too_early"); + fail(); + } catch (IllegalStateException e) { + assertThat(e).hasMessage("Caches are not started"); + } + } + static class Element implements Serializable { }