use of org.apache.ignite.internal.binary.BinaryTypeImpl in project ignite by apache.
the class PlatformContextImpl method writeMetadata0.
/**
* Write binary metadata.
*
* @param writer Writer.
* @param typeId Type id.
* @param meta Metadata.
*/
private void writeMetadata0(BinaryRawWriterEx writer, int typeId, BinaryType meta) {
if (meta == null)
writer.writeBoolean(false);
else {
writer.writeBoolean(true);
BinaryMetadata meta0 = ((BinaryTypeImpl) meta).metadata();
Map<String, BinaryFieldMetadata> fields = meta0.fieldsMap();
writer.writeInt(typeId);
writer.writeString(meta.typeName());
writer.writeString(meta.affinityKeyFieldName());
writer.writeInt(fields.size());
for (Map.Entry<String, BinaryFieldMetadata> e : fields.entrySet()) {
writer.writeString(e.getKey());
writer.writeInt(e.getValue().typeId());
writer.writeInt(e.getValue().fieldId());
}
if (meta.isEnum()) {
writer.writeBoolean(true);
Map<String, Integer> enumMap = meta0.enumMap();
writer.writeInt(enumMap.size());
for (Map.Entry<String, Integer> e : enumMap.entrySet()) {
writer.writeString(e.getKey());
writer.writeInt(e.getValue());
}
} else
writer.writeBoolean(false);
}
}
use of org.apache.ignite.internal.binary.BinaryTypeImpl in project ignite by apache.
the class PlatformContextImpl method writeSchema.
/** {@inheritDoc} */
@Override
public void writeSchema(BinaryRawWriterEx writer, int typeId, int schemaId) {
BinarySchemaRegistry schemaReg = cacheObjProc.binaryContext().schemaRegistry(typeId);
BinarySchema schema = schemaReg.schema(schemaId);
if (schema == null) {
BinaryTypeImpl meta = (BinaryTypeImpl) cacheObjProc.metadata(typeId);
if (meta != null) {
for (BinarySchema typeSchema : meta.metadata().schemas()) {
if (schemaId == typeSchema.schemaId()) {
schema = typeSchema;
break;
}
}
}
if (schema != null)
schemaReg.addSchema(schemaId, schema);
}
int[] fieldIds = schema == null ? null : schema.fieldIds();
writer.writeIntArray(fieldIds);
}
use of org.apache.ignite.internal.binary.BinaryTypeImpl in project ignite by apache.
the class CacheObjectBinaryProcessorImpl method addMeta.
/**
* {@inheritDoc}
*/
@Override
public void addMeta(final int typeId, final BinaryType newMeta) throws BinaryObjectException {
assert newMeta != null;
assert newMeta instanceof BinaryTypeImpl;
BinaryMetadata newMeta0 = ((BinaryTypeImpl) newMeta).metadata();
try {
BinaryMetadataHolder metaHolder = metadataLocCache.get(typeId);
BinaryMetadata oldMeta = metaHolder != null ? metaHolder.metadata() : null;
BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(oldMeta, newMeta0);
// metadata requested to be added is exactly the same as already presented in the cache
if (mergedMeta == oldMeta)
return;
MetadataUpdateResult res = transport.requestMetadataUpdate(mergedMeta).get();
assert res != null;
if (res.rejected())
throw res.error();
} catch (IgniteCheckedException e) {
throw new BinaryObjectException("Failed to update meta data for type: " + newMeta.typeName(), e);
}
}
use of org.apache.ignite.internal.binary.BinaryTypeImpl in project ignite by apache.
the class BinaryMetadataMoveLegacyFolderTest method createBinaryType.
/**
* Get byte representation of simple binary type with one field
*
* @param typeName Type name.
* @param fieldName Field name.
*/
private byte[] createBinaryType(String typeName, String fieldName) throws Exception {
IgniteConfiguration configuration = getConfiguration();
IgniteEx grid = startGrid(configuration);
IgniteBinary binary = grid.binary();
BinaryObjectBuilder builder = binary.builder("TestBinaryType");
builder.setField(fieldName, 1);
builder.build();
BinaryMetadata metadata = ((BinaryTypeImpl) binary.type(typeName)).metadata();
byte[] marshalled = U.marshal(grid.context(), metadata);
stopAllGrids();
cleanPersistenceDir();
return marshalled;
}
use of org.apache.ignite.internal.binary.BinaryTypeImpl in project ignite by apache.
the class CacheObjectBinaryProcessorImpl method start.
/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
if (marsh instanceof BinaryMarshaller) {
if (ctx.clientNode())
ctx.event().addLocalEventListener(clientDisconLsnr, EVT_CLIENT_NODE_DISCONNECTED);
transport = new BinaryMetadataTransport(metadataLocCache, ctx, log);
BinaryMetadataHandler metaHnd = new BinaryMetadataHandler() {
@Override
public void addMeta(int typeId, BinaryType newMeta) throws BinaryObjectException {
assert newMeta != null;
assert newMeta instanceof BinaryTypeImpl;
if (!discoveryStarted) {
BinaryMetadataHolder holder = metadataLocCache.get(typeId);
BinaryMetadata oldMeta = holder != null ? holder.metadata() : null;
BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(oldMeta, ((BinaryTypeImpl) newMeta).metadata());
if (oldMeta != mergedMeta)
metadataLocCache.putIfAbsent(typeId, new BinaryMetadataHolder(mergedMeta, 0, 0));
return;
}
BinaryMetadata newMeta0 = ((BinaryTypeImpl) newMeta).metadata();
CacheObjectBinaryProcessorImpl.this.addMeta(typeId, newMeta0.wrap(binaryCtx));
}
@Override
public BinaryType metadata(int typeId) throws BinaryObjectException {
return CacheObjectBinaryProcessorImpl.this.metadata(typeId);
}
@Override
public BinaryMetadata metadata0(int typeId) throws BinaryObjectException {
return CacheObjectBinaryProcessorImpl.this.metadata0(typeId);
}
@Override
public BinaryType metadata(int typeId, int schemaId) throws BinaryObjectException {
return CacheObjectBinaryProcessorImpl.this.metadata(typeId, schemaId);
}
};
BinaryMarshaller bMarsh0 = (BinaryMarshaller) marsh;
binaryCtx = new BinaryContext(metaHnd, ctx.config(), ctx.log(BinaryContext.class));
IgniteUtils.invoke(BinaryMarshaller.class, bMarsh0, "setBinaryContext", binaryCtx, ctx.config());
binaryMarsh = new GridBinaryMarshaller(binaryCtx);
binaries = new IgniteBinaryImpl(ctx, this);
if (!getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) {
BinaryConfiguration bCfg = ctx.config().getBinaryConfiguration();
if (bCfg != null) {
Map<String, Object> map = 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());
if (bCfg.getTypeConfigurations() != null) {
Map<Object, Object> typeCfgsMap = new HashMap<>();
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 (c.isEnum())
BinaryUtils.validateEnumValues(c.getTypeName(), c.getEnumValues());
}
map.put("typeCfgs", typeCfgsMap);
}
ctx.addNodeAttribute(IgniteNodeAttributes.ATTR_BINARY_CONFIGURATION, map);
}
}
}
}
Aggregations