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 Remove instanceOf BinaryMarshaller #11968

Merged
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 @@ -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 @@ -222,117 +222,115 @@ public CacheObjectBinaryProcessorImpl(GridKernalContext ctx) {

/** {@inheritDoc} */
@Override public void start() throws IgniteCheckedException {
if (marsh instanceof BinaryMarshaller) {
if (!ctx.clientNode()) {
if (BinaryMetadataFileStore.enabled(ctx.config()) && binaryMetadataFileStoreDir == null)
binaryMetadataFileStoreDir = ctx.pdsFolderResolver().fileTree().mkdirBinaryMeta();
if (!ctx.clientNode()) {
if (BinaryMetadataFileStore.enabled(ctx.config()) && binaryMetadataFileStoreDir == null)
binaryMetadataFileStoreDir = ctx.pdsFolderResolver().fileTree().mkdirBinaryMeta();

metadataFileStore = new BinaryMetadataFileStore(metadataLocCache, ctx, log, binaryMetadataFileStoreDir, false);
metadataFileStore = new BinaryMetadataFileStore(metadataLocCache, ctx, log, binaryMetadataFileStoreDir, false);

metadataFileStore.start();
}

BinaryMetadataHandler metaHnd = new BinaryMetadataHandler() {
@Override public void addMeta(
int typeId,
BinaryType newMeta,
boolean failIfUnregistered) throws BinaryObjectException {
assert newMeta != null;
assert newMeta instanceof BinaryTypeImpl;

if (!discoveryStarted) {
BinaryMetadataHolder holder = metadataLocCache.get(typeId);
metadataFileStore.start();
}

BinaryMetadata oldMeta = holder != null ? holder.metadata() : null;
BinaryMetadataHandler metaHnd = new BinaryMetadataHandler() {
@Override public void addMeta(
int typeId,
BinaryType newMeta,
boolean failIfUnregistered) throws BinaryObjectException {
assert newMeta != null;
assert newMeta instanceof BinaryTypeImpl;

BinaryMetadata mergedMeta = mergeMetadata(oldMeta, ((BinaryTypeImpl)newMeta).metadata());
if (!discoveryStarted) {
BinaryMetadataHolder holder = metadataLocCache.get(typeId);

if (oldMeta != mergedMeta)
metadataLocCache.put(typeId, new BinaryMetadataHolder(mergedMeta, 0, 0));
BinaryMetadata oldMeta = holder != null ? holder.metadata() : null;

return;
}
BinaryMetadata mergedMeta = mergeMetadata(oldMeta, ((BinaryTypeImpl)newMeta).metadata());

BinaryMetadata newMeta0 = ((BinaryTypeImpl)newMeta).metadata();
if (oldMeta != mergedMeta)
metadataLocCache.put(typeId, new BinaryMetadataHolder(mergedMeta, 0, 0));

CacheObjectBinaryProcessorImpl.this.addMeta(
typeId,
newMeta0.wrap(binaryCtx),
failIfUnregistered
);
return;
}

@Override public void addMetaLocally(int typeId, BinaryType meta, boolean failIfUnregistered)
throws BinaryObjectException {
CacheObjectBinaryProcessorImpl.this.addMetaLocally(typeId, meta);
}
BinaryMetadata newMeta0 = ((BinaryTypeImpl)newMeta).metadata();

@Override public BinaryType metadata(int typeId) throws BinaryObjectException {
return CacheObjectBinaryProcessorImpl.this.metadata(typeId);
}
CacheObjectBinaryProcessorImpl.this.addMeta(
typeId,
newMeta0.wrap(binaryCtx),
failIfUnregistered
);
}

@Override public BinaryMetadata metadata0(int typeId) throws BinaryObjectException {
return CacheObjectBinaryProcessorImpl.this.metadata0(typeId);
}
@Override public void addMetaLocally(int typeId, BinaryType meta, boolean failIfUnregistered)
throws BinaryObjectException {
CacheObjectBinaryProcessorImpl.this.addMetaLocally(typeId, meta);
}

@Override public BinaryType metadata(int typeId, int schemaId) throws BinaryObjectException {
return CacheObjectBinaryProcessorImpl.this.metadata(typeId, schemaId);
}
@Override public BinaryType metadata(int typeId) throws BinaryObjectException {
return CacheObjectBinaryProcessorImpl.this.metadata(typeId);
}

@Override public Collection<BinaryType> metadata() throws BinaryObjectException {
return CacheObjectBinaryProcessorImpl.this.metadata();
}
};
@Override public BinaryMetadata metadata0(int typeId) throws BinaryObjectException {
return CacheObjectBinaryProcessorImpl.this.metadata0(typeId);
}

binaryCtx = useTestBinaryCtx ?
new TestBinaryContext(metaHnd, ctx.config(), ctx.log(BinaryContext.class)) :
new BinaryContext(metaHnd, ctx.config(), ctx.log(BinaryContext.class));
@Override public BinaryType metadata(int typeId, int schemaId) throws BinaryObjectException {
return CacheObjectBinaryProcessorImpl.this.metadata(typeId, schemaId);
}

transport = new BinaryMetadataTransport(metadataLocCache, metadataFileStore, binaryCtx, ctx, log);
@Override public Collection<BinaryType> metadata() throws BinaryObjectException {
return CacheObjectBinaryProcessorImpl.this.metadata();
}
};

binaryCtx = useTestBinaryCtx ?
new TestBinaryContext(metaHnd, ctx.config(), ctx.log(BinaryContext.class)) :
new BinaryContext(metaHnd, ctx.config(), ctx.log(BinaryContext.class));

marsh.setBinaryContext(binaryCtx, ctx.config());
transport = new BinaryMetadataTransport(metadataLocCache, metadataFileStore, binaryCtx, ctx, log);

binaryMarsh = new GridBinaryMarshaller(binaryCtx);
marsh.setBinaryContext(binaryCtx, ctx.config());

binaries = new IgniteBinaryImpl(ctx, this);
binaryMarsh = new GridBinaryMarshaller(binaryCtx);

if (!getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) {
BinaryConfiguration bCfg = ctx.config().getBinaryConfiguration();
binaries = new IgniteBinaryImpl(ctx, this);

if (bCfg != null) {
Map<String, Object> map = new HashMap<>();
if (!getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) {
BinaryConfiguration bCfg = ctx.config().getBinaryConfiguration();

map.put("globIdMapper", bCfg.getIdMapper() != null ? bCfg.getIdMapper().getClass().getName() : null);
map.put("globSerializer", bCfg.getSerializer() != null ? bCfg.getSerializer().getClass() : null);
map.put("compactFooter", bCfg.isCompactFooter());
if (bCfg != null) {
Map<String, Object> map = new HashMap<>();

if (bCfg.getTypeConfigurations() != null) {
Map<Object, Object> typeCfgsMap = new HashMap<>();
map.put("globIdMapper", bCfg.getIdMapper() != null ? bCfg.getIdMapper().getClass().getName() : null);
map.put("globSerializer", bCfg.getSerializer() != null ? bCfg.getSerializer().getClass() : null);
map.put("compactFooter", bCfg.isCompactFooter());

for (BinaryTypeConfiguration c : bCfg.getTypeConfigurations()) {
typeCfgsMap.put(
c.getTypeName() != null,
Arrays.asList(
c.getIdMapper() != null ? c.getIdMapper().getClass() : null,
c.getSerializer() != null ? c.getSerializer().getClass() : null,
c.isEnum()
)
);
if (bCfg.getTypeConfigurations() != null) {
Map<Object, Object> typeCfgsMap = new HashMap<>();

if (c.isEnum())
BinaryUtils.validateEnumValues(c.getTypeName(), c.getEnumValues());
}
for (BinaryTypeConfiguration c : bCfg.getTypeConfigurations()) {
typeCfgsMap.put(
c.getTypeName() != null,
Arrays.asList(
c.getIdMapper() != null ? c.getIdMapper().getClass() : null,
c.getSerializer() != null ? c.getSerializer().getClass() : null,
c.isEnum()
)
);

map.put("typeCfgs", typeCfgsMap);
if (c.isEnum())
BinaryUtils.validateEnumValues(c.getTypeName(), c.getEnumValues());
}

ctx.addNodeAttribute(IgniteNodeAttributes.ATTR_BINARY_CONFIGURATION, map);
map.put("typeCfgs", typeCfgsMap);
}
}

if (!ctx.clientNode())
metadataFileStore.restoreMetadata();
ctx.addNodeAttribute(IgniteNodeAttributes.ATTR_BINARY_CONFIGURATION, map);
}
}

if (!ctx.clientNode())
metadataFileStore.restoreMetadata();
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -1163,9 +1161,9 @@ public BinaryContext binaryContext() {

boolean storeVal = !ccfg.isCopyOnRead();

boolean binaryEnabled = marsh instanceof BinaryMarshaller && !GridCacheUtils.isSystemCache(ccfg.getName());
boolean notSysCache = !GridCacheUtils.isSystemCache(ccfg.getName());

AffinityKeyMapper dfltAffMapper = binaryEnabled ?
AffinityKeyMapper dfltAffMapper = notSysCache ?
new CacheDefaultBinaryAffinityKeyMapper(ccfg.getKeyConfiguration()) :
new GridCacheDefaultAffinityKeyMapper();

Expand All @@ -1178,7 +1176,7 @@ public BinaryContext binaryContext() {
ccfg.isCopyOnRead(),
storeVal,
false,
binaryEnabled
notSysCache
);
}

Expand Down Expand Up @@ -1448,7 +1446,7 @@ private int partition(CacheObjectContext ctx, @Nullable GridCacheContext cctx, O
) {
IgniteNodeValidationResult res;

if (getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK) || !(marsh instanceof BinaryMarshaller))
if (getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK))
return null;

if ((res = validateBinaryConfiguration(rmtNode)) != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.ignite.internal.processors.cache.query;

import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.internal.binary.BinaryMarshaller;

/**
* Message which needs to be marshalled and unmarshalled before sending or processing it.
Expand All @@ -27,11 +27,10 @@ public interface GridCacheQueryMarshallable {
/**
* @param m Marshaller.
*/
public void marshall(Marshaller m);
public void marshall(BinaryMarshaller m);

/**
* @param m Marshaller.
* @param ctx Context.
*/
public void unmarshall(Marshaller m, GridKernalContext ctx);
public void unmarshall(GridKernalContext ctx);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.ignite.cache.store.CacheStore;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.processors.platform.PlatformProcessor;
import org.apache.ignite.internal.processors.platform.cache.store.PlatformCacheStore;

Expand Down Expand Up @@ -85,6 +84,6 @@ public CacheOsStoreManager(GridKernalContext ctx, CacheConfiguration cfg) {

/** {@inheritDoc} */
@Override public boolean configuredConvertBinary() {
return !(ctx.marshaller() instanceof BinaryMarshaller && cfg.isStoreKeepBinary());
return !cfg.isStoreKeepBinary();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.lang.IgniteFuture;
import org.apache.ignite.lang.IgniteInClosure;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.plugin.extensions.communication.Message;
import org.apache.ignite.plugin.security.SecurityPermission;
import org.apache.ignite.resources.LoggerResource;
Expand Down Expand Up @@ -195,7 +194,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
private UUID nodeId;

/** */
private Marshaller marshaller;
private BinaryMarshaller marshaller;

/** */
private GridMapQueryExecutor mapQryExec;
Expand Down Expand Up @@ -426,18 +425,12 @@ private GridQueryFieldsResult executeSelectLocal(
PreparedStatement stmt = conn.prepareStatement(qry, H2StatementCache.queryFlags(qryDesc));

// Convert parameters into BinaryObjects.
Marshaller m = ctx.marshaller();
BinaryMarshaller m = ctx.marshaller();
byte[] paramsBytes = U.marshal(m, qryParams.arguments());
final ClassLoader ldr = U.resolveClassLoader(ctx.config());

Object[] params;

if (m instanceof BinaryMarshaller) {
params = BinaryUtils.rawArrayFromBinary(((BinaryMarshaller)m).binaryMarshaller()
.unmarshal(paramsBytes, ldr));
}
else
params = U.unmarshal(m, paramsBytes, ldr);
Object[] params = BinaryUtils.rawArrayFromBinary(m.binaryMarshaller()
.unmarshal(paramsBytes, ldr));

H2Utils.bindParameters(stmt, F.asList(params));

Expand Down Expand Up @@ -1660,7 +1653,7 @@ public void onMessage(UUID nodeId, Object msg) {

try {
if (msg instanceof GridCacheQueryMarshallable)
((GridCacheQueryMarshallable)msg).unmarshall(ctx.marshaller(), ctx);
((GridCacheQueryMarshallable)msg).unmarshall(ctx);

try {
boolean processed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.plugin.extensions.communication.Message;
import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType;
import org.apache.ignite.plugin.extensions.communication.MessageReader;
Expand Down Expand Up @@ -320,7 +319,7 @@ public GridH2DmlRequest explicitTimeout(boolean explicitTimeout) {
}

/** {@inheritDoc} */
@Override public void marshall(Marshaller m) {
@Override public void marshall(BinaryMarshaller m) {
if (paramsBytes != null)
return;

Expand All @@ -336,24 +335,16 @@ public GridH2DmlRequest explicitTimeout(boolean explicitTimeout) {

/** {@inheritDoc} */
@SuppressWarnings("IfMayBeConditional")
@Override public void unmarshall(Marshaller m, GridKernalContext ctx) {
@Override public void unmarshall(GridKernalContext ctx) {
if (params != null)
return;

assert paramsBytes != null;

try {
final ClassLoader ldr = U.resolveClassLoader(ctx.config());
final ClassLoader ldr = U.resolveClassLoader(ctx.config());

if (m instanceof BinaryMarshaller)
// To avoid deserializing of enum types.
params = BinaryUtils.rawArrayFromBinary(((BinaryMarshaller)m).binaryMarshaller().unmarshal(paramsBytes, ldr));
else
params = U.unmarshal(m, paramsBytes, ldr);
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
// To avoid deserializing of enum types.
params = BinaryUtils.rawArrayFromBinary(ctx.marshaller().binaryMarshaller().unmarshal(paramsBytes, ldr));
}

/** {@inheritDoc} */
Expand Down
Loading