Skip to content

Commit

Permalink
GG-19690 H2TreeIndex should throw CorruptTreeException with cacheId, …
Browse files Browse the repository at this point in the history
…cacheName and indexName
  • Loading branch information
denis-chudov committed Aug 23, 2019
1 parent 6e96e04 commit 6a05476
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ protected static class TestTree extends BPlusTree<Long, Long> {
super(
"test",
cacheId,
null,
pageMem,
null,
new AtomicLong(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public TxLogTree(
super(
TxLog.TX_LOG_CACHE_NAME,
TxLog.TX_LOG_CACHE_ID,
TxLog.TX_LOG_CACHE_NAME,
pageMem,
wal,
new AtomicLong(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public abstract class DataStructure {
/** */
protected final int grpId;

/** */
protected final String grpName;

/** */
protected final PageMemory pageMem;

Expand All @@ -62,19 +65,22 @@ public abstract class DataStructure {
protected ReuseList reuseList;

/**
* @param cacheId Cache group ID.
* @param cacheGrpId Cache group ID.
* @param grpName Cache group name.
* @param pageMem Page memory.
* @param wal Write ahead log manager.
*/
public DataStructure(
int cacheId,
int cacheGrpId,
String grpName,
PageMemory pageMem,
IgniteWriteAheadLogManager wal,
PageLockListener lockLsnr
) {
assert pageMem != null;

this.grpId = cacheId;
this.grpId = cacheGrpId;
this.grpName = grpName;
this.pageMem = pageMem;
this.wal = wal;
this.lockLsnr = lockLsnr == null ? NOOP_LSNR : lockLsnr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,18 @@ public IndexStorageImpl(
/** {@inheritDoc} */
@Override public Collection<String> getIndexNames() throws IgniteCheckedException {
assert metaTree != null;

GridCursor<IndexItem> cursor = metaTree.find(null, null);

ArrayList<String> names = new ArrayList<>((int)metaTree.size());

while (cursor.next()) {
IndexItem item = cursor.get();

if (item != null)
names.add(new String(item.idxName));
}

return names;
}

Expand Down Expand Up @@ -258,6 +258,7 @@ private MetaTree(
super(
treeName("meta", "Meta"),
cacheId,
null,
pageMem,
wal,
globalRmvId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected PagesList(
long metaPageId,
PageLockListener lockLsnr
) {
super(cacheId, pageMem, wal, lockLsnr);
super(cacheId, null, pageMem, wal, lockLsnr);

this.name = name;
this.buckets = buckets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public MetastorageTree(
super(
name,
cacheId,
null,
pageMem,
wal,
globalRmvId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,8 @@ private class InitRoot extends PageHandler<Long, Bool> {

/**
* @param name Tree name.
* @param cacheId Cache ID.
* @param cacheGrpId Cache group ID.
* @param cacheGrpName Cache group name.
* @param pageMem Page memory.
* @param wal Write ahead log manager.
* @param globalRmvId Remove ID.
Expand All @@ -752,7 +753,8 @@ private class InitRoot extends PageHandler<Long, Bool> {
*/
protected BPlusTree(
String name,
int cacheId,
int cacheGrpId,
String cacheGrpName,
PageMemory pageMem,
IgniteWriteAheadLogManager wal,
AtomicLong globalRmvId,
Expand All @@ -765,7 +767,8 @@ protected BPlusTree(
) throws IgniteCheckedException {
this(
name,
cacheId,
cacheGrpId,
cacheGrpName,
pageMem,
wal,
globalRmvId,
Expand All @@ -780,7 +783,8 @@ protected BPlusTree(

/**
* @param name Tree name.
* @param cacheId Cache ID.
* @param cacheGrpId Cache ID.
* @param grpName Cache group name.
* @param pageMem Page memory.
* @param wal Write ahead log manager.
* @param globalRmvId Remove ID.
Expand All @@ -791,7 +795,8 @@ protected BPlusTree(
*/
protected BPlusTree(
String name,
int cacheId,
int cacheGrpId,
String grpName,
PageMemory pageMem,
IgniteWriteAheadLogManager wal,
AtomicLong globalRmvId,
Expand All @@ -800,7 +805,7 @@ protected BPlusTree(
@Nullable FailureProcessor failureProcessor,
@Nullable PageLockListener lsnr
) throws IgniteCheckedException {
super(cacheId, pageMem, wal, lsnr);
super(cacheGrpId, grpName, pageMem, wal, lsnr);

assert !F.isEmpty(name);

Expand Down Expand Up @@ -1575,8 +1580,7 @@ private void validateFirstPages(long metaId, long metaPage, int rootLvl) throws
private void fail(Object msg) {
AssertionError err = new AssertionError(msg);

if (failureProcessor != null)
failureProcessor.process(new FailureContext(FailureType.CRITICAL_ERROR, err));
processFailure(FailureType.CRITICAL_ERROR, err);

throw err;
}
Expand Down Expand Up @@ -2909,8 +2913,7 @@ void checkLockRetry() throws IgniteCheckedException {
"(the tree may be corrupted). Increase " + IGNITE_BPLUS_TREE_LOCK_RETRIES + " system property " +
"if you regularly see this message (current value is " + getLockRetries() + ").");

if (failureProcessor != null)
failureProcessor.process(new FailureContext(FailureType.CRITICAL_ERROR, e));
processFailure(FailureType.CRITICAL_ERROR, e);

throw e;
}
Expand Down Expand Up @@ -5920,15 +5923,25 @@ private long[] pages(boolean empty, Supplier<long[]> pages) {
* @param pageIds Pages ids.
* @return New CorruptedTreeException instance.
*/
private CorruptedTreeException corruptedTreeException(String msg, Throwable cause, int grpId, long... pageIds) {
CorruptedTreeException e = new CorruptedTreeException(msg, cause, grpId, pageIds);
protected CorruptedTreeException corruptedTreeException(String msg, Throwable cause, int grpId, long... pageIds) {
CorruptedTreeException e = new CorruptedTreeException(msg, cause, grpId, grpName, pageIds);

if (failureProcessor != null)
failureProcessor.process(new FailureContext(FailureType.CRITICAL_ERROR, e));
processFailure(FailureType.CRITICAL_ERROR, e);

return e;
}

/**
* Processes failure with failure processor.
*
* @param failureType Failure type.
* @param e Exception.
*/
protected void processFailure(FailureType failureType, Throwable e) {
if (failureProcessor != null)
failureProcessor.process(new FailureContext(failureType, e));
}

/**
* Creates a formatted message even if "toString" of optioanl parameters failed.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
import org.apache.ignite.internal.pagemem.PageIdAllocator;
import org.apache.ignite.internal.pagemem.PageIdUtils;
import org.apache.ignite.internal.processors.cache.persistence.CorruptedPersistenceException;
import org.apache.ignite.internal.util.GridStringBuilder;
import org.apache.ignite.internal.util.typedef.T2;
import org.apache.ignite.internal.util.typedef.X;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.CU;
import org.jetbrains.annotations.Nullable;

import static java.util.Arrays.asList;
Expand All @@ -45,19 +46,51 @@ public class CorruptedTreeException extends IgniteCheckedException implements Co
* @param msg Message.
* @param cause Cause.
* @param grpId Group id of potentially corrupted pages.
* @param grpName Group name of potentially corrupted pages.
* @param pageIds Potentially corrupted pages.
*/
public CorruptedTreeException(String msg, @Nullable Throwable cause, int grpId, long... pageIds) {
this(msg, cause, toPagesArray(grpId, pageIds));
public CorruptedTreeException(String msg, @Nullable Throwable cause, int grpId, String grpName, long... pageIds) {
this(msg, null, null, grpName, cause, toPagesArray(grpId, pageIds));
}

/**
* @param msg Message.
* @param cause Cause.
* @param grpId Group id of potentially corrupted pages.
* @param grpName Group name of potentially corrupted pages.
* @param cacheName Cache name.
* @param indexName Index name.
* @param pageIds Potentially corrupted pages.
*/
public CorruptedTreeException(
String msg,
@Nullable Throwable cause,
int grpId,
String grpName,
String cacheName,
String indexName,
long... pageIds
) {
this(msg, cacheName, indexName, grpName, cause, toPagesArray(grpId, pageIds));
}

/**
* @param msg Message.
* @param cacheName Cache name.
* @param indexName Index name.
* @param grpName Cache group name.
* @param cause Cause.
* @param pages (groupId, pageId) pairs for pages that might be corrupted.
*/
public CorruptedTreeException(String msg, @Nullable Throwable cause, T2<Integer, Long>... pages) {
super(getMsg(msg, pages), cause);
public CorruptedTreeException(
String msg,
String cacheName,
String indexName,
String grpName,
@Nullable Throwable cause,
T2<Integer, Long>... pages
) {
super(getMsg(msg, cacheName, indexName, grpName, pages), cause);

this.pages = expandPagesArray(pages, cause);
}
Expand Down Expand Up @@ -98,11 +131,25 @@ private static T2<Integer, Long>[] expandPagesArray(T2<Integer, Long>[] pages, T
}

/** */
private static String getMsg(String msg, T2<Integer, Long>... pages) {
return S.toString("B+Tree is corrupted",
"pages(groupId, pageId)", Arrays.toString(pages), false,
"msg", msg, false
);
private static String getMsg(String msg, String cacheName, String indexName, String grpName, T2<Integer, Long>... pages) {
GridStringBuilder stringBuilder = new GridStringBuilder("B+Tree is corrupted [")
.a("pages(groupId, pageId)=").a(Arrays.toString(pages));

if (cacheName != null) {
stringBuilder
.a(", cacheId=").a(CU.cacheId(cacheName))
.a(", cacheName=").a(cacheName);
}

if (indexName != null)
stringBuilder.a(", indexName=").a(indexName);

if (grpName != null)
stringBuilder.a(", groupName=").a(grpName);

stringBuilder.a(", msg=").a(msg).a("]");

return stringBuilder.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public CacheDataTree(
super(
name,
grp.groupId(),
grp.name(),
grp.dataRegion().pageMemory(),
grp.dataRegion().config().isPersistenceEnabled() ? grp.shared().wal() : null,
grp.offheap().globalRemoveId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public PendingEntriesTree(
super(
name,
grp.groupId(),
grp.name(),
pageMem,
grp.dataRegion().config().isPersistenceEnabled() ? grp.shared().wal() : null,
grp.offheap().globalRemoveId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2765,6 +2765,7 @@ public TestTree(
super(
"test",
cacheId,
null,
pageMem,
null,
new AtomicLong(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,7 @@ private JavaObjectSerializer h2Serializer() {
BPlusTree<H2Row, H2Row> tree = new BPlusTree<H2Row, H2Row>(
indexName,
grpId,
grpName,
pageMemory,
ctx.cache().context().wal(),
removeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteSystemProperties;
import org.apache.ignite.failure.FailureType;
import org.apache.ignite.internal.metric.IoStatisticsHolder;
import org.apache.ignite.internal.pagemem.FullPageId;
import org.apache.ignite.internal.pagemem.PageIdUtils;
Expand All @@ -36,6 +37,7 @@
import org.apache.ignite.internal.processors.cache.mvcc.MvccUtils;
import org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter;
import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree;
import org.apache.ignite.internal.processors.cache.persistence.tree.CorruptedTreeException;
import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO;
import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO;
import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList;
Expand Down Expand Up @@ -164,6 +166,7 @@ protected H2Tree(
String tblName,
ReuseList reuseList,
int grpId,
String grpName,
PageMemory pageMem,
IgniteWriteAheadLogManager wal,
AtomicLong globalRmvId,
Expand All @@ -183,6 +186,7 @@ protected H2Tree(
super(
name,
grpId,
grpName,
pageMem,
wal,
globalRmvId,
Expand Down Expand Up @@ -785,4 +789,21 @@ public boolean created() {
@Override public String toString() {
return S.toString(H2Tree.class, this, "super", super.toString());
}

/**
* Construct the exception and invoke failure processor.
*
* @param msg Message.
* @param cause Cause.
* @param grpId Group id.
* @param pageIds Pages ids.
* @return New CorruptedTreeException instance.
*/
@Override protected CorruptedTreeException corruptedTreeException(String msg, Throwable cause, int grpId, long... pageIds) {
CorruptedTreeException e = new CorruptedTreeException(msg, cause, grpId, grpName, cacheName, idxName, pageIds);

processFailure(FailureType.CRITICAL_ERROR, e);

return e;
}
}

0 comments on commit 6a05476

Please sign in to comment.