Skip to content

Commit f45a509

Browse files
RELEASE 2021.1 hotfix patch 05.10
1 parent d8a532b commit f45a509

12 files changed

Lines changed: 275 additions & 87 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ protected synchronized void removeByPtr(int i) {
107107
}
108108
}
109109
imap.get(c.getDcs()).remove(i_);
110-
list.remove(hmap.get(i));
110+
if (imap.get(c.getDcs()).size() == 0) {
111+
imap.remove(c.getDcs());
112+
}
113+
list.remove(c);
111114
}
112115
sorted = false;
113116
used = used - c.getBytesAmount();

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,5 +579,50 @@ public synchronized Table bootstrapLoad() throws Exception {
579579
return res;
580580
}
581581

582+
public void createSystemLog() throws Exception {
583+
final Table t = new Table(true);
584+
for (DataFile df : Storage.getStorage().getInitDataFiles()) {
585+
long start = Instance.getInstance().getFrameSize(); //first data frame
586+
while (true) {
587+
final FrameData bb = new FrameData(df.getFileId(), start, df.getType() == Storage.INDXFILE_TYPEID ? Instance.getInstance().getFrameSize2() : Instance.getInstance().getFrameSize(), t);
588+
DataFrame db = null;
589+
try {
590+
db = bb.getDataFrame();
591+
} catch (Exception e) {
592+
e.printStackTrace();
593+
}
594+
start = db.getNextFrame();
595+
for (Chunk c : db.getChunks()) {
596+
if (c.getHeader().getState()==Header.RECORD_NORMAL_STATE) { //miss deleted or archived records
597+
final FrameData bd = (FrameData)((DataChunk)c).getEntity(FrameData.class, null);
598+
if (bd.getFrameId()==bb.getFrameId()) {
599+
bd.setFrame(db);
600+
}
601+
//res.add(bd.getObjectId(), c);
602+
}
603+
}
604+
if (start==0) { break; }
605+
}
606+
}
607+
}
582608

609+
public String getHexByInt (int val) {
610+
String s = Integer.toHexString(val);
611+
StringBuffer p = new StringBuffer();
612+
for (int i = 0; i < 8 - s.length(); i++) {
613+
p.append("0");
614+
}
615+
p.append(s);
616+
return p.toString();
617+
}
618+
619+
public String getHexByLong (long val) {
620+
String s = Long.toHexString(val);
621+
StringBuffer p = new StringBuffer();
622+
for (int i = 0; i < 16 - s.length(); i++) {
623+
p.append("0");
624+
}
625+
p.append(s);
626+
return p.toString();
627+
}
583628
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class SyncFrame implements Comparable, Serializable, AllowRPredicate {
5656
private final boolean proc;
5757
private final boolean started;
5858
private final boolean distributed;
59+
private final boolean freed;
5960
private final Map<Long, Long> imap;
6061
private final Map<Long, Transaction> rtran;
6162
private final Map<Long, List<Long>> uframes;
@@ -73,11 +74,12 @@ public SyncFrame(Frame frame, Session s, FreeFrame fb, boolean proc) throws Exce
7374
final Table t = Instance.getInstance().getTableById(frame.getObjectId());
7475
final FrameData bd = Instance.getInstance().getFrameById(frame.getPtr());
7576
//allowR = frame.isLocal() || bd.isLockedLocally() ? !t.isNoTran() || t.getName().equals("su.interference.persistent.UndoChunk") : false;
76-
allowR = !t.isNoTran() || (frame.isLocal() && t.getName().equals("su.interference.persistent.UndoChunk"));
77+
this.allowR = !t.isNoTran() || (frame.isLocal() && t.getName().equals("su.interference.persistent.UndoChunk"));
7778
this.proc = bd == null ? false : proc;
78-
distributed = t.isDistributed();
79+
this.distributed = t.isDistributed();
80+
this.freed = bd == null || bd.isFree();
7981

80-
if (bd == null && allowR) {
82+
if ((bd == null || bd.isFree()) && allowR) {
8183
final FreeFrame fframe = Instance.getInstance().getFreeFrameById(frame.getPtr());
8284
if (fframe == null) {
8385
logger.warn(frame.getClass().getSimpleName()+" does not match any system objects");
@@ -250,6 +252,10 @@ public boolean isDistributed() {
250252
return distributed;
251253
}
252254

255+
public boolean isFree() {
256+
return freed;
257+
}
258+
253259
public boolean equals (SyncFrame bl) {
254260
return (this.getFile() == bl.getFile()) && (this.getPointer() == bl.getPointer());
255261
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ this software and associated documentation files (the "Software"), to deal in
5050
@Entity
5151
@SystemEntity
5252
@DisableSync
53-
public class FrameData implements Serializable, Comparable, FrameApi, FilePartitioned {
53+
public class FrameData implements Serializable, Comparable, FrameApi, FilePartitioned, OnDelete {
5454

5555
@Transient
5656
private final static long serialVersionUID = 8712349857239487288L;
@@ -116,6 +116,8 @@ public class FrameData implements Serializable, Comparable, FrameApi, FilePartit
116116
@Transient
117117
private volatile Frame frame;
118118
@Transient
119+
private AtomicInteger freed = new AtomicInteger(0);
120+
@Transient
119121
private Table dataObject;
120122
@Transient
121123
private Class entityClass;
@@ -499,6 +501,11 @@ public void decreaseTcounter(long id) {
499501
tcounter.remove(id);
500502
}
501503

504+
public int checkTcounter(long id) {
505+
Map<Long, TransFrame> map = tcounter.get(id);
506+
return map == null ? -1 : map.size();
507+
}
508+
502509
public synchronized Map<Long, List<Long>> getLiveUFrameAllocIds() {
503510
final Map<Long, List<Long>> uframes = new HashMap<>();
504511
for (Map.Entry<Long, Map<Long, TransFrame>> entry : tcounter.entrySet()) {
@@ -647,6 +654,23 @@ public synchronized void setMv(ValueSet mv) {
647654
this.mv = mv;
648655
}
649656

657+
public boolean isFree() {
658+
return freed.compareAndSet(1, 1);
659+
}
660+
661+
public boolean isValid() {
662+
return freed.compareAndSet(0, 0);
663+
}
664+
665+
public void free() {
666+
this.freed.compareAndSet(0, 1);
667+
}
668+
669+
public void onDelete() {
670+
this.frame = null;
671+
this.free();
672+
}
673+
650674
@Override
651675
public boolean isProcess() {
652676
return false;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ public void close() {
389389
}
390390

391391
//todo uncommitted data not retrieved
392+
@Deprecated
392393
public void stream (Class c, StreamCallable task) {
393394
final Map<Long, Long> retrieved = new HashMap<>();
394395
final Table t = Instance.getInstance().getTableByName(c.getName());

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

Lines changed: 88 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,38 @@ public void usedSpace (final FrameData bd, final int used, final boolean persist
10991099
}
11001100
}
11011101

1102+
protected synchronized void freeFrames (List<Long> flist, Session s, Transaction tran, String cause) throws Exception {
1103+
for (Long frameId : flist) {
1104+
final FrameData cb = Instance.getInstance().getFrameById(frameId);
1105+
logger.info("freeing frame " + cb.getFile() + " " + cb.getPtr() + " by " + cause + " of " + tran.getTransId());
1106+
if (cb.getUsed() > 0) {
1107+
throw new InternalException();
1108+
}
1109+
if (!this.checkLBS(cb)) { //LB can't deallocated!!! May be empty
1110+
//check for other transactions, which locked this frame
1111+
if (!cb.isFrameBusy()) {
1112+
final FreeFrame fb = new FreeFrame(0, cb.getFrameId(), cb.getSize());
1113+
final FrameData pb = cb.getPrevFrameId() > 0 ? Instance.getInstance().getFrameById(cb.getPrevFrameId()) : null;
1114+
final FrameData nb = Instance.getInstance().getFrameById(cb.getNextFrameId());
1115+
if (nb != null) {
1116+
nb.setPrevFile(pb == null ? 0 : pb.getFile());
1117+
nb.setPrevFrame(pb == null ? 0 : pb.getPtr());
1118+
s.persist(nb); //update
1119+
}
1120+
if (pb != null) {
1121+
pb.setNextFile(nb.getFile());
1122+
pb.setNextFrame(nb.getPtr());
1123+
s.persist(pb); //update
1124+
}
1125+
s.persist(fb); //insert
1126+
s.delete(cb);
1127+
this.decFrameAmount();
1128+
s.persist(this);
1129+
}
1130+
}
1131+
}
1132+
}
1133+
11021134
private WaitFrame getAvailableFrame(final Object o, final boolean fpart) throws ClassNotFoundException, InstantiationException, InternalException, IllegalAccessException {
11031135
Metrics.get("getAvailableFrame").start();
11041136
final long st = System.currentTimeMillis();
@@ -1157,6 +1189,7 @@ public synchronized DataChunk persist (final Object o, final Session s) throws E
11571189
}
11581190

11591191
protected DataChunk persist (final Object o, final Session s, final LLT extllt) throws Exception {
1192+
final boolean ignoreNoLocal = false;
11601193
final Class cc = o.getClass();
11611194
boolean fpart = false;
11621195

@@ -1307,10 +1340,16 @@ protected DataChunk persist (final Object o, final Session s, final LLT extllt)
13071340
return nc;
13081341

13091342
} else {
1343+
final FrameData bd = Instance.getInstance().getFrameById(dc.getHeader().getRowID().getFileId()+dc.getHeader().getRowID().getFramePointer());
1344+
1345+
if (!bd.getFrame().isLocal()) {
1346+
if (!ignoreNoLocal) {
1347+
throw new CannotAccessToForeignRecord();
1348+
}
1349+
}
13101350

13111351
final DataChunk udc = dc.lock(s, llt);
13121352
final int len = dc.getBytesAmount();
1313-
final FrameData bd = Instance.getInstance().getFrameById(dc.getHeader().getRowID().getFileId() + dc.getHeader().getRowID().getFramePointer());
13141353
final int newlen = bd.updateChunk(dc, o, s, llt);
13151354
final int diff = newlen - len - bd.getFrameFree();
13161355

@@ -1383,25 +1422,28 @@ protected void delete (final Object o, final Session s, LLT extllt, boolean igno
13831422
}
13841423

13851424
final LLT llt = extllt==null?LLT.getLLT():extllt;
1386-
final DataChunk dc = this.getChunkByEntity(o, s, llt);
1387-
if (dc == null) {
1388-
throw new CannotAccessToDeletedRecord();
1389-
}
1390-
if (dc.getHeader().getState() == Header.RECORD_DELETED_STATE) {
1391-
throw new CannotAccessToDeletedRecord();
1392-
}
1393-
final int len = dc.getBytesAmount();
1394-
final FrameData bd = Instance.getInstance().getFrameById(dc.getHeader().getRowID().getFileId()+dc.getHeader().getRowID().getFramePointer());
1425+
try {
1426+
final DataChunk dc = this.getChunkByEntity(o, s, llt);
13951427

1396-
if (!bd.getFrame().isLocal()) {
1397-
if (!ignoreNoLocal) {
1398-
throw new CannotAccessToForeignRecord();
1428+
if (dc == null) {
1429+
throw new CannotAccessToDeletedRecord();
13991430
}
1400-
}
14011431

1402-
DataChunk udc = null;
1432+
if (dc.getHeader().getState() == Header.RECORD_DELETED_STATE) {
1433+
throw new CannotAccessToDeletedRecord();
1434+
}
1435+
1436+
final int len = dc.getBytesAmount();
1437+
final FrameData bd = Instance.getInstance().getFrameById(dc.getHeader().getRowID().getFileId()+dc.getHeader().getRowID().getFramePointer());
1438+
1439+
if (!bd.getFrame().isLocal()) {
1440+
if (!ignoreNoLocal) {
1441+
throw new CannotAccessToForeignRecord();
1442+
}
1443+
}
1444+
1445+
DataChunk udc = null;
14031446

1404-
try {
14051447
if (!noTran) { //save undo information
14061448
udc = dc.lock(s, llt);
14071449
}
@@ -1585,8 +1627,10 @@ public Boolean call() throws Exception {
15851627
if (stopped.get()) {
15861628
return true;
15871629
}
1588-
for (Chunk c : b.getDataFrame().getFrameChunks(s)) {
1589-
q.put(c);
1630+
if (b.isValid()) {
1631+
for (Chunk c : b.getDataFrame().getFrameChunks(s)) {
1632+
q.put(c);
1633+
}
15901634
}
15911635
}
15921636
}
@@ -1717,6 +1761,7 @@ public Chunk cpoll(Session s) {
17171761
return null;
17181762
}
17191763

1764+
@Deprecated
17201765
protected ArrayList<FrameData> getStream (Map<Long, Long> retrieved, Session s) throws Exception {
17211766
final ArrayList<FrameData> r = new ArrayList<>();
17221767
if (this.isIndex()) { //index table
@@ -1729,8 +1774,10 @@ protected ArrayList<FrameData> getStream (Map<Long, Long> retrieved, Session s)
17291774
if (b.getObjectId() == 0 && b.getFrameId() == 0) {
17301775
cnue = false;
17311776
} else {
1732-
if (retrieved.get(b.getFrameId()) == null) {
1733-
r.add(b);
1777+
if (b.isValid()) {
1778+
if (retrieved.get(b.getFrameId()) == null) {
1779+
r.add(b);
1780+
}
17341781
}
17351782
}
17361783
}
@@ -1770,10 +1817,14 @@ public DataChunk getChunkByEntity (Object o, Session s, LLT llt) throws Exceptio
17701817
if (b.getObjectId() == 0 && b.getFrameId() == 0) {
17711818
cnue = false;
17721819
} else {
1773-
for (Chunk dc : b.getDataFrame().getFrameChunks(s)) {
1774-
if (Arrays.equals(id, ((DataChunk) dc).getSerializedId(s))) {
1775-
if (llt != null) { llt.add(((DataChunk) dc).getFrameData().getFrame()); }
1776-
return (DataChunk) dc;
1820+
if (b.isValid()) {
1821+
for (Chunk dc : b.getDataFrame().getFrameChunks(s)) {
1822+
if (Arrays.equals(id, ((DataChunk) dc).getSerializedId(s))) {
1823+
if (llt != null) {
1824+
llt.add(((DataChunk) dc).getFrameData().getFrame());
1825+
}
1826+
return (DataChunk) dc;
1827+
}
17771828
}
17781829
}
17791830
}
@@ -1803,10 +1854,14 @@ public DataChunk getChunkByEntity (Object o, Session s, LLT llt) throws Exceptio
18031854
if (b.getObjectId() == 0 && b.getFrameId() == 0) {
18041855
cnue = false;
18051856
} else {
1806-
for (Chunk dc : b.getDataFrame().getFrameChunks(s)) {
1807-
if (Arrays.equals(id, ((DataChunk) dc).getSerializedId(s))) {
1808-
if (llt != null) { llt.add(((DataChunk) dc).getFrameData().getFrame()); }
1809-
return (DataChunk) dc;
1857+
if (b.isValid()) {
1858+
for (Chunk dc : b.getDataFrame().getFrameChunks(s)) {
1859+
if (Arrays.equals(id, ((DataChunk) dc).getSerializedId(s))) {
1860+
if (llt != null) {
1861+
llt.add(((DataChunk) dc).getFrameData().getFrame());
1862+
}
1863+
return (DataChunk) dc;
1864+
}
18101865
}
18111866
}
18121867
}
@@ -1857,9 +1912,11 @@ public DataChunk getChunkById (long id, Session s) throws Exception {
18571912
if (b.getObjectId() == 0 && b.getFrameId() == 0) {
18581913
cnue = false;
18591914
} else {
1860-
for (Chunk c : b.getDataFrame().getFrameChunks(s)) {
1861-
if (Arrays.equals(iid, ((DataChunk) c).getSerializedId(s))) {
1862-
return (DataChunk) c;
1915+
if (b.isValid()) {
1916+
for (Chunk c : b.getDataFrame().getFrameChunks(s)) {
1917+
if (Arrays.equals(iid, ((DataChunk) c).getSerializedId(s))) {
1918+
return (DataChunk) c;
1919+
}
18631920
}
18641921
}
18651922
}

0 commit comments

Comments
 (0)