Skip to content

Commit d2ef9e7

Browse files
committed
CNDB-15157: limit log lines during commitlog replay
1 parent c0ee3e1 commit d2ef9e7

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,35 @@ public static CommitLogReplayer construct(CommitLog commitLog, UUID localHostId)
180180
cfPersisted.put(cfs.metadata.id, filter);
181181
}
182182
CommitLogPosition globalPosition = firstNotCovered(cfPersisted.values());
183-
logger.debug("Global replay position is {} from columnfamilies {}", globalPosition, FBUtilities.toString(cfPersisted));
183+
184+
// Limit the amount of column family data logged to prevent massive log lines
185+
if (logger.isDebugEnabled())
186+
{
187+
int maxColumnFamiliesToLog = 10;
188+
int cfCount = cfPersisted.size();
189+
if (cfCount <= maxColumnFamiliesToLog)
190+
{
191+
logger.debug("Global replay position is {} from {} columnfamilies: {}",
192+
globalPosition, cfCount, FBUtilities.toString(cfPersisted));
193+
}
194+
else
195+
{
196+
// For large numbers of column families, just log the count and a sample
197+
Map<TableId, IntervalSet<CommitLogPosition>> sample = new HashMap<>();
198+
int count = 0;
199+
for (Map.Entry<TableId, IntervalSet<CommitLogPosition>> entry : cfPersisted.entrySet())
200+
{
201+
if (count++ >= maxColumnFamiliesToLog)
202+
break;
203+
sample.put(entry.getKey(), entry.getValue());
204+
}
205+
logger.debug("Global replay position is {} from {} columnfamilies (showing first {}): {}",
206+
globalPosition, cfCount, maxColumnFamiliesToLog, FBUtilities.toString(sample));
207+
logger.debug("Use TRACE level to see all {} columnfamilies", cfCount);
208+
logger.trace("Full columnfamilies list: {}", FBUtilities.toString(cfPersisted));
209+
}
210+
}
211+
184212
return new CommitLogReplayer(commitLog, globalPosition, cfPersisted, replayFilter);
185213
}
186214

@@ -429,7 +457,18 @@ public static IntervalSet<CommitLogPosition> persistedIntervals(Iterable<SSTable
429457

430458
if (!skippedSSTables.isEmpty()) {
431459
logger.warn("Origin of {} sstables is unknown or doesn't match the local node; commitLogIntervals for them were ignored", skippedSSTables.size());
432-
logger.debug("Ignored commitLogIntervals from the following sstables: {}", skippedSSTables);
460+
461+
// Limit the number of SSTable names logged to prevent massive log lines
462+
int maxSSTablesToLog = 100;
463+
if (skippedSSTables.size() <= maxSSTablesToLog) {
464+
logger.debug("Ignored commitLogIntervals from the following sstables: {}", skippedSSTables);
465+
} else {
466+
List<String> sample = new ArrayList<>(skippedSSTables).subList(0, maxSSTablesToLog);
467+
logger.debug("Ignored commitLogIntervals from {} sstables (showing first {}): {}",
468+
skippedSSTables.size(), maxSSTablesToLog, sample);
469+
logger.debug("Use TRACE level to see all {} skipped sstables", skippedSSTables.size());
470+
logger.trace("Full list of ignored sstables: {}", skippedSSTables);
471+
}
433472
}
434473

435474
if (truncatedAt != null)

0 commit comments

Comments
 (0)