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 @Override
85 public String toString() {
86 return "sequence=" + this.sequence + ", " + super.toString();
87 };
88
89 boolean isInMemstore() {
90 return this.inMemstore;
91 }
92
93 HTableDescriptor getHTableDescriptor() {
94 return this.htd;
95 }
96
97 HRegionInfo getHRegionInfo() {
98 return this.hri;
99 }
100
101
102
103
104 long getSequence() {
105 return this.sequence;
106 }
107
108
109
110
111
112
113
114
115 long stampRegionSequenceId(MultiVersionConcurrencyControl.WriteEntry we) throws IOException {
116 long regionSequenceId = we.getWriteNumber();
117 if (!this.getEdit().isReplay() && inMemstore) {
118 for (Cell c : getEdit().getCells()) {
119 CellUtil.setSequenceId(c, regionSequenceId);
120 }
121 }
122 getKey().setWriteEntry(we);
123 return regionSequenceId;
124 }
125
126
127
128
129 Set<byte[]> getFamilyNames() {
130 return familyNames;
131 }
132 }