continue;
}
Map<byte[], Long> maxStoreSequenceIds = null;
boolean needSkip = false;
HRegionLocation loc = null;
String locKey = null;
List<KeyValue> kvs = edit.getKeyValues();
List<KeyValue> skippedKVs = new ArrayList<KeyValue>();
HConnection hconn = this.getConnectionByTableName(table);
for (KeyValue kv : kvs) {
// filtering HLog meta entries
// We don't handle HBASE-2231 because we may or may not replay a compaction event.
// Details at https://issues.apache.org/jira/browse/HBASE-2231?focusedCommentId=13647143&
// page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13647143
if (kv.matchingFamily(WALEdit.METAFAMILY)) {
skippedKVs.add(kv);
continue;
}
try {
loc =
locateRegionAndRefreshLastFlushedSequenceId(hconn, table, kv.getRow(),
encodeRegionNameStr);
} catch (TableNotFoundException ex) {
// table has been deleted so skip edits of the table
LOG.info("Table " + table + " doesn't exist. Skip log replay for region "
+ encodeRegionNameStr);
lastFlushedSequenceIds.put(encodeRegionNameStr, Long.MAX_VALUE);
if (nonExistentTables == null) {
nonExistentTables = new TreeSet<TableName>();
}
nonExistentTables.add(table);
this.skippedEdits.incrementAndGet();
needSkip = true;
break;
}
cachedLastFlushedSequenceId =
lastFlushedSequenceIds.get(loc.getRegionInfo().getEncodedName());
if (cachedLastFlushedSequenceId != null
&& cachedLastFlushedSequenceId >= entry.getKey().getLogSeqNum()) {
// skip the whole HLog entry
this.skippedEdits.incrementAndGet();
needSkip = true;
break;
} else {
if (maxStoreSequenceIds == null) {
maxStoreSequenceIds =
regionMaxSeqIdInStores.get(loc.getRegionInfo().getEncodedName());
}
if (maxStoreSequenceIds != null) {
Long maxStoreSeqId = maxStoreSequenceIds.get(kv.getFamily());
if (maxStoreSeqId == null || maxStoreSeqId >= entry.getKey().getLogSeqNum()) {
// skip current kv if column family doesn't exist anymore or already flushed
skippedKVs.add(kv);
continue;
}
}
}
}
// skip the edit
if (loc == null || needSkip) continue;
if (!skippedKVs.isEmpty()) {
kvs.removeAll(skippedKVs);
}
synchronized (serverToBufferQueueMap) {
locKey = loc.getHostnamePort() + KEY_DELIMITER + table;
List<Pair<HRegionLocation, HLog.Entry>> queue = serverToBufferQueueMap.get(locKey);
if (queue == null) {
queue =
Collections.synchronizedList(new ArrayList<Pair<HRegionLocation, HLog.Entry>>());
serverToBufferQueueMap.put(locKey, queue);
}
queue.add(new Pair<HRegionLocation, HLog.Entry>(loc, entry));
}
// store regions we have recovered so far
addToRecoveredRegions(loc.getRegionInfo().getEncodedName());
}
}