Skip to content

Commit 2f840a7

Browse files
async trans clean + improve common persist performance
1 parent 5161629 commit 2f840a7

28 files changed

Lines changed: 571 additions & 529 deletions

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,19 @@ 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;
110+
public final int CHECK_AVAIL_FRAME_TIMEOUT = 3000;
111111
// transport
112112
public final int REMOTE_SYNC_TIMEOUT = 60000;
113113
public final int READ_BUFFER_SIZE = 33554432;
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;
117118
public final int CLEANUP_TIMEOUT = 3000;
118119
public final int CLEANUP_PROTECTION_THR = 1000;
119-
public final int IX_CLEANUP_PROTECTION_THR = 5000;
120+
public final int IX_CLEANUP_PROTECTION_THR = 2000;
120121
public final int HEAP_USE_THR_DATA = 60;
121-
public final int HEAP_USE_THR_INDX = 80;
122+
public final int HEAP_USE_THR_INDX = 70;
122123
public final int HEAP_USE_THR_TEMP = 40;
123124
public final int HEAP_USE_THR_UNDO = 50;
124125

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

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class DataChunk implements Chunk {
6464
private Comparable id;
6565
private byte[] serializedId;
6666
private volatile Object entity;
67+
private volatile ValueSet dcs;
6768
private Object undoentity;
6869
private Map<Integer, DataChunk> ics = new HashMap<>();
6970
private UndoChunk uc;
@@ -73,10 +74,21 @@ public class DataChunk implements Chunk {
7374

7475
//returns datacolumn set
7576
public ValueSet getDcs() {
77+
if (t.isIndex() && dcs != null) {
78+
return dcs;
79+
}
7680
if (state == INIT_STATE) {
81+
if (t.isIndex()) {
82+
dcs = getDcsFromBytes();
83+
return dcs;
84+
}
7785
return getDcsFromBytes();
7886
}
7987
if (state == NORMAL_STATE) {
88+
if (t.isIndex()) {
89+
dcs = getDcsFromEntity();
90+
return dcs;
91+
}
8092
return getDcsFromEntity();
8193
}
8294
return null;
@@ -176,6 +188,7 @@ public Table getT() {
176188
return t;
177189
}
178190

191+
@Deprecated
179192
public Comparable getId (Field idfield, Session s) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
180193
if (serializedId==null) {
181194
if (entity==null) {
@@ -220,30 +233,19 @@ public byte[] getSerializedId (Session s) throws InvocationTargetException, NoSu
220233
if (entity==null) {
221234
getEntity();
222235
}
223-
Class c = entity.getClass();
224-
final TransEntity ta = (TransEntity)c.getAnnotation(TransEntity.class);
225-
final SystemEntity sa = (SystemEntity)c.getAnnotation(SystemEntity.class);
226-
if (ta!=null) {
227-
//for Transactional Wrapper Entity we must get superclass (original Entity class)
228-
c = c.getSuperclass();
229-
}
230-
Field[] f = c.getDeclaredFields();
231-
for (int i=0; i<f.length; i++) {
232-
final Id a = f[i].getAnnotation(Id.class);
233-
if (a!=null) {
234-
if (sa!=null) {
235-
Method z = c.getMethod("get"+f[i].getName().substring(0,1).toUpperCase()+f[i].getName().substring(1,f[i].getName().length()), null);
236-
Object v = z.invoke(entity, null);
237-
id = (Comparable) v;
238-
serializedId = sr.serialize(f[i].getType().getName(), v);
239-
} else {
240-
Method z = c.getMethod("get"+f[i].getName().substring(0,1).toUpperCase()+f[i].getName().substring(1,f[i].getName().length()), new Class<?>[]{Session.class});
241-
Object v = z.invoke(entity, new Object[]{s});
242-
id = (Comparable) v;
243-
serializedId = sr.serialize(f[i].getType().getName(), v);
244-
}
236+
final Field idf = t.getIdField();
237+
if (idf != null) {
238+
if (t.isNoTran()) {
239+
final Method z = t.getIdmethod();
240+
id = (Comparable) z.invoke(entity, null);
241+
serializedId = sr.serialize(idf.getType().getName(), id);
242+
} else {
243+
final Method z = t.getIdmethod_();
244+
id = (Comparable) z.invoke(entity, new Object[]{s});
245+
serializedId = sr.serialize(idf.getType().getName(), id);
245246
}
246247
}
248+
247249
}
248250
return serializedId;
249251
}
@@ -693,8 +695,8 @@ private synchronized DataChunk insertUC (UndoChunk uc, Session s, LLT llt) throw
693695
final int p = ub.getDataFrame().insertChunk(dc, s, true, llt);
694696
if (p == 0) {
695697
final Table t = Instance.getInstance().getTableByName(UndoChunk.class.getName());
696-
final FrameData nb = t.createNewFrame(ub, ub.getFile(), 0, 0, false, false, false, s, llt);
697-
s.getTransaction().setNewLB(ub, nb, false);
698+
final FrameData nb = t.createNewFrame(ub, ubw, ub.getFile(), 0, 0, false, false, false, s, llt);
699+
s.getTransaction().setNewLB(ub, nb);
698700
nb.getDataFrame().insertChunk(dc, s, true, llt);
699701
dc.uframe = nb;
700702
} else {

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

Lines changed: 13 additions & 29 deletions
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
@@ -26,10 +26,9 @@ this software and associated documentation files (the "Software"), to deal in
2626

2727
import su.interference.persistent.Session;
2828
import su.interference.exception.InternalException;
29+
import su.interference.persistent.Table;
2930
import su.interference.serialize.CustomSerializer;
3031

31-
import javax.persistence.Entity;
32-
import javax.persistence.Id;
3332
import java.io.IOException;
3433
import java.io.UnsupportedEncodingException;
3534
import java.lang.reflect.Field;
@@ -63,32 +62,17 @@ private byte[] getBytes(Field f, Object o) throws IllegalAccessException, Unsupp
6362

6463
//serializer
6564
@SuppressWarnings("unchecked")
66-
public DataChunkId (Object o, Session s) throws IOException, InvocationTargetException, NoSuchMethodException, InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException {
67-
Class c = o.getClass();
68-
final SystemEntity sa = (SystemEntity)c.getAnnotation(SystemEntity.class);
69-
final TransEntity ta = (TransEntity)c.getAnnotation(TransEntity.class);
70-
Entity ea = (Entity)c.getAnnotation(Entity.class);
71-
if (ta!=null) {
72-
//for Transactional Wrapper Entity we must get superclass (original Entity class)
73-
c = c.getSuperclass();
74-
ea = (Entity)c.getAnnotation(Entity.class);
75-
}
76-
if (ea==null) {
77-
throw new InternalException();
78-
}
79-
final Field[] f = c.getDeclaredFields();
80-
for (int i=0; i<f.length; i++) {
81-
final Id a = f[i].getAnnotation(Id.class);
82-
if (a!=null) {
83-
if (sa!=null) {
84-
final Method z = c.getMethod("get"+f[i].getName().substring(0,1).toUpperCase()+f[i].getName().substring(1,f[i].getName().length()), null);
85-
id = z.invoke(o, null);
86-
idb = sr.serialize(f[i].getType().getName(), id);
87-
} else {
88-
final Method z = c.getMethod("get"+f[i].getName().substring(0,1).toUpperCase()+f[i].getName().substring(1,f[i].getName().length()), new Class<?>[]{Session.class});
89-
id = z.invoke(o, new Object[]{s});
90-
idb = sr.serialize(f[i].getType().getName(), id);
91-
}
65+
public DataChunkId (Object o, Table t, Session s) throws IOException, InvocationTargetException, InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException {
66+
final Field idf = t.getIdField();
67+
if (idf != null) {
68+
if (t.isNoTran()) {
69+
final Method z = t.getIdmethod();
70+
id = z.invoke(o, null);
71+
idb = sr.serialize(idf.getType().getName(), id);
72+
} else {
73+
final Method z = t.getIdmethod_();
74+
id = z.invoke(o, new Object[]{s});
75+
idb = sr.serialize(idf.getType().getName(), id);
9276
}
9377
}
9478
}

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

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,14 @@ public void cleanICEntities() {
136136
}
137137
}
138138

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

142142
final int nfileId = t.getIndexFileId(this.getFrameData());
143-
final IndexFrame res = t.createNewFrame(this.getFrameData(), nfileId, this.getType(), 0, false, false, false, s, llt).getIndexFrame();
143+
final IndexFrame res = t.createNewFrame(this.getFrameData(), null, nfileId, this.getType(), 0, false, false, false, s, llt).getIndexFrame();
144+
//paranoid fix
145+
llt.add(res);
146+
llt.add(this);
144147
res.setParentF(this.getParentF());
145148
res.setParentB(this.getParentB());
146149
final ValueSet max = this.sort();
@@ -159,19 +162,18 @@ public IndexFrame add (DataChunk e, Table t, Session s, LLT llt) throws Exceptio
159162
}
160163
this.setHasMV(1);
161164
}
162-
res.setLcF(this.getLcF());
163-
res.setLcB(this.getLcB());
164-
this.setLcF(0);
165-
this.setLcB(0);
165+
res.setLcId(this.getLcId());
166+
this.setLcId(0);
166167
} else {
167-
final int cmv = e.getDcs().compareTo(this.getFrameData().getMv());
168+
//final int cmv = e.getDcs().compareTo(this.getFrameData().getMv());
169+
final int cmv = e.getDcs().compareTo(max);
168170
if (cmv > 0) {
169171
throw new InternalException();
170172
} else {
171173
res.setDivided(1);
172174
this.insertChunk(e, s, false, llt);
173175
final ValueSet max2 = this.sort();
174-
final ArrayList<DataChunk> nlist = new ArrayList<DataChunk>();
176+
final ArrayList<DataChunk> nlist = new ArrayList<>();
175177
ValueSet pkey = null;
176178
boolean keyrpt = false;
177179
boolean norpt = false;
@@ -222,7 +224,7 @@ private boolean isFill(DataChunk ie) {
222224
return ie.getBytesAmount() > this.getFrameFree();
223225
}
224226

225-
public ValueSet sort() throws InternalException {
227+
public synchronized ValueSet sort() throws InternalException {
226228
if (!this.data.isSorted()) {
227229
this.data.sort();
228230
}
@@ -236,7 +238,7 @@ public ValueSet sort() throws InternalException {
236238

237239
//accepted only to node element lists
238240
//for unique indexes
239-
public DataChunk getChildElementPtr(ValueSet value) throws InternalException {
241+
public synchronized DataChunk getChildElementPtr(ValueSet value) throws InternalException {
240242
//todo if (!this.sorted) {
241243
this.sort();
242244
//}
@@ -348,7 +350,7 @@ public synchronized int removeObjects(ValueSet key, Object o) throws InternalExc
348350
return len;
349351
}
350352

351-
public ValueSet getMaxValue() throws InternalException {
353+
public synchronized ValueSet getMaxValue() throws InternalException {
352354
this.sort();
353355
return ((DataChunk)this.data.get(this.data.size()-1)).getDcs();
354356
}
@@ -364,59 +366,52 @@ public HashMap<Long, Long> getAllocateMap() {
364366
return imap;
365367
}
366368

367-
public int getType() {
369+
public synchronized int getType() {
368370
return this.getRes01();
369371
}
370372

371-
public void setType(int type) {
373+
public synchronized void setType(int type) {
372374
this.setRes01(type);
373375
}
374376

375-
public int getHasMV() {
377+
public synchronized int getHasMV() {
376378
return this.getRes02();
377379
}
378380

379-
public void setHasMV(int hasMV) {
381+
public synchronized void setHasMV(int hasMV) {
380382
this.setRes02(hasMV);
381383
}
382384

383-
public int getDivided() {
385+
public synchronized int getDivided() {
384386
return this.getRes03();
385387
}
386388

387-
public void setDivided(int divided) {
389+
public synchronized void setDivided(int divided) {
388390
this.setRes03(divided);
389391
}
390392

391-
public int getParentF() {
393+
public synchronized int getParentF() {
392394
return this.getRes04();
393395
}
394396

395-
public void setParentF(int parentF) {
397+
public synchronized void setParentF(int parentF) {
396398
this.setRes04(parentF);
397399
}
398400

399-
public long getParentB() {
401+
public synchronized long getParentB() {
400402
return this.getRes06();
401403
}
402404

403-
public void setParentB(long parentB) {
405+
public synchronized void setParentB(long parentB) {
404406
this.setRes06(parentB);
405407
}
406408

407-
public int getLcF() {
408-
return this.getRes05();
409+
public synchronized long getLcId() {
410+
return this.getRes05() + this.getRes07();
409411
}
410412

411-
public void setLcF(int lcF) {
412-
this.setRes05(lcF);
413-
}
414-
415-
public long getLcB() {
416-
return this.getRes07();
417-
}
418-
419-
public void setLcB(long lcB) {
420-
this.setRes07(lcB);
413+
public synchronized void setLcId(long lcId) {
414+
this.setRes05((int)lcId%4096);
415+
this.setRes07(lcId - lcId%4096);
421416
}
422417
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ this software and associated documentation files (the "Software"), to deal in
2929
import su.interference.persistent.Process;
3030
import su.interference.exception.*;
3131

32-
import java.beans.Transient;
3332
import java.io.IOException;
3433
import java.io.File;
3534
import java.net.URL;
@@ -48,8 +47,8 @@ this software and associated documentation files (the "Software"), to deal in
4847

4948
public class Instance implements Interference {
5049

51-
public static final String RELEASE = "2020.2";
52-
public static final int SYSTEM_VERSION = 20201205;
50+
public static final String RELEASE = "2020.3";
51+
public static final int SYSTEM_VERSION = 20201220;
5352

5453
public static final String DATA_FILE = "datafile";
5554
public static final String INDX_FILE = "indxfile";
@@ -364,7 +363,7 @@ public void startupInstance(Session s) throws Exception, NoSuchMethodException,
364363
if (ok) {
365364

366365
logger.info("interference is starting...");
367-
Thread.currentThread().setName("interference-main-thread");
366+
Thread.currentThread().setName("interference-main-thread-"+Thread.currentThread().getId());
368367
Storage.getStorage().restoreJournal();
369368
Storage.getStorage().openDataFiles();
370369
initSystemTable();
@@ -433,7 +432,7 @@ private void checkInMemoryIndexes() {
433432

434433
private void checkOpenTransactions(Session s) {
435434
for (Transaction t : getTransactions()) {
436-
if (t.getCid() == 0 && t.getTransType() != Transaction.TRAN_THR) {
435+
if (t.getCid() == 0 && t.getTransType() < Transaction.TRAN_THR) {
437436
logger.info("Rollback incomplete transaction id="+t.getTransId());
438437
t.retrieveTframes();
439438
if (t.isLocal()) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static long getSyncId() {
6464
return sync.get();
6565
}
6666

67-
public static LLT getLLT() throws InterruptedException {
67+
public static LLT getLLT() {
6868
final long id_ = Thread.currentThread().getId();
6969
if (pool.get(id_) != null) {
7070
if (debug) {
@@ -82,7 +82,7 @@ public static LLT getLLT() throws InterruptedException {
8282
return llt;
8383
}
8484

85-
public static LLT getLLTAndLock() throws InterruptedException {
85+
public static LLT getLLTAndLock() {
8686
final long id_ = Thread.currentThread().getId();
8787
if (pool.get(id_) != null) {
8888
logger.error("an unexpected attempt to get llt with id = "+id_+" which already exists");

0 commit comments

Comments
 (0)