activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1235427 - in /activemq/activemq-apollo/trunk: apollo-bdb/src/main/scala/org/apache/activemq/apollo/broker/store/bdb/ apollo-leveldb/src/main/scala/org/apache/activemq/apollo/broker/store/leveldb/leveldb/ apollo-stomp/src/test/resources/
Date Tue, 24 Jan 2012 19:21:05 GMT
Author: chirino
Date: Tue Jan 24 19:21:05 2012
New Revision: 1235427

URL: http://svn.apache.org/viewvc?rev=1235427&view=rev
Log:
Fixes APLO-131 - Stores should track "storage schema version number" to detect when the store
is incompatible with a new broker version.

Modified:
    activemq/activemq-apollo/trunk/apollo-bdb/src/main/scala/org/apache/activemq/apollo/broker/store/bdb/BDBClient.scala
    activemq/activemq-apollo/trunk/apollo-leveldb/src/main/scala/org/apache/activemq/apollo/broker/store/leveldb/leveldb/LevelDBClient.scala
    activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-bdb.xml
    activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-leveldb.xml

Modified: activemq/activemq-apollo/trunk/apollo-bdb/src/main/scala/org/apache/activemq/apollo/broker/store/bdb/BDBClient.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-bdb/src/main/scala/org/apache/activemq/apollo/broker/store/bdb/BDBClient.scala?rev=1235427&r1=1235426&r2=1235427&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-bdb/src/main/scala/org/apache/activemq/apollo/broker/store/bdb/BDBClient.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-bdb/src/main/scala/org/apache/activemq/apollo/broker/store/bdb/BDBClient.scala
Tue Jan 24 19:21:05 2012
@@ -26,8 +26,12 @@ import org.apache.activemq.apollo.util._
 import java.io.{InputStream, OutputStream}
 import com.sleepycat.je._
 import org.fusesource.hawtbuf.Buffer
+import FileSupport._
 
-object BDBClient extends Log
+object BDBClient extends Log {
+  final val STORE_SCHEMA_PREFIX = "bdb_store:"
+  final val STORE_SCHEMA_VERSION = 1
+}
 /**
  *
  * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
@@ -73,8 +77,26 @@ class BDBClient(store: BDBStore) {
 
     directory.mkdirs
 
-    direct_buffer_allocator = new FileDirectBufferAllocator(direct_buffer_file)
+    val version_file = directory / "store-version.txt"
+    if( version_file.exists( ) ) {
+      val ver = try {
+        var tmp: String = version_file.read_text().trim()
+        if( tmp.startsWith(STORE_SCHEMA_PREFIX) ) {
+          tmp.stripPrefix(STORE_SCHEMA_PREFIX).toInt
+        } else {
+          -1
+        }
+      } catch {
+        case e => throw new Exception("Unexpected version file format: "+version_file)
+      }
+      ver match {
+        case STORE_SCHEMA_VERSION => // All is good.
+        case _ => throw new Exception("Cannot open the store.  It's schema version is
not supported.")
+      }
+    }
+    version_file.write_text(STORE_SCHEMA_PREFIX+STORE_SCHEMA_VERSION)
 
+    direct_buffer_allocator = new FileDirectBufferAllocator(direct_buffer_file)
     environment = new Environment(directory, env_config);
 
     with_ctx() { ctx=>

Modified: activemq/activemq-apollo/trunk/apollo-leveldb/src/main/scala/org/apache/activemq/apollo/broker/store/leveldb/leveldb/LevelDBClient.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-leveldb/src/main/scala/org/apache/activemq/apollo/broker/store/leveldb/leveldb/LevelDBClient.scala?rev=1235427&r1=1235426&r2=1235427&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-leveldb/src/main/scala/org/apache/activemq/apollo/broker/store/leveldb/leveldb/LevelDBClient.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-leveldb/src/main/scala/org/apache/activemq/apollo/broker/store/leveldb/leveldb/LevelDBClient.scala
Tue Jan 24 19:21:05 2012
@@ -45,6 +45,9 @@ import org.fusesource.hawtbuf.{AsciiBuff
  */
 object LevelDBClient extends Log {
 
+  final val STORE_SCHEMA_PREFIX = "leveldb_store:"
+  final val STORE_SCHEMA_VERSION = 1
+
   final val queue_prefix = 'q'.toByte
   final val queue_entry_prefix = 'e'.toByte
   final val map_prefix = 'p'.toByte
@@ -228,6 +231,7 @@ class LevelDBClient(store: LevelDBStore)
   def start() = {
     import OptionSupport._
 
+
     val factory_names = Option(config.index_factory).getOrElse("org.fusesource.leveldbjni.JniDBFactory,
org.iq80.leveldb.impl.Iq80DBFactory")
     factory = factory_names.split("""(,|\s)+""").map(_.trim()).flatMap { name=>
       try {
@@ -279,7 +283,6 @@ class LevelDBClient(store: LevelDBStore)
     }
 
     lock_file = new LockFile(directory / "lock", true)
-
     def time[T](func: =>T):Long = {
       val start = System.nanoTime()
       func  
@@ -289,6 +292,26 @@ class LevelDBClient(store: LevelDBStore)
     // Lock before we open anything..
     lock_store
 
+    // Lets check store compatibility...
+    val version_file = directory / "store-version.txt"
+    if( version_file.exists( ) ) {
+      val ver = try {
+        var tmp: String = version_file.read_text().trim()
+        if( tmp.startsWith(STORE_SCHEMA_PREFIX) ) {
+          tmp.stripPrefix(STORE_SCHEMA_PREFIX).toInt
+        } else {
+          -1
+        }
+      } catch {
+        case e => throw new Exception("Unexpected version file format: "+version_file)
+      }
+      ver match {
+        case STORE_SCHEMA_VERSION => // All is good.
+        case _ => throw new Exception("Cannot open the store.  It's schema version is
not supported.")
+      }
+    }
+    version_file.write_text(STORE_SCHEMA_PREFIX+STORE_SCHEMA_VERSION)
+
     val log_open_duration = time {
       retry {
         log.open

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-bdb.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-bdb.xml?rev=1235427&r1=1235426&r2=1235427&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-bdb.xml (original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-bdb.xml Tue
Jan 24 19:21:05 2012
@@ -23,7 +23,7 @@
 
     <queue name="unified.**" unified="true"/>
 
-    <bdb_store directory="${basedir}/target/test-data"/>
+    <bdb_store directory="${basedir}/target/bdb-test-data"/>
   </virtual_host>
 
   <web_admin bind="http://127.0.0.1:0"/>

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-leveldb.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-leveldb.xml?rev=1235427&r1=1235426&r2=1235427&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-leveldb.xml
(original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-leveldb.xml
Tue Jan 24 19:21:05 2012
@@ -23,7 +23,7 @@
 
     <queue name="unified.**" unified="true"/>
 
-    <leveldb_store directory="${basedir}/target/test-data"/>
+    <leveldb_store directory="${basedir}/target/leveldb-test-data"/>
   </virtual_host>
 
   <web_admin bind="http://127.0.0.1:0"/>



Mime
View raw message