Skip to content

Commit e1b4a2a

Browse files
saintstackApache9
authored andcommitted
HBASE-23221 Polish the WAL interface after HBASE-23181 (#774)
Removes the closeRegion flag added by HBASE-23181 and instead relies on reading meta WALEdit content. Modified how qualifier is written when the meta WALEdit is for a RegionEventDescriptor so the 'type' is added to the qualifer so can figure type w/o having to deserialize protobuf value content: e.g. HBASE::REGION_EVENT::REGION_CLOSE Added doc on WALEdit and tried to formalize the 'meta' WALEdit type and how it works. Needs complete redo in part as suggested by HBASE-8457. Meantime, some doc and cleanup. Also changed the LogRoller constructor to remove redundant param. Because of constructor change, need to change also TestFailedAppendAndSync, TestWALLockup, TestAsyncFSWAL & WALPerformanceEvaluation.java Signed-off-by: Duo Zhang <[email protected]> Signed-off-by: Lijin Bin <[email protected]>
1 parent 255be63 commit e1b4a2a

28 files changed

Lines changed: 308 additions & 230 deletions

‎hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,15 @@ public static boolean matchingQualifier(final Cell left, final byte[] buf) {
499499
}
500500

501501
public static boolean matchingColumn(final Cell left, final byte[] fam, final byte[] qual) {
502-
if (!matchingFamily(left, fam))
503-
return false;
504-
return matchingQualifier(left, qual);
502+
return matchingFamily(left, fam) && matchingQualifier(left, qual);
503+
}
504+
505+
/**
506+
* @return True if matching column family and the qualifier starts with <code>qual</code>
507+
*/
508+
public static boolean matchingColumnFamilyAndQualifierPrefix(final Cell left, final byte[] fam,
509+
final byte[] qual) {
510+
return matchingFamily(left, fam) && PrivateCellUtil.qualifierStartsWith(left, qual);
505511
}
506512

507513
public static boolean matchingColumn(final Cell left, final Cell right) {

‎hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/WALPlayer.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,10 @@ public void map(WALKey key, WALEdit value, Context context) throws IOException {
157157
Delete del = null;
158158
Cell lastCell = null;
159159
for (Cell cell : value.getCells()) {
160-
// filtering WAL meta entries
160+
// Filtering WAL meta marker entries.
161161
if (WALEdit.isMetaEditFamily(cell)) {
162162
continue;
163163
}
164-
165164
// Allow a subclass filter out this cell.
166165
if (filter(context, cell)) {
167166
// A WALEdit may contain multiple operations (HBASE-3584) and/or

‎hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3599,7 +3599,7 @@ public List<ReplicationPeerDescription> listReplicationPeers(String regex)
35993599
if (cpHost != null) {
36003600
cpHost.preListReplicationPeers(regex);
36013601
}
3602-
LOG.info(getClientIdAuditPrefix() + " list replication peers, regex=" + regex);
3602+
LOG.debug("{} list replication peers, regex={}", getClientIdAuditPrefix(), regex);
36033603
Pattern pattern = regex == null ? null : Pattern.compile(regex);
36043604
List<ReplicationPeerDescription> peers =
36053605
this.replicationPeerManager.listPeers(pattern);

‎hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,7 @@ public Pair<byte[], Collection<HStoreFile>> call() throws IOException {
17371737

17381738
status.setStatus("Writing region close event to WAL");
17391739
// Always write close marker to wal even for read only table. This is not a big problem as we
1740-
// do not write any data into the region.
1740+
// do not write any data into the region; it is just a meta edit in the WAL file.
17411741
if (!abort && wal != null && getRegionServerServices() != null &&
17421742
RegionReplicaUtil.isDefaultReplica(getRegionInfo())) {
17431743
writeRegionCloseMarker(wal);
@@ -2720,7 +2720,8 @@ private void logFatLineOnFlush(Collection<HStore> storesToFlush, long sequenceId
27202720
}
27212721
}
27222722
MemStoreSize mss = this.memStoreSizing.getMemStoreSize();
2723-
LOG.info("Flushing " + storesToFlush.size() + "/" + stores.size() + " column families," +
2723+
LOG.info("Flushing " + this.getRegionInfo().getEncodedName() + " " +
2724+
storesToFlush.size() + "/" + stores.size() + " column families," +
27242725
" dataSize=" + StringUtils.byteDesc(mss.getDataSize()) +
27252726
" heapSize=" + StringUtils.byteDesc(mss.getHeapSize()) +
27262727
((perCfExtras != null && perCfExtras.length() > 0)? perCfExtras.toString(): "") +
@@ -4869,7 +4870,7 @@ private long replayRecoveredEdits(final Path edits,
48694870
for (Cell cell: val.getCells()) {
48704871
// Check this edit is for me. Also, guard against writing the special
48714872
// METACOLUMN info such as HBASE::CACHEFLUSH entries
4872-
if (CellUtil.matchingFamily(cell, WALEdit.METAFAMILY)) {
4873+
if (WALEdit.isMetaEditFamily(cell)) {
48734874
// if region names don't match, skipp replaying compaction marker
48744875
if (!checkRowWithinBoundary) {
48754876
//this is a special edit, we should handle it

‎hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,7 @@ private void startServices() throws IOException {
19441944
this.getRegionServerMetrics().getMetricsSource());
19451945
}
19461946

1947-
this.walRoller = new LogRoller(this, this);
1947+
this.walRoller = new LogRoller(this);
19481948
this.flushThroughputController = FlushThroughputControllerFactory.create(this, conf);
19491949
this.procedureResultReporter = new RemoteProcedureResultReporter(this);
19501950

‎hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
*
33
* Licensed to the Apache Software Foundation (ASF) under one
44
* or more contributor license agreements. See the NOTICE file
@@ -29,7 +29,6 @@
2929
import java.util.concurrent.ConcurrentHashMap;
3030
import java.util.concurrent.ConcurrentMap;
3131
import org.apache.hadoop.hbase.HConstants;
32-
import org.apache.hadoop.hbase.Server;
3332
import org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL;
3433
import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException;
3534
import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
@@ -58,7 +57,6 @@
5857
public class LogRoller extends HasThread implements Closeable {
5958
private static final Logger LOG = LoggerFactory.getLogger(LogRoller.class);
6059
private final ConcurrentMap<WAL, Boolean> walNeedsRoll = new ConcurrentHashMap<>();
61-
private final Server server;
6260
protected final RegionServerServices services;
6361
private volatile long lastRollTime = System.currentTimeMillis();
6462
// Period to roll log.
@@ -101,16 +99,14 @@ public void requestRollAll() {
10199
}
102100
}
103101

104-
/** @param server */
105-
public LogRoller(final Server server, final RegionServerServices services) {
102+
public LogRoller(RegionServerServices services) {
106103
super("LogRoller");
107-
this.server = server;
108104
this.services = services;
109-
this.rollPeriod = this.server.getConfiguration().
105+
this.rollPeriod = this.services.getConfiguration().
110106
getLong("hbase.regionserver.logroll.period", 3600000);
111-
this.threadWakeFrequency = this.server.getConfiguration().
107+
this.threadWakeFrequency = this.services.getConfiguration().
112108
getInt(HConstants.THREAD_WAKE_FREQUENCY, 10 * 1000);
113-
this.checkLowReplicationInterval = this.server.getConfiguration().getLong(
109+
this.checkLowReplicationInterval = this.services.getConfiguration().getLong(
114110
"hbase.regionserver.hlog.check.lowreplication.interval", 30 * 1000);
115111
}
116112

@@ -146,7 +142,7 @@ private void abort(String reason, Throwable cause) {
146142
LOG.warn("Failed to shutdown wal", e);
147143
}
148144
}
149-
server.abort(reason, cause);
145+
this.services.abort(reason, cause);
150146
}
151147

152148
@Override
@@ -158,7 +154,7 @@ public void run() {
158154
periodic = (now - this.lastRollTime) > this.rollPeriod;
159155
if (periodic) {
160156
// Time for periodic roll, fall through
161-
LOG.debug("Wal roll period {} ms elapsed", this.rollPeriod);
157+
LOG.debug("WAL roll period {} ms elapsed", this.rollPeriod);
162158
} else {
163159
synchronized (this) {
164160
if (walNeedsRoll.values().stream().anyMatch(Boolean::booleanValue)) {

‎hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AbstractFSWAL.java‎

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ public abstract class AbstractFSWAL<W extends WriterBase> implements WAL {
271271
private static final class WalProps {
272272

273273
/**
274-
* Map the encoded region name to the highest sequence id. Contain all the regions it has
275-
* entries of
274+
* Map the encoded region name to the highest sequence id.
275+
* <p/>Contains all the regions it has an entry for.
276276
*/
277277
public final Map<byte[], Long> encodedName2HighestSequenceId;
278278

@@ -628,9 +628,9 @@ public int getNumLogFiles() {
628628
}
629629

630630
/**
631-
* If the number of un-archived WAL files is greater than maximum allowed, check the first
632-
* (oldest) WAL file, and returns those regions which should be flushed so that it can be
633-
* archived.
631+
* If the number of un-archived WAL files ('live' WALs) is greater than maximum allowed,
632+
* check the first (oldest) WAL, and return those regions which should be flushed so that
633+
* it can be let-go/'archived'.
634634
* @return regions (encodedRegionNames) to flush in order to archive oldest WAL file.
635635
*/
636636
byte[][] findRegionsToForceFlush() throws IOException {
@@ -930,10 +930,6 @@ public void close() throws IOException {
930930
/**
931931
* updates the sequence number of a specific store. depending on the flag: replaces current seq
932932
* number if the given seq id is bigger, or even if it is lower than existing one
933-
* @param encodedRegionName
934-
* @param familyName
935-
* @param sequenceid
936-
* @param onlyIfGreater
937933
*/
938934
@Override
939935
public void updateStore(byte[] encodedRegionName, byte[] familyName, Long sequenceid,
@@ -1057,7 +1053,7 @@ protected final void postSync(long timeInNanos, int handlerSyncs) {
10571053
}
10581054

10591055
protected final long stampSequenceIdAndPublishToRingBuffer(RegionInfo hri, WALKeyImpl key,
1060-
WALEdit edits, boolean inMemstore, boolean closeRegion, RingBuffer<RingBufferTruck> ringBuffer)
1056+
WALEdit edits, boolean inMemstore, RingBuffer<RingBufferTruck> ringBuffer)
10611057
throws IOException {
10621058
if (this.closed) {
10631059
throw new IOException(
@@ -1071,7 +1067,7 @@ protected final long stampSequenceIdAndPublishToRingBuffer(RegionInfo hri, WALKe
10711067
ServerCall<?> rpcCall = RpcServer.getCurrentCall().filter(c -> c instanceof ServerCall)
10721068
.filter(c -> c.getCellScanner() != null).map(c -> (ServerCall) c).orElse(null);
10731069
try (TraceScope scope = TraceUtil.createTrace(implClassName + ".append")) {
1074-
FSWALEntry entry = new FSWALEntry(txid, key, edits, hri, inMemstore, closeRegion, rpcCall);
1070+
FSWALEntry entry = new FSWALEntry(txid, key, edits, hri, inMemstore, rpcCall);
10751071
entry.stampRegionSequenceId(we);
10761072
ringBuffer.get(txid).load(entry);
10771073
} finally {
@@ -1109,13 +1105,13 @@ public OptionalLong getLogFileSizeIfBeingWritten(Path path) {
11091105

11101106
@Override
11111107
public long appendData(RegionInfo info, WALKeyImpl key, WALEdit edits) throws IOException {
1112-
return append(info, key, edits, true, false);
1108+
return append(info, key, edits, true);
11131109
}
11141110

11151111
@Override
1116-
public long appendMarker(RegionInfo info, WALKeyImpl key, WALEdit edits, boolean closeRegion)
1112+
public long appendMarker(RegionInfo info, WALKeyImpl key, WALEdit edits)
11171113
throws IOException {
1118-
return append(info, key, edits, false, closeRegion);
1114+
return append(info, key, edits, false);
11191115
}
11201116

11211117
/**
@@ -1139,17 +1135,17 @@ public long appendMarker(RegionInfo info, WALKeyImpl key, WALEdit edits, boolean
11391135
* @param key Modified by this call; we add to it this edits region edit/sequence id.
11401136
* @param edits Edits to append. MAY CONTAIN NO EDITS for case where we want to get an edit
11411137
* sequence id that is after all currently appended edits.
1142-
* @param inMemstore Always true except for case where we are writing a region event marker, for
1143-
* example, a compaction completion record into the WAL; in this case the entry is just
1144-
* so we can finish an unfinished compaction -- it is not an edit for memstore.
1145-
* @param closeRegion Whether this is a region close marker, i.e, the last wal edit for this
1146-
* region on this region server. The WAL implementation should remove all the related
1147-
* stuff, for example, the sequence id accounting.
1138+
* @param inMemstore Always true except for case where we are writing a region event meta
1139+
* marker edit, for example, a compaction completion record into the WAL or noting a
1140+
* Region Open event. In these cases the entry is just so we can finish an unfinished
1141+
* compaction after a crash when the new Server reads the WAL on recovery, etc. These
1142+
* transition event 'Markers' do not go via the memstore. When memstore is false,
1143+
* we presume a Marker event edit.
11481144
* @return Returns a 'transaction id' and <code>key</code> will have the region edit/sequence id
11491145
* in it.
11501146
*/
1151-
protected abstract long append(RegionInfo info, WALKeyImpl key, WALEdit edits, boolean inMemstore,
1152-
boolean closeRegion) throws IOException;
1147+
protected abstract long append(RegionInfo info, WALKeyImpl key, WALEdit edits, boolean inMemstore)
1148+
throws IOException;
11531149

11541150
protected abstract void doAppend(W writer, FSWALEntry entry) throws IOException;
11551151

‎hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AsyncFSWAL.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -615,12 +615,12 @@ protected boolean markerEditOnly() {
615615
}
616616

617617
@Override
618-
protected long append(RegionInfo hri, WALKeyImpl key, WALEdit edits, boolean inMemstore,
619-
boolean closeRegion) throws IOException {
620-
if (markerEditOnly() && !edits.isMetaEdit()) {
621-
throw new IOException("WAL is closing, only marker edit is allowed");
622-
}
623-
long txid = stampSequenceIdAndPublishToRingBuffer(hri, key, edits, inMemstore, closeRegion,
618+
protected long append(RegionInfo hri, WALKeyImpl key, WALEdit edits, boolean inMemstore)
619+
throws IOException {
620+
if (markerEditOnly() && !edits.isMetaEdit()) {
621+
throw new IOException("WAL is closing, only marker edit is allowed");
622+
}
623+
long txid = stampSequenceIdAndPublishToRingBuffer(hri, key, edits, inMemstore,
624624
waitingConsumePayloads);
625625
if (shouldScheduleConsumer()) {
626626
consumeExecutor.execute(consumer);

‎hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ protected void doShutdown() throws IOException {
435435

436436
@Override
437437
protected long append(final RegionInfo hri, final WALKeyImpl key, final WALEdit edits,
438-
final boolean inMemstore, boolean closeRegion) throws IOException {
439-
return stampSequenceIdAndPublishToRingBuffer(hri, key, edits, inMemstore, closeRegion,
438+
final boolean inMemstore) throws IOException {
439+
return stampSequenceIdAndPublishToRingBuffer(hri, key, edits, inMemstore,
440440
disruptor.getRingBuffer());
441441
}
442442

‎hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSWALEntry.java‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/**
4141
* A WAL Entry for {@link AbstractFSWAL} implementation. Immutable.
4242
* A subclass of {@link Entry} that carries extra info across the ring buffer such as
43-
* region sequence id (we want to use this later, just before we write the WAL to ensure region
43+
* region sequenceid (we want to use this later, just before we write the WAL to ensure region
4444
* edits maintain order). The extra info added here is not 'serialized' as part of the WALEdit
4545
* hence marked 'transient' to underline this fact. It also adds mechanism so we can wait on
4646
* the assign of the region sequence id. See #stampRegionSequenceId().
@@ -50,25 +50,40 @@ class FSWALEntry extends Entry {
5050
// The below data members are denoted 'transient' just to highlight these are not persisted;
5151
// they are only in memory and held here while passing over the ring buffer.
5252
private final transient long txid;
53+
54+
/**
55+
* If false, means this is a meta edit written by the hbase system itself. It was not in
56+
* memstore. HBase uses these edit types to note in the log operational transitions such
57+
* as compactions, flushes, or region open/closes.
58+
*/
5359
private final transient boolean inMemstore;
60+
61+
/**
62+
* Set if this is a meta edit and it is of close region type.
63+
*/
5464
private final transient boolean closeRegion;
65+
5566
private final transient RegionInfo regionInfo;
5667
private final transient Set<byte[]> familyNames;
5768
private final transient ServerCall<?> rpcCall;
5869

70+
/**
71+
* @param inMemstore If true, then this is a data edit, one that came from client. If false, it
72+
* is a meta edit made by the hbase system itself and is for the WAL only.
73+
*/
5974
FSWALEntry(final long txid, final WALKeyImpl key, final WALEdit edit, final RegionInfo regionInfo,
60-
final boolean inMemstore, boolean closeRegion, ServerCall<?> rpcCall) {
75+
final boolean inMemstore, ServerCall<?> rpcCall) {
6176
super(key, edit);
6277
this.inMemstore = inMemstore;
63-
this.closeRegion = closeRegion;
78+
this.closeRegion = !inMemstore && edit.isRegionCloseMarker();
6479
this.regionInfo = regionInfo;
6580
this.txid = txid;
6681
if (inMemstore) {
6782
// construct familyNames here to reduce the work of log sinker.
6883
Set<byte[]> families = edit.getFamilies();
6984
this.familyNames = families != null ? families : collectFamilies(edit.getCells());
7085
} else {
71-
this.familyNames = Collections.<byte[]> emptySet();
86+
this.familyNames = Collections.emptySet();
7287
}
7388
this.rpcCall = rpcCall;
7489
if (rpcCall != null) {
@@ -83,7 +98,7 @@ static Set<byte[]> collectFamilies(List<Cell> cells) {
8398
} else {
8499
Set<byte[]> set = new TreeSet<>(Bytes.BYTES_COMPARATOR);
85100
for (Cell cell: cells) {
86-
if (!CellUtil.matchingFamily(cell, WALEdit.METAFAMILY)) {
101+
if (!WALEdit.isMetaEditFamily(cell)) {
87102
set.add(CellUtil.cloneFamily(cell));
88103
}
89104
}

0 commit comments

Comments
 (0)