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