Skip to content

Commit a876581

Browse files
committed
HBASE-25975: Row Commit Sequencer
Use a row commit sequencer in HRegion to ensure that only the operations that mutate disjoint sets of rows are able to commit within the same clock tick. This maintains the invariant that more than one mutation to a given row will never be committed in the same clock tick. Callers will first acquire row locks for the row(s) the pending mutation will mutate. Then they will use RowCommitSequencer.getRowSequence to ensure that the set of rows about to be mutated do not overlap with those for any other pending mutations in the current clock tick. If an overlap is identified, getRowSequence will yield and loop until there is no longer an overlap and the caller's pending mutation can succeed.
1 parent 26ab9d0 commit a876581

File tree

13 files changed

+507
-28
lines changed

13 files changed

+507
-28
lines changed

hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSource.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public interface MetricsRegionSource extends Comparable<MetricsRegionSource> {
3838
String NUM_FILES_COMPACTED_COUNT = "numFilesCompactedCount";
3939
String FLUSHES_QUEUED_COUNT = "flushesQueuedCount";
4040
String MAX_FLUSH_QUEUE_SIZE = "maxFlushQueueSize";
41+
String ROW_SEQUENCING_YIELDS = "rowSequencingYields";
4142
String COMPACTIONS_COMPLETED_DESC = "Number of compactions that have completed.";
4243
String COMPACTIONS_FAILED_DESC = "Number of compactions that have failed.";
4344
String LAST_MAJOR_COMPACTION_DESC = "Age of the last major compaction in milliseconds.";
@@ -57,6 +58,7 @@ public interface MetricsRegionSource extends Comparable<MetricsRegionSource> {
5758
String ROW_READS_ONLY_ON_MEMSTORE_DESC = "Row reads happening completely out of memstore";
5859
String MIXED_ROW_READS = "mixedRowReadsCount";
5960
String MIXED_ROW_READS_ON_STORE_DESC = "Row reads happening out of files and memstore on store";
61+
String ROW_SEQUENCING_YIELDS_DESC = "Number of yields taken to sequence row commits";
6062

6163
/**
6264
* Close the region's metrics as this region is closing.
@@ -99,5 +101,9 @@ public interface MetricsRegionSource extends Comparable<MetricsRegionSource> {
99101
*/
100102
MetricsRegionAggregateSource getAggregateSource();
101103

104+
/**
105+
* Update count of row sequencing yields.
106+
*/
107+
void updateRowSequencingYields();
102108

103109
}

hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource {
5757
private final String regionIncrementKey;
5858
private final String regionAppendKey;
5959
private final String regionScanKey;
60-
60+
private final String regionRowSequencerYieldsKey;
6161
/*
6262
* Implementation note: Do not put histograms per region. With hundreds of regions in a server
6363
* histograms allocate too many counters. See HBASE-17016.
@@ -69,6 +69,8 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource {
6969
private final MutableFastCounter regionGet;
7070
private final MutableFastCounter regionScan;
7171

72+
private final MutableFastCounter regionRowSequencerYields;
73+
7274
private final int hashCode;
7375

7476
public MetricsRegionSourceImpl(MetricsRegionWrapper regionWrapper,
@@ -107,6 +109,10 @@ public MetricsRegionSourceImpl(MetricsRegionWrapper regionWrapper,
107109

108110
regionScanKey = regionNamePrefix + MetricsRegionServerSource.SCAN_KEY + suffix;
109111
regionScan = registry.getCounter(regionScanKey, 0L);
112+
113+
regionRowSequencerYieldsKey = regionNamePrefix + MetricsRegionSource.ROW_SEQUENCING_YIELDS +
114+
suffix;
115+
regionRowSequencerYields = registry.getCounter(regionRowSequencerYieldsKey, 0L);
110116
}
111117

112118
@Override
@@ -135,6 +141,7 @@ public void close() {
135141
registry.removeMetric(regionAppendKey);
136142
registry.removeMetric(regionGetKey);
137143
registry.removeMetric(regionScanKey);
144+
registry.removeMetric(regionRowSequencerYieldsKey);
138145

139146
regionWrapper = null;
140147
}
@@ -170,6 +177,11 @@ public void updateAppend() {
170177
regionAppend.incr();
171178
}
172179

180+
@Override
181+
public void updateRowSequencingYields() {
182+
regionRowSequencerYields.incr();
183+
}
184+
173185
@Override
174186
public MetricsRegionAggregateSource getAggregateSource() {
175187
return agg;
@@ -302,6 +314,10 @@ void snapshot(MetricsRecordBuilder mrb, boolean ignored) {
302314
regionNamePrefix + MetricsRegionSource.MAX_FLUSH_QUEUE_SIZE,
303315
MetricsRegionSource.MAX_FLUSH_QUEUE_DESC),
304316
this.regionWrapper.getMaxFlushQueueSize());
317+
mrb.addCounter(Interns.info(
318+
regionNamePrefix + MetricsRegionSource.ROW_SEQUENCING_YIELDS,
319+
MetricsRegionSource.ROW_SEQUENCING_YIELDS_DESC),
320+
this.regionWrapper.getRowSequencingYields());
305321
addCounter(mrb, this.regionWrapper.getMemstoreOnlyRowReadsCount(),
306322
MetricsRegionSource.ROW_READS_ONLY_ON_MEMSTORE,
307323
MetricsRegionSource.ROW_READS_ONLY_ON_MEMSTORE_DESC);

hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionWrapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,8 @@ public interface MetricsRegionWrapper {
183183
*/
184184
Map<String, Long> getMixedRowReadsCount();
185185

186+
/**
187+
* @return the number of yields made for row sequencing
188+
*/
189+
long getRowSequencingYields();
186190
}

hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,10 @@ public Map<String, Long> getMixedRowReadsCount() {
233233
map.put("info", 0L);
234234
return map;
235235
}
236+
237+
@Override
238+
public long getRowSequencingYields() {
239+
return 0;
240+
}
236241
}
237242
}

0 commit comments

Comments
 (0)