Skip to content

Commit 463eb1b

Browse files
2020.2 optimized performance and improved stability
1 parent 4e0848e commit 463eb1b

19 files changed

Lines changed: 165 additions & 535 deletions

src/main/java/su/interference/core/ByteArray.java

Lines changed: 0 additions & 455 deletions
This file was deleted.

src/main/java/su/interference/core/DataFrame.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,17 @@ public DataFrame(int file, long pointer, int size, FrameData bd, Table t, Class
8787
}
8888

8989
//constructor for replication service - data frames
90-
public DataFrame(byte[] b, int file, long pointer, Map<Long, List<Chunk>> umap, Table t) throws Exception {
90+
public DataFrame(byte[] b, int file, long pointer, Table t) throws Exception {
9191
super(b, file, pointer, t);
9292

9393
int ptr = FRAME_HEADER_SIZE;
94-
final Map<Integer, UndoChunk> ucmap = new HashMap<>();
95-
if (umap.get(file + pointer) != null) {
96-
for (Chunk c : umap.get(file + pointer)) {
97-
ucmap.put(((UndoChunk) c.getEntity()).getPtr(), (UndoChunk) c.getEntity());
98-
}
99-
}
10094
final ByteString bs = new ByteString(this.b);
95+
10196
while (ptr<this.b.length) {
10297
if (this.b.length>=ptr+ROW_HEADER_SIZE) {
10398
final RowHeader h = new RowHeader(bs.substring(ptr, ptr+ROW_HEADER_SIZE), this.getFile(), this.getPointer());
10499
if ((h.getPtr()>0)&&(h.getLen()>0)) {
105100
final DataChunk dc = new DataChunk(bs.substring(ptr, ptr+ROW_HEADER_SIZE+h.getLen()), this.getFile(), this.getPointer(), ROW_HEADER_SIZE, this.getDataObject(), this.getEntityClass());
106-
dc.setUndoChunk(ucmap.get(h.getPtr()));
107101
dc.getHeader().setTran(dc.getHeader().getTran());
108102
data.add(dc);
109103
ptr = ptr + ROW_HEADER_SIZE + h.getLen();
@@ -118,7 +112,7 @@ public DataFrame(byte[] b, int file, long pointer, Map<Long, List<Chunk>> umap,
118112
}
119113

120114
// constructor for replication service - undo frames
121-
public DataFrame(byte[] b, int file, long pointer, HashMap<Long, Long> imap, HashMap<Long, Long> hmap, Map<Long, List<Chunk>> umap, Table t, Session s) throws Exception {
115+
public DataFrame(byte[] b, int file, long pointer, Map<Long, Long> imap, Map<Long, Long> hmap, Table t, Session s) throws Exception {
122116
super(b, file, pointer, t);
123117

124118
if (!t.getName().equals("su.interference.persistent.UndoChunk")) {
@@ -139,10 +133,6 @@ public DataFrame(byte[] b, int file, long pointer, HashMap<Long, Long> imap, Has
139133
uc.setFile((int) bptr % 4096);
140134
uc.setFrame(bptr - (bptr % 4096));
141135
data.add(dc);
142-
if (umap.get(bptr) == null) {
143-
umap.put(bptr, new ArrayList<>());
144-
}
145-
umap.get(bptr).add(dc);
146136
ptr = ptr + ROW_HEADER_SIZE + h.getLen();
147137
} else {
148138
ptr = this.b.length;

src/main/java/su/interference/core/IndexFrame.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,10 @@ public IndexFrame(int file, long pointer, int size, FrameData bd, Table t, Class
100100
}
101101

102102
//constructor for replication service
103-
public IndexFrame(byte[] b, int file, long pointer, HashMap<Long, Long> imap, HashMap<Long, Long> hmap, Map<Long, List<Chunk>> umap, Table t) {
103+
public IndexFrame(byte[] b, int file, long pointer, Map<Long, Long> imap, Map<Long, Long> hmap, Table t) {
104104
super(b, file, pointer, t);
105105
int ptr = FRAME_HEADER_SIZE;
106106

107-
final Map<Integer, UndoChunk> ucmap = new HashMap<>();
108-
if (umap.get(file + pointer) != null) {
109-
for (Chunk c : umap.get(file + pointer)) {
110-
ucmap.put(((UndoChunk) c.getEntity()).getPtr(), (UndoChunk) c.getEntity());
111-
}
112-
}
113-
114107
final ByteString bs = new ByteString(this.b);
115108
while (ptr<this.b.length) {
116109
if (this.b.length>=ptr+INDEX_HEADER_SIZE) {
@@ -124,13 +117,7 @@ public IndexFrame(byte[] b, int file, long pointer, HashMap<Long, Long> imap, Ha
124117
h.getFramePtrRowId().setFramePointer(bptr - (bptr % 4096));
125118
}
126119
final DataChunk dc = new DataChunk(bs.substring(ptr, ptr+INDEX_HEADER_SIZE+h.getLen()), this.getFile(), this.getPointer(), INDEX_HEADER_SIZE, this.getDataObject(), this.getEntityClass());
127-
dc.setUndoChunk(ucmap.get(h.getPtr()));
128120
dc.setHeader(h);
129-
if (this.getType()==INDEX_FRAME_LEAF) {
130-
if (INITIALIZE_DURING_CONSTRUCT == 1) {
131-
final IndexChunk ib = (IndexChunk) dc.getEntity();
132-
}
133-
}
134121
data.add(dc);
135122
ptr = ptr + INDEX_HEADER_SIZE + h.getLen();
136123
} else {
@@ -144,12 +131,10 @@ public IndexFrame(byte[] b, int file, long pointer, HashMap<Long, Long> imap, Ha
144131
}
145132

146133
public IndexFrame add (DataChunk e, Table t, Session s, LLT llt) throws Exception {
147-
IndexFrame res = null;
148-
149134
if (this.isFill(e)) {
150135

151136
final int nfileId = t.getIndexFileId(this.getFrameData());
152-
res = t.createNewFrame(this.getFrameData(), nfileId, this.getType(), 0, false, false, false, s, llt).getIndexFrame();
137+
final IndexFrame res = t.createNewFrame(this.getFrameData(), nfileId, this.getType(), 0, false, false, false, s, llt).getIndexFrame();
153138
res.setParentF(this.getParentF());
154139
res.setParentB(this.getParentB());
155140
final ValueSet max = this.sort();
@@ -173,7 +158,8 @@ public IndexFrame add (DataChunk e, Table t, Session s, LLT llt) throws Exceptio
173158
this.setLcF(0);
174159
this.setLcB(0);
175160
} else {
176-
if (e.getDcs().compareTo(this.mv)>0) {
161+
final int cmv = e.getDcs().compareTo(this.mv);
162+
if (cmv > 0) {
177163
throw new InternalException();
178164
} else {
179165
res.setDivided(1);
@@ -215,10 +201,11 @@ public IndexFrame add (DataChunk e, Table t, Session s, LLT llt) throws Exceptio
215201
}
216202
}
217203
}
204+
return res;
218205
} else {
219206
this.insertChunk(e, s, false, llt);
207+
return null;
220208
}
221-
return res;
222209
}
223210

224211
public DataChunk get (int index) {

src/main/java/su/interference/core/Instance.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,17 @@ private static void registerMetrics() throws Exception {
408408
Metrics.register(Metrics.TIMER, "persistGetChunk");
409409
Metrics.register(Metrics.TIMER, "persistInsertChunk");
410410
Metrics.register(Metrics.TIMER, "persistInsertIndex");
411+
Metrics.register(Metrics.TIMER, "syncFrameEvent");
411412
Metrics.register(Metrics.HISTOGRAM, "recordRCount");
412413
Metrics.register(Metrics.HISTOGRAM, "recordLCount");
413414
Metrics.register(Metrics.HISTOGRAM, "syncQueue");
414415
Metrics.register(Metrics.TIMER, "systemCleanUp");
415416
Metrics.register(Metrics.HISTOGRAM, "сleanUpDataFrames");
416417
Metrics.register(Metrics.HISTOGRAM, "сleanUpIndexFrames");
417418
Metrics.register(Metrics.HISTOGRAM, "сleanUpUndoFrames");
419+
Metrics.register(Metrics.METER, "imDataFrames");
420+
Metrics.register(Metrics.METER, "imIndexFrames");
421+
Metrics.register(Metrics.METER, "imUndoFrames");
418422
}
419423

420424
private void checkInMemoryIndexes() {

src/main/java/su/interference/core/SyncFrame.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ this software and associated documentation files (the "Software"), to deal in
3030
import su.interference.persistent.*;
3131

3232
import java.io.Serializable;
33-
import java.util.ArrayList;
34-
import java.util.HashMap;
33+
import java.util.List;
34+
import java.util.Map;
3535

3636
/**
3737
* @author Yuriy Glotanov
@@ -41,6 +41,7 @@ this software and associated documentation files (the "Software"), to deal in
4141
public class SyncFrame implements Comparable, Serializable, AllowRPredicate {
4242

4343
private final static Logger logger = LoggerFactory.getLogger(SyncFrame.class);
44+
private final static long serialVersionUID = 8712349857239487289L;
4445
private final byte[] b;
4546
private final long frameId;
4647
private final long allocId;
@@ -53,12 +54,13 @@ public class SyncFrame implements Comparable, Serializable, AllowRPredicate {
5354
private final long lcId;
5455
private final boolean allowR;
5556
private final boolean started;
56-
private FrameData bd;
57-
private DataFile df;
58-
private Frame rFrame;
59-
private final HashMap<Long, Long> imap;
60-
private final HashMap<Long, Transaction> rtran;
61-
private final static long serialVersionUID = 8712349857239487289L;
57+
private final Map<Long, Long> imap;
58+
private final Map<Long, Transaction> rtran;
59+
private final Map<Long, List<Long>> uframes;
60+
61+
private transient FrameData bd;
62+
private transient DataFile df;
63+
private transient Frame rFrame;
6264

6365
public SyncFrame(Frame frame, Session s, FreeFrame fb) throws Exception {
6466
final Table t = Instance.getInstance().getTableById(frame.getObjectId());
@@ -78,7 +80,10 @@ public SyncFrame(Frame frame, Session s, FreeFrame fb) throws Exception {
7880
}
7981

8082
className = bd == null ? null : t.getName();
83+
8184
rtran = frame.getLiveTransactions();
85+
uframes = allowR ? bd.getLiveUFrameAllocIds() : null;
86+
8287
if (frame.getClass().getName().equals("su.interference.core.DataFrame")) {
8388
if (frame.getType()!=0) {
8489
throw new InternalException();
@@ -215,14 +220,18 @@ public void setDf(DataFile df) {
215220
this.df = df;
216221
}
217222

218-
public HashMap<Long, Long> getImap() {
223+
public Map<Long, Long> getImap() {
219224
return imap;
220225
}
221226

222-
public HashMap<Long, Transaction> getRtran() {
227+
public Map<Long, Transaction> getRtran() {
223228
return rtran;
224229
}
225230

231+
public Map<Long, List<Long>> getUFrames() {
232+
return uframes;
233+
}
234+
226235
public boolean equals (SyncFrame bl) {
227236
if ((this.getFile()==bl.getFile())&&(this.getPointer()==bl.getPointer())) {
228237
return true;

src/main/java/su/interference/core/SyncQueue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class SyncQueue implements Runnable, ManagedProcess {
4646
private volatile boolean f = true;
4747
private volatile boolean running = false;
4848
private final ExecutorService pool = Executors.newFixedThreadPool(Config.getConfig().FILES_AMOUNT);
49-
private final ExecutorService pool2 = Executors.newCachedThreadPool();
49+
private final ExecutorService pool2 = Executors.newFixedThreadPool(1);
5050
CountDownLatch latch;
5151
private final static Logger logger = LoggerFactory.getLogger(SyncQueue.class);
5252

src/main/java/su/interference/core/SystemCleanUp.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.slf4j.LoggerFactory;
55
import su.interference.metrics.Metrics;
66
import su.interference.persistent.FrameData;
7-
import su.interference.persistent.Table;
87

98
import java.util.Map;
109
import java.util.concurrent.CountDownLatch;
@@ -51,6 +50,10 @@ private void cleanUpFrames() {
5150
int d = 0;
5251
int x = 0;
5352
int u = 0;
53+
int i_ = 0;
54+
int d_ = 0;
55+
int x_ = 0;
56+
int u_ = 0;
5457
for (Object entry : Instance.getInstance().getFramesMap().entrySet()) {
5558
final FrameData f = (FrameData) ((DataChunk) ((Map.Entry) entry).getValue()).getEntity();
5659
final long frameAmount = f.getDataObject().getFrameAmount();
@@ -61,6 +64,9 @@ private void cleanUpFrames() {
6164
d++;
6265
}
6366
}
67+
if (f.isFrame()) {
68+
d_++;
69+
}
6470
}
6571
if (f.getDataFile().isIndex()) {
6672
f.decreasePriority();
@@ -69,25 +75,37 @@ private void cleanUpFrames() {
6975
x++;
7076
}
7177
}
78+
if (f.isFrame()) {
79+
x_++;
80+
}
7281
}
7382
if (f.getDataFile().isTemp()) {
7483
if (f.isSynced() && f.getObjectId() > 999 && frameAmount > CLEANUP_PROTECTION_THR) {
7584
if (f.clearFrame()) {
7685
i++;
7786
}
7887
}
88+
if (f.isFrame()) {
89+
i_++;
90+
}
7991
}
8092
if (f.getDataFile().isUndo()) {
8193
if (f.isSynced() && frameAmount > CLEANUP_PROTECTION_THR) {
8294
if (f.clearFrame()) {
8395
u++;
8496
}
8597
}
98+
if (f.isFrame()) {
99+
u_++;
100+
}
86101
}
87102
}
88103
Metrics.get("сleanUpDataFrames").put(d);
89104
Metrics.get("сleanUpIndexFrames").put(x);
90105
Metrics.get("сleanUpUndoFrames").put(u);
106+
Metrics.get("imDataFrames").put(d_);
107+
Metrics.get("imIndexFrames").put(x_);
108+
Metrics.get("imUndoFrames").put(u_);
91109
Metrics.get("systemCleanUp").stop();
92110

93111
}

src/main/java/su/interference/metrics/Histogram.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,12 @@ public long getAvg() {
7777
return avg.get();
7878
}
7979

80+
@Override
81+
public void reset() {
82+
cnt.set(0);
83+
min.set(Long.MAX_VALUE);
84+
max.set(Long.MIN_VALUE);
85+
sum.set(0);
86+
avg.set(0);
87+
}
8088
}

src/main/java/su/interference/metrics/HistogramMBean.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ public interface HistogramMBean {
3535
long getMax();
3636
long getSum();
3737
long getAvg();
38+
void reset();
3839
}

src/main/java/su/interference/metrics/Timer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,10 @@ public void stop() {
5858
}
5959
}
6060

61+
@Override
62+
public void reset() {
63+
super.reset();
64+
}
65+
6166
}
6267

0 commit comments

Comments
 (0)