Search in sources :

Example 1 with InMemoryKeyValueStore

use of org.apache.samza.storage.kv.inmemory.InMemoryKeyValueStore in project samza by apache.

the class TestLargeMessageSafeKeyValueStores method setup.

@Before
public void setup() {
    KeyValueStore<byte[], byte[]> kvStore;
    switch(typeOfStore) {
        case "inmemory":
            {
                kvStore = new InMemoryKeyValueStore(keyValueStoreMetrics);
                break;
            }
        case "rocksdb":
            {
                kvStore = new RocksDbKeyValueStore(dir, new org.rocksdb.Options().setCreateIfMissing(true).setCompressionType(org.rocksdb.CompressionType.SNAPPY_COMPRESSION), new MapConfig(), false, storeName, new WriteOptions(), new FlushOptions(), keyValueStoreMetrics);
                break;
            }
        default:
            throw new IllegalArgumentException("Type of store undefined: " + typeOfStore);
    }
    MessageCollector collector = envelope -> {
        int messageLength = ((byte[]) envelope.getMessage()).length;
        if (messageLength > maxMessageSize) {
            throw new SamzaException("Logged store message size " + messageLength + " for store " + storeName + " was larger than the maximum allowed message size " + maxMessageSize + ".");
        }
    };
    loggedStore = new LoggedStore<>(kvStore, systemStreamPartition, collector, loggedStoreMetrics);
    switch(storeConfig) {
        case "serde":
            {
                KeyValueStore<byte[], byte[]> largeMessageSafeStore = new LargeMessageSafeStore(loggedStore, storeName, dropLargeMessage, maxMessageSize);
                store = new SerializedKeyValueStore<>(largeMessageSafeStore, stringSerde, stringSerde, serializedKeyValueStoreMetrics);
                break;
            }
        case "cache-then-serde":
            {
                KeyValueStore<byte[], byte[]> toBeSerializedStore = loggedStore;
                if (dropLargeMessage) {
                    toBeSerializedStore = new LargeMessageSafeStore(loggedStore, storeName, dropLargeMessage, maxMessageSize);
                }
                KeyValueStore<String, String> serializedStore = new SerializedKeyValueStore<>(toBeSerializedStore, stringSerde, stringSerde, serializedKeyValueStoreMetrics);
                store = new CachedStore<>(serializedStore, cacheSize, batchSize, cachedStoreMetrics);
                break;
            }
        // large messages are expected and StorageConfig.DISALLOW_LARGE_MESSAGES is true.
        case "serde-then-cache":
            {
                KeyValueStore<byte[], byte[]> cachedStore = new CachedStore<>(loggedStore, cacheSize, batchSize, cachedStoreMetrics);
                KeyValueStore<byte[], byte[]> largeMessageSafeStore = new LargeMessageSafeStore(cachedStore, storeName, dropLargeMessage, maxMessageSize);
                store = new SerializedKeyValueStore<>(largeMessageSafeStore, stringSerde, stringSerde, serializedKeyValueStoreMetrics);
                break;
            }
        default:
            throw new IllegalArgumentException("Store config undefined: " + storeConfig);
    }
    store = new NullSafeKeyValueStore<>(store);
}
Also used : Arrays(java.util.Arrays) RunWith(org.junit.runner.RunWith) FlushOptions(org.rocksdb.FlushOptions) Random(java.util.Random) Serde(org.apache.samza.serializers.Serde) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) StringSerde(org.apache.samza.serializers.StringSerde) MessageCollector(org.apache.samza.task.MessageCollector) After(org.junit.After) MapConfig(org.apache.samza.config.MapConfig) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) Int(scala.Int) Collection(java.util.Collection) Partition(org.apache.samza.Partition) Test(org.junit.Test) MetricsRegistry(org.apache.samza.metrics.MetricsRegistry) WriteOptions(org.rocksdb.WriteOptions) File(java.io.File) SamzaException(org.apache.samza.SamzaException) List(java.util.List) InMemoryKeyValueStore(org.apache.samza.storage.kv.inmemory.InMemoryKeyValueStore) Assert(org.junit.Assert) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) InMemoryKeyValueStore(org.apache.samza.storage.kv.inmemory.InMemoryKeyValueStore) FlushOptions(org.rocksdb.FlushOptions) SamzaException(org.apache.samza.SamzaException) WriteOptions(org.rocksdb.WriteOptions) MessageCollector(org.apache.samza.task.MessageCollector) MapConfig(org.apache.samza.config.MapConfig) InMemoryKeyValueStore(org.apache.samza.storage.kv.inmemory.InMemoryKeyValueStore) Before(org.junit.Before)

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Random (java.util.Random)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Partition (org.apache.samza.Partition)1 SamzaException (org.apache.samza.SamzaException)1 MapConfig (org.apache.samza.config.MapConfig)1 MetricsRegistry (org.apache.samza.metrics.MetricsRegistry)1 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)1 Serde (org.apache.samza.serializers.Serde)1 StringSerde (org.apache.samza.serializers.StringSerde)1 InMemoryKeyValueStore (org.apache.samza.storage.kv.inmemory.InMemoryKeyValueStore)1 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)1 MessageCollector (org.apache.samza.task.MessageCollector)1 After (org.junit.After)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1