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.ArrayList;
23 import java.util.Collections;
24 import java.util.Set;
25
26 import org.apache.hadoop.hbase.Cell;
27 import org.apache.hadoop.hbase.CellUtil;
28 import org.apache.hadoop.hbase.HRegionInfo;
29 import org.apache.hadoop.hbase.HTableDescriptor;
30 import org.apache.hadoop.hbase.classification.InterfaceAudience;
31 import org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl;
32 import org.apache.hadoop.hbase.util.Bytes;
33 import org.apache.hadoop.hbase.util.CollectionUtils;
34
35 import com.google.common.collect.Sets;
36
37 import org.apache.hadoop.hbase.wal.WAL.Entry;
38 import org.apache.hadoop.hbase.wal.WALKey;
39
40
41
42
43
44
45
46
47
48 @InterfaceAudience.Private
49 class FSWALEntry extends Entry {
50
51
52 private final transient long sequence;
53 private final transient boolean inMemstore;
54 private final transient HTableDescriptor htd;
55 private final transient HRegionInfo hri;
56 private final Set<byte[]> familyNames;
57
58 FSWALEntry(final long sequence, final WALKey key, final WALEdit edit,
59 final HTableDescriptor htd, final HRegionInfo hri, final boolean inMemstore) {
60 super(key, edit);
61 this.inMemstore = inMemstore;
62 this.htd = htd;
63 this.hri = hri;
64 this.sequence = sequence;
65 if (inMemstore) {
66
67 ArrayList<Cell> cells = this.getEdit().getCells();
68 if (CollectionUtils.isEmpty(cells)) {
69 this.familyNames = Collections.<byte[]> emptySet();
70 } else {
71 Set<byte[]> familySet = Sets.newTreeSet(Bytes.BYTES_COMPARATOR);
72 for (Cell cell : cells) {
73 if (!CellUtil.matchingFamily(cell, WALEdit.METAFAMILY)) {
74 familySet.add(CellUtil.cloneFamily(cell));
75 }
76 }
77 this.familyNames = Collections.unmodifiableSet(familySet);
78 }
79 } else {
80 this.familyNames = Collections.<byte[]> emptySet();
81 }
82 }
83
84 public String toString() {
85 return "sequence=" + this.sequence + ", " + super.toString();
86 };
87
88 boolean isInMemstore() {
89 return this.inMemstore;
90 }
91
92 HTableDescriptor getHTableDescriptor() {
93 return this.htd;
94 }
95
96 HRegionInfo getHRegionInfo() {
97 return this.hri;
98 }
99
100
101
102
103 long getSequence() {
104 return this.sequence;
105 }
106
107
108
109
110
111
112 long stampRegionSequenceId() throws IOException {
113 long regionSequenceId = WALKey.NO_SEQUENCE_ID;
114 MultiVersionConcurrencyControl mvcc = getKey().getMvcc();
115 MultiVersionConcurrencyControl.WriteEntry we = null;
116
117 if (mvcc != null) {
118 we = mvcc.begin();
119 regionSequenceId = we.getWriteNumber();
120 }
121
122 if (!this.getEdit().isReplay() && inMemstore) {
123 for (Cell c:getEdit().getCells()) {
124 CellUtil.setSequenceId(c, regionSequenceId);
125 }
126 }
127
128
129 WALKey key = getKey();
130 key.setLogSeqNum(regionSequenceId);
131 key.setWriteEntry(we);
132 return regionSequenceId;
133 }
134
135
136
137
138 Set<byte[]> getFamilyNames() {
139 return familyNames;
140 }
141 }