Search in sources :

Example 1 with PartitioningStrategy

use of com.hazelcast.partition.PartitioningStrategy in project hazelcast by hazelcast.

the class BasicMapStoreContext method create.

static MapStoreContext create(MapContainer mapContainer) {
    final BasicMapStoreContext context = new BasicMapStoreContext();
    final String mapName = mapContainer.getName();
    final MapServiceContext mapServiceContext = mapContainer.getMapServiceContext();
    final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    final PartitioningStrategy partitioningStrategy = mapContainer.getPartitioningStrategy();
    final MapConfig mapConfig = mapContainer.getMapConfig();
    final MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig();
    final ClassLoader configClassLoader = nodeEngine.getConfigClassLoader();
    // create store.
    final Object store = createStore(mapName, mapStoreConfig, configClassLoader);
    final MapStoreWrapper storeWrapper = new MapStoreWrapper(mapName, store);
    storeWrapper.instrument(nodeEngine);
    context.setMapName(mapName);
    context.setMapStoreConfig(mapStoreConfig);
    context.setPartitioningStrategy(partitioningStrategy);
    context.setMapServiceContext(mapServiceContext);
    context.setStoreWrapper(storeWrapper);
    final MapStoreManager mapStoreManager = createMapStoreManager(context);
    context.setMapStoreManager(mapStoreManager);
    // todo this is user code. it may also block map store creation.
    callLifecycleSupportInit(context);
    return context;
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) MapStoreWrapper(com.hazelcast.map.impl.MapStoreWrapper) PartitioningStrategy(com.hazelcast.partition.PartitioningStrategy) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 2 with PartitioningStrategy

use of com.hazelcast.partition.PartitioningStrategy in project hazelcast by hazelcast.

the class AbstractSerializationService method calculatePartitionHash.

protected final int calculatePartitionHash(Object obj, PartitioningStrategy strategy) {
    int partitionHash = 0;
    PartitioningStrategy partitioningStrategy = strategy == null ? globalPartitioningStrategy : strategy;
    if (partitioningStrategy != null) {
        Object pk = partitioningStrategy.getPartitionKey(obj);
        if (pk != null && pk != obj) {
            final Data partitionKey = toData(pk, EMPTY_PARTITIONING_STRATEGY);
            partitionHash = partitionKey == null ? 0 : partitionKey.getPartitionHash();
        }
    }
    return partitionHash;
}
Also used : PartitioningStrategy(com.hazelcast.partition.PartitioningStrategy) SerializationUtil.isNullData(com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData) Data(com.hazelcast.internal.serialization.Data)

Example 3 with PartitioningStrategy

use of com.hazelcast.partition.PartitioningStrategy in project hazelcast by hazelcast.

the class WriteMapP method init.

@Override
public void init(@Nonnull Outbox outbox, @Nonnull Context context) {
    map = instance().getMap(mapName);
    boolean hasCustomSerializers = serializationService instanceof DelegatingSerializationService && ((DelegatingSerializationService) serializationService).hasAddedSerializers();
    boolean hasNearCache = map instanceof NearCachedMapProxyImpl;
    if (hasNearCache && hasCustomSerializers) {
        // See https://github.com/hazelcast/hazelcast-jet/issues/3046
        throw new JetException("Writing into IMap with both near cache and custom serializers not supported");
    }
    if (!hasCustomSerializers) {
        addToBuffer = item -> buffer.add(new SimpleEntry<>(key(item), value(item)));
    } else if (map instanceof MapProxyImpl) {
        PartitioningStrategy<?> partitionStrategy = ((MapProxyImpl<K, V>) map).getPartitionStrategy();
        addToBuffer = item -> {
            Data key = serializationService.toData(key(item), partitionStrategy);
            Data value = serializationService.toData(value(item));
            buffer.add(new SimpleEntry<>(key, value));
        };
    } else if (map instanceof ClientMapProxy) {
        // TODO: add strategy/unify after https://github.com/hazelcast/hazelcast/issues/13950 is fixed
        addToBuffer = item -> {
            Data key = serializationService.toData(key(item));
            Data value = serializationService.toData(value(item));
            buffer.add(new SimpleEntry<>(key, value));
        };
    } else {
        throw new RuntimeException("Unexpected map class: " + map.getClass().getName());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) FunctionEx(com.hazelcast.function.FunctionEx) EdgeConfig(com.hazelcast.jet.config.EdgeConfig) DelegatingSerializationService(com.hazelcast.jet.impl.serialization.DelegatingSerializationService) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) PartitioningStrategy(com.hazelcast.partition.PartitioningStrategy) Outbox(com.hazelcast.jet.core.Outbox) Data(com.hazelcast.internal.serialization.Data) Processor(com.hazelcast.jet.core.Processor) Collections.singletonList(java.util.Collections.singletonList) JetException(com.hazelcast.jet.JetException) Consumer(java.util.function.Consumer) ArrayMap(com.hazelcast.jet.impl.connector.HazelcastWriters.ArrayMap) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) PermissionsUtil.mapPutPermission(com.hazelcast.security.PermissionsUtil.mapPutPermission) Integer.max(java.lang.Integer.max) List(java.util.List) Permission(java.security.Permission) SerializationService(com.hazelcast.internal.serialization.SerializationService) ClientMapProxy(com.hazelcast.client.impl.proxy.ClientMapProxy) Inbox(com.hazelcast.jet.core.Inbox) Nonnull(javax.annotation.Nonnull) SimpleEntry(java.util.AbstractMap.SimpleEntry) IMap(com.hazelcast.map.IMap) DelegatingSerializationService(com.hazelcast.jet.impl.serialization.DelegatingSerializationService) SimpleEntry(java.util.AbstractMap.SimpleEntry) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) Data(com.hazelcast.internal.serialization.Data) JetException(com.hazelcast.jet.JetException) ClientMapProxy(com.hazelcast.client.impl.proxy.ClientMapProxy) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) PartitioningStrategy(com.hazelcast.partition.PartitioningStrategy)

Example 4 with PartitioningStrategy

use of com.hazelcast.partition.PartitioningStrategy in project hazelcast by hazelcast.

the class DefaultClientExtension method createSerializationService.

@Override
public InternalSerializationService createSerializationService(byte version) {
    try {
        ClientConfig config = client.getClientConfig();
        ClassLoader configClassLoader = config.getClassLoader();
        HazelcastInstance hazelcastInstance = client;
        PartitioningStrategy partitioningStrategy = getPartitioningStrategy(configClassLoader);
        SerializationConfig serializationConfig = config.getSerializationConfig() != null ? config.getSerializationConfig() : new SerializationConfig();
        SerializationServiceBuilder builder = new DefaultSerializationServiceBuilder();
        if (version > 0) {
            builder.setVersion(version);
        }
        return builder.setClassLoader(configClassLoader).setConfig(serializationConfig).setManagedContext(new HazelcastClientManagedContext(client, config.getManagedContext())).setPartitioningStrategy(partitioningStrategy).setHazelcastInstance(hazelcastInstance).setNotActiveExceptionSupplier(HazelcastClientNotActiveException::new).setSchemaService(client.getSchemaService()).build();
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationServiceBuilder(com.hazelcast.internal.serialization.SerializationServiceBuilder) DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SerializationConfig(com.hazelcast.config.SerializationConfig) HazelcastClientNotActiveException(com.hazelcast.client.HazelcastClientNotActiveException) DefaultPartitioningStrategy(com.hazelcast.partition.strategy.DefaultPartitioningStrategy) PartitioningStrategy(com.hazelcast.partition.PartitioningStrategy) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientNotActiveException(com.hazelcast.client.HazelcastClientNotActiveException)

Example 5 with PartitioningStrategy

use of com.hazelcast.partition.PartitioningStrategy in project hazelcast by hazelcast.

the class DefaultNodeExtension method createSerializationService.

/**
 * Creates a serialization service. The {@code isCompatibility} parameter defines
 * whether the serialization format used by the service will conform to the
 * 3.x or the 4.x format.
 *
 * @param isCompatibility {@code true} if the serialized format should conform to the
 *                 3.x serialization format, {@code false} otherwise
 * @return the serialization service
 */
private InternalSerializationService createSerializationService(boolean isCompatibility) {
    InternalSerializationService ss;
    try {
        Config config = node.getConfig();
        ClassLoader configClassLoader = node.getConfigClassLoader();
        HazelcastInstanceImpl hazelcastInstance = node.hazelcastInstance;
        PartitioningStrategy partitioningStrategy = getPartitioningStrategy(configClassLoader);
        SerializationServiceBuilder builder = new DefaultSerializationServiceBuilder();
        SerializationConfig serializationConfig = config.getSerializationConfig() != null ? config.getSerializationConfig() : new SerializationConfig();
        byte version = (byte) node.getProperties().getInteger(ClusterProperty.SERIALIZATION_VERSION);
        ss = builder.setClassLoader(configClassLoader).setConfig(serializationConfig).setManagedContext(hazelcastInstance.managedContext).setPartitioningStrategy(partitioningStrategy).setHazelcastInstance(hazelcastInstance).setVersion(version).setSchemaService(node.memberSchemaService).setNotActiveExceptionSupplier(new Supplier<RuntimeException>() {

            @Override
            public RuntimeException get() {
                return new HazelcastInstanceNotActiveException();
            }
        }).isCompatibility(isCompatibility).build();
    } catch (Exception e) {
        throw rethrow(e);
    }
    return ss;
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) SerializationServiceBuilder(com.hazelcast.internal.serialization.SerializationServiceBuilder) DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationConfig(com.hazelcast.config.SerializationConfig) PersistenceConfig(com.hazelcast.config.PersistenceConfig) CPSubsystemConfig(com.hazelcast.config.cp.CPSubsystemConfig) ConfigAccessor.getActiveMemberNetworkConfig(com.hazelcast.config.ConfigAccessor.getActiveMemberNetworkConfig) InstanceTrackingConfig(com.hazelcast.config.InstanceTrackingConfig) JetConfig(com.hazelcast.jet.config.JetConfig) SymmetricEncryptionConfig(com.hazelcast.config.SymmetricEncryptionConfig) Config(com.hazelcast.config.Config) SecurityConfig(com.hazelcast.config.SecurityConfig) AuditlogConfig(com.hazelcast.config.AuditlogConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) DefaultPartitioningStrategy(com.hazelcast.partition.strategy.DefaultPartitioningStrategy) PartitioningStrategy(com.hazelcast.partition.PartitioningStrategy) Supplier(java.util.function.Supplier) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) VersionMismatchException(com.hazelcast.internal.cluster.impl.VersionMismatchException) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Aggregations

PartitioningStrategy (com.hazelcast.partition.PartitioningStrategy)11 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 StringPartitioningStrategy (com.hazelcast.partition.strategy.StringPartitioningStrategy)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 PartitioningStrategyConfig (com.hazelcast.config.PartitioningStrategyConfig)4 Data (com.hazelcast.internal.serialization.Data)3 SerializationConfig (com.hazelcast.config.SerializationConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 SerializationService (com.hazelcast.internal.serialization.SerializationService)2 SerializationServiceBuilder (com.hazelcast.internal.serialization.SerializationServiceBuilder)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 DefaultPartitioningStrategy (com.hazelcast.partition.strategy.DefaultPartitioningStrategy)2 HazelcastClientNotActiveException (com.hazelcast.client.HazelcastClientNotActiveException)1 ClientConfig (com.hazelcast.client.config.ClientConfig)1 ClientMapProxy (com.hazelcast.client.impl.proxy.ClientMapProxy)1 AuditlogConfig (com.hazelcast.config.AuditlogConfig)1 Config (com.hazelcast.config.Config)1 ConfigAccessor.getActiveMemberNetworkConfig (com.hazelcast.config.ConfigAccessor.getActiveMemberNetworkConfig)1 InstanceTrackingConfig (com.hazelcast.config.InstanceTrackingConfig)1