reduce log spam from invalid counter shards

patch by slebresne and jbellis for CASSANDRA-5026
This commit is contained in:
Jonathan Ellis 2012-12-08 09:18:10 -06:00
parent 5e4629793b
commit 5b511b6213
3 changed files with 23 additions and 9 deletions

View File

@ -1,4 +1,5 @@
1.1.8
* reduce log spam from invalid counter shards (CASSANDRA-5026)
* Improve schema propagation performance (CASSANDRA-5025)
* Fall back to old describe_splits if d_s_ex is not available (CASSANDRA-4803)
* Improve error reporting when streaming ranges fail (CASSANDRA-5009)

View File

@ -19,7 +19,6 @@
package org.apache.cassandra.db.compaction;
import java.io.File;
import java.io.IOError;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.nio.ByteBuffer;
@ -47,7 +46,6 @@ import org.apache.cassandra.dht.Range;
import org.apache.cassandra.dht.Token;
import org.apache.cassandra.io.sstable.*;
import org.apache.cassandra.io.util.FileUtils;
import org.apache.cassandra.io.util.RandomAccessReader;
import org.apache.cassandra.service.AntiEntropyService;
import org.apache.cassandra.service.CacheService;
import org.apache.cassandra.service.StorageService;
@ -77,6 +75,16 @@ public class CompactionManager implements CompactionManagerMBean
public static final int NO_GC = Integer.MIN_VALUE;
public static final int GC_ALL = Integer.MAX_VALUE;
// A thread local that tells us if the current thread is owned by the compaction manager. Used
// by CounterContext to figure out if it should log a warning for invalid counter shards.
public static final ThreadLocal<Boolean> isCompactionManager = new ThreadLocal<Boolean>() {
@Override
protected Boolean initialValue()
{
return false;
}
};
/**
* compactionLock has two purposes:
* - "Special" compactions will acquire writelock instead of readlock to make sure that all
@ -931,6 +939,13 @@ public class CompactionManager implements CompactionManagerMBean
return totalCompactionsCompleted;
}
protected void beforeExecute(Thread t, Runnable r)
{
// can't set this in Thread factory, so we do it redundantly here
isCompactionManager.set(true);
super.beforeExecute(t, r);
}
// modified from DebuggableThreadPoolExecutor so that CompactionInterruptedExceptions are not logged
@Override
public void afterExecute(Runnable r, Throwable t)

View File

@ -27,6 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.cassandra.db.DBConstants;
import org.apache.cassandra.db.compaction.CompactionManager;
import org.apache.cassandra.db.marshal.MarshalException;
import org.apache.cassandra.utils.Allocator;
import org.apache.cassandra.utils.ByteBufferUtil;
@ -376,14 +377,11 @@ public class CounterContext implements IContext
long leftCount = leftState.getCount();
long rightCount = rightState.getCount();
if (leftCount != rightCount)
if (leftCount != rightCount && CompactionManager.isCompactionManager.get())
{
logger.error("invalid counter shard detected; ({}, {}, {}) and ({}, {}, {}) differ only in "
+ "count; will pick highest to self-heal; this indicates a bug or corruption generated a bad counter shard",
new Object[] {
leftState.getNodeId(), leftClock, leftCount,
rightState.getNodeId(), rightClock, rightCount,
});
logger.warn("invalid counter shard detected; ({}, {}, {}) and ({}, {}, {}) differ only in "
+ "count; will pick highest to self-heal on compaction",
new Object[] { leftState.getNodeId(), leftClock, leftCount, rightState.getNodeId(), rightClock, rightCount, });
}
if (leftCount > rightCount)