Skip to content

Commit 68840ad

Browse files
RELEASE 2021.1 hotfix patch 19.08
1 parent 8288720 commit 68840ad

39 files changed

Lines changed: 827 additions & 477 deletions

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ this software and associated documentation files (the "Software"), to deal in
3535
*/
3636

3737
public class GenericObject implements Serializable, GenericResult {
38-
private final Map<String, Object> vmap;
38+
private final static long serialVersionUID = 4330809121118587364L;
39+
private final Map<String, Object> vmap;
3940

40-
protected GenericObject(Map<String, Object> vmap) {
41+
protected GenericObject(Map<String, Object> vmap) {
4142
this.vmap = vmap;
4243
}
4344

44-
public Object getValueByName(String name) {
45+
public Object getValueByName(String name) {
4546
return vmap.get(name);
4647
}
4748
}

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ this software and associated documentation files (the "Software"), to deal in
2424

2525
package su.interference.core;
2626

27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2729
import su.interference.exception.*;
2830
import su.interference.persistent.*;
2931
import su.interference.serialize.ByteString;
@@ -36,22 +38,32 @@ this software and associated documentation files (the "Software"), to deal in
3638
*/
3739

3840
public class IndexFrame extends Frame {
41+
private final static Logger logger = LoggerFactory.getLogger(IndexFrame.class);
3942
private boolean sorted = false;
43+
private final boolean terminate;
4044
public static final int INDEX_FRAME_NODE = 2;
4145
public static final int INDEX_FRAME_LEAF = 1;
4246
public static final int INITIALIZE_DURING_CONSTRUCT = 1;
4347

4448
public IndexFrame(int file, long pointer, int size, int objectId, Table t) throws InternalException {
4549
super(file, pointer, size, t);
50+
this.terminate = false;
4651
}
4752

4853
public IndexFrame(FrameData bd, int frameType, Table t) throws InternalException {
4954
super(bd, t);
5055
this.setType(frameType);
56+
this.terminate = false;
57+
}
58+
59+
public IndexFrame() {
60+
super(0, 0, 0, null);
61+
this.terminate = true;
5162
}
5263

5364
public IndexFrame(int file, long pointer, int size, FrameData bd, Table t, Class c, List<FrameData> uframes) throws Exception {
5465
super(null, file, pointer, size, bd, t, c);
66+
this.terminate = false;
5567

5668
Map<Integer, UndoChunk> ucs = new HashMap<>();
5769
for (FrameData uframe : uframes) {
@@ -97,6 +109,7 @@ public IndexFrame(int file, long pointer, int size, FrameData bd, Table t, Class
97109
public IndexFrame(byte[] b, int file, long pointer, Map<Long, Long> imap, Map<Long, Long> hmap, Table t) {
98110
super(b, file, pointer, t);
99111
int ptr = FRAME_HEADER_SIZE;
112+
this.terminate = false;
100113

101114
final ByteString bs = new ByteString(this.b);
102115
while (ptr<this.b.length) {
@@ -107,8 +120,9 @@ public IndexFrame(byte[] b, int file, long pointer, Map<Long, Long> imap, Map<Lo
107120
if (h.getFramePtr() > 0) { //IOT does not contains frameptr
108121
final long allocId = imap.get(h.getFramePtr());
109122
final long bptr = hmap.get(allocId) != null ? hmap.get(allocId) : Instance.getInstance().getFrameByAllocId(allocId).getFrameId();
110-
h.getFramePtrRowId().setFileId((int) bptr % 4096);
111-
h.getFramePtrRowId().setFramePointer(bptr - (bptr % 4096));
123+
final long fbptr = bptr%4096;
124+
h.getFramePtrRowId().setFileId((int) fbptr);
125+
h.getFramePtrRowId().setFramePointer(bptr - fbptr);
112126
}
113127
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());
114128
dc.setHeader(h);
@@ -402,11 +416,16 @@ public synchronized ValueSet getMaxValue() throws InternalException {
402416
}
403417

404418
public HashMap<Long, Long> getAllocateMap() {
405-
final HashMap<Long, Long> imap = new HashMap<Long, Long>();
419+
final HashMap<Long, Long> imap = new HashMap<>();
406420
for (Chunk c : data.getChunks()) {
407421
if (c.getHeader().getFramePtr() > 0) { //IOT does not contains frameptr
408-
final long allocId = Instance.getInstance().getFrameById(c.getHeader().getFramePtr()).getAllocId();
409-
imap.put(c.getHeader().getFramePtr(), allocId);
422+
final FrameData bd = Instance.getInstance().getFrameById(c.getHeader().getFramePtr());
423+
if (bd != null) {
424+
final long allocId = bd.getAllocId();
425+
imap.put(c.getHeader().getFramePtr(), allocId);
426+
} else {
427+
logger.error("getAllocaleMap found null data frame for frame id " + c.getHeader().getFramePtr());
428+
}
410429
}
411430
}
412431
return imap;
@@ -461,4 +480,8 @@ public synchronized void setLcId(long lcId) {
461480
this.setRes05((int)lcF);
462481
this.setRes07(lcId - lcF);
463482
}
483+
484+
public boolean isTerminate() {
485+
return terminate;
486+
}
464487
}

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public void rollback (Session s) {
135135

136136
public static boolean initParams (String[] params) {
137137
final Config cfg = Config.getConfig();
138+
138139
/*
139140
try {
140141
new HTTPServer(cfg.MMPORT);
@@ -145,6 +146,7 @@ public static boolean initParams (String[] params) {
145146
return false;
146147
}
147148
*/
149+
148150
return true;
149151
}
150152

@@ -625,7 +627,7 @@ public DataFile getDataFileById (int id) {
625627

626628
public ArrayList<DataFile> getDataFilesByType (int id) {
627629
final Table t = getTableByName("su.interference.persistent.DataFile");
628-
final ArrayList<DataFile> r = new ArrayList<DataFile>();
630+
final ArrayList<DataFile> r = new ArrayList<>();
629631
for (Object o : t.getIndexFieldByColumn("type").getIndex().getObjectsByKey(id)) {
630632
r.add((DataFile)((DataChunk)o).getEntity());
631633
}
@@ -649,13 +651,22 @@ public synchronized Session getSessionBySid (long sid) {
649651
public synchronized Transaction getTransactionById (long transId) {
650652
if (transId == 0) { return null; }
651653
Table t = getTableByName("su.interference.persistent.Transaction");
652-
DataChunk dc = ((DataChunk)t.getIndexFieldByColumn("transId").getIndex().getObjectByKey(transId));
654+
DataChunk dc = ((DataChunk)t.getMapFieldByColumn("transId").getMap().get(transId));
653655
if (dc==null) {
654656
return null;
655657
}
656658
return (Transaction)dc.getEntity();
657659
}
658660

661+
public List<Transaction> getTransactionsBySid (long id) {
662+
final Table t = getTableByName("su.interference.persistent.Transaction");
663+
final ArrayList<Transaction> r = new ArrayList<>();
664+
for (Object o : t.getIndexFieldByColumn("sid").getIndex().getObjectsByKey(id)) {
665+
r.add((Transaction)((DataChunk)o).getEntity());
666+
}
667+
return r;
668+
}
669+
659670
public FreeFrame getFreeFrameById (long id) {
660671
final Table t = getTableByName("su.interference.persistent.FreeFrame");
661672
final DataChunk dc = (DataChunk)t.getIndexFieldByColumn("frameId").getIndex().getObjectByKey(id);
@@ -722,6 +733,17 @@ public List<TransFrame> getTransFramesByTransId(long transId) {
722733
return res;
723734
}
724735

736+
public String getEventSubscriberByEntityId (String id) {
737+
final Table t = getTableByName("su.interference.persistent.EventSubscriber");
738+
final MapField ixf = t.getMapFieldByColumn("entityId");
739+
final Map ixl = ixf.getMap();
740+
final DataChunk dc = (DataChunk)ixl.get(id);
741+
if (dc != null) {
742+
return ((EventSubscriber) dc.getEntity()).getSubscriberId();
743+
}
744+
return null;
745+
}
746+
725747
//used in unlock table mechanism
726748
@Deprecated
727749
public synchronized ArrayList<TransFrame> getTransFrameByObjectId (int objectId) {
@@ -752,7 +774,7 @@ public RetrieveLock getRetrieveLockById(int obj, long tran) {
752774
}
753775

754776
public ArrayList<RetrieveLock> getRetrieveLocksByObjectId(int obj) {
755-
final ArrayList<RetrieveLock> r = new ArrayList<RetrieveLock>();
777+
final ArrayList<RetrieveLock> r = new ArrayList<>();
756778
final Table t = getTableByName("su.interference.persistent.RetrieveLock");
757779
for (Object o : t.getIndexFieldByColumn("objectId").getIndex().getObjectsByKey(obj)) {
758780
final RetrieveLock rl = (RetrieveLock)((DataChunk)o).getEntity();
@@ -763,9 +785,9 @@ public ArrayList<RetrieveLock> getRetrieveLocksByObjectId(int obj) {
763785

764786
public synchronized List<Transaction> getTransactions() {
765787
final Table t = getTableByName("su.interference.persistent.Transaction");
766-
final ArrayList<Transaction> res = new ArrayList<Transaction>();
767-
for (Object o : t.getIndexFieldByColumn("transId").getIndex().getContent()) {
768-
res.add((Transaction)((DataChunk)o).getEntity());
788+
final ArrayList<Transaction> res = new ArrayList<>();
789+
for (Object o : t.getMapFieldByColumn("transId").getMap().entrySet()) {
790+
res.add((Transaction)((DataChunk)((Map.Entry)o).getValue()).getEntity());
769791
}
770792
return res;
771793
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class SyncFrame implements Comparable, Serializable, AllowRPredicate {
5555
private final boolean allowR;
5656
private final boolean proc;
5757
private final boolean started;
58+
private final boolean distributed;
5859
private final Map<Long, Long> imap;
5960
private final Map<Long, Transaction> rtran;
6061
private final Map<Long, List<Long>> uframes;
@@ -73,6 +74,7 @@ public SyncFrame(Frame frame, Session s, FreeFrame fb, boolean proc) throws Exce
7374
final FrameData bd = Instance.getInstance().getFrameById(frame.getPtr());
7475
allowR = frame.isLocal() ? !t.isNoTran() || t.getName().equals("su.interference.persistent.UndoChunk") : false;
7576
this.proc = bd == null ? false : proc;
77+
distributed = t.isDistributed();
7678

7779
if (bd == null && allowR) {
7880
final FreeFrame fframe = Instance.getInstance().getFreeFrameById(frame.getPtr());
@@ -243,6 +245,10 @@ public Map<Long, List<Long>> getUFrames() {
243245
return uframes;
244246
}
245247

248+
public boolean isDistributed() {
249+
return distributed;
250+
}
251+
246252
public boolean equals (SyncFrame bl) {
247253
return (this.getFile() == bl.getFile()) && (this.getPointer() == bl.getPointer());
248254
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ this software and associated documentation files (the "Software"), to deal in
2626

2727
import java.util.concurrent.*;
2828
import java.util.*;
29+
import java.util.stream.Collectors;
2930

3031
import org.slf4j.Logger;
3132
import org.slf4j.LoggerFactory;
@@ -117,8 +118,11 @@ private synchronized boolean syncFramesFromQueue() throws Exception {
117118
for (FreeFrame fb : fframes) {
118119
s.persist(fb);
119120
}
121+
120122
//todo async process must depends from stop() method
121-
pool2.submit(new TransportSyncTask(frames));
123+
124+
final List<SyncFrame> dframes = frames.stream().filter(p -> p.isDistributed()).collect(Collectors.toList());
125+
pool2.submit(new TransportSyncTask(dframes));
122126

123127
running = false;
124128
return true;

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private void cleanUpFrames() {
9292
final long frameAmount = f.getDataObject().getFrameAmount();
9393
if (f.getDataFile().isData() && cleanupDataEnabled()) {
9494
f.decreasePriority();
95-
if (f.isSynced() && f.getObjectId() > 999 && frameAmount > Config.getConfig().CLEANUP_PROTECTION_THR) {
95+
if (f.isSynced() && f.getObjectId() > 999 && frameAmount > getThr()) {
9696
if (f.clearFrame()) {
9797
d++;
9898
}
@@ -107,7 +107,7 @@ private void cleanUpFrames() {
107107
if (f.isSynced() && f.getFrameType() == IndexFrame.INDEX_FRAME_NODE) {
108108
xn++;
109109
}
110-
if (f.isSynced() && f.getFrameType() != IndexFrame.INDEX_FRAME_NODE && !f.isRbck() && frameAmount > Config.getConfig().IX_CLEANUP_PROTECTION_THR) {
110+
if (f.isSynced() && f.getFrameType() != IndexFrame.INDEX_FRAME_NODE && !f.isRbck() && frameAmount > getIxThr()) {
111111
if (f.clearFrame()) {
112112
x++;
113113
}
@@ -117,7 +117,7 @@ private void cleanUpFrames() {
117117
}
118118
}
119119
if (f.getDataFile().isTemp() && cleanupTempEnabled()) {
120-
if (f.isSynced() && f.getFrameType() != IndexFrame.INDEX_FRAME_NODE && frameAmount > Config.getConfig().CLEANUP_PROTECTION_THR) {
120+
if (f.isSynced() && f.getFrameType() != IndexFrame.INDEX_FRAME_NODE && frameAmount > getThr()) {
121121
if (f.clearFrame()) {
122122
i++;
123123
}
@@ -127,7 +127,7 @@ private void cleanUpFrames() {
127127
}
128128
}
129129
if (f.getDataFile().isUndo() && cleanupUndoEnabled()) {
130-
if (f.isSynced() && frameAmount > Config.getConfig().CLEANUP_PROTECTION_THR) {
130+
if (f.isSynced() && frameAmount > getThr()) {
131131
if (f.clearFrame()) {
132132
u++;
133133
}
@@ -185,4 +185,12 @@ private boolean cleanupTempEnabled() {
185185
// todo cleanup affects temp indices, disable until fix is released
186186
return false;
187187
}
188+
189+
private int getThr() {
190+
return Config.getConfig().CLEANUP_PROTECTION_THR/(Config.getConfig().FRAMESIZE/4096);
191+
}
192+
193+
private int getIxThr() {
194+
return Config.getConfig().IX_CLEANUP_PROTECTION_THR/(Config.getConfig().FRAMESIZE/4096);
195+
}
188196
}

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

Lines changed: 3 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-2021 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,7 +44,7 @@ this software and associated documentation files (the "Software"), to deal in
4444
*/
4545

4646
public class SystemInit {
47-
private final static int INITIAL_CLASSES_AMT = 15;
47+
private final static int INITIAL_CLASSES_AMT = 16;
4848
private final static Logger logger = LoggerFactory.getLogger(SystemInit.class);
4949

5050
public static Table initSystem (boolean initStorage, int nodeType, Session s) throws Exception {
@@ -69,6 +69,7 @@ public static String[] getInitialClasses() {
6969
initialClasses[12] = "su.interference.persistent.MgmtModule";
7070
initialClasses[13] = "su.interference.persistent.Cursor";
7171
initialClasses[14] = "su.interference.persistent.FrameSync";
72+
initialClasses[15] = "su.interference.persistent.EventSubscriber";
7273
return initialClasses;
7374
}
7475

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
1+
/**
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2010-2021 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+
125
package su.interference.core;
226

327
import java.io.Serializable;
428

29+
/**
30+
* @author Yuriy Glotanov
31+
* @since 1.0
32+
*/
33+
534
public class TransFrameId implements Serializable {
35+
private final static long serialVersionUID = 2122989901000213555L;
636
private final long cframeId;
737
private final long uframeId;
838
private final long transId;

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

Lines changed: 5 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-2021 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
@@ -46,7 +46,7 @@ public Object[] getValueSet() {
4646
}
4747

4848
public int compareTo (Object obj) {
49-
return compare(obj, vs.length);
49+
return compare(obj, ((ValueSet) obj).getValueSet().length);
5050
}
5151

5252
//used in partial compare datachunks in sql group algorithm
@@ -55,12 +55,12 @@ public int compareTo (Object obj) {
5555
public int compare (Object obj, int thr) {
5656
final ValueSet j = (ValueSet)obj;
5757

58-
for (int i=0; i<vs.length; i++) {
59-
final int ct = ((Comparable)this.vs[i]).compareTo(j.getValueSet()[i]);
58+
for (int i = 0; i < vs.length; i++) {
59+
final int ct = ((Comparable) this.vs[i]).compareTo(j.getValueSet()[i]);
6060
if (ct != 0) {
6161
return ct;
6262
}
63-
if (i==thr-1) {
63+
if (i == thr - 1) {
6464
break;
6565
}
6666
}

0 commit comments

Comments
 (0)