use of org.gridgain.internal.h2.message.DbException in project ignite by apache.
the class ValidateIndexesClosure method processIndex.
/**
* @param cacheCtxWithIdx Cache context and appropriate index.
* @param idleChecker Idle check closure.
*/
private Map<String, ValidateIndexesPartitionResult> processIndex(T2<GridCacheContext, Index> cacheCtxWithIdx, IgniteInClosure<Integer> idleChecker) {
if (validateCtx.isCancelled())
return emptyMap();
GridCacheContext ctx = cacheCtxWithIdx.get1();
Index idx = cacheCtxWithIdx.get2();
ValidateIndexesPartitionResult idxValidationRes = new ValidateIndexesPartitionResult();
boolean enoughIssues = false;
Cursor cursor = null;
try (Session session = mvccSession(cacheCtxWithIdx.get1())) {
cursor = idx.find(session, null, null);
if (cursor == null)
throw new IgniteCheckedException("Can't iterate through index: " + idx);
} catch (Throwable t) {
IndexValidationIssue is = new IndexValidationIssue(null, ctx.name(), idx.getName(), t);
log.error("Find in index failed: " + is.toString());
idxValidationRes.reportIssue(is);
enoughIssues = true;
}
final boolean skipConditions = checkFirst > 0 || checkThrough > 0;
final boolean bothSkipConditions = checkFirst > 0 && checkThrough > 0;
long current = 0;
long processedNumber = 0;
KeyCacheObject previousKey = null;
while (!enoughIssues && !validateCtx.isCancelled()) {
KeyCacheObject h2key = null;
try {
try {
if (!cursor.next())
break;
} catch (DbException e) {
if (X.hasCause(e, CorruptedTreeException.class))
throw new IgniteCheckedException("Key is present in SQL index, but is missing in corresponding " + "data page. Previous successfully read key: " + CacheObjectUtils.unwrapBinaryIfNeeded(ctx.cacheObjectContext(), previousKey, true, true), X.cause(e, CorruptedTreeException.class));
throw e;
}
H2CacheRow h2Row = (H2CacheRow) cursor.get();
if (skipConditions) {
if (bothSkipConditions) {
if (processedNumber > checkFirst)
break;
else if (current++ % checkThrough > 0)
continue;
else
processedNumber++;
} else {
if (checkFirst > 0) {
if (current++ > checkFirst)
break;
} else {
if (current++ % checkThrough > 0)
continue;
}
}
}
h2key = h2Row.key();
if (h2Row.link() != 0L) {
CacheDataRow cacheDataStoreRow = ctx.group().offheap().read(ctx, h2key);
if (cacheDataStoreRow == null)
throw new IgniteCheckedException("Key is present in SQL index, but can't be found in CacheDataTree.");
} else
throw new IgniteCheckedException("Invalid index row, possibly deleted " + h2Row);
} catch (Throwable t) {
Object o = CacheObjectUtils.unwrapBinaryIfNeeded(ctx.cacheObjectContext(), h2key, true, true);
IndexValidationIssue is = new IndexValidationIssue(String.valueOf(o), ctx.name(), idx.getName(), t);
log.error("Failed to lookup key: " + is.toString());
enoughIssues |= idxValidationRes.reportIssue(is);
} finally {
previousKey = h2key;
}
}
CacheGroupContext group = ctx.group();
String uniqueIdxName = String.format("[cacheGroup=%s, cacheGroupId=%s, cache=%s, cacheId=%s, idx=%s]", group.name(), group.groupId(), ctx.name(), ctx.cacheId(), idx.getName());
idleChecker.apply(group.groupId());
processedIndexes.incrementAndGet();
printProgressOfIndexValidationIfNeeded();
return Collections.singletonMap(uniqueIdxName, idxValidationRes);
}
use of org.gridgain.internal.h2.message.DbException in project h2database by h2database.
the class Parser method parseColumnWithType.
private Column parseColumnWithType(String columnName) {
String original = currentToken;
boolean regular = false;
int originalScale = -1;
if (readIf("LONG")) {
if (readIf("RAW")) {
original += " RAW";
}
} else if (readIf("DOUBLE")) {
if (readIf("PRECISION")) {
original += " PRECISION";
}
} else if (readIf("CHARACTER")) {
if (readIf("VARYING")) {
original += " VARYING";
}
} else if (readIf("TIME")) {
if (readIf("(")) {
originalScale = readPositiveInt();
if (originalScale > ValueTime.MAXIMUM_SCALE) {
throw DbException.get(ErrorCode.INVALID_VALUE_SCALE_PRECISION, Integer.toString(originalScale));
}
read(")");
}
if (readIf("WITHOUT")) {
read("TIME");
read("ZONE");
original += " WITHOUT TIME ZONE";
}
} else if (readIf("TIMESTAMP")) {
if (readIf("(")) {
originalScale = readPositiveInt();
// Allow non-standard TIMESTAMP(..., ...) syntax
if (readIf(",")) {
originalScale = readPositiveInt();
}
if (originalScale > ValueTimestamp.MAXIMUM_SCALE) {
throw DbException.get(ErrorCode.INVALID_VALUE_SCALE_PRECISION, Integer.toString(originalScale));
}
read(")");
}
if (readIf("WITH")) {
read("TIME");
read("ZONE");
original += " WITH TIME ZONE";
} else if (readIf("WITHOUT")) {
read("TIME");
read("ZONE");
original += " WITHOUT TIME ZONE";
}
} else {
regular = true;
}
long precision = -1;
int displaySize = -1;
String[] enumerators = null;
int scale = -1;
String comment = null;
Column templateColumn = null;
DataType dataType;
if (!identifiersToUpper) {
original = StringUtils.toUpperEnglish(original);
}
UserDataType userDataType = database.findUserDataType(original);
if (userDataType != null) {
templateColumn = userDataType.getColumn();
dataType = DataType.getDataType(templateColumn.getType());
comment = templateColumn.getComment();
original = templateColumn.getOriginalSQL();
precision = templateColumn.getPrecision();
displaySize = templateColumn.getDisplaySize();
scale = templateColumn.getScale();
enumerators = templateColumn.getEnumerators();
} else {
Mode mode = database.getMode();
dataType = DataType.getTypeByName(original, mode);
if (dataType == null || mode.disallowedTypes.contains(original)) {
throw DbException.get(ErrorCode.UNKNOWN_DATA_TYPE_1, currentToken);
}
}
if (database.getIgnoreCase() && dataType.type == Value.STRING && !equalsToken("VARCHAR_CASESENSITIVE", original)) {
original = "VARCHAR_IGNORECASE";
dataType = DataType.getTypeByName(original, database.getMode());
}
if (regular) {
read();
}
precision = precision == -1 ? dataType.defaultPrecision : precision;
displaySize = displaySize == -1 ? dataType.defaultDisplaySize : displaySize;
scale = scale == -1 ? dataType.defaultScale : scale;
if (dataType.supportsPrecision || dataType.supportsScale) {
int t = dataType.type;
if (t == Value.TIME || t == Value.TIMESTAMP || t == Value.TIMESTAMP_TZ) {
if (originalScale >= 0) {
scale = originalScale;
switch(t) {
case Value.TIME:
if (original.equals("TIME WITHOUT TIME ZONE")) {
original = "TIME(" + originalScale + ") WITHOUT TIME ZONE";
} else {
original = original + '(' + originalScale + ')';
}
precision = displaySize = ValueTime.getDisplaySize(originalScale);
break;
case Value.TIMESTAMP:
if (original.equals("TIMESTAMP WITHOUT TIME ZONE")) {
original = "TIMESTAMP(" + originalScale + ") WITHOUT TIME ZONE";
} else {
original = original + '(' + originalScale + ')';
}
precision = displaySize = ValueTimestamp.getDisplaySize(originalScale);
break;
case Value.TIMESTAMP_TZ:
original = "TIMESTAMP(" + originalScale + ") WITH TIME ZONE";
precision = displaySize = ValueTimestampTimeZone.getDisplaySize(originalScale);
break;
}
}
} else if (readIf("(")) {
if (!readIf("MAX")) {
long p = readLong();
if (readIf("K")) {
p *= 1024;
} else if (readIf("M")) {
p *= 1024 * 1024;
} else if (readIf("G")) {
p *= 1024 * 1024 * 1024;
}
if (p > Long.MAX_VALUE) {
p = Long.MAX_VALUE;
}
original += "(" + p;
// Oracle syntax
if (!readIf("CHAR")) {
readIf("BYTE");
}
if (dataType.supportsScale) {
if (readIf(",")) {
scale = readInt();
original += ", " + scale;
} else {
scale = 0;
}
}
precision = p;
displaySize = MathUtils.convertLongToInt(precision);
original += ")";
}
read(")");
}
} else if (dataType.type == Value.DOUBLE && original.equals("FLOAT")) {
if (readIf("(")) {
int p = readPositiveInt();
read(")");
if (p > 53) {
throw DbException.get(ErrorCode.INVALID_VALUE_SCALE_PRECISION, Integer.toString(p));
}
if (p <= 24) {
dataType = DataType.getDataType(Value.FLOAT);
}
original = original + '(' + p + ')';
}
} else if (dataType.type == Value.ENUM) {
if (readIf("(")) {
java.util.List<String> enumeratorList = new ArrayList<>();
original += '(';
String enumerator0 = readString();
enumeratorList.add(enumerator0);
original += "'" + enumerator0 + "'";
while (readIfMore(true)) {
original += ',';
String enumeratorN = readString();
original += "'" + enumeratorN + "'";
enumeratorList.add(enumeratorN);
}
original += ')';
enumerators = enumeratorList.toArray(new String[0]);
}
try {
ValueEnum.check(enumerators);
} catch (DbException e) {
throw e.addSQL(original);
}
} else if (readIf("(")) {
// Support for MySQL: INT(11), MEDIUMINT(8) and so on.
// Just ignore the precision.
readPositiveInt();
read(")");
}
if (readIf("FOR")) {
read("BIT");
read("DATA");
if (dataType.type == Value.STRING) {
dataType = DataType.getTypeByName("BINARY", database.getMode());
}
}
// MySQL compatibility
readIf("UNSIGNED");
int type = dataType.type;
if (scale > precision) {
throw DbException.get(ErrorCode.INVALID_VALUE_SCALE_PRECISION, Integer.toString(scale), Long.toString(precision));
}
Column column = new Column(columnName, type, precision, scale, displaySize, enumerators);
if (templateColumn != null) {
column.setNullable(templateColumn.isNullable());
column.setDefaultExpression(session, templateColumn.getDefaultExpression());
int selectivity = templateColumn.getSelectivity();
if (selectivity != Constants.SELECTIVITY_DEFAULT) {
column.setSelectivity(selectivity);
}
Expression checkConstraint = templateColumn.getCheckConstraint(session, columnName);
column.addCheckConstraint(session, checkConstraint);
}
column.setComment(comment);
column.setOriginalSQL(original);
return column;
}
use of org.gridgain.internal.h2.message.DbException in project h2database by h2database.
the class Insert method addRowImpl.
private Row addRowImpl(Value[] values) {
Row newRow = table.getTemplateRow();
setCurrentRowNumber(++rowNumber);
for (int j = 0, len = columns.length; j < len; j++) {
Column c = columns[j];
int index = c.getColumnId();
try {
Value v = c.convert(values[j], session.getDatabase().getMode());
newRow.setValue(index, v);
} catch (DbException ex) {
throw setRow(ex, rowNumber, getSQL(values));
}
}
table.validateConvertUpdateSequence(session, newRow);
boolean done = table.fireBeforeRow(session, null, newRow);
if (!done) {
table.addRow(session, newRow);
session.log(table, UndoLogRecord.INSERT, newRow);
table.fireAfterRow(session, null, newRow, false);
return newRow;
}
return null;
}
use of org.gridgain.internal.h2.message.DbException in project h2database by h2database.
the class Replace method update.
@Override
public int update() {
int count;
session.getUser().checkRight(table, Right.INSERT);
session.getUser().checkRight(table, Right.UPDATE);
setCurrentRowNumber(0);
if (!list.isEmpty()) {
count = 0;
for (int x = 0, size = list.size(); x < size; x++) {
setCurrentRowNumber(x + 1);
Expression[] expr = list.get(x);
Row newRow = table.getTemplateRow();
for (int i = 0, len = columns.length; i < len; i++) {
Column c = columns[i];
int index = c.getColumnId();
Expression e = expr[i];
if (e != null) {
// e can be null (DEFAULT)
try {
Value v = c.convert(e.getValue(session));
newRow.setValue(index, v);
} catch (DbException ex) {
throw setRow(ex, count, getSQL(expr));
}
}
}
replace(newRow);
count++;
}
} else {
ResultInterface rows = query.query(0);
count = 0;
table.fire(session, Trigger.UPDATE | Trigger.INSERT, true);
table.lock(session, true, false);
while (rows.next()) {
count++;
Value[] r = rows.currentRow();
Row newRow = table.getTemplateRow();
setCurrentRowNumber(count);
for (int j = 0; j < columns.length; j++) {
Column c = columns[j];
int index = c.getColumnId();
try {
Value v = c.convert(r[j]);
newRow.setValue(index, v);
} catch (DbException ex) {
throw setRow(ex, count, getSQL(r));
}
}
replace(newRow);
}
rows.close();
table.fire(session, Trigger.UPDATE | Trigger.INSERT, false);
}
return count;
}
use of org.gridgain.internal.h2.message.DbException in project h2database by h2database.
the class Database method throwLastBackgroundException.
private void throwLastBackgroundException() {
if (backgroundException != null) {
// we don't care too much about concurrency here,
// we just want to make sure the exception is _normally_
// not just logged to the .trace.db file
DbException b = backgroundException;
backgroundException = null;
if (b != null) {
// wrap the exception, so we see it was thrown here
throw DbException.get(b.getErrorCode(), b, b.getMessage());
}
}
}
Aggregations