1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.regionserver.wal;
19
20
21 import java.io.IOException;
22 import java.util.List;
23 import java.util.concurrent.atomic.AtomicLong;
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.hbase.Cell;
26 import org.apache.hadoop.hbase.CellUtil;
27 import org.apache.hadoop.hbase.HRegionInfo;
28 import org.apache.hadoop.hbase.HTableDescriptor;
29
30 import org.apache.hadoop.hbase.wal.WAL.Entry;
31 import org.apache.hadoop.hbase.wal.WALKey;
32
33
34
35
36
37
38
39
40
41 @InterfaceAudience.Private
42 class FSWALEntry extends Entry {
43
44
45 private final transient long sequence;
46 private final transient AtomicLong regionSequenceIdReference;
47 private final transient boolean inMemstore;
48 private final transient HTableDescriptor htd;
49 private final transient HRegionInfo hri;
50 private final transient List<Cell> memstoreCells;
51
52 FSWALEntry(final long sequence, final WALKey key, final WALEdit edit,
53 final AtomicLong referenceToRegionSequenceId, final boolean inMemstore,
54 final HTableDescriptor htd, final HRegionInfo hri, List<Cell> memstoreCells) {
55 super(key, edit);
56 this.regionSequenceIdReference = referenceToRegionSequenceId;
57 this.inMemstore = inMemstore;
58 this.htd = htd;
59 this.hri = hri;
60 this.sequence = sequence;
61 this.memstoreCells = memstoreCells;
62 }
63
64 public String toString() {
65 return "sequence=" + this.sequence + ", " + super.toString();
66 };
67
68 boolean isInMemstore() {
69 return this.inMemstore;
70 }
71
72 HTableDescriptor getHTableDescriptor() {
73 return this.htd;
74 }
75
76 HRegionInfo getHRegionInfo() {
77 return this.hri;
78 }
79
80
81
82
83 long getSequence() {
84 return this.sequence;
85 }
86
87
88
89
90
91
92
93
94
95
96
97 long stampRegionSequenceId() throws IOException {
98 long regionSequenceId = this.regionSequenceIdReference.incrementAndGet();
99 if (!this.getEdit().isReplay() && memstoreCells != null && !memstoreCells.isEmpty()) {
100 for (Cell cell : this.memstoreCells) {
101 CellUtil.setSequenceId(cell, regionSequenceId);
102 }
103 }
104 WALKey key = getKey();
105 key.setLogSeqNum(regionSequenceId);
106 return regionSequenceId;
107 }
108 }