Skip to content

Commit f206477

Browse files
pre-release 2020.3
1 parent 0e9fc71 commit f206477

14 files changed

Lines changed: 455 additions & 217 deletions

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ public class Config {
107107
public final String CODEPAGE;
108108
public final String DATEFORMAT;
109109
public final int TEST_DISTRIBUTE_MODE = 1;
110+
public final int CHECK_AVAIL_FRAME_TIMEOUT = 200;
111+
// transport
112+
public final int REMOTE_SYNC_TIMEOUT = 60000;
113+
public final int READ_BUFFER_SIZE = 33554432;
114+
public final int WRITE_BUFFER_SIZE = 33554432;
115+
// cleanup
116+
public final int CLEANUP_TIMEOUT = 3000;
117+
public final int CLEANUP_PROTECTION_THR = 1000;
118+
public final int IX_CLEANUP_PROTECTION_THR = 5000;
119+
public final int HEAP_USE_THR_DATA = 60;
120+
public final int HEAP_USE_THR_INDX = 80;
121+
public final int HEAP_USE_THR_TEMP = 40;
122+
public final int HEAP_USE_THR_UNDO = 50;
123+
110124

111125
private final Properties p;
112126

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public ValueSet getDcs() {
8484

8585
//returns datacolumn set
8686
private ValueSet getDcsFromEntity() {
87-
ValueSet dcs = null;
8887
try {
8988
final Field[] f = this.t == null ? this.entity.getClass().getDeclaredFields() : t.getFields();
9089
final List<Object> vs = new ArrayList<>();
@@ -98,11 +97,10 @@ private ValueSet getDcsFromEntity() {
9897
vs.add(f[i].get(entity));
9998
}
10099
}
101-
dcs = new ValueSet(vs.toArray(new Object[]{}));
100+
return new ValueSet(vs.toArray(new Object[]{}));
102101
} catch (Exception e) {
103102
throw new RuntimeException(e);
104103
}
105-
return dcs;
106104
}
107105

108106
private ValueSet getDcsFromBytes() {
@@ -111,12 +109,12 @@ private ValueSet getDcsFromBytes() {
111109
}
112110

113111
try {
114-
Field[] cs = null;
112+
Field[] cs;
115113
if (t != null) {
116114
cs = t.getFields();
117115
} else {
118-
Field[] f = class_.getDeclaredFields();
119-
List<Field> ff = new ArrayList<Field>();
116+
final Field[] f = class_.getDeclaredFields();
117+
final List<Field> ff = new ArrayList<>();
120118
for (int i = 0; i < f.length; i++) {
121119
int m = f[i].getModifiers();
122120
Transient ta = f[i].getAnnotation(Transient.class);
@@ -489,10 +487,10 @@ public synchronized Object getEntity () {
489487
final ResultSetEntity rsa = (ResultSetEntity) ((Table) this.t).getTableClass().getAnnotation(ResultSetEntity.class);
490488
final DataChunk dc = rsa == null ? (DataChunk) Instance.getInstance().getChunkByPointer(this.getHeader().getFramePtr(), this.getHeader().getFramePtrRowId().getRowPointer()) : this;
491489
if (dc == null) {
492-
// todo during rframe.IndexFrame.init system directory not yet contains replicated FrameData objects
493-
logger.error("null datachunk found");
490+
logger.warn("null data record found during index entity construct");
491+
} else {
492+
dc.setIc(this);
494493
}
495-
dc.setIc(this);
496494
((IndexChunk)o).setFramePtrRowId(this.getHeader().getFramePtrRowId());
497495
((IndexChunk)o).setDataChunk(dc);
498496
}
@@ -546,7 +544,7 @@ public Object getEntity (Class c, Object[] params) {
546544
SystemEntity ca = (SystemEntity)c.getAnnotation(SystemEntity.class);
547545
try {
548546
if (ca!=null) { //System non-transactional
549-
Object o = null;
547+
Object o;
550548
if (params!=null) {
551549
final Class<?>[] cs = new Class<?>[params.length];
552550
for (int i=0; i<params.length; i++) {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2010-2020 head systems, ltd
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of
7+
this software and associated documentation files (the "Software"), to deal in
8+
the Software without restriction, including without limitation the rights to
9+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10+
the Software, and to permit persons to whom the Software is furnished to do so,
11+
subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
23+
*/
24+
25+
package su.interference.core;
26+
27+
import java.util.List;
28+
29+
/**
30+
* @author Yuriy Glotanov
31+
* @since 1.0
32+
*/
33+
34+
public class IndexContainer {
35+
private final List<IndexFrame> frameList;
36+
private int fptr;
37+
private int cptr;
38+
39+
public IndexContainer(List<IndexFrame> frameList) {
40+
this.frameList = frameList;
41+
fptr = 0;
42+
cptr = 0;
43+
}
44+
45+
public void reset() {
46+
fptr = 0;
47+
cptr = 0;
48+
}
49+
50+
public Chunk next() {
51+
if (frameList.size() == fptr) {
52+
return null;
53+
}
54+
cptr++;
55+
if (frameList.get(fptr).data.size() == cptr) {
56+
fptr++;
57+
cptr = 0;
58+
}
59+
if (frameList.size() == fptr) {
60+
return null;
61+
}
62+
return frameList.get(fptr).data.get(cptr);
63+
}
64+
65+
public Chunk get() {
66+
if (frameList.size() == 0 || frameList.size() == fptr) {
67+
return null;
68+
}
69+
if (frameList.get(fptr).data.size() == 0) {
70+
return null;
71+
}
72+
return frameList.get(fptr).data.get(cptr);
73+
}
74+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class IndexElementList {
4949

5050
public IndexElementList (int type) {
5151
this.type = type;
52-
elementList = new CopyOnWriteArrayList<IndexElement>();
52+
elementList = new CopyOnWriteArrayList<>();
5353
}
5454

5555
private void _add (IndexElement e) {
@@ -79,7 +79,7 @@ public synchronized IndexElementList add (IndexElement e) {
7979
this.lc = 0;
8080
} else {
8181
if (e.getKey().compareTo(this.maxValue)>0) {
82-
82+
throw new RuntimeException("internal error");
8383
} else {
8484
res.divided = true;
8585
this._add(e);

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

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ this software and associated documentation files (the "Software"), to deal in
2828
import su.interference.persistent.*;
2929
import su.interference.persistent.Process;
3030
import su.interference.exception.*;
31+
32+
import java.beans.Transient;
3133
import java.io.IOException;
3234
import java.io.File;
3335
import java.net.URL;
@@ -46,6 +48,9 @@ this software and associated documentation files (the "Software"), to deal in
4648

4749
public class Instance implements Interference {
4850

51+
public static final String RELEASE = "2020.2";
52+
public static final int SYSTEM_VERSION = 20201205;
53+
4954
public static final String DATA_FILE = "datafile";
5055
public static final String INDX_FILE = "indxfile";
5156
public static final String JRNL_FILE = "jrnlfile";
@@ -58,8 +63,6 @@ public class Instance implements Interference {
5863
private static final int MAX_NODE_ID = 32;
5964
public static final int SESSION_EXPIRE = 7200000; //in ms
6065

61-
public static final int SYSTEM_VERSION = 20201122;
62-
6366
public static final int SYSTEM_STATE_ONLINE = 1;
6467
public static final int SYSTEM_STATE_UP = 2;
6568
public static final int SYSTEM_STATE_FAIL = 3;
@@ -377,12 +380,13 @@ public void startupInstance(Session s) throws Exception, NoSuchMethodException,
377380
}
378381
TransportContext.getInstance().start();
379382
startProcesses(s);
383+
checkOpenTransactions(s);
380384
systemState = Instance.SYSTEM_STATE_UP;
381385
//checkInMemoryIndexes();
382386
logger.info("\n----------------------------------------------------------------------\n" +
383387
"------------------------ interference started ------------------------\n" +
384388
"------------------ (c) head systems, ltd 2010-2020 -------------------\n" +
385-
"--------------------------- release 2020.2 ---------------------------\n" +
389+
"--------------------------- release "+RELEASE+" ---------------------------\n" +
386390
"----------------------------------------------------------------------");
387391
} else {
388392

@@ -427,6 +431,18 @@ private void checkInMemoryIndexes() {
427431
}
428432
}
429433

434+
private void checkOpenTransactions(Session s) {
435+
for (Transaction t : getTransactions()) {
436+
if (t.getCid() == 0 && t.getTransType() != Transaction.TRAN_THR) {
437+
logger.info("Rollback incomplete transaction id="+t.getTransId());
438+
t.retrieveTframes();
439+
if (t.isLocal()) {
440+
t.rollback(s, false);
441+
}
442+
}
443+
}
444+
}
445+
430446
@SuppressWarnings("unchecked")
431447
private void startProcesses(Session s) throws Exception {
432448
final Table t = getTableByName("su.interference.persistent.Process");
@@ -614,8 +630,7 @@ public synchronized Session getSessionBySid (long sid) {
614630
}
615631

616632
public synchronized Transaction getTransactionById (long transId) {
617-
if (systemState!=SYSTEM_STATE_UP) { return null; }
618-
if (transId==0) { return null; }
633+
if (transId == 0) { return null; }
619634
Table t = getTableByName("su.interference.persistent.Transaction");
620635
DataChunk dc = ((DataChunk)t.getIndexFieldByColumn("transId").getIndex().getObjectByKey(transId));
621636
if (dc==null) {
@@ -698,6 +713,18 @@ public TransFrame getTransFrameById(long transId, long cframeId, long uframe) {
698713
return null;
699714
}
700715

716+
public List<TransFrame> getTransFramesByTransId(long transId) {
717+
List<TransFrame> res = new ArrayList<>();
718+
final Table t = getTableByName("su.interference.persistent.TransFrame");
719+
for (Map.Entry entry : ((Map<Object, Object>)t.getMapFieldByColumn("frameId").getMap()).entrySet()) {
720+
final TransFrame tf = (TransFrame) ((DataChunk) entry.getValue()).getEntity();
721+
if (tf.getTransId() == transId) {
722+
res.add(tf);
723+
}
724+
}
725+
return res;
726+
}
727+
701728
//used in unlock table mechanism
702729
@Deprecated
703730
public synchronized ArrayList<TransFrame> getTransFrameByObjectId (int objectId) {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,18 @@ public void createSystemDataFiles (Session s, LLT llt) throws Exception {
332332

333333
public void openDataFiles () throws Exception {
334334
for (Map.Entry e : ifs.entrySet()) {
335-
if (((DataFile)e.getValue()).checkFile()==1) {
335+
final int state = ((DataFile)e.getValue()).checkFile();
336+
if (state == DataFile.FILE_OK) {
337+
((DataFile)e.getValue()).openFile(Config.getConfig().DISKIO_MODE);
338+
}
339+
if (state == DataFile.FILE_VERSION_NOT_MATCH) {
340+
final int filesv = ((DataFile)e.getValue()).checkSystemVersion();
341+
logger.warn("\n----------------------------------------------------------------------\n" +
342+
"--- data files were created by a different version of the software ---\n" +
343+
"--- datafile version: "+filesv+" ---------------------------------------\n" +
344+
"--- software version: "+Instance.SYSTEM_VERSION+" ---------------------------------------\n" +
345+
"--- SERVICE MAY BE UNSTABLE ------------------------------------------\n" +
346+
"----------------------------------------------------------------------");
336347
((DataFile)e.getValue()).openFile(Config.getConfig().DISKIO_MODE);
337348
}
338349
}

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

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@ public class SystemCleanUp implements Runnable, ManagedProcess {
4141
private volatile boolean f = true;
4242
CountDownLatch latch;
4343
private final static Logger logger = LoggerFactory.getLogger(SystemCleanUp.class);
44-
private static final int CLEANUP_TIMEOUT = 3000;
4544
public static final int DATA_RETRIEVED_PRIORITY = 6;
4645
public static final int INDEX_RETRIEVED_PRIORITY = 9;
47-
private static final int CLEANUP_PROTECTION_THR = 1000;
48-
private static final int IX_CLEANUP_PROTECTION_THR = 5000;
4946

5047
public void run () {
5148
Thread.currentThread().setName("interference-cleanup-thread");
@@ -58,7 +55,7 @@ public void run () {
5855
}
5956

6057
try {
61-
Thread.sleep(CLEANUP_TIMEOUT);
58+
Thread.sleep(Config.getConfig().CLEANUP_TIMEOUT);
6259
} catch (InterruptedException e) {
6360
e.printStackTrace();
6461
}
@@ -74,7 +71,6 @@ public void stop() throws InterruptedException{
7471
}
7572

7673
private void cleanUpFrames() {
77-
7874
Metrics.get("systemCleanUp").start();
7975
int i = 0;
8076
int d = 0;
@@ -87,9 +83,9 @@ private void cleanUpFrames() {
8783
for (Object entry : Instance.getInstance().getFramesMap().entrySet()) {
8884
final FrameData f = (FrameData) ((DataChunk) ((Map.Entry) entry).getValue()).getEntity();
8985
final long frameAmount = f.getDataObject().getFrameAmount();
90-
if (f.getDataFile().isData()) {
86+
if (f.getDataFile().isData() && cleanupDataEnabled()) {
9187
f.decreasePriority();
92-
if (f.isSynced() && f.getObjectId() > 999 && f.getPriority() == 0 && frameAmount > CLEANUP_PROTECTION_THR) {
88+
if (f.isSynced() && f.getObjectId() > 999 && f.getPriority() == 0 && frameAmount > Config.getConfig().CLEANUP_PROTECTION_THR) {
9389
if (f.clearFrame()) {
9490
d++;
9591
}
@@ -98,9 +94,9 @@ private void cleanUpFrames() {
9894
d_++;
9995
}
10096
}
101-
if (f.getDataFile().isIndex()) {
97+
if (f.getDataFile().isIndex() && cleanupIndxEnabled()) {
10298
f.decreasePriority();
103-
if (f.isSynced() && f.getObjectId() > 999 && f.getPriority() == 0 && frameAmount > IX_CLEANUP_PROTECTION_THR) {
99+
if (f.getPriority() == 0 && frameAmount > Config.getConfig().IX_CLEANUP_PROTECTION_THR) {
104100
if (f.clearFrame()) {
105101
x++;
106102
}
@@ -109,8 +105,8 @@ private void cleanUpFrames() {
109105
x_++;
110106
}
111107
}
112-
if (f.getDataFile().isTemp()) {
113-
if (f.isSynced() && f.getObjectId() > 999 && frameAmount > CLEANUP_PROTECTION_THR) {
108+
if (f.getDataFile().isTemp() && cleanupTempEnabled()) {
109+
if (frameAmount > Config.getConfig().CLEANUP_PROTECTION_THR) {
114110
if (f.clearFrame()) {
115111
i++;
116112
}
@@ -119,8 +115,8 @@ private void cleanUpFrames() {
119115
i_++;
120116
}
121117
}
122-
if (f.getDataFile().isUndo()) {
123-
if (f.isSynced() && frameAmount > CLEANUP_PROTECTION_THR) {
118+
if (f.getDataFile().isUndo() && cleanupUndoEnabled()) {
119+
if (f.isSynced() && frameAmount > Config.getConfig().CLEANUP_PROTECTION_THR) {
124120
if (f.clearFrame()) {
125121
u++;
126122
}
@@ -148,4 +144,32 @@ public static void forceCleanUp() {
148144
}
149145
}
150146
}
147+
148+
private boolean cleanupDataEnabled() {
149+
final long maxmem = Runtime.getRuntime().maxMemory();
150+
final long alloc = Runtime.getRuntime().totalMemory();
151+
final long allocpc = alloc * 100 / maxmem;
152+
return allocpc > Config.getConfig().HEAP_USE_THR_DATA;
153+
}
154+
155+
private boolean cleanupIndxEnabled() {
156+
final long maxmem = Runtime.getRuntime().maxMemory();
157+
final long alloc = Runtime.getRuntime().totalMemory();
158+
final long allocpc = alloc * 100 / maxmem;
159+
return allocpc > Config.getConfig().HEAP_USE_THR_INDX;
160+
}
161+
162+
private boolean cleanupUndoEnabled() {
163+
final long maxmem = Runtime.getRuntime().maxMemory();
164+
final long alloc = Runtime.getRuntime().totalMemory();
165+
final long allocpc = alloc * 100 / maxmem;
166+
return allocpc > Config.getConfig().HEAP_USE_THR_UNDO;
167+
}
168+
169+
private boolean cleanupTempEnabled() {
170+
final long maxmem = Runtime.getRuntime().maxMemory();
171+
final long alloc = Runtime.getRuntime().totalMemory();
172+
final long allocpc = alloc * 100 / maxmem;
173+
return allocpc > Config.getConfig().HEAP_USE_THR_TEMP;
174+
}
151175
}

0 commit comments

Comments
 (0)