Skip to content

Commit 19fdc8f

Browse files
improve overall performance & stability
1 parent 0ca5189 commit 19fdc8f

12 files changed

Lines changed: 165 additions & 111 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public synchronized void removeChunk (int ptr, LLT llt, boolean ignore) {
508508

509509
//returns all actual records
510510
public synchronized ArrayList<Chunk> getFrameChunks (Session s) {
511-
final ArrayList<Chunk> res = new ArrayList<Chunk>();
511+
final ArrayList<Chunk> res = new ArrayList<>();
512512

513513
if (dataObject==null) {
514514
dataObject = Instance.getInstance().getTableById(this.objectId);

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ 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-
import javax.management.InstanceAlreadyExistsException;
32-
import javax.management.MBeanRegistrationException;
33-
import javax.management.MalformedObjectNameException;
34-
import javax.management.NotCompliantMBeanException;
3531
import java.io.IOException;
3632
import java.io.File;
3733
import java.net.URL;
@@ -62,7 +58,7 @@ public class Instance implements Interference {
6258
private static final int MAX_NODE_ID = 32;
6359
public static final int SESSION_EXPIRE = 7200000; //in ms
6460

65-
public static final int SYSTEM_VERSION = 20200920;
61+
public static final int SYSTEM_VERSION = 20201122;
6662

6763
public static final int SYSTEM_STATE_ONLINE = 1;
6864
public static final int SYSTEM_STATE_UP = 2;
@@ -100,26 +96,26 @@ private static class InstanceHolder {
10096
//public static Instance instance = new Instance();
10197
}
10298

103-
private Instance() throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanRegistrationException, IOException {
99+
private Instance() {
104100

105101
}
106102

107-
public boolean isStarted () throws InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException {
103+
public boolean isStarted () throws InternalException {
108104
//checkInstance();
109105
return this.getSystemState()==SYSTEM_STATE_UP;
110106
}
111107

112-
public boolean isStopped () throws InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException {
108+
public boolean isStopped () throws InternalException {
113109
//checkInstance();
114110
return this.getSystemState()==SYSTEM_STATE_DOWN;
115111
}
116112

117-
public boolean isCreated () throws InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException {
113+
public boolean isCreated () throws InternalException {
118114
//checkInstance();
119115
return !(this.getSystemState()==SYSTEM_STATE_IDLE);
120116
}
121117

122-
public boolean isIdle () throws InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException {
118+
public boolean isIdle () throws InternalException {
123119
//checkInstance();
124120
return (this.getSystemState()==SYSTEM_STATE_IDLE);
125121
}
@@ -457,7 +453,7 @@ private void stopProcesses(Session s) throws Exception {
457453
}
458454
}
459455

460-
private static int ccheckInstance() throws IOException, InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException {
456+
private static int ccheckInstance() throws InternalException {
461457
final int sstate = Storage.getStorage().getState();
462458
if (sstate==Storage.STORAGE_STATE_OPEN) {
463459
return Instance.SYSTEM_STATE_UP;

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

Lines changed: 6 additions & 6 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
@@ -34,14 +34,14 @@ this software and associated documentation files (the "Software"), to deal in
3434
public class RetrieveQueue {
3535
private final LinkedBlockingQueue<Chunk> q;
3636
private final ManagedCallable r;
37-
private boolean retrieve = true;
37+
private volatile boolean retrieve = true;
3838

3939
public RetrieveQueue(LinkedBlockingQueue<Chunk> q, ManagedCallable r) {
4040
this.q = q;
4141
this.r = r;
4242
}
4343

44-
public Object poll() {
44+
public synchronized Object poll() {
4545
try {
4646
if (retrieve) {
4747
Chunk c = q.take();
@@ -57,7 +57,7 @@ public Object poll() {
5757
return null;
5858
}
5959

60-
public Chunk cpoll() {
60+
public synchronized Chunk cpoll() {
6161
try {
6262
if (retrieve) {
6363
Chunk c = q.take();
@@ -73,7 +73,7 @@ public Chunk cpoll() {
7373
return null;
7474
}
7575

76-
public void stop() {
76+
public synchronized void stop() {
7777
retrieve = false;
7878
if (r != null) {
7979
r.stop();
@@ -88,7 +88,7 @@ public ManagedCallable getR() {
8888
return r;
8989
}
9090

91-
public boolean isRetrieve() {
91+
public synchronized boolean isRetrieve() {
9292
return retrieve;
9393
}
9494
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ public IndexFrame getIndexFrame() throws Exception {
192192

193193
public synchronized ArrayList<Chunk> getFrameChunks(Session s) throws Exception {
194194
if (getDataObject().isIndex()) {
195-
return getIndexFrame().getFrameChunks(s);
195+
final IndexFrame f = getIndexFrame();
196+
f.sort();
197+
return f.getFrameChunks(s);
196198
} else {
197199
return getDataFrame().getFrameChunks(s);
198200
}

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public static int getCLASS_ID() {
111111
@Transient
112112
private static final ExecutorService rqpool = Executors.newCachedThreadPool();
113113
@Transient
114-
private volatile RetrieveQueue retrieveQueue;
114+
private volatile Map<Integer, RetrieveQueue> retrieveQueue = new ConcurrentHashMap<>();
115115
@Transient
116116
private static final ExecutorService streampool = Executors.newCachedThreadPool();
117117
@Transient
@@ -301,12 +301,15 @@ public Object find_ (Class c, long id) throws Exception {
301301
}
302302

303303
@SuppressWarnings("unchecked")
304-
protected synchronized RetrieveQueue getContentQueue(Table t) {
304+
public synchronized RetrieveQueue getContentQueue(Table t) {
305305
if (t != null) {
306306
try {
307-
retrieveQueue = t.getContentQueue(this);
308-
Future f = rqpool.submit(retrieveQueue.getR());
309-
return retrieveQueue;
307+
if (retrieveQueue.get(t.getObjectId()) == null || !retrieveQueue.get(t.getObjectId()).isRetrieve()) {
308+
final RetrieveQueue rq = t.getContentQueue(this);
309+
Future f = rqpool.submit(rq.getR());
310+
retrieveQueue.put(t.getObjectId(), rq);
311+
}
312+
return retrieveQueue.get(t.getObjectId());
310313
} catch (Exception e) {
311314
if (e instanceof ExecutionException) {
312315
e.getCause().printStackTrace();
@@ -318,11 +321,10 @@ protected synchronized RetrieveQueue getContentQueue(Table t) {
318321
return null;
319322
}
320323

321-
public void closeQueue() {
322-
if (this.retrieveQueue != null) {
323-
retrieveQueue.stop();
324+
public void closeQueue(int objectId) {
325+
if (this.retrieveQueue.get(objectId) != null) {
326+
retrieveQueue.get(objectId).stop();
324327
}
325-
retrieveQueue = null;
326328
}
327329

328330
public void closeStreamQueue() {
@@ -594,8 +596,8 @@ public static void setDntmSession(Session dntmSession) {
594596
Session.dntmSession = dntmSession;
595597
}
596598

597-
public RetrieveQueue getRetrieveQueue() {
598-
return retrieveQueue;
599+
public RetrieveQueue getRetrieveQueue(int objectId) {
600+
return retrieveQueue.get(objectId);
599601
}
600602

601603
public void streamFramePtr(Frame f, int ptr) {

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ public String getSystemName() {
263263
return this.name;
264264
}
265265

266-
public LinkedBlockingQueue<FrameData> getFrames(Session s)
267-
throws IOException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InternalException, IllegalAccessException, InstantiationException {
266+
public LinkedBlockingQueue<FrameData> getFrames(Session s) {
268267
if (this.isIndex()) {
269268
//get ordered frame sequence
270269
return this.getLeafFrames(s);
@@ -1506,7 +1505,7 @@ public Boolean call() throws Exception {
15061505

15071506
@Override
15081507
public void stop() {
1509-
stopped.set(false);
1508+
stopped.set(true);
15101509
}
15111510
};
15121511
return new RetrieveQueue(q, r);
@@ -1582,18 +1581,16 @@ public Boolean call() throws Exception {
15821581

15831582
@Override
15841583
public void stop() {
1585-
stopped.set(false);
1584+
stopped.set(true);
15861585
}
15871586
};
15881587
return new RetrieveQueue(q, r);
15891588
}
15901589

15911590
public Object poll(Session s) {
15921591
try {
1593-
if (s.getRetrieveQueue() == null || !s.getRetrieveQueue().isRetrieve()) {
1594-
s.getContentQueue(this);
1595-
}
1596-
return s.getRetrieveQueue().poll();
1592+
final RetrieveQueue rq = s.getContentQueue(this);
1593+
return rq.poll();
15971594
} catch (Exception e) {
15981595
e.printStackTrace();
15991596
}
@@ -1602,18 +1599,16 @@ public Object poll(Session s) {
16021599

16031600
public Chunk cpoll(Session s) {
16041601
try {
1605-
if (s.getRetrieveQueue() == null || !s.getRetrieveQueue().isRetrieve()) {
1606-
s.getContentQueue(this);
1607-
}
1608-
return s.getRetrieveQueue().cpoll();
1602+
final RetrieveQueue rq = s.getContentQueue(this);
1603+
return rq.cpoll();
16091604
} catch (Exception e) {
16101605
e.printStackTrace();
16111606
}
16121607
return null;
16131608
}
16141609

16151610
protected ArrayList<FrameData> getStream (Map<Long, Long> retrieved, Session s) throws Exception {
1616-
final ArrayList<FrameData> r = new ArrayList<FrameData>();
1611+
final ArrayList<FrameData> r = new ArrayList<>();
16171612
if (this.isIndex()) { //index table
16181613
throw new InternalException();
16191614
} else {
@@ -1952,7 +1947,7 @@ private synchronized List<Chunk> getLocalContent(long start, Session s) throws E
19521947
return res;
19531948
}
19541949

1955-
private synchronized LinkedBlockingQueue<FrameData> getLeafFrames (Session s) throws IOException, InternalException, NoSuchMethodException, InvocationTargetException, EmptyFrameHeaderFound, ClassNotFoundException, InstantiationException, IllegalAccessException {
1950+
private synchronized LinkedBlockingQueue<FrameData> getLeafFrames (Session s) throws InternalException, EmptyFrameHeaderFound {
19561951
final LinkedBlockingQueue<FrameData> q = new LinkedBlockingQueue<>(1000);
19571952
final ArrayList<Long> startfs = new ArrayList<>();
19581953
startfs.add(this.fileStart+this.frameStart);

src/main/java/su/interference/sql/FrameJoinTask.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ public List<Object> call() throws Exception {
102102
boolean cnue = true;
103103
while (cnue) {
104104
if (s1 > 0 && s2 > 0) {
105-
final Comparable o1 = getKeyValue(drs1.get(p1).getClass(), drs1.get(p1), ((SQLIndexFrame)bd2).getLkey(), s);
106-
final Comparable o2 = getKeyValue(drs2.get(p2).getClass(), drs2.get(p2), ((SQLIndexFrame)bd2).getRkey(), s);
105+
final Comparable o1 = getKeyValue(drs1.get(p1), ((SQLIndexFrame)bd2).getLkey(), s);
106+
final Comparable o2 = getKeyValue(drs2.get(p2), ((SQLIndexFrame)bd2).getRkey(), s);
107107
final int cmp = o1.compareTo(o2);
108108
if (cmp < 0) {
109109
p1++;
@@ -133,7 +133,7 @@ public List<Object> call() throws Exception {
133133
if (n==s2) {
134134
p1++;
135135
} else {
136-
final Comparable next = getKeyValue(drs2.get(n).getClass(), drs2.get(n), ((SQLIndexFrame)bd2).getRkey(), s);
136+
final Comparable next = getKeyValue(drs2.get(n), ((SQLIndexFrame)bd2).getRkey(), s);
137137
if (o1.compareTo(next)<0) {
138138
p1++;
139139
} else {
@@ -260,7 +260,7 @@ public Object joinDataRecords (Class r, Class c1, Class c2, int t1, int t2, Obje
260260
return ret;
261261
}
262262

263-
private Comparable getKeyValue(Class c, Object o, SQLColumn sqlc, Session s) throws InvocationTargetException, IllegalAccessException {
263+
private Comparable getKeyValue(Object o, SQLColumn sqlc, Session s) throws InvocationTargetException, IllegalAccessException {
264264
final Method y = sqlc.getKeyGetter();
265265
return sqlc.isCursor() ? (Comparable) y.invoke(o, null) : (Comparable) y.invoke(o, new Object[]{s});
266266
}

src/main/java/su/interference/sql/SQLCursor.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
@@ -147,7 +147,7 @@ public SQLCursor (int id, FrameIterator lbi, FrameIterator rbi, NestedCondition
147147
final ValueCondition vc = nc.getIndexVC(lbi, null);
148148
if (vc != null) {
149149
final Table lt = Instance.getInstance().getTableById(lbi.getObjectId());
150-
this.lbi = new SQLIndex(vc.getConditionColumn().getIndex(), lt, false, vc.getConditionColumn(), vc.getConditionColumn(), true, nc, s);
150+
this.lbi = new SQLIndex(vc.getConditionColumn().getIndex(), lt, false, vc.getConditionColumn(), vc.getConditionColumn(), true, nc, 0, s);
151151
this.rbi = rbi;
152152
} else {
153153
this.lbi = lbi;

src/main/java/su/interference/sql/SQLHashMap.java

Lines changed: 25 additions & 19 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
@@ -53,8 +53,9 @@ public class SQLHashMap implements FrameIterator {
5353
private final Table t;
5454
private final Class c;
5555
private final Session s;
56+
private SQLHashMapFrame hframe;
5657

57-
public SQLHashMap(SQLColumn cmap, SQLColumn ckey, FrameIterator rbi, Table t, Session s) throws MalformedURLException, ClassNotFoundException {
58+
public SQLHashMap(SQLColumn cmap, SQLColumn ckey, FrameIterator rbi, Table t, Session s) {
5859
this.cmap = cmap;
5960
this.ckey = ckey;
6061
this.rbi = rbi;
@@ -72,26 +73,31 @@ public Comparable getKeyValue(Class c, Object o, SQLColumn sqlc, Session s) thro
7273
}
7374

7475
public FrameApi nextFrame() throws Exception {
75-
if (!complete.get()) {
76-
while (rbi.hasNextFrame()) {
77-
FrameApi bd = rbi.nextFrame();
78-
if (bd != null) {
79-
ArrayList<Object> drs = bd.getFrameEntities(s);
80-
for (Object o : drs) {
81-
if (bd.getImpl() == FrameApi.IMPL_INDEX) {
82-
final IndexChunk ib1 = (IndexChunk) o;
83-
o = ib1.getDataChunk().getEntity();
76+
if (!returned.get()) {
77+
synchronized (this) {
78+
if (hframe == null) {
79+
if (!complete.get()) {
80+
while (rbi.hasNextFrame()) {
81+
FrameApi bd = rbi.nextFrame();
82+
if (bd != null) {
83+
ArrayList<Object> drs = bd.getFrameEntities(s);
84+
for (Object o : drs) {
85+
if (bd.getImpl() == FrameApi.IMPL_INDEX) {
86+
final IndexChunk ib1 = (IndexChunk) o;
87+
o = ib1.getDataChunk().getEntity();
88+
}
89+
90+
hmap.put(getKeyValue(c, o, cmap, s), o);
91+
}
92+
}
8493
}
85-
86-
hmap.put(getKeyValue(c, o, cmap, s), o);
94+
complete.compareAndSet(false, true);
8795
}
96+
hframe = new SQLHashMapFrame(hmap, cmap, ckey, t);
8897
}
98+
returned.compareAndSet(false, true);
99+
return hframe;
89100
}
90-
complete.compareAndSet(false, true);
91-
}
92-
if (!returned.get()) {
93-
returned.compareAndSet(false, true);
94-
return new SQLHashMapFrame(hmap, cmap, ckey, t);
95101
}
96102
return null;
97103
}
@@ -108,7 +114,7 @@ public int getType() {
108114
return FrameIterator.TYPE_TABLE;
109115
}
110116

111-
public boolean isIndex() throws MalformedURLException, ClassNotFoundException {
117+
public boolean isIndex() {
112118
return false;
113119
}
114120

0 commit comments

Comments
 (0)