HBASE-15441 Fix WAL splitting when region has moved multiple times

Summary:
Currently WAL splitting is broken when a region has been opened multiple times in recent minutes.

Region open and region close write event markers to the wal. These markers should have the sequence id in them. However it is currently getting 1. That means that if a region has moved multiple times in the last few mins then multiple split log workers will try and create the recovered edits file for sequence id 1. One of the workers will fail and on failing they will delete the recovered edits. Causing all split wal attempts to fail.

We need to:

It appears that the close event with a sequence id of one is coming from region warm up.

This patch fixes that by making sure the close on warm up doesn't happen. Also splitting will ignore any of the events that are already in the logs.

Test Plan: Unit tests pass

Differential Revision: https://reviews.facebook.net/D55557
This commit is contained in:
Elliott Clark 2016-03-10 14:48:57 -08:00
parent 94d576025f
commit aaaae83423
5 changed files with 69 additions and 13 deletions

View File

@ -2672,15 +2672,36 @@ public final class ProtobufUtil {
public static RegionEventDescriptor toRegionEventDescriptor(
EventType eventType, HRegionInfo hri, long seqId, ServerName server,
Map<byte[], List<Path>> storeFiles) {
final byte[] tableNameAsBytes = hri.getTable().getName();
final byte[] encodedNameAsBytes = hri.getEncodedNameAsBytes();
final byte[] regionNameAsBytes = hri.getRegionName();
return toRegionEventDescriptor(eventType,
tableNameAsBytes,
encodedNameAsBytes,
regionNameAsBytes,
seqId,
server,
storeFiles);
}
public static RegionEventDescriptor toRegionEventDescriptor(EventType eventType,
byte[] tableNameAsBytes,
byte[] encodedNameAsBytes,
byte[] regionNameAsBytes,
long seqId,
ServerName server,
Map<byte[], List<Path>> storeFiles) {
RegionEventDescriptor.Builder desc = RegionEventDescriptor.newBuilder()
.setEventType(eventType)
.setTableName(ByteStringer.wrap(hri.getTable().getName()))
.setEncodedRegionName(ByteStringer.wrap(hri.getEncodedNameAsBytes()))
.setRegionName(ByteStringer.wrap(hri.getRegionName()))
.setTableName(ByteStringer.wrap(tableNameAsBytes))
.setEncodedRegionName(ByteStringer.wrap(encodedNameAsBytes))
.setRegionName(ByteStringer.wrap(regionNameAsBytes))
.setLogSequenceNumber(seqId)
.setServer(toServerName(server));
for (Map.Entry<byte[], List<Path>> entry : storeFiles.entrySet()) {
for (Entry<byte[], List<Path>> entry : storeFiles.entrySet()) {
StoreDescriptor.Builder builder = StoreDescriptor.newBuilder()
.setFamilyName(ByteStringer.wrap(entry.getKey()))
.setStoreHomeDir(Bytes.toString(entry.getKey()));

View File

@ -972,10 +972,13 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
private void initializeWarmup(final CancelableProgressable reporter) throws IOException {
MonitoredTask status = TaskMonitor.get().createStatus("Initializing region " + this);
// Initialize all the HStores
status.setStatus("Warming up all the Stores");
initializeStores(reporter, status);
try {
initializeStores(reporter, status);
} finally {
status.markComplete("Done warming up.");
}
}
/**
@ -6575,9 +6578,8 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
fs = FileSystem.get(conf);
}
HRegion r = HRegion.newHRegion(tableDir, wal, fs, conf, info, htd, rsServices);
HRegion r = HRegion.newHRegion(tableDir, wal, fs, conf, info, htd, null);
r.initializeWarmup(reporter);
r.close();
}

View File

@ -89,10 +89,14 @@ public class WALEdit implements Writable, HeapSize {
// TODO: Get rid of this; see HBASE-8457
public static final byte [] METAFAMILY = Bytes.toBytes("METAFAMILY");
static final byte [] METAROW = Bytes.toBytes("METAROW");
static final byte[] COMPACTION = Bytes.toBytes("HBASE::COMPACTION");
static final byte [] FLUSH = Bytes.toBytes("HBASE::FLUSH");
static final byte [] REGION_EVENT = Bytes.toBytes("HBASE::REGION_EVENT");
@VisibleForTesting
public static final byte [] METAROW = Bytes.toBytes("METAROW");
@VisibleForTesting
public static final byte[] COMPACTION = Bytes.toBytes("HBASE::COMPACTION");
@VisibleForTesting
public static final byte [] FLUSH = Bytes.toBytes("HBASE::FLUSH");
@VisibleForTesting
public static final byte [] REGION_EVENT = Bytes.toBytes("HBASE::REGION_EVENT");
@VisibleForTesting
public static final byte [] BULK_LOAD = Bytes.toBytes("HBASE::BULK_LOAD");
@ -343,7 +347,7 @@ public class WALEdit implements Writable, HeapSize {
return new WALEdit().add(kv); //replication scope null so that this won't be replicated
}
private static byte[] getRowForRegion(HRegionInfo hri) {
public static byte[] getRowForRegion(HRegionInfo hri) {
byte[] startKey = hri.getStartKey();
if (startKey.length == 0) {
// empty row key is not allowed in mutations because it is both the start key and the end key

View File

@ -367,6 +367,11 @@ public class RegionReplicaReplicationEndpoint extends HBaseReplicationEndpoint {
return super.flush();
}
@Override
public boolean keepRegionEvents() {
return true;
}
@Override
public List<Path> finishWritingAndClose() throws IOException {
finishWriting(true);

View File

@ -368,6 +368,11 @@ public class WALSplitter {
editsSkipped++;
continue;
}
// Don't send Compaction/Close/Open region events to recovered edit type sinks.
if (entry.getEdit().isMetaEdit() && !outputSink.keepRegionEvents()) {
editsSkipped++;
continue;
}
entryBuffers.appendEntry(entry);
editsCount++;
int moreWritersFromLastCheck = this.getNumOpenWriters() - numOpenedFilesLastCheck;
@ -1273,6 +1278,15 @@ public class WALSplitter {
public boolean flush() throws IOException {
return false;
}
/**
* Some WALEdit's contain only KV's for account on what happened to a region.
* Not all sinks will want to get those edits.
*
* @return Return true if this sink wants to get all WALEdit's regardless of if it's a region
* event.
*/
public abstract boolean keepRegionEvents();
}
/**
@ -1615,6 +1629,11 @@ public class WALSplitter {
}
}
@Override
public boolean keepRegionEvents() {
return false;
}
/**
* @return a map from encoded region ID to the number of edits written out for that region.
*/
@ -2063,6 +2082,11 @@ public class WALSplitter {
return false;
}
@Override
public boolean keepRegionEvents() {
return true;
}
void addWriterError(Throwable t) {
thrown.add(t);
}