Skip to content

Commit c09a4de

Browse files
improve overall performance & stability
1 parent 9a96ae6 commit c09a4de

21 files changed

Lines changed: 514 additions & 241 deletions

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

Lines changed: 30 additions & 2 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
@@ -509,6 +509,34 @@ public Object getEntity () {
509509
return entity;
510510
}
511511

512+
public Object getStandaloneEntity() {
513+
try {
514+
final ValueSet dcs = getDcs();
515+
final Object o = t.getInstance(); //returns empty instance
516+
final Field[] cs = t.getFields();
517+
for (int i=0; i<cs.length; i++) {
518+
final int m = cs[i].getModifiers();
519+
if (Modifier.isPrivate(m)) {
520+
cs[i].setAccessible(true);
521+
}
522+
if (dcs.getValueSet()[i]!=null) {
523+
cs[i].set(o, dcs.getValueSet()[i]);
524+
}
525+
}
526+
if (!t.isNoTran()) {
527+
((EntityContainer) o).setRowId(header.getRowID());
528+
((EntityContainer) o).setTran(header.getTran());
529+
if (!t.isIndex()) {
530+
((EntityContainer) o).setDataChunk(this);
531+
}
532+
}
533+
return o;
534+
} catch (Exception e) {
535+
e.printStackTrace();
536+
}
537+
return null;
538+
}
539+
512540
//for bootstrap system / not use table objects
513541
public Object getEntity (Class c, Object[] params) {
514542
SystemEntity ca = (SystemEntity)c.getAnnotation(SystemEntity.class);
@@ -622,7 +650,7 @@ public DataChunk cloneEntity(Session s) throws InternalException {
622650
}
623651

624652
public DataChunk restore(UndoChunk uc) throws Exception {
625-
// second, since we are using a dirty hack with changing the header in a source chunk for rollback his,
653+
// since we are using a dirty hack with changing the header in a source chunk for rollback his,
626654
// we need to first delete the source chunk in the target block to prevent inconsistency within ChunkMap / chunk headers
627655
if (!(this.getHeader().getRowID().getFileId() == uc.getFile() && this.getHeader().getRowID().getFramePointer() == uc.getFrame())) {
628656
final long srcFrameId = uc.getFile() + uc.getFrame();

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

Lines changed: 2 additions & 4 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
@@ -492,9 +492,6 @@ public synchronized boolean checkChunk(int ptr) {
492492
}
493493

494494
public synchronized void removeChunk (int ptr, LLT llt, boolean ignore) {
495-
if (!this.isLocal()) {
496-
throw new CannotAccessToForeignRecord();
497-
}
498495
final long sync = LLT.getSyncId();
499496
final Chunk chunk = data.getByPtr(ptr);
500497
if (chunk == null) {
@@ -577,6 +574,7 @@ public synchronized void rollbackTransaction(Transaction tran, ArrayList<FrameDa
577574
for (Chunk c : data.getChunks()) {
578575
if (c.getHeader().getTran().getTransId() == tran.getTransId()) {
579576
((DataChunk) c).setUndoChunk(null);
577+
// todo ((DataChunk) c).cleanUpIcs();
580578
r.add(c.getHeader().getPtr());
581579
}
582580
}

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

Lines changed: 2 additions & 2 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
@@ -192,7 +192,7 @@ public synchronized Object getObjectByKey(final IndexElementKey key) {
192192

193193
//return all element which found - for non-unique indexes
194194
public synchronized List<Object> getObjectsByKey(final IndexElementKey key) {
195-
final ArrayList<Object> r = new ArrayList<Object>();
195+
final ArrayList<Object> r = new ArrayList<>();
196196
for (IndexElement ie : this.elementList) {
197197
if (ie.getKey().equals(key)) {
198198
r.add(ie.getElement());

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

Lines changed: 4 additions & 16 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
@@ -44,9 +44,6 @@ public class IndexFrame extends Frame {
4444
public static final int INDEX_FRAME_LEAF = 1;
4545
public static final int INITIALIZE_DURING_CONSTRUCT = 1;
4646

47-
//non-persistent value (must set if hasMv=1)
48-
private ValueSet mv;
49-
5047
public IndexFrame(int file, long pointer, int size, int objectId, Table t) throws InternalException {
5148
super(file, pointer, size, t);
5249
}
@@ -158,7 +155,7 @@ public IndexFrame add (DataChunk e, Table t, Session s, LLT llt) throws Exceptio
158155
this.setLcF(0);
159156
this.setLcB(0);
160157
} else {
161-
final int cmv = e.getDcs().compareTo(this.mv);
158+
final int cmv = e.getDcs().compareTo(this.getFrameData().getMv());
162159
if (cmv > 0) {
163160
throw new InternalException();
164161
} else {
@@ -277,7 +274,7 @@ public DataChunk getObjectByKey(ValueSet key, Session s) {
277274
if (dc.getUndoChunk() != null && dc.getHeader().getTran().getCid() == 0) { //updated chunk in live transaction
278275
return dc;
279276
} else {
280-
if (dc.getHeader().getTran() == null) {
277+
if (dc.getHeader().getTran() == null || s.isStream()) {
281278
return dc;
282279
} else {
283280
if ((tr == dc.getHeader().getTran().getTransId()) || (dc.getHeader().getTran().getCid() > 0 && dc.getHeader().getTran().getCid() <= mtran)) {
@@ -308,7 +305,7 @@ public synchronized List<DataChunk> getObjectsByKey(ValueSet key, Session s) thr
308305
if (((DataChunk) ie).getUndoChunk() != null && ((DataChunk) ie).getHeader().getTran().getCid() == 0) { //updated chunk in live transaction
309306
r.add((DataChunk) ie);
310307
} else {
311-
if (((DataChunk) ie).getHeader().getTran() == null) {
308+
if (((DataChunk) ie).getHeader().getTran() == null || s.isStream()) {
312309
r.add((DataChunk) ie);
313310
} else {
314311
if ((tr == ((DataChunk) ie).getHeader().getTran().getTransId()) || (((DataChunk) ie).getHeader().getTran().getCid() > 0 && ((DataChunk) ie).getHeader().getTran().getCid() <= mtran)) {
@@ -416,13 +413,4 @@ public long getLcB() {
416413
public void setLcB(long lcB) {
417414
this.setRes07(lcB);
418415
}
419-
420-
public ValueSet getMv() {
421-
return mv;
422-
}
423-
424-
public void setMv(ValueSet mv) {
425-
this.mv = mv;
426-
}
427-
428416
}

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

Lines changed: 55 additions & 15 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
@@ -119,28 +119,42 @@ public synchronized void remove (IndexElementKey key, Object o) {
119119
removeObjects(key, o);
120120
}
121121

122-
public synchronized List<Object> getObjectsByKey (final IndexElementKey key) {
122+
public synchronized List<Object> getObjectsByKey (final IndexElementKey key, final int amount) {
123123
final ArrayList<Object> r = new ArrayList<Object>();
124124
boolean cnue = true;
125125
ArrayList<IndexElementList> targets = new ArrayList<IndexElementList>();
126126
IndexElementList el = list.get(start);
127127
//el.sort();
128128
targets.add(el);
129+
int amount_ = 0;
129130
while (cnue) {
130131
final ArrayList<IndexElementList> ntargets = new ArrayList<IndexElementList>();
131132
for (IndexElementList target : targets) {
132133
//target.sort();
133-
if (target.getType()==1) { //leaf
134-
r.addAll(target.getObjectsByKey(key));
134+
if (target.getType() == 1) { //leaf
135+
if (amount == 0) {
136+
final List<Object> list = target.getObjectsByKey(key);
137+
r.addAll(list);
138+
} else {
139+
if (amount - amount_ > 0) {
140+
final List<Object> list = target.getObjectsByKey(key);
141+
for (Object o : list) {
142+
if (amount - amount_ > 0) {
143+
r.add(o);
144+
}
145+
amount_++;
146+
}
147+
}
148+
}
135149
cnue = false;
136150
} else {
137151
final ArrayList<Integer> cptr = target.getChildElementsPtr(key);
138-
if (cptr.size()>0) {
152+
if (cptr.size() > 0) {
139153
for (Integer i : cptr) {
140154
ntargets.add(list.get(i));
141155
}
142156
}
143-
if (target.getLc()>0) {
157+
if (target.getLc() > 0) {
144158
ntargets.add(list.get(target.getLc())); //get by last child
145159
}
146160
}
@@ -151,24 +165,38 @@ public synchronized List<Object> getObjectsByKey (final IndexElementKey key) {
151165
}
152166

153167
public synchronized List<Object> getContent() {
154-
ArrayList<Object> res = new ArrayList<Object>();
155-
ArrayList<IndexElementList> levelNodes = new ArrayList<IndexElementList>();
168+
return getContent(0);
169+
}
170+
171+
public synchronized List<Object> getContent(int amount) {
172+
ArrayList<Object> res = new ArrayList<>();
173+
ArrayList<IndexElementList> levelNodes = new ArrayList<>();
156174
boolean cnue = true;
157175
IndexElementList el = list.get(start);
158176
el.sort();
159177
levelNodes.add(el);
178+
int amount_ = 0;
160179
while (cnue) {
161-
ArrayList<IndexElementList> inNodes = new ArrayList<IndexElementList>();
180+
ArrayList<IndexElementList> inNodes = new ArrayList<>();
162181
int lc = 0;
163182
for (int k=0; k<levelNodes.size(); k++) {
164183
levelNodes.get(k).sort();
165-
if (levelNodes.get(k).getType()==1) {
166-
cnue = false;
167-
for (IndexElement ie : levelNodes.get(k).getElementList()) {
168-
if (levelNodes.get(k).getType()==1) {
184+
if (levelNodes.get(k).getType() == 1) {
185+
if (amount == 0) {
186+
for (IndexElement ie : levelNodes.get(k).getElementList()) {
169187
res.add(ie.getElement());
170188
}
189+
} else {
190+
if (amount - amount_ > 0) {
191+
for (IndexElement ie : levelNodes.get(k).getElementList()) {
192+
if (amount - amount_ > 0) {
193+
res.add(ie.getElement());
194+
}
195+
amount_++;
196+
}
197+
}
171198
}
199+
cnue = false;
172200
} else {
173201
for (int i=0; i<levelNodes.get(k).getElementList().size(); i++) {
174202
inNodes.add(this.list.get((Integer)levelNodes.get(k).getElementList().get(i).getElement()));
@@ -302,11 +330,23 @@ public synchronized Object getObjectByKey (final IndexElementKey key) {
302330

303331

304332
public synchronized List<Object> getObjectsByKey (final int obj) {
305-
return getObjectsByKey (new IndexElementKey(new Integer[]{obj}));
333+
return getObjectsByKey (new IndexElementKey(new Integer[]{obj}), 0);
306334
}
307335

308336
public synchronized List<Object> getObjectsByKey (final long obj) {
309-
return getObjectsByKey (new IndexElementKey(new Long[]{obj}));
337+
return getObjectsByKey (new IndexElementKey(new Long[]{obj}), 0);
338+
}
339+
340+
public synchronized List<Object> getObjectsByKey (final String obj) {
341+
return getObjectsByKey (new IndexElementKey(new String[]{obj}), 0);
342+
}
343+
344+
public synchronized List<Object> getObjectsByKey (final int obj, final int amount) {
345+
return getObjectsByKey (new IndexElementKey(new Integer[]{obj}), amount);
346+
}
347+
348+
public synchronized List<Object> getObjectsByKey (final long obj, final int amount) {
349+
return getObjectsByKey (new IndexElementKey(new Long[]{obj}), amount);
310350
}
311351

312352
//for non-unique indexes

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

Lines changed: 27 additions & 5 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
@@ -635,18 +635,40 @@ public FreeFrame getFreeFrameById (long id) {
635635
return (FreeFrame)dc.getEntity();
636636
}
637637

638-
public ArrayList<FrameSync> getSyncFrames(int nodeId) {
638+
@Deprecated
639+
public ArrayList<FrameSync> getSyncFrames(int nodeId, int amount, boolean bulk) {
640+
final Table t = getTableByName("su.interference.persistent.FrameSync");
641+
final ArrayList<FrameSync> r = new ArrayList<>();
642+
for (Object o : t.getIndexFieldByColumn("nodeId").getIndex().getObjectsByKey(nodeId, amount)) {
643+
r.add((FrameSync)((DataChunk)o).getEntity());
644+
}
645+
return r;
646+
}
647+
648+
public ArrayList<FrameSync> getSyncFrames(int nodeId, int amount) {
649+
final Table t = getTableByName("su.interference.persistent.FrameSync");
650+
final ArrayList<FrameSync> r = new ArrayList<>();
651+
for (Object o : t.getIndexFieldByColumn("syncId").getIndex().getContent(amount)) {
652+
final FrameSync fs = (FrameSync)((DataChunk)o).getEntity();
653+
if (fs.getNodeId() == nodeId) {
654+
r.add(fs);
655+
}
656+
}
657+
return r;
658+
}
659+
660+
public ArrayList<FrameSync> getSyncFramesByUUID(String UUID) {
639661
final Table t = getTableByName("su.interference.persistent.FrameSync");
640-
final ArrayList<FrameSync> r = new ArrayList<FrameSync>();
641-
for (Object o : t.getIndexFieldByColumn("nodeId").getIndex().getObjectsByKey(nodeId)) {
662+
final ArrayList<FrameSync> r = new ArrayList<>();
663+
for (Object o : t.getIndexFieldByColumn("syncUUID").getIndex().getObjectsByKey(UUID)) {
642664
r.add((FrameSync)((DataChunk)o).getEntity());
643665
}
644666
return r;
645667
}
646668

647669
public ArrayList<FrameSync> getSyncFramesById(long frameId) {
648670
final Table t = getTableByName("su.interference.persistent.FrameSync");
649-
final ArrayList<FrameSync> r = new ArrayList<FrameSync>();
671+
final ArrayList<FrameSync> r = new ArrayList<>();
650672
for (Object o : t.getIndexFieldByColumn("frameId").getIndex().getObjectsByKey(frameId)) {
651673
r.add((FrameSync)((DataChunk)o).getEntity());
652674
}

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

Lines changed: 11 additions & 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
@@ -53,6 +53,7 @@ public class SyncFrame implements Comparable, Serializable, AllowRPredicate {
5353
private final long parentId;
5454
private final long lcId;
5555
private final boolean allowR;
56+
private final boolean proc;
5657
private final boolean started;
5758
private final Map<Long, Long> imap;
5859
private final Map<Long, Transaction> rtran;
@@ -63,9 +64,14 @@ public class SyncFrame implements Comparable, Serializable, AllowRPredicate {
6364
private transient Frame rFrame;
6465

6566
public SyncFrame(Frame frame, Session s, FreeFrame fb) throws Exception {
67+
this(frame, s, fb, true);
68+
}
69+
70+
public SyncFrame(Frame frame, Session s, FreeFrame fb, boolean proc) throws Exception {
6671
final Table t = Instance.getInstance().getTableById(frame.getObjectId());
6772
final FrameData bd = Instance.getInstance().getFrameById(frame.getPtr());
6873
allowR = frame.isLocal() ? !t.isNoTran() || t.getName().equals("su.interference.persistent.UndoChunk") : false;
74+
this.proc = proc;
6975

7076
if (bd == null && allowR) {
7177
final FreeFrame fframe = Instance.getInstance().getFreeFrameById(frame.getPtr());
@@ -200,6 +206,10 @@ public boolean isAllowR() {
200206
return allowR;
201207
}
202208

209+
public boolean isProc() {
210+
return proc;
211+
}
212+
203213
public boolean isStarted() {
204214
return started;
205215
}

0 commit comments

Comments
 (0)