Search in sources :

Example 1 with VectorClockInconsistencyResolver

use of voldemort.versioning.VectorClockInconsistencyResolver in project voldemort by voldemort.

the class AbstractStoreClientFactory method getRawStore.

@SuppressWarnings("unchecked")
public <K, V, T> Store<K, V, T> getRawStore(String storeName, InconsistencyResolver<Versioned<V>> resolver, String customStoresXml, String clusterXmlString, FailureDetector fd) {
    logger.info("Client zone-id [" + this.routedStoreConfig.getClientZoneId() + "] Attempting to get raw store [" + storeName + "] ");
    if (logger.isDebugEnabled()) {
        for (URI uri : bootstrapUrls) {
            logger.debug("Client Bootstrap url [" + uri + "]");
        }
    }
    // Get cluster and store metadata
    String clusterXml = clusterXmlString;
    if (clusterXml == null) {
        logger.debug("Fetching cluster.xml ...");
        clusterXml = bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY, bootstrapUrls);
    }
    this.cluster = clusterMapper.readCluster(new StringReader(clusterXml), false);
    String storesXml = customStoresXml;
    if (storesXml == null) {
        String storesKey = storeName;
        if (config.isFetchAllStoresXmlInBootstrap()) {
            storesKey = MetadataStore.STORES_KEY;
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Fetching store definition for Store " + storeName + " key " + storesKey);
        }
        storesXml = bootstrapMetadataWithRetries(storesKey, bootstrapUrls);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Obtained cluster metadata xml" + clusterXml);
        logger.debug("Obtained stores  metadata xml" + storesXml);
    }
    storeDefs = storeMapper.readStoreList(new StringReader(storesXml), false);
    StoreDefinition storeDef = null;
    for (StoreDefinition d : storeDefs) if (d.getName().equals(storeName))
        storeDef = d;
    if (storeDef == null) {
        logger.error("Bootstrap - unknown store: " + storeName);
        throw new BootstrapFailureException("Unknown store '" + storeName + "'.");
    }
    if (logger.isDebugEnabled()) {
        logger.debug(this.cluster.toString(true));
        logger.debug(storeDef.toString());
    }
    boolean repairReads = !storeDef.isView();
    // construct mapping
    Map<Integer, Store<ByteArray, byte[], byte[]>> clientMapping = Maps.newHashMap();
    Map<Integer, NonblockingStore> nonblockingStores = Maps.newHashMap();
    Map<Integer, NonblockingStore> nonblockingSlopStores = Maps.newHashMap();
    Map<Integer, Store<ByteArray, Slop, byte[]>> slopStores = null;
    if (storeDef.hasHintedHandoffStrategyType())
        slopStores = Maps.newHashMap();
    for (Node node : this.cluster.getNodes()) {
        Store<ByteArray, byte[], byte[]> store = getStore(storeDef.getName(), node.getHost(), getPort(node), this.requestFormatType);
        clientMapping.put(node.getId(), store);
        NonblockingStore nonblockingStore = routedStoreFactory.toNonblockingStore(store);
        nonblockingStores.put(node.getId(), nonblockingStore);
        if (slopStores != null) {
            Store<ByteArray, byte[], byte[]> rawSlopStore = getStore("slop", node.getHost(), getPort(node), this.requestFormatType);
            Store<ByteArray, Slop, byte[]> slopStore = SerializingStore.wrap(rawSlopStore, slopKeySerializer, slopValueSerializer, new IdentitySerializer());
            slopStores.put(node.getId(), slopStore);
            nonblockingSlopStores.put(node.getId(), routedStoreFactory.toNonblockingStore(rawSlopStore));
        }
    }
    /*
         * Check if we need to retrieve a reference to the failure detector. For
         * system stores - the FD reference would be passed in.
         */
    FailureDetector failureDetectorRef = fd;
    if (failureDetectorRef == null) {
        failureDetectorRef = getFailureDetector();
    } else {
        logger.debug("Using existing failure detector.");
    }
    this.routedStoreConfig.setRepairReads(repairReads);
    Store<ByteArray, byte[], byte[]> store = routedStoreFactory.create(this.cluster, storeDef, clientMapping, nonblockingStores, slopStores, nonblockingSlopStores, failureDetectorRef, this.routedStoreConfig);
    store = new LoggingStore(store);
    if (isJmxEnabled) {
        StatTrackingStore statStore = new StatTrackingStore(store, this.aggregateStats, this.cachedStoreStats);
        statStore.getStats().registerJmx(identifierString);
        store = statStore;
    }
    if (this.config.isEnableCompressionLayer()) {
        if (storeDef.getKeySerializer().hasCompression() || storeDef.getValueSerializer().hasCompression()) {
            store = new CompressingStore(store, getCompressionStrategy(storeDef.getKeySerializer()), getCompressionStrategy(storeDef.getValueSerializer()));
        }
    }
    /*
         * Initialize the finalstore object only once the store object itself is
         * wrapped by a StatrackingStore seems like the finalstore object is
         * redundant?
         */
    Store<K, V, T> finalStore = (Store<K, V, T>) store;
    if (this.config.isEnableSerializationLayer()) {
        Serializer<K> keySerializer = (Serializer<K>) serializerFactory.getSerializer(storeDef.getKeySerializer());
        Serializer<V> valueSerializer = (Serializer<V>) serializerFactory.getSerializer(storeDef.getValueSerializer());
        if (storeDef.isView() && (storeDef.getTransformsSerializer() == null))
            throw new SerializationException("Transforms serializer must be specified with a view ");
        Serializer<T> transformsSerializer = (Serializer<T>) serializerFactory.getSerializer(storeDef.getTransformsSerializer() != null ? storeDef.getTransformsSerializer() : new SerializerDefinition("identity"));
        finalStore = SerializingStore.wrap(store, keySerializer, valueSerializer, transformsSerializer);
    }
    // resolver (if they gave us one)
    if (this.config.isEnableInconsistencyResolvingLayer()) {
        InconsistencyResolver<Versioned<V>> secondaryResolver = resolver == null ? new TimeBasedInconsistencyResolver() : resolver;
        finalStore = new InconsistencyResolvingStore<K, V, T>(finalStore, new ChainedResolver<Versioned<V>>(new VectorClockInconsistencyResolver(), secondaryResolver));
    }
    return finalStore;
}
Also used : Versioned(voldemort.versioning.Versioned) Node(voldemort.cluster.Node) Store(voldemort.store.Store) LoggingStore(voldemort.store.logging.LoggingStore) SerializingStore(voldemort.store.serialized.SerializingStore) StatTrackingStore(voldemort.store.stats.StatTrackingStore) MetadataStore(voldemort.store.metadata.MetadataStore) CompressingStore(voldemort.store.compress.CompressingStore) InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) NonblockingStore(voldemort.store.nonblockingstore.NonblockingStore) URI(java.net.URI) CompressingStore(voldemort.store.compress.CompressingStore) StoreDefinition(voldemort.store.StoreDefinition) FailureDetector(voldemort.cluster.failuredetector.FailureDetector) StringReader(java.io.StringReader) ByteArray(voldemort.utils.ByteArray) IdentitySerializer(voldemort.serialization.IdentitySerializer) IdentitySerializer(voldemort.serialization.IdentitySerializer) Serializer(voldemort.serialization.Serializer) SlopSerializer(voldemort.serialization.SlopSerializer) ByteArraySerializer(voldemort.serialization.ByteArraySerializer) StringSerializer(voldemort.serialization.StringSerializer) ChainedResolver(voldemort.versioning.ChainedResolver) SerializationException(voldemort.serialization.SerializationException) NonblockingStore(voldemort.store.nonblockingstore.NonblockingStore) LoggingStore(voldemort.store.logging.LoggingStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StatTrackingStore(voldemort.store.stats.StatTrackingStore) TimeBasedInconsistencyResolver(voldemort.versioning.TimeBasedInconsistencyResolver) Slop(voldemort.store.slop.Slop) SerializerDefinition(voldemort.serialization.SerializerDefinition) VectorClockInconsistencyResolver(voldemort.versioning.VectorClockInconsistencyResolver)

Example 2 with VectorClockInconsistencyResolver

use of voldemort.versioning.VectorClockInconsistencyResolver in project voldemort by voldemort.

the class InMemoryMultiThreadedTest method main.

public static void main(String[] args) throws Exception {
    Store<byte[], byte[], byte[]> store = new VersionIncrementingStore<byte[], byte[], byte[]>(new InMemoryStorageEngine<byte[], byte[], byte[]>("test"), 0, new SystemTime());
    store = new InconsistencyResolvingStore<byte[], byte[], byte[]>(store, new VectorClockInconsistencyResolver<byte[]>());
    new MultithreadedStressTest(store, 5, 1000000, 10).testGetAndPut();
}
Also used : VersionIncrementingStore(voldemort.store.versioned.VersionIncrementingStore) VectorClockInconsistencyResolver(voldemort.versioning.VectorClockInconsistencyResolver) SystemTime(voldemort.utils.SystemTime)

Example 3 with VectorClockInconsistencyResolver

use of voldemort.versioning.VectorClockInconsistencyResolver in project voldemort by voldemort.

the class StorageService method registerNodeStores.

/**
     * For server side routing create NodeStore (socketstore) and pass it on to
     * a {@link RebootstrappingStore}.
     * <p>
     * 
     * The {@link RebootstrappingStore} handles invalid-metadata exceptions
     * introduced due to changes in cluster.xml at different nodes.
     * 
     * @param def
     * @param cluster
     * @param localNode
     */
public void registerNodeStores(StoreDefinition def, Cluster cluster, int localNode) {
    Map<Integer, Store<ByteArray, byte[], byte[]>> nodeStores = new HashMap<Integer, Store<ByteArray, byte[], byte[]>>(cluster.getNumberOfNodes());
    Map<Integer, NonblockingStore> nonblockingStores = new HashMap<Integer, NonblockingStore>(cluster.getNumberOfNodes());
    try {
        for (Node node : cluster.getNodes()) {
            Store<ByteArray, byte[], byte[]> store = getNodeStore(def.getName(), node, localNode);
            this.storeRepository.addNodeStore(node.getId(), store);
            nodeStores.put(node.getId(), store);
            NonblockingStore nonblockingStore = routedStoreFactory.toNonblockingStore(store);
            nonblockingStores.put(node.getId(), nonblockingStore);
        }
        Store<ByteArray, byte[], byte[]> store = routedStoreFactory.create(cluster, def, nodeStores, nonblockingStores, null, null, failureDetector, routedStoreConfig);
        store = new RebootstrappingStore(metadata, storeRepository, voldemortConfig, (RoutedStore) store, storeFactory);
        store = new InconsistencyResolvingStore<ByteArray, byte[], byte[]>(store, new VectorClockInconsistencyResolver<byte[]>());
        this.storeRepository.addRoutedStore(store);
    } catch (Exception e) {
        // Roll back
        for (Node node : cluster.getNodes()) this.storeRepository.removeNodeStore(def.getName(), node.getId());
        throw new VoldemortException(e);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) NonblockingStore(voldemort.store.nonblockingstore.NonblockingStore) Node(voldemort.cluster.Node) InvalidMetadataCheckingStore(voldemort.store.invalidmetadata.InvalidMetadataCheckingStore) RoutedStore(voldemort.store.routed.RoutedStore) RedirectingStore(voldemort.store.rebalancing.RedirectingStore) InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) RebootstrappingStore(voldemort.store.rebalancing.RebootstrappingStore) NonblockingStore(voldemort.store.nonblockingstore.NonblockingStore) Store(voldemort.store.Store) RetentionEnforcingStore(voldemort.store.retention.RetentionEnforcingStore) LoggingStore(voldemort.store.logging.LoggingStore) StatTrackingStore(voldemort.store.stats.StatTrackingStore) QuotaLimitingStore(voldemort.store.quota.QuotaLimitingStore) MetadataStore(voldemort.store.metadata.MetadataStore) RoutedStore(voldemort.store.routed.RoutedStore) VoldemortException(voldemort.VoldemortException) ConfigurationException(voldemort.utils.ConfigurationException) NoSuchCapabilityException(voldemort.store.NoSuchCapabilityException) DisabledStoreException(voldemort.store.DisabledStoreException) VoldemortException(voldemort.VoldemortException) RebootstrappingStore(voldemort.store.rebalancing.RebootstrappingStore) ByteArray(voldemort.utils.ByteArray) VectorClockInconsistencyResolver(voldemort.versioning.VectorClockInconsistencyResolver)

Example 4 with VectorClockInconsistencyResolver

use of voldemort.versioning.VectorClockInconsistencyResolver 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)

Example 5 with VectorClockInconsistencyResolver

use of voldemort.versioning.VectorClockInconsistencyResolver in project voldemort by voldemort.

the class MockStoreClientFactory method getRawStore.

public <K1, V1, T1> Store<K1, V1, T1> getRawStore(String storeName, InconsistencyResolver<Versioned<V1>> resolver) {
    if (this.storesXml != null)
        return getRawStore(storeName);
    // Add inconsistency resolving decorator, using their inconsistency
    // resolver (if they gave us one)
    InconsistencyResolver<Versioned<V1>> secondaryResolver = new TimeBasedInconsistencyResolver();
    if (resolver != null)
        secondaryResolver = resolver;
    Store store = new VersionIncrementingStore(new InMemoryStorageEngine(storeName), nodeId, time);
    if (isSerialized())
        store = new SerializingStore(store, keySerializer, valueSerializer, 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) VersionIncrementingStore(voldemort.store.versioned.VersionIncrementingStore) InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) TimeBasedInconsistencyResolver(voldemort.versioning.TimeBasedInconsistencyResolver) SerializingStore(voldemort.store.serialized.SerializingStore) VectorClockInconsistencyResolver(voldemort.versioning.VectorClockInconsistencyResolver)

Aggregations

VectorClockInconsistencyResolver (voldemort.versioning.VectorClockInconsistencyResolver)5 Store (voldemort.store.Store)4 InconsistencyResolvingStore (voldemort.store.versioned.InconsistencyResolvingStore)4 SerializingStore (voldemort.store.serialized.SerializingStore)3 VersionIncrementingStore (voldemort.store.versioned.VersionIncrementingStore)3 TimeBasedInconsistencyResolver (voldemort.versioning.TimeBasedInconsistencyResolver)3 Versioned (voldemort.versioning.Versioned)3 StringReader (java.io.StringReader)2 Node (voldemort.cluster.Node)2 Serializer (voldemort.serialization.Serializer)2 StoreDefinition (voldemort.store.StoreDefinition)2 LoggingStore (voldemort.store.logging.LoggingStore)2 InMemoryStorageEngine (voldemort.store.memory.InMemoryStorageEngine)2 MetadataStore (voldemort.store.metadata.MetadataStore)2 NonblockingStore (voldemort.store.nonblockingstore.NonblockingStore)2 StatTrackingStore (voldemort.store.stats.StatTrackingStore)2 ByteArray (voldemort.utils.ByteArray)2 URI (java.net.URI)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1