Search in sources :

Example 6 with StorageEngine

use of voldemort.store.StorageEngine in project voldemort by voldemort.

the class MockStoreClientFactory method getRawStore.

private <K1, V1, T1> Store<K1, V1, T1> getRawStore(String storeName) {
    List<StoreDefinition> storeDefs = storeMapper.readStoreList(new StringReader(storesXml));
    StoreDefinition storeDef = null;
    for (StoreDefinition d : storeDefs) if (d.getName().equals(storeName))
        storeDef = d;
    if (storeDef == null)
        throw new BootstrapFailureException("Unknown store '" + storeName + "'.");
    DefaultSerializerFactory serializerFactory = new DefaultSerializerFactory();
    Serializer<K1> keySerializer = (Serializer<K1>) serializerFactory.getSerializer(storeDef.getKeySerializer());
    Serializer<V1> valueSerializer = (Serializer<V1>) serializerFactory.getSerializer(storeDef.getValueSerializer());
    Serializer<T1> transformsSerializer = null;
    if (storeDef.isView())
        transformsSerializer = (Serializer<T1>) serializerFactory.getSerializer(storeDef.getTransformsSerializer());
    // Add inconsistency resolving decorator, using their inconsistency
    // resolver (if they gave us one)
    InconsistencyResolver<Versioned<V1>> secondaryResolver = new TimeBasedInconsistencyResolver();
    StorageEngine engine;
    if (storeDef.isView())
        engine = new InMemoryStorageEngine(storeDef.getViewTargetStoreName());
    else
        engine = new InMemoryStorageEngine(storeDef.getName());
    if (storeDef.isView()) {
        // instantiate view
        String targetName = storeDef.getViewTargetStoreName();
        StoreDefinition targetDef = StoreUtils.getStoreDef(storeDefs, targetName);
        engine = new ViewStorageEngine(storeName, engine, this.viewValueSerializer != null ? this.viewValueSerializer : serializerFactory.getSerializer(storeDef.getValueSerializer()), this.transformsSerializer != null ? this.transformsSerializer : serializerFactory.getSerializer(storeDef.getTransformsSerializer()), this.keySerializer != null ? this.keySerializer : serializerFactory.getSerializer(targetDef.getKeySerializer()), this.valueSerializer != null ? this.valueSerializer : serializerFactory.getSerializer(targetDef.getValueSerializer()), null, ViewStorageConfiguration.loadTransformation(storeDef.getValueTransformation()));
    }
    Store store = new VersionIncrementingStore(engine, nodeId, time);
    store = new SerializingStore(store, this.keySerializer != null ? this.keySerializer : keySerializer, this.valueSerializer != null ? this.valueSerializer : valueSerializer, this.transformsSerializer != null ? this.transformsSerializer : transformsSerializer);
    Store<K1, V1, T1> consistentStore = new InconsistencyResolvingStore<K1, V1, T1>(store, new ChainedResolver<Versioned<V1>>(new VectorClockInconsistencyResolver(), secondaryResolver));
    return consistentStore;
}
Also used : Versioned(voldemort.versioning.Versioned) Store(voldemort.store.Store) SerializingStore(voldemort.store.serialized.SerializingStore) InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) VersionIncrementingStore(voldemort.store.versioned.VersionIncrementingStore) ViewStorageEngine(voldemort.store.views.ViewStorageEngine) StorageEngine(voldemort.store.StorageEngine) InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) VersionIncrementingStore(voldemort.store.versioned.VersionIncrementingStore) InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) StoreDefinition(voldemort.store.StoreDefinition) StringReader(java.io.StringReader) SerializingStore(voldemort.store.serialized.SerializingStore) Serializer(voldemort.serialization.Serializer) ViewStorageEngine(voldemort.store.views.ViewStorageEngine) DefaultSerializerFactory(voldemort.serialization.DefaultSerializerFactory) TimeBasedInconsistencyResolver(voldemort.versioning.TimeBasedInconsistencyResolver) VectorClockInconsistencyResolver(voldemort.versioning.VectorClockInconsistencyResolver)

Aggregations

StorageEngine (voldemort.store.StorageEngine)6 ReadOnlyStorageEngine (voldemort.store.readonly.ReadOnlyStorageEngine)5 VoldemortException (voldemort.VoldemortException)4 SlopStorageEngine (voldemort.store.slop.SlopStorageEngine)4 StringReader (java.io.StringReader)3 StoreDefinition (voldemort.store.StoreDefinition)3 MysqlStorageEngine (voldemort.store.mysql.MysqlStorageEngine)3 StoreVersionManager (voldemort.store.readonly.StoreVersionManager)3 DisabledStoreException (voldemort.store.DisabledStoreException)2 NoSuchCapabilityException (voldemort.store.NoSuchCapabilityException)2 ViewStorageEngine (voldemort.store.views.ViewStorageEngine)2 ConfigurationException (voldemort.utils.ConfigurationException)2 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)2 Versioned (voldemort.versioning.Versioned)2 File (java.io.File)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1