Skip to content

Commit 316229a

Browse files
improve overall stability (pre-release 2021.1)
1 parent 2f840a7 commit 316229a

13 files changed

Lines changed: 131 additions & 66 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public class Config {
114114
public final int WRITE_BUFFER_SIZE = 33554432;
115115
// cleanup
116116
public final int TRANS_CLEANUP_TIMEOUT = 5000;
117-
public final int CLEANUP_ENABLE = 0;
117+
public final int CLEANUP_ENABLE = 1;
118118
public final int CLEANUP_TIMEOUT = 3000;
119119
public final int CLEANUP_PROTECTION_THR = 1000;
120120
public final int IX_CLEANUP_PROTECTION_THR = 2000;

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public synchronized byte[] getFrame() throws InvalidFrame {
350350
res.append(res2.getBytes());
351351

352352
if (used > getFrameSize()) {
353-
logger.error("Build snapshot for "+this.getClass().getName()+":"+this.getObjectId()+":"+this.pointer+" with used length="+used+" failed, not enough size for expected framesize="+getFrameSize()+"");
353+
logger.error("Build snapshot for "+this.getClass().getName()+":"+this.getObjectId()+":"+this.getPtr()+" with used length="+used+" failed, not enough size for expected framesize="+getFrameSize()+"");
354354
throw new InvalidFrame();
355355
}
356356
if (used < getFrameSize()) {
@@ -561,7 +561,7 @@ public ArrayList<Chunk> getFrameChunks (Session s) {
561561
return res;
562562
}
563563

564-
public synchronized void rollbackTransaction(Transaction tran, ArrayList<FrameData> ubs, Session s) throws InterruptedException {
564+
public synchronized void rollbackTransaction(Transaction tran, ArrayList<FrameData> ubs, Session s) throws Exception {
565565
data.check();
566566

567567
//rollback inserted records
@@ -579,23 +579,19 @@ public synchronized void rollbackTransaction(Transaction tran, ArrayList<FrameDa
579579

580580
//rollback deleted & updated records
581581
if (ubs!=null) {
582-
try {
583-
for (FrameData ub : ubs) {
584-
for (Chunk c : ub.getDataFrame().getChunks()) {
585-
final UndoChunk uc = (UndoChunk)c.getEntity();
586-
final int ucfile = uc.getDataChunk().getHeader().getRowID().getFileId();
587-
final long frameptr = uc.getDataChunk().getHeader().getRowID().getFramePointer();
588-
if (uc.getTransId() == tran.getTransId() && ucfile == this.file && frameptr == this.pointer) {
589-
final DataChunk rc = uc.getDataChunk().restore(uc);
590-
if (this instanceof IndexFrame && rc.getExistingEntity() != null) {
591-
((IndexChunk) rc.getExistingEntity()).setDataChunk(null);
592-
}
593-
data.add(rc);
582+
for (FrameData ub : ubs) {
583+
for (Chunk c : ub.getDataFrame().getChunks()) {
584+
final UndoChunk uc = (UndoChunk)c.getEntity();
585+
final int ucfile = uc.getDataChunk().getHeader().getRowID().getFileId();
586+
final long frameptr = uc.getDataChunk().getHeader().getRowID().getFramePointer();
587+
if (uc.getTransId() == tran.getTransId() && ucfile == this.file && frameptr == this.pointer) {
588+
final DataChunk rc = uc.getDataChunk().restore(uc);
589+
if (this instanceof IndexFrame && rc.getExistingEntity() != null) {
590+
((IndexChunk) rc.getExistingEntity()).setDataChunk(null);
594591
}
592+
data.add(rc);
595593
}
596594
}
597-
} catch (Exception e) {
598-
e.printStackTrace();
599595
}
600596
}
601597
final LLT llt = LLT.getLLT();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
The MIT License (MIT)
33
4-
Copyright (c) 2010-2019 head systems, ltd
4+
Copyright (c) 2010-2020 head systems, ltd
55
66
Permission is hereby granted, free of charge, to any person obtaining a copy of
77
this software and associated documentation files (the "Software"), to deal in

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

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ this software and associated documentation files (the "Software"), to deal in
2525
package su.interference.core;
2626

2727
import su.interference.exception.*;
28-
import su.interference.persistent.Table;
29-
import su.interference.persistent.FrameData;
30-
import su.interference.persistent.Session;
31-
import su.interference.persistent.UndoChunk;
28+
import su.interference.persistent.*;
3229
import su.interference.serialize.ByteString;
3330

3431
import java.util.*;
@@ -127,6 +124,42 @@ public IndexFrame(byte[] b, int file, long pointer, Map<Long, Long> imap, Map<Lo
127124
this.b = null; //throw bytes to GC
128125
}
129126

127+
@Override
128+
public synchronized void rollbackTransaction(Transaction tran, ArrayList<FrameData> ubs, Session s) throws Exception {
129+
data.check();
130+
final Map<Integer, DataChunk> ucmap = new HashMap();
131+
132+
if (ubs!=null) {
133+
for (FrameData ub : ubs) {
134+
for (Chunk c : ub.getDataFrame().getChunks()) {
135+
final UndoChunk uc = (UndoChunk) c.getEntity();
136+
final int ucfile = uc.getDataChunk().getHeader().getRowID().getFileId();
137+
final long frameptr = uc.getDataChunk().getHeader().getRowID().getFramePointer();
138+
if (uc.getTransId() == tran.getTransId() && ucfile == this.getFile() && frameptr == this.getPointer()) {
139+
ucmap.put(uc.getPtr(), uc.getDataChunk());
140+
}
141+
}
142+
}
143+
}
144+
145+
//rollback modified index records
146+
for (Chunk c : data.getChunks()) {
147+
if (c.getHeader().getTran().getTransId() == tran.getTransId()) {
148+
final DataChunk dc = ucmap.get(c.getHeader().getPtr());
149+
final DataChunk dc_ = ((IndexChunk) c.getEntity()).getDataChunk().getUndoChunk().getDataChunk();
150+
((DataChunk) c).setUndoChunk(null);
151+
((DataChunk) c).cleanUpIcs();
152+
((IndexChunk)c.getEntity()).setDataChunk(dc_);
153+
((IndexChunk)c.getEntity()).setFramePtrRowId(dc_.getHeader().getRowID());
154+
((DataChunk)c).getHeader().setFramePtr(dc_.getHeader().getRowID());
155+
}
156+
}
157+
158+
final LLT llt = LLT.getLLT();
159+
llt.add(this);
160+
llt.commit();
161+
}
162+
130163
public void cleanICEntities() {
131164
for (Chunk c : this.data.getChunks()) {
132165
final Object e = ((DataChunk) c).getExistingEntity();
@@ -136,11 +169,12 @@ public void cleanICEntities() {
136169
}
137170
}
138171

139-
public synchronized IndexFrame add (DataChunk e, Table t, Session s, LLT llt) throws Exception {
172+
public synchronized FrameData add (DataChunk e, Table t, Session s, LLT llt) throws Exception {
140173
if (this.isFill(e)) {
141174

142175
final int nfileId = t.getIndexFileId(this.getFrameData());
143-
final IndexFrame res = t.createNewFrame(this.getFrameData(), null, nfileId, this.getType(), 0, false, false, false, s, llt).getIndexFrame();
176+
final FrameData res_ = t.createNewFrame(this.getFrameData(), null, nfileId, this.getType(), 0, false, false, false, s, llt);
177+
final IndexFrame res = res_.getIndexFrame();
144178
//paranoid fix
145179
llt.add(res);
146180
llt.add(this);
@@ -182,7 +216,7 @@ public synchronized IndexFrame add (DataChunk e, Table t, Session s, LLT llt) th
182216
for (int i=0; i<this.data.size(); i++) {
183217
if (!norpt) {
184218
if (pkey!=null) {
185-
if (((DataChunk)this.data.get(i)).getDcs().compareTo(pkey)==0) {
219+
if (this.data.get(i).getDcs().compareTo(pkey)==0) {
186220
keyrpt = true;
187221
}
188222
} else {
@@ -192,15 +226,15 @@ public synchronized IndexFrame add (DataChunk e, Table t, Session s, LLT llt) th
192226
if (i==this.data.size()-1) {
193227
keyrpt = false;
194228
}
195-
if (this.getFrameSize()-resamt>this.data.get(i).getBytesAmount()&&(keyrpt||((DataChunk)this.data.get(i)).getDcs().compareTo(max2)<0)) {
229+
if (this.getFrameSize()-resamt>this.data.get(i).getBytesAmount()&&(keyrpt||this.data.get(i).getDcs().compareTo(max2)<0)) {
196230
res.insertChunk(this.data.get(i), s, false, true, llt);
197231
resamt = resamt + this.data.get(i).getBytesAmount();
198232
res.setHasMV(1);
199233
} else {
200234
norpt = true;
201235
nlist.add((DataChunk)this.data.get(i));
202236
}
203-
pkey = ((DataChunk)this.data.get(i)).getDcs();
237+
pkey = this.data.get(i).getDcs();
204238
keyrpt = false;
205239
}
206240
this.data.clear();
@@ -209,7 +243,7 @@ public synchronized IndexFrame add (DataChunk e, Table t, Session s, LLT llt) th
209243
}
210244
}
211245
}
212-
return res;
246+
return res_;
213247
} else {
214248
this.insertChunk(e, s, false, llt);
215249
return null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ public Table getFrameDataTable() {
561561
return (Table)((DataChunk)tt.getMapFieldByColumn("name").getMap().get("su.interference.persistent.FrameData")).getEntity();
562562
}
563563

564-
protected Map getFramesMap () {
564+
public Map getFramesMap () {
565565
final Table t = getTableByName("su.interference.persistent.FrameData");
566566
final MapField ixf = t.getMapFieldByColumn("frameId");
567567
return ixf.getMap();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ private synchronized ArrayList<FrameData> getLBSArray(int objectId, IndexList ix
527527
final ArrayList<FrameData> res = new ArrayList<FrameData>();
528528
for (Object b : bds) {
529529
final FrameData bd = (FrameData)((DataChunk)b).getEntity(FrameData.class, null);
530-
if (bd.getCurrent().get()>0) {
530+
if (bd.getCurrent() > 0) {
531531
res.add(bd);
532532
}
533533
}

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ private void cleanUpFrames() throws Exception {
7979
int i = 0;
8080
int d = 0;
8181
int x = 0;
82+
int xn = 0;
83+
int xall = 0;
8284
int u = 0;
8385
int i_ = 0;
8486
int d_ = 0;
@@ -89,7 +91,7 @@ private void cleanUpFrames() throws Exception {
8991
final long frameAmount = f.getDataObject().getFrameAmount();
9092
if (f.getDataFile().isData() && cleanupDataEnabled()) {
9193
f.decreasePriority();
92-
if (f.isSynced() && f.getObjectId() > 999 && f.getPriority() == 0 && frameAmount > Config.getConfig().CLEANUP_PROTECTION_THR) {
94+
if (f.isSynced() && f.getObjectId() > 999 && frameAmount > Config.getConfig().CLEANUP_PROTECTION_THR) {
9395
if (f.clearFrame()) {
9496
d++;
9597
}
@@ -100,7 +102,11 @@ private void cleanUpFrames() throws Exception {
100102
}
101103
if (f.getDataFile().isIndex() && cleanupIndxEnabled()) {
102104
f.decreasePriority();
103-
if (f.getFrameType() == IndexFrame.INDEX_FRAME_LEAF && f.getPriority() == 0 && frameAmount > Config.getConfig().IX_CLEANUP_PROTECTION_THR) {
105+
xall++;
106+
if (f.getFrameType() == IndexFrame.INDEX_FRAME_NODE) {
107+
xn++;
108+
}
109+
if (f.getFrameType() != IndexFrame.INDEX_FRAME_NODE && !f.isRbck() && frameAmount > Config.getConfig().IX_CLEANUP_PROTECTION_THR) {
104110
if (f.clearFrame()) {
105111
x++;
106112
}
@@ -110,7 +116,7 @@ private void cleanUpFrames() throws Exception {
110116
}
111117
}
112118
if (f.getDataFile().isTemp() && cleanupTempEnabled()) {
113-
if (frameAmount > Config.getConfig().CLEANUP_PROTECTION_THR) {
119+
if (f.getFrameType() != IndexFrame.INDEX_FRAME_NODE && frameAmount > Config.getConfig().CLEANUP_PROTECTION_THR) {
114120
if (f.clearFrame()) {
115121
i++;
116122
}
@@ -143,7 +149,7 @@ private void cleanUpFrames() throws Exception {
143149
public static void forceCleanUp() {
144150
for (Object entry : Instance.getInstance().getFramesMap().entrySet()) {
145151
final FrameData f = (FrameData) ((DataChunk) ((Map.Entry) entry).getValue()).getEntity();
146-
if (f.isSynced()) {
152+
if (f.isSynced() && f.getObjectId() > 999) {
147153
f.clearFrame();
148154
}
149155
}
@@ -174,6 +180,8 @@ private boolean cleanupTempEnabled() {
174180
final long maxmem = Runtime.getRuntime().maxMemory();
175181
final long alloc = Runtime.getRuntime().totalMemory();
176182
final long allocpc = alloc * 100 / maxmem;
177-
return allocpc > Config.getConfig().HEAP_USE_THR_TEMP;
183+
// todo return allocpc > Config.getConfig().HEAP_USE_THR_TEMP;
184+
// todo cleanup affects temp indices, disable until fix is released
185+
return false;
178186
}
179187
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package su.interference.metrics;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import su.interference.core.DataChunk;
6+
import su.interference.core.Instance;
37
import su.interference.core.SystemCleanUp;
8+
import su.interference.persistent.FrameData;
9+
10+
import java.util.Map;
411

512
public class Call extends Meter implements CallMBean {
613

14+
private final static Logger logger = LoggerFactory.getLogger(Call.class);
715
public Call(String name) {
816
super(name);
917
}
@@ -12,4 +20,11 @@ public void forceCleanUp() {
1220
SystemCleanUp.forceCleanUp();
1321
}
1422

23+
public void reportFrames() {
24+
for (Object entry : Instance.getInstance().getFramesMap().entrySet()) {
25+
final FrameData f = (FrameData) ((DataChunk) ((Map.Entry) entry).getValue()).getEntity();
26+
logger.info("frame table:id:used "+f.getObjectId()+":"+f.getFrameId()+":"+f.getUsed());
27+
}
28+
}
29+
1530
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
public interface CallMBean {
44
void forceCleanUp();
5+
void reportFrames();
56
}

src/main/java/su/interference/persistent/DataFile.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ public synchronized void writeFrame(final long ptr, final byte[] b) throws IOExc
495495
this.file.write(b);
496496
}
497497

498-
public synchronized void writeFrame(FrameData bd, final long ptr, final byte[] b, LLT llt, Session s) throws Exception {
498+
public void writeFrame(FrameData bd, final long ptr, final byte[] b, LLT llt, Session s) throws Exception {
499499
final ByteString bs = new ByteString(b);
500500
final int file_ = bs.getIntFromBytes(0);
501501
final long ptr_ = bs.getLongFromBytes(4);
@@ -508,9 +508,10 @@ public synchronized void writeFrame(FrameData bd, final long ptr, final byte[] b
508508
if (ptr != ptr_) {
509509
logger.error("Wrong write frame operation with file = " + this.file + " ptr = " + ptr + ", internal file = " + file_ + " ptr = " + ptr_);
510510
}
511-
512-
this.file.seek(ptr);
513-
this.file.write(b);
511+
synchronized (this) {
512+
this.file.seek(ptr);
513+
this.file.write(b);
514+
}
514515
s.persist(bd, llt);
515516
}
516517

0 commit comments

Comments
 (0)