Skip to content

Commit b5ecf97

Browse files
fix frame recycle misfunc : index frame size init updated : getframes methods optimized : improve stream mechanism
1 parent 2345654 commit b5ecf97

21 files changed

Lines changed: 373 additions & 232 deletions

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public interface DataObject {
5757
void setFileLast (int fileLast);
5858
void setFrameLast (long frameLast);
5959
void setFrameAmount(long frameAmount);
60+
long getFrameOrder(Session s, LLT llt) throws Exception;
6061
long getIdValue(Session s, LLT llt) throws Exception;
6162
long getIncValue(Session s, LLT llt) throws Exception;
6263
void incFrameAmount ();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2010-2019 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 su.interference.sql.FrameApi;
28+
29+
import java.util.Comparator;
30+
31+
/**
32+
* @author Yuriy Glotanov
33+
* @since 1.0
34+
*/
35+
36+
public class FrameOrderComparator implements Comparator<FrameApi> {
37+
public int compare(FrameApi f1, FrameApi f2) {
38+
if (f1.getFrameOrder() < f2.getFrameOrder()) {
39+
return -1;
40+
} else if (f1.getFrameOrder() > f2.getFrameOrder()) {
41+
return 1;
42+
}
43+
return 0;
44+
}
45+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class Instance implements Interference {
6262
private static final int MAX_NODE_ID = 32;
6363
public static final int SESSION_EXPIRE = 7200000; //in ms
6464

65-
public static final int SYSTEM_VERSION = 20193;
65+
public static final int SYSTEM_VERSION = 20200524;
6666

6767
public static final int SYSTEM_STATE_ONLINE = 1;
6868
public static final int SYSTEM_STATE_UP = 2;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ private synchronized IndexList bootstrapFrameLoad() throws IOException, ClassNot
475475
for (DataFile df : Storage.getStorage().getInitDataFiles()) {
476476
long start = Instance.getInstance().getFrameSize(); //first data frame
477477
while (true) {
478-
final FrameData bb = new FrameData(df.getFileId(), start, Instance.getInstance().getFrameSize(), t);
478+
final FrameData bb = new FrameData(df.getFileId(), start, df.getType() == Storage.INDXFILE_TYPEID ? Instance.getInstance().getFrameSize2() : Instance.getInstance().getFrameSize(), t);
479479
DataFrame db = null;
480480
try {
481481
db = bb.getDataFrame();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ int auth (int user, int pass, Session s) throws NoSuchMethodException, Invocatio
9898
return 0;
9999
}
100100

101-
SystemData getSystemData() {
101+
public SystemData getSystemData() {
102102
for (Chunk c : data.getChunks()) {
103103
final DataChunk dc = (DataChunk)c;
104104
return (SystemData)dc.getEntity();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ public static Table createInitialFrames(boolean initStorage, int nodeType, Sessi
179179
int ufsCntr = 0;
180180
for (int x=1; x<dfs.length; x++) {
181181
DataFile f = dfs[x];
182-
if (f.getType()==DataFile.DATA_TYPE) {
182+
if (f.getType() == Storage.DATAFILE_TYPEID) {
183183
FrameData frame = f.allocateFrame(t, s, null);
184184
frame.markAsCurrent();
185-
if (f.getFileId()==df.getFileId()) {
185+
if (f.getFileId() == df.getFileId()) {
186186
t.setFrameStart(frame.getPtr());
187187
t.setFrameLast(frame.getPtr());
188188
}
@@ -201,7 +201,7 @@ public static Table createInitialFrames(boolean initStorage, int nodeType, Sessi
201201
DataChunk dc = new DataChunk(f, s);
202202
ret[framesCntr].insertChunk(dc, s, true, null);
203203
for (int y=1; y<dfs.length; y++) {
204-
if (dfs[y].getType()!=DataFile.DATA_TYPE) {
204+
if (dfs[y].getType() != Storage.DATAFILE_TYPEID) {
205205
int p = Config.getConfig().FILES_AMOUNT*(dfs[y].getType()-1);
206206
if (f.getFileId()==(dfs[y].getFileId()-p)) {
207207
dc = new DataChunk(dfs[y], s);

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ this software and associated documentation files (the "Software"), to deal in
4949
@Entity
5050
@SystemEntity
5151
public class DataFile implements Serializable {
52-
@Transient
53-
public static final int DATA_TYPE = 1;
54-
@Transient
55-
public static final int INDX_TYPE = 2;
56-
@Transient
57-
public static final int UNDO_TYPE = 3;
58-
@Transient
59-
public static final int TEMP_TYPE = 4;
6052

6153
@Column
6254
@Id
@@ -334,6 +326,8 @@ public synchronized RandomAccessFile openFile(String mode) {
334326
this.file.seek(0);
335327
this.file.read(b,0,SYSTEM_FRAME_SIZE);
336328
this.sframe = new SystemFrame(b,this.getFileId(),0);
329+
final SystemData sd = this.sframe.getSystemData();
330+
logger.info("open " + this.fileName + " file completed successfully (ver." + sd.getVersion() + ")");
337331
} catch (Exception e) {
338332
logger.error("open " + this.fileName + " file throws " + e.getMessage());
339333
}
@@ -375,7 +369,7 @@ public synchronized void createFile(Session s, LLT llt) throws IOException, Invo
375369
}
376370

377371
private synchronized void createHeaderFrame(Session s, LLT llt) throws IOException, InvocationTargetException, NoSuchMethodException, InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException {
378-
this.sframe = new SystemFrame(this.getFileId(), 0, Instance.getInstance().getFrameSize());
372+
this.sframe = new SystemFrame(this.getFileId(), 0, type == Storage.INDXFILE_TYPEID ? Instance.getInstance().getFrameSize2() : Instance.getInstance().getFrameSize());
379373
this.sframe.insertSU(s, llt);
380374
// Storage.getStorage().writeFrame(this.sframe);
381375
this.writeFrame(0, this.sframe.getFrame());
@@ -388,6 +382,8 @@ public synchronized FrameData allocateFrame(DataObject t, Session s, LLT llt) th
388382
final FreeFrame fframe = getReallocFreeFrame(size);
389383
if (fframe != null) {
390384
final FrameData bd = new FrameData(fframe.getFile(), fframe.getPtr(), fframe.getSize(), t);
385+
// t should be updated mandatory during createFrame
386+
bd.setFrameOrder(t.getFrameOrder(s, llt));
391387
s.delete(fframe, llt);
392388
Metrics.get("reallocateFrame").stop();
393389
return bd;
@@ -406,6 +402,8 @@ public synchronized FrameData allocateFrame(DataObject t, Session s, LLT llt) th
406402
// Storage.getStorage().writeFrame(this.sframe);
407403
this.writeFrame(0, this.sframe.getFrame());
408404
final FrameData bd = new FrameData(this.getFileId(), ptr, size, t);
405+
// t should be updated mandatory during createFrame
406+
bd.setFrameOrder(t.getFrameOrder(s, llt));
409407
Metrics.get("allocateFrame").stop();
410408
return bd;
411409
}

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ public class FrameData implements Serializable, Comparable, FrameApi, FilePartit
100100
private AtomicInteger current;
101101
@Column
102102
private volatile int started;
103+
@Column
104+
private volatile long frameOrder;
103105
@Id
104106
@MapColumn
105107
@Transient
@@ -222,10 +224,6 @@ public long getNextFrameId() {
222224
return this.nextFile+this.nextFrame;
223225
}
224226

225-
protected int getFrameSize() throws ClassNotFoundException, InternalException, IllegalAccessException, InstantiationException {
226-
return Instance.getInstance().getFrameSize();
227-
}
228-
229227
//real current transactional value
230228
//skip negative differences for prevent frame oversize when many transactions change data
231229
public int getFrameUsed() {
@@ -245,7 +243,7 @@ public int getCUsed() {
245243
}
246244

247245
public int getFrameFree() throws ClassNotFoundException, InternalException, InstantiationException, IllegalAccessException {
248-
return getFrameSize() - Frame.FRAME_HEADER_SIZE - getFrameUsed();
246+
return size - Frame.FRAME_HEADER_SIZE - getFrameUsed();
249247
}
250248

251249
public FrameData() {
@@ -468,4 +466,12 @@ public int getStarted() {
468466
public void setStarted(int started) {
469467
this.started = started;
470468
}
469+
470+
public long getFrameOrder() {
471+
return frameOrder;
472+
}
473+
474+
public void setFrameOrder(long frameOrder) {
475+
this.frameOrder = frameOrder;
476+
}
471477
}

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,8 @@ public Table registerTable (String n, Session s, List<SQLColumn> cols, java.lang
204204
final Class proxy = cols==null&&flds==null?ppf.register(n):flds==null?rpf.register(cols,n,ixflag):ipf.register(flds,n,pt.getName());
205205
final String sname = proxy==null?null:proxy.getName();
206206

207-
w = (Table)t.newInstance(new Object[]{n, proxy==null?new String("x"):proxy});
208-
// w.setName(n);
209-
w.setFrameSize(Instance.getInstance().getFrameSize());
210-
// w.setFileStart(cols==null?dataf:tmpdf);
211-
// w.setFileLast(cols==null?dataf:tmpdf);
212-
w.setParentId(pt==null?0:pt.getObjectId());
213-
s.persist(w); //ident
214-
215207
boolean setlbs = true;
216-
208+
int framesize = Instance.getInstance().getFrameSize();
217209
DataFile[] datafs = Storage.getStorage().getInitDataFiles();
218210

219211
if (cols!=null) {
@@ -222,9 +214,15 @@ public Table registerTable (String n, Session s, List<SQLColumn> cols, java.lang
222214

223215
if (flds!=null&&pt!=null) {
224216
datafs = Storage.getStorage().getIndexFiles();
217+
framesize = Instance.getInstance().getFrameSize2();
225218
setlbs = false;
226219
}
227220

221+
w = (Table)t.newInstance(new Object[]{n, proxy==null?new String("x"):proxy});
222+
w.setFrameSize(framesize);
223+
w.setParentId(pt==null?0:pt.getObjectId());
224+
s.persist(w); //ident
225+
228226
final LLT llt = LLT.getLLT();
229227

230228
for (DataFile df : datafs) {
@@ -344,15 +342,16 @@ public void run() {
344342
}
345343

346344
@Deprecated
347-
public Object nfind (Class c, long id) throws InternalException, NoSuchMethodException, InvocationTargetException, IOException, InvalidFrameHeader, InvalidFrame, EmptyFrameHeaderFound, IncorrectUndoChunkFound, ClassNotFoundException, InstantiationException, IllegalAccessException {
345+
public Object nfind (Class c, long id)
346+
throws InternalException, NoSuchMethodException, InvocationTargetException, IOException, InterruptedException, ClassNotFoundException, InstantiationException, IllegalAccessException {
348347
final Table t = Instance.getInstance().getTableByName(c.getName());
349348
if (t != null) {
350349
return t.getChunkById(id, this).getEntity();
351350
}
352351
return null;
353352
}
354353

355-
public void lock (Object o) throws Exception, InterruptedException, InvocationTargetException, NoSuchMethodException, InternalException, InvalidFrame, EmptyFrameHeaderFound, IncorrectUndoChunkFound, ClassNotFoundException, InstantiationException, IllegalAccessException, InvalidParameter, CannotAccessToDeletedRecord, CannotAccessToLockedRecord, NotEnoughFrameSpace {
354+
public void lock (Object o) throws Exception {
356355
((EntityContainer)o).getDataChunk().lock(this, null);
357356
}
358357

@@ -382,7 +381,15 @@ public ResultSet execute(String sql) throws Exception {
382381
public void delete (Object o, LLT llt) throws Exception {
383382
final Table t = Instance.getInstance().getTableByName(o.getClass().getName());
384383
if (t != null) {
385-
t.delete(o, this, llt);
384+
t.delete(o, this, llt, false);
385+
}
386+
o = null;
387+
}
388+
389+
public void purge (Object o, LLT llt) throws Exception {
390+
final Table t = Instance.getInstance().getTableByName(o.getClass().getName());
391+
if (t != null) {
392+
t.delete(o, this, llt, true);
386393
}
387394
o = null;
388395
}

0 commit comments

Comments
 (0)