summaryrefslogtreecommitdiff
path: root/qpid/java/bdbstore/src/main
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org = kwall = Keith Wall kwall@apache.org@apache.org>2014-04-14 08:54:19 +0000
committerKeith Wall <kwall@apache.org = kwall = Keith Wall kwall@apache.org@apache.org>2014-04-14 08:54:19 +0000
commitcde1072e86b57286594eb4fdb494576689aa8bca (patch)
tree8e0f378d16d5cf564f8ab0d2f93e5ec6f338621f /qpid/java/bdbstore/src/main
parent981b8f5357355f842a523e4b50a1d5c711095a68 (diff)
downloadqpid-python-cde1072e86b57286594eb4fdb494576689aa8bca.tar.gz
QPID-5685: Store configuration version as an attribute of virtualhost within configuration store rather than within separate database/table
* ConfiguredObjectRecordHandler begin/end methods no longer take/return config version * DefaultUpgraderProvider uses the virtualhost record for the config version only and uses this to trigger the correct upgrade. Note this record is *not* recovered (yet). * BDB/SQL Upgraders migrate the config version from database/table to be the modelVersion attribute of a virtualhost entry. * BDB Upgrader tests (7 to 8). git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1587165 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/bdbstore/src/main')
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java87
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8.java104
2 files changed, 82 insertions, 109 deletions
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
index 652e4c135d..722a3a090d 100644
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
@@ -70,7 +70,6 @@ import org.apache.qpid.server.util.MapValueConverter;
import org.apache.qpid.util.FileUtils;
import com.sleepycat.bind.tuple.ByteBinding;
-import com.sleepycat.bind.tuple.IntegerBinding;
import com.sleepycat.bind.tuple.LongBinding;
import com.sleepycat.je.CheckpointConfig;
import com.sleepycat.je.Cursor;
@@ -109,8 +108,7 @@ public class BDBMessageStore implements MessageStore, DurableConfigurationStore
private static String BRIDGEDB_NAME = "BRIDGES";
private static String LINKDB_NAME = "LINKS";
private static String XID_DB_NAME = "XIDS";
- private static String CONFIG_VERSION_DB_NAME = "CONFIG_VERSION";
- private static final String[] CONFIGURATION_STORE_DATABASE_NAMES = new String[] { CONFIGURED_OBJECTS_DB_NAME, CONFIG_VERSION_DB_NAME , CONFIGURED_OBJECT_HIERARCHY_DB_NAME};
+ private static final String[] CONFIGURATION_STORE_DATABASE_NAMES = new String[] { CONFIGURED_OBJECTS_DB_NAME, CONFIGURED_OBJECT_HIERARCHY_DB_NAME};
private static final String[] MESSAGE_STORE_DATABASE_NAMES = new String[] { MESSAGE_META_DATA_DB_NAME, MESSAGE_CONTENT_DB_NAME, DELIVERY_DB_NAME, BRIDGEDB_NAME, LINKDB_NAME, XID_DB_NAME };
private EnvironmentFacade _environmentFacade;
@@ -182,16 +180,9 @@ public class BDBMessageStore implements MessageStore, DurableConfigurationStore
try
{
- int configVersion = getConfigVersion();
-
- handler.begin(configVersion);
+ handler.begin();
doVisitAllConfiguredObjectRecords(handler);
-
- int newConfigVersion = handler.end();
- if(newConfigVersion != configVersion)
- {
- updateConfigVersion(newConfigVersion);
- }
+ handler.end();
}
catch (DatabaseException e)
{
@@ -372,70 +363,6 @@ public class BDBMessageStore implements MessageStore, DurableConfigurationStore
}
}
- @SuppressWarnings("resource")
- private void updateConfigVersion(int newConfigVersion) throws StoreException
- {
- Transaction txn = null;
- Cursor cursor = null;
- try
- {
- txn = _environmentFacade.getEnvironment().beginTransaction(null, null);
- cursor = getConfigVersionDb().openCursor(txn, null);
- DatabaseEntry key = new DatabaseEntry();
- ByteBinding.byteToEntry((byte) 0,key);
- DatabaseEntry value = new DatabaseEntry();
-
- while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
- {
- IntegerBinding.intToEntry(newConfigVersion, value);
- OperationStatus status = cursor.put(key, value);
- if (status != OperationStatus.SUCCESS)
- {
- throw new StoreException("Error setting config version: " + status);
- }
- }
- cursor.close();
- cursor = null;
- txn.commit();
- txn = null;
- }
- finally
- {
- closeCursorSafely(cursor);
- abortTransactionIgnoringException("Error setting config version", txn);;
- }
-
- }
-
- private int getConfigVersion() throws StoreException
- {
- Cursor cursor = null;
- try
- {
- cursor = getConfigVersionDb().openCursor(null, null);
- DatabaseEntry key = new DatabaseEntry();
- DatabaseEntry value = new DatabaseEntry();
- while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
- {
- return IntegerBinding.entryToInt(value);
- }
-
- // Insert 0 as the default config version
- IntegerBinding.intToEntry(0,value);
- ByteBinding.byteToEntry((byte) 0,key);
- OperationStatus status = getConfigVersionDb().put(null, key, value);
- if (status != OperationStatus.SUCCESS)
- {
- throw new StoreException("Error initialising config version: " + status);
- }
- return 0;
- }
- finally
- {
- closeCursorSafely(cursor);
- }
- }
-
private void closeCursorSafely(Cursor cursor) throws StoreException
{
if (cursor != null)
@@ -1622,11 +1549,6 @@ public class BDBMessageStore implements MessageStore, DurableConfigurationStore
return _environmentFacade.getOpenDatabase(MESSAGE_CONTENT_DB_NAME);
}
- private Database getConfigVersionDb()
- {
- return _environmentFacade.getOpenDatabase(CONFIG_VERSION_DB_NAME);
- }
-
private Database getMessageMetaDataDb()
{
return _environmentFacade.getOpenDatabase(MESSAGE_META_DATA_DB_NAME);
@@ -1644,8 +1566,7 @@ public class BDBMessageStore implements MessageStore, DurableConfigurationStore
class UpgradeTask implements EnvironmentFacadeTask
{
-
- private ConfiguredObject<?> _parent;
+ private final ConfiguredObject<?> _parent;
public UpgradeTask(ConfiguredObject<?> parent)
{
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8.java
index e5e1201c6a..8f3cf73275 100644
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8.java
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8.java
@@ -20,32 +20,38 @@
*/
package org.apache.qpid.server.store.berkeleydb.upgrade;
-import com.sleepycat.bind.tuple.ByteBinding;
-import com.sleepycat.bind.tuple.IntegerBinding;
-import com.sleepycat.bind.tuple.TupleBinding;
-import com.sleepycat.bind.tuple.TupleInput;
-import com.sleepycat.bind.tuple.TupleOutput;
-import com.sleepycat.je.*;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
import org.apache.qpid.server.model.ConfiguredObject;
-
+import org.apache.qpid.server.model.Model;
+import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.store.ConfiguredObjectRecord;
import org.apache.qpid.server.store.StoreException;
-import org.apache.qpid.server.store.berkeleydb.BDBConfiguredObjectRecord;
-import org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey;
import org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding;
-import org.apache.qpid.server.store.berkeleydb.tuple.HierarchyKeyBinding;
import org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding;
import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
+import com.sleepycat.bind.tuple.IntegerBinding;
+import com.sleepycat.bind.tuple.TupleBinding;
+import com.sleepycat.bind.tuple.TupleInput;
+import com.sleepycat.bind.tuple.TupleOutput;
+import com.sleepycat.je.Cursor;
+import com.sleepycat.je.Database;
+import com.sleepycat.je.DatabaseConfig;
+import com.sleepycat.je.DatabaseEntry;
+import com.sleepycat.je.Environment;
+import com.sleepycat.je.LockMode;
+import com.sleepycat.je.OperationStatus;
+import com.sleepycat.je.Transaction;
public class UpgradeFrom7To8 extends AbstractStoreUpgrade
{
+ private static final TypeReference<HashMap<String, Object>> MAP_TYPE_REFERENCE = new TypeReference<HashMap<String,Object>>(){};
@Override
public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent)
@@ -58,9 +64,25 @@ public class UpgradeFrom7To8 extends AbstractStoreUpgrade
Database hierarchyDb = environment.openDatabase(null, "CONFIGURED_OBJECT_HIERARCHY", dbConfig);
Database configuredObjectsDb = environment.openDatabase(null, "CONFIGURED_OBJECTS", dbConfig);
+ Database configVersionDb = environment.openDatabase(null, "CONFIG_VERSION", dbConfig);
Cursor objectsCursor = null;
+ String stringifiedConfigVersion = Model.MODEL_VERSION;
+ int configVersion = getConfigVersion(configVersionDb);
+ if (configVersion > -1)
+ {
+ stringifiedConfigVersion = "0." + configVersion;
+ }
+ configVersionDb.close();
+
+ Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+ virtualHostAttributes.put("modelVersion", stringifiedConfigVersion);
+
+ String virtualHostName = parent.getName();
+ UUID virtualHostId = UUIDGenerator.generateVhostUUID(virtualHostName);
+ ConfiguredObjectRecord virtualHostRecord = new org.apache.qpid.server.store.ConfiguredObjectRecordImpl(virtualHostId, "VirtualHost", virtualHostAttributes);
+
Transaction txn = environment.beginTransaction(null, null);
try
@@ -69,9 +91,6 @@ public class UpgradeFrom7To8 extends AbstractStoreUpgrade
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
- Map<UUID, BDBConfiguredObjectRecord> configuredObjects =
- new HashMap<UUID, BDBConfiguredObjectRecord>();
-
while (objectsCursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
{
UUID id = UUIDTupleBinding.getInstance().entryToObject(key);
@@ -80,7 +99,7 @@ public class UpgradeFrom7To8 extends AbstractStoreUpgrade
if(!type.endsWith("Binding"))
{
- UUIDTupleBinding.getInstance().objectToEntry(parent.getId(),value);
+ UUIDTupleBinding.getInstance().objectToEntry(virtualHostId, value);
TupleOutput tupleOutput = new TupleOutput();
tupleOutput.writeLong(id.getMostSignificantBits());
tupleOutput.writeLong(id.getLeastSignificantBits());
@@ -97,7 +116,7 @@ public class UpgradeFrom7To8 extends AbstractStoreUpgrade
DatabaseEntry hierarchyKey = new DatabaseEntry();
DatabaseEntry hierarchyValue = new DatabaseEntry();
- Map<String,Object> attributes = mapper.readValue(json, Map.class);
+ Map<String,Object> attributes = mapper.readValue(json, MAP_TYPE_REFERENCE);
Object queueIdString = attributes.remove("queue");
if(queueIdString instanceof String)
{
@@ -134,13 +153,8 @@ public class UpgradeFrom7To8 extends AbstractStoreUpgrade
{
throw new StoreException(e);
}
-
}
-
-
}
-
-
}
finally
{
@@ -149,13 +163,51 @@ public class UpgradeFrom7To8 extends AbstractStoreUpgrade
objectsCursor.close();
}
}
+
+ storeConfiguredObjectEntry(configuredObjectsDb, txn, virtualHostRecord);
txn.commit();
hierarchyDb.close();
configuredObjectsDb.close();
+ reportFinished(environment, 8);
+ }
+ private int getConfigVersion(Database configVersionDb)
+ {
+ Cursor cursor = null;
+ try
+ {
+ cursor = configVersionDb.openCursor(null, null);
+ DatabaseEntry key = new DatabaseEntry();
+ DatabaseEntry value = new DatabaseEntry();
+ while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
+ {
+ return IntegerBinding.entryToInt(value);
+ }
+ return -1;
+ }
+ finally
+ {
+ cursor.close();
+ }
+ }
- reportFinished(environment, 8);
+ private void storeConfiguredObjectEntry(Database configuredObjectsDb, final Transaction txn, ConfiguredObjectRecord configuredObject)
+ {
+ DatabaseEntry key = new DatabaseEntry();
+ UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance();
+ uuidBinding.objectToEntry(configuredObject.getId(), key);
+
+ DatabaseEntry value = new DatabaseEntry();
+ ConfiguredObjectBinding configuredObjectBinding = ConfiguredObjectBinding.getInstance();
+
+ configuredObjectBinding.objectToEntry(configuredObject, value);
+ OperationStatus status = configuredObjectsDb.put(txn, key, value);
+ if (status != OperationStatus.SUCCESS)
+ {
+ throw new StoreException("Error writing configured object " + configuredObject + " to database: "
+ + status);
+ }
}
}