use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class BinaryUtils method mergeMetadata.
/**
* Merge old and new metas.
*
* @param oldMeta Old meta.
* @param newMeta New meta.
* @return New meta if old meta was null, old meta if no changes detected, merged meta otherwise.
* @throws BinaryObjectException If merge failed due to metadata conflict.
*/
public static BinaryMetadata mergeMetadata(@Nullable BinaryMetadata oldMeta, BinaryMetadata newMeta) {
assert newMeta != null;
if (oldMeta == null)
return newMeta;
else {
assert oldMeta.typeId() == newMeta.typeId();
// Check type name.
if (!F.eq(oldMeta.typeName(), newMeta.typeName())) {
throw new BinaryObjectException("Two binary types have duplicate type ID [" + "typeId=" + oldMeta.typeId() + ", typeName1=" + oldMeta.typeName() + ", typeName2=" + newMeta.typeName() + ']');
}
// Check affinity field names.
if (!F.eq(oldMeta.affinityKeyFieldName(), newMeta.affinityKeyFieldName())) {
throw new BinaryObjectException("Binary type has different affinity key fields [" + "typeName=" + newMeta.typeName() + ", affKeyFieldName1=" + oldMeta.affinityKeyFieldName() + ", affKeyFieldName2=" + newMeta.affinityKeyFieldName() + ']');
}
// Check enum flag.
if (oldMeta.isEnum() != newMeta.isEnum()) {
if (oldMeta.isEnum())
throw new BinaryObjectException("Binary type already registered as enum: " + newMeta.typeName());
else
throw new BinaryObjectException("Binary type already registered as non-enum: " + newMeta.typeName());
}
// Check and merge fields.
Map<String, BinaryFieldMetadata> mergedFields;
if (FIELDS_SORTED_ORDER)
mergedFields = new TreeMap<>(oldMeta.fieldsMap());
else
mergedFields = new LinkedHashMap<>(oldMeta.fieldsMap());
Map<String, BinaryFieldMetadata> newFields = newMeta.fieldsMap();
boolean changed = false;
Map<String, Integer> mergedEnumMap = null;
if (!F.isEmpty(newMeta.enumMap())) {
mergedEnumMap = mergeEnumValues(oldMeta.typeName(), oldMeta.enumMap(), newMeta.enumMap());
changed = mergedEnumMap.size() > oldMeta.enumMap().size();
}
for (Map.Entry<String, BinaryFieldMetadata> newField : newFields.entrySet()) {
BinaryFieldMetadata oldFieldMeta = mergedFields.put(newField.getKey(), newField.getValue());
if (oldFieldMeta == null)
changed = true;
else {
String oldFieldTypeName = fieldTypeName(oldFieldMeta.typeId());
String newFieldTypeName = fieldTypeName(newField.getValue().typeId());
if (!F.eq(oldFieldTypeName, newFieldTypeName)) {
throw new BinaryObjectException("Binary type has different field types [" + "typeName=" + oldMeta.typeName() + ", fieldName=" + newField.getKey() + ", fieldTypeName1=" + oldFieldTypeName + ", fieldTypeName2=" + newFieldTypeName + ']');
}
}
}
// Check and merge schemas.
Collection<BinarySchema> mergedSchemas = new HashSet<>(oldMeta.schemas());
for (BinarySchema newSchema : newMeta.schemas()) {
if (mergedSchemas.add(newSchema))
changed = true;
}
// Return either old meta if no changes detected, or new merged meta.
return changed ? new BinaryMetadata(oldMeta.typeId(), oldMeta.typeName(), mergedFields, oldMeta.affinityKeyFieldName(), mergedSchemas, oldMeta.isEnum(), mergedEnumMap) : oldMeta;
}
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class JdbcBatchExecuteRequest method readBinary.
/**
* {@inheritDoc}
*/
@Override
public void readBinary(BinaryReaderExImpl reader) throws BinaryObjectException {
super.readBinary(reader);
schemaName = reader.readString();
int n = reader.readInt();
queries = new ArrayList<>(n);
for (int i = 0; i < n; ++i) {
JdbcQuery qry = new JdbcQuery();
qry.readBinary(reader);
queries.add(qry);
}
try {
if (reader.available() > 0)
lastStreamBatch = reader.readBoolean();
} catch (IOException e) {
throw new BinaryObjectException(e);
}
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class JdbcBulkLoadBatchRequest method readBinary.
/**
* {@inheritDoc}
*/
@Override
public void readBinary(BinaryReaderExImpl reader) throws BinaryObjectException {
super.readBinary(reader);
qryId = reader.readLong();
batchIdx = reader.readInt();
int c = reader.readInt();
if (!isCmdValid(c))
throw new BinaryObjectException("Invalid command: " + cmd);
cmd = c;
data = reader.readByteArray();
assert data != null;
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class JdbcQueryExecuteRequest method readBinary.
/**
* {@inheritDoc}
*/
@Override
public void readBinary(BinaryReaderExImpl reader) throws BinaryObjectException {
super.readBinary(reader);
schemaName = reader.readString();
pageSize = reader.readInt();
maxRows = reader.readInt();
sqlQry = reader.readString();
int argsNum = reader.readInt();
args = new Object[argsNum];
for (int i = 0; i < argsNum; ++i) args[i] = SqlListenerUtils.readObject(reader, false);
try {
if (reader.available() > 0)
stmtType = JdbcStatementType.fromOrdinal(reader.readByte());
else
stmtType = JdbcStatementType.ANY_STATEMENT_TYPE;
} catch (IOException e) {
throw new BinaryObjectException(e);
}
}
use of org.apache.ignite.binary.BinaryObjectException 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);
}
}
Aggregations