Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-15803 Continue to remove BinaryMarshaller explicit usage in tests #11784

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.ignite.internal.processors.query.calcite.schema;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
Expand Down Expand Up @@ -67,7 +65,6 @@
import org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory;
import org.apache.ignite.internal.processors.query.calcite.util.Commons;
import org.apache.ignite.internal.processors.query.calcite.util.TypeUtils;
import org.apache.ignite.internal.util.GridUnsafe;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
Expand Down Expand Up @@ -335,13 +332,11 @@ private <Row> ModifyTuple insertTuple(Row row, ExecutionContext<Row> ectx) throw
Object key = insertKey(row, ectx);
Object val = insertVal(row, ectx);

if (cacheContext().binaryMarshaller()) {
if (key instanceof BinaryObjectBuilder)
key = ((BinaryObjectBuilder)key).build();
if (key instanceof BinaryObjectBuilder)
key = ((BinaryObjectBuilder)key).build();

if (val instanceof BinaryObjectBuilder)
val = ((BinaryObjectBuilder)val).build();
}
if (val instanceof BinaryObjectBuilder)
val = ((BinaryObjectBuilder)val).build();

typeDesc.validateKeyAndValue(key, val);

Expand Down Expand Up @@ -409,34 +404,10 @@ private <Row> Object insertVal(Row row, ExecutionContext<Row> ectx) throws Ignit
private Object newVal(String typeName, Class<?> typeCls) throws IgniteCheckedException {
GridCacheContext<?, ?> cctx = cacheContext();

if (cctx.binaryMarshaller()) {
BinaryObjectBuilder builder = cctx.grid().binary().builder(typeName);
cctx.prepareAffinityField(builder);

return builder;
}

Class<?> cls = U.classForName(typeName, typeCls);

try {
Constructor<?> ctor = cls.getDeclaredConstructor();
ctor.setAccessible(true);

return ctor.newInstance();
}
catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw instantiationException(typeName, e);
}
catch (NoSuchMethodException | SecurityException e) {
try {
return GridUnsafe.allocateInstance(cls);
}
catch (InstantiationException e0) {
e0.addSuppressed(e);
BinaryObjectBuilder builder = cctx.grid().binary().builder(typeName);
cctx.prepareAffinityField(builder);

throw instantiationException(typeName, e0);
}
}
return builder;
}

/** */
Expand Down Expand Up @@ -469,7 +440,7 @@ private <Row> ModifyTuple updateTuple(Row row, List<String> updateColList, int o
val = TypeUtils.fromInternal(ectx, fieldVal, desc.storageType());
}

if (cacheContext().binaryMarshaller() && val instanceof BinaryObjectBuilder)
if (val instanceof BinaryObjectBuilder)
val = ((BinaryObjectBuilder)val).build();

typeDesc.validateKeyAndValue(key, val);
Expand Down Expand Up @@ -503,15 +474,12 @@ else if (rowColumnsCnt == descriptors.length + updateColList.size())
}

/** */
private Object clone(Object val) throws IgniteCheckedException {
private Object clone(Object val) {
if (val == null || QueryUtils.isSqlType(val.getClass()))
return val;

GridCacheContext<?, ?> cctx = cacheContext();

if (!cctx.binaryMarshaller())
return cctx.marshaller().unmarshal(cctx.marshaller().marshal(val), U.resolveClassLoader(cctx.gridConfig()));

BinaryObjectBuilder builder = cctx.grid().binary().builder(
cctx.grid().binary().<BinaryObject>toBinary(val));

Expand Down
4 changes: 0 additions & 4 deletions modules/clients/src/test/config/jdbc-bin-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@

<property name="localHost" value="127.0.0.1"/>

<property name="marshaller">
<bean class="org.apache.ignite.internal.binary.BinaryMarshaller" />
</property>

<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.apache.ignite.cache.store.jdbc.dialect.OracleDialect;
import org.apache.ignite.cache.store.jdbc.dialect.SQLServerDialect;
import org.apache.ignite.internal.binary.BinaryEnumObjectImpl;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
import org.apache.ignite.internal.util.typedef.C1;
import org.apache.ignite.internal.util.typedef.F;
Expand Down Expand Up @@ -543,33 +542,13 @@ private void checkTypeConfiguration(@Nullable String cacheName, TypeKind kind, S

/**
* @param type Type name to check.
* @param binarySupported True if binary marshaller enable.
* @return {@code True} if class not found.
*/
protected TypeKind kindForName(String type, boolean binarySupported) {
protected TypeKind kindForName(String type) {
if (BUILT_IN_TYPES.contains(type))
return TypeKind.BUILT_IN;

if (binarySupported)
return TypeKind.BINARY;

try {
Class.forName(type);

return TypeKind.POJO;
}
catch (ClassNotFoundException e) {
throw new CacheException("Failed to find class " + type +
" (make sure the class is present in classPath or use BinaryMarshaller)", e);
}
}

/**
* @param type Type name to check.
* @return {@code True} if class not found.
*/
protected TypeKind kindForName(String type) {
return kindForName(type, ignite.configuration().getMarshaller() instanceof BinaryMarshaller);
return TypeKind.BINARY;
}

/**
Expand Down Expand Up @@ -600,13 +579,11 @@ private Map<Object, EntryMapping> getOrCreateCacheMappings(@Nullable String cach
entryMappings = U.newHashMap(cacheTypes.size());

if (!cacheTypes.isEmpty()) {
boolean binarySupported = ignite.configuration().getMarshaller() instanceof BinaryMarshaller;

for (JdbcType type : cacheTypes) {
String keyType = type.getKeyType();
String valType = type.getValueType();

TypeKind keyKind = kindForName(keyType, binarySupported);
TypeKind keyKind = kindForName(keyType);

checkTypeConfiguration(cacheName, keyKind, keyType, type.getKeyFields());

Expand All @@ -616,7 +593,7 @@ private Map<Object, EntryMapping> getOrCreateCacheMappings(@Nullable String cach
throw new CacheException("Key type must be unique in type metadata [cache=" +
U.maskName(cacheName) + ", type=" + keyType + "]");

TypeKind valKind = kindForName(valType, binarySupported);
TypeKind valKind = kindForName(valType);

checkTypeConfiguration(cacheName, valKind, valType, type.getValueFields());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_LANG_RUNTIME;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_LATE_AFFINITY_ASSIGNMENT;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MACS;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MARSHALLER;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MARSHALLER_COMPACT_FOOTER;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MARSHALLER_USE_BINARY_STRING_SER_VER_2;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MARSHALLER_USE_DFLT_SUID;
Expand Down Expand Up @@ -1525,10 +1524,12 @@ private void initializeMarshaller() {

if (marsh == null) {
if (!BinaryMarshaller.available()) {
U.warn(log, "Standard BinaryMarshaller can't be used on this JVM. " +
"Switch to HotSpot JVM or reach out Apache Ignite community for recommendations.");
String errMsg = "Standard BinaryMarshaller can't be used on this JVM. " +
"Switch to HotSpot JVM or reach out Apache Ignite community for recommendations.";

marsh = ctx.marshallerContext().jdkMarshaller();
U.warn(log, errMsg);

throw new IgniteException(errMsg);
}
else
marsh = new BinaryMarshaller();
Expand Down Expand Up @@ -1558,9 +1559,6 @@ private void suggestOptimizations(IgniteConfiguration cfg) {

if (cfg.getIncludeEventTypes() != null && cfg.getIncludeEventTypes().length != 0)
perf.add("Disable grid events (remove 'includeEventTypes' from configuration)");

if (BinaryMarshaller.available() && (cfg.getMarshaller() != null && !(cfg.getMarshaller() instanceof BinaryMarshaller)))
perf.add("Use default binary marshaller (do not set 'marshaller' explicitly)");
}

/**
Expand Down Expand Up @@ -1649,20 +1647,17 @@ private void fillNodeAttributes(boolean notifyEnabled) throws IgniteCheckedExcep
add(ATTR_JIT_NAME, U.getCompilerMx() == null ? "" : U.getCompilerMx().getName());
add(ATTR_BUILD_VER, VER_STR);
add(ATTR_BUILD_DATE, BUILD_TSTAMP_STR);
add(ATTR_MARSHALLER, cfg.getMarshaller().getClass().getName());
add(ATTR_MARSHALLER_USE_DFLT_SUID,
getBoolean(IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID, OptimizedMarshaller.USE_DFLT_SUID));
add(ATTR_LATE_AFFINITY_ASSIGNMENT, cfg.isLateAffinityAssignment());

if (cfg.getMarshaller() instanceof BinaryMarshaller) {
add(ATTR_MARSHALLER_COMPACT_FOOTER, cfg.getBinaryConfiguration() == null ?
BinaryConfiguration.DFLT_COMPACT_FOOTER :
cfg.getBinaryConfiguration().isCompactFooter());
add(ATTR_MARSHALLER_COMPACT_FOOTER, cfg.getBinaryConfiguration() == null ?
BinaryConfiguration.DFLT_COMPACT_FOOTER :
cfg.getBinaryConfiguration().isCompactFooter());

add(ATTR_MARSHALLER_USE_BINARY_STRING_SER_VER_2,
getBoolean(IGNITE_BINARY_MARSHALLER_USE_STRING_SERIALIZATION_VER_2,
BinaryUtils.USE_STR_SERIALIZATION_VER_2));
}
add(ATTR_MARSHALLER_USE_BINARY_STRING_SER_VER_2,
getBoolean(IGNITE_BINARY_MARSHALLER_USE_STRING_SERIALIZATION_VER_2,
BinaryUtils.USE_STR_SERIALIZATION_VER_2));

add(ATTR_USER_NAME, System.getProperty("user.name"));
add(ATTR_IGNITE_INSTANCE_NAME, igniteInstanceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.marshaller.MarshallerContext;
import org.apache.ignite.marshaller.MarshallerUtils;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -163,7 +164,7 @@ public class BinaryContext {
private BinaryMetadataHandler metaHnd;

/** Actual marshaller. */
private BinaryMarshaller marsh;
private Marshaller marsh;

/** */
private MarshallerContext marshCtx;
Expand Down Expand Up @@ -292,7 +293,7 @@ public IgniteLogger log() {
/**
* @return Marshaller.
*/
public BinaryMarshaller marshaller() {
public Marshaller marshaller() {
return marsh;
}

Expand Down Expand Up @@ -1613,38 +1614,4 @@ else if (!other.canOverride)
throw new BinaryObjectException("Duplicate explicit class definition in configuration: " + clsName);
}
}

/**
* Type id wrapper.
*/
static class Type {
/** Type id */
private final int id;

/** Whether the following type is registered in a cache or not */
private final boolean registered;

/**
* @param id Id.
* @param registered Registered.
*/
public Type(int id, boolean registered) {
this.id = id;
this.registered = registered;
}

/**
* @return Type ID.
*/
public int id() {
return id;
}

/**
* @return Registered flag value.
*/
public boolean registered() {
return registered;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public CacheGroupContext(

ioPlc = cacheType.ioPolicy();

depEnabled = ctx.kernalContext().deploy().enabled() && !ctx.kernalContext().cacheObjects().isBinaryEnabled(ccfg);
depEnabled = false;

storeCacheId = affNode && dataRegion.config().getPageEvictionMode() != DataPageEvictionMode.DISABLED;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class CacheObjectContext implements CacheObjectValueContext {
/** */
private final boolean addDepInfo;

/** Boinary enabled flag. */
/** Binary enabled flag. */
private final boolean binaryEnabled;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.IgniteKernal;
import org.apache.ignite.internal.IgnitionEx;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
import org.apache.ignite.internal.cache.context.SessionContextImpl;
import org.apache.ignite.internal.managers.communication.GridIoManager;
Expand Down Expand Up @@ -385,7 +384,7 @@ public GridCacheContext(
this.locStartTopVer = locStartTopVer;
this.affNode = affNode;
this.updatesAllowed = updatesAllowed;
this.depEnabled = ctx.deploy().enabled() && !cacheObjects().isBinaryEnabled(cacheCfg);
this.depEnabled = false;

/*
* Managers in starting order!
Expand Down Expand Up @@ -1687,13 +1686,6 @@ public IgniteCacheObjectProcessor cacheObjects() {
return kernalContext().cacheObjects();
}

/**
* @return {@code True} if {@link BinaryMarshaller is configured}.
*/
public boolean binaryMarshaller() {
return marshaller() instanceof BinaryMarshaller;
}

/**
* @return Keep binary flag.
*/
Expand Down Expand Up @@ -2242,7 +2234,6 @@ else if (type == EVT_CACHE_REBALANCE_STOPPED) {
* @param builder Builder.
*/
public void prepareAffinityField(BinaryObjectBuilder builder) {
assert binaryMarshaller();
assert builder instanceof BinaryObjectBuilderImpl;

BinaryObjectBuilderImpl builder0 = (BinaryObjectBuilderImpl)builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,6 @@ public void addEvent(
oldVal0 = cctx.cacheObjectContext().unwrapBinaryIfNeeded(oldVal, keepBinary, false, null);
}
catch (Exception e) {
if (!cctx.cacheObjectContext().kernalContext().cacheObjects().isBinaryEnabled(cctx.config()))
throw e;

if (log.isDebugEnabled())
log.debug("Failed to unmarshall cache object value for the event notification: " + e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.IgniteTransactionsEx;
import org.apache.ignite.internal.binary.BinaryContext;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.binary.GridBinaryMarshaller;
import org.apache.ignite.internal.cdc.CdcManager;
import org.apache.ignite.internal.cdc.CdcUtilityActiveCdcManager;
Expand Down Expand Up @@ -2198,12 +2197,6 @@ private void initCacheContext(

caches.put(cacheCtx.name(), cache);

// Intentionally compare Boolean references using '!=' below to check if the flag has been explicitly set.
if (cfg.isStoreKeepBinary() && cfg.isStoreKeepBinary() != CacheConfiguration.DFLT_STORE_KEEP_BINARY
&& !(ctx.config().getMarshaller() instanceof BinaryMarshaller))
U.warn(log, "CacheConfiguration.isStoreKeepBinary() configuration property will be ignored because " +
"BinaryMarshaller is not used");

// Start managers.
for (GridCacheManager mgr : F.view(cacheCtx.managers(), F.notContains(dhtExcludes(cacheCtx))))
mgr.start(cacheCtx);
Expand Down
Loading
Loading