Skip to content

Commit 76040f3

Browse files
pre-release 2020.2 unstable
1 parent a254096 commit 76040f3

49 files changed

Lines changed: 766 additions & 464 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public interface Chunk extends Comparable {
4747
ValueSet getDcs();
4848
boolean isTerminate();
4949
void setTerminate(boolean terminate);
50-
Object getEntity() throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException;
51-
Object getUndoEntity() throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException;
52-
void updateEntity(Object o) throws InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, MalformedURLException;
50+
Object getEntity();
51+
Object getUndoEntity();
52+
void updateEntity(Object o) throws InternalException, IllegalAccessException;
5353
UndoChunk getUndoChunk();
5454
String getHexByChunk();
5555

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ this software and associated documentation files (the "Software"), to deal in
3535

3636
public class ChunkMap {
3737
private final ConcurrentHashMap<Integer, Chunk> hmap;
38-
private final ConcurrentHashMap<ValueSet, Chunk> imap;
38+
private final ConcurrentHashMap<ValueSet, List<Chunk>> imap;
3939
private final List<Chunk> list;
4040
private final Frame frame;
4141
private volatile boolean sorted;
@@ -55,7 +55,10 @@ public synchronized void sort() {
5555
public synchronized void add(Chunk c) {
5656
hmap.put(c.getHeader().getPtr(), c);
5757
if (frame instanceof IndexFrame) {
58-
imap.put(c.getDcs(), c);
58+
if (imap.get(c.getDcs()) == null) {
59+
imap.put(c.getDcs(), new ArrayList<>());
60+
}
61+
imap.get(c.getDcs()).add(c);
5962
}
6063
list.add(c);
6164
sorted = false;
@@ -73,15 +76,22 @@ public synchronized Chunk get(int i) {
7376
return list.get(i);
7477
}
7578

76-
public synchronized Chunk getByKey(ValueSet key) {
79+
//for unique indexes
80+
public synchronized List<Chunk> getByKey(ValueSet key) {
7781
return imap.get(key);
7882
}
7983

8084
public synchronized void removeByPtr(int i) {
8185
final boolean x = list.remove(hmap.get(i));
8286
final Chunk c = (Chunk)hmap.remove(i);
8387
if (frame instanceof IndexFrame) {
84-
imap.remove(c.getDcs());
88+
int i_ = 0;
89+
for (int i__ = 0; i__ < imap.get(c.getDcs()).size(); i__++) {
90+
if (imap.get(c.getDcs()).get(i__).getHeader().getPtr() == c.getHeader().getPtr()) {
91+
i_ = i__;
92+
}
93+
}
94+
imap.get(c.getDcs()).remove(i_);
8595
}
8696
sorted = false;
8797
if (!x || c == null) {
@@ -94,7 +104,13 @@ public synchronized void remove(int i) {
94104
list.remove(i);
95105
hmap.remove(c.getHeader().getPtr());
96106
if (frame instanceof IndexFrame) {
97-
imap.remove(c.getDcs());
107+
int i_ = 0;
108+
for (int i__ = 0; i__ < imap.get(c.getDcs()).size(); i__++) {
109+
if (imap.get(c.getDcs()).get(i__).getHeader().getPtr() == c.getHeader().getPtr()) {
110+
i_ = i__;
111+
}
112+
}
113+
imap.get(c.getDcs()).remove(i_);
98114
}
99115
sorted = false;
100116
}

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

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ this software and associated documentation files (the "Software"), to deal in
3535

3636
import javax.persistence.*;
3737
import java.io.UnsupportedEncodingException;
38-
import java.io.IOException;
3938
import java.lang.reflect.Field;
4039
import java.util.ArrayList;
40+
import java.util.HashMap;
4141
import java.util.List;
4242
import java.lang.reflect.*;
43-
import java.net.MalformedURLException;
43+
import java.util.Map;
4444
import java.util.concurrent.atomic.AtomicInteger;
4545

4646
/**
@@ -63,8 +63,10 @@ public class DataChunk implements Chunk {
6363
private byte[] serializedId;
6464
private Object entity;
6565
private Object undoentity;
66+
private Map<Integer, DataChunk> ics = new HashMap<>();
6667
private DataChunk source;
6768
private UndoChunk uc;
69+
private FrameData uframe;
6870
private boolean terminate;
6971
private final CustomSerializer sr = new CustomSerializer();
7072

@@ -175,6 +177,10 @@ public Table getT() {
175177
return t;
176178
}
177179

180+
protected void setT(Table t) {
181+
this.t = t;
182+
}
183+
178184
public Comparable getId (Field idfield, Session s) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
179185
if (serializedId==null) {
180186
if (entity==null) {
@@ -275,7 +281,7 @@ public DataChunk () {
275281
}
276282

277283
//for index implementation
278-
public DataChunk (ValueSet vs, Session s, RowId r, Table t) throws ClassNotFoundException, IllegalAccessException, UnsupportedEncodingException, InternalException, MalformedURLException, InstantiationException {
284+
public DataChunk (ValueSet vs, Session s, RowId r, Table t) throws ClassNotFoundException, IllegalAccessException, UnsupportedEncodingException, InternalException, InstantiationException {
279285
this.state = INIT_STATE;
280286
this.t = t;
281287
final ByteString res = new ByteString();
@@ -325,18 +331,18 @@ public DataChunk (ValueSet vs, Session s, Table t) {
325331
}
326332

327333
//serializer INSERT ONLY!!! (with generate Id value)
328-
public DataChunk (Object o, Session s) throws IOException, InvocationTargetException, NoSuchMethodException, InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException {
334+
public DataChunk (Object o, Session s) {
329335
this(o, s, null);
330336
}
331337

332338
//serializer INSERT ONLY!!! (with generate Id value) - rowid for index chunk
333-
public DataChunk (Object o, Session s, RowId r) throws IOException, InvocationTargetException, NoSuchMethodException, InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException {
339+
public DataChunk (Object o, Session s, RowId r) {
334340
this.entity = o;
335341
this.state = NORMAL_STATE;
336342
this.header = new RowHeader(r, null, getChunk().length, false);
337343
}
338344

339-
public DataChunk (byte[] b, int file, long frame, int hsize, Table t, Class c) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InternalException, MalformedURLException {
345+
public DataChunk (byte[] b, int file, long frame, int hsize, Table t, Class c) {
340346
final ByteString bs = new ByteString(b);
341347
this.t = t;
342348
this.class_= c;
@@ -347,7 +353,7 @@ public DataChunk (byte[] b, int file, long frame, int hsize, Table t, Class c) t
347353
}
348354

349355
//constructor for clone method - de-serialize chunk only without header
350-
public DataChunk (byte[] b, Table t, RowHeader h, DataChunk source) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InternalException, MalformedURLException {
356+
public DataChunk (byte[] b, Table t, RowHeader h, DataChunk source) {
351357
this.chunk = b;
352358
this.header = h;
353359
this.state = INIT_STATE;
@@ -484,6 +490,7 @@ public Object getEntity () {
484490
if (t.isIndex()) {
485491
final ResultSetEntity rsa = (ResultSetEntity) ((Table) this.t).getTableClass().getAnnotation(ResultSetEntity.class);
486492
final DataChunk dc = rsa == null ? (DataChunk) Instance.getInstance().getChunkByPointer(this.getHeader().getFramePtr(), this.getHeader().getFramePtrRowId().getRowPointer()) : this;
493+
dc.setIc(this);
487494
((IndexChunk)o).setDataChunk(dc);
488495
if (dc == null) {
489496
// todo during rframe.IndexFrame.init system directory not yet contains replicated FrameData objects
@@ -553,7 +560,8 @@ public void setFrameData(FrameData b) {
553560
entity = b;
554561
}
555562

556-
public Object getUndoEntity () { //throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
563+
@Deprecated
564+
public Object getUndoEntity () {
557565
if (undoentity==null) {
558566
try {
559567
final ClassLoader cl = this.getClass().getClassLoader();
@@ -575,7 +583,7 @@ public Object getUndoEntity () { //throws ClassNotFoundException, InstantiationE
575583
return undoentity;
576584
}
577585

578-
public void updateEntity(Object o) throws InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, MalformedURLException {
586+
public void updateEntity(Object o) throws InternalException, IllegalAccessException {
579587
final Object oo = this.getEntity();
580588
if (!oo.getClass().getName().equals(o.getClass().getName())) {
581589
throw new InternalException(); //classes of object do not match
@@ -610,9 +618,15 @@ protected void setNormalState() {
610618
}
611619

612620
//for UNDO processing
613-
public DataChunk cloneEntity(Session s) throws IOException, InvocationTargetException, NoSuchMethodException, InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException {
621+
public DataChunk cloneEntity(Session s) throws InternalException {
614622
final byte[] b = this.getChunk();
615-
return new DataChunk(b, this.t, new RowHeader(this.getHeader()), this);
623+
final DataChunk dc_ = new DataChunk(b, this.t, new RowHeader(this.getHeader()), this);
624+
final Object entity_ = this.getEntity();
625+
if (this.t == null) {
626+
dc_.t = Instance.getInstance().getTableByName(entity_.getClass().getName());
627+
}
628+
dc_.class_ = entity_.getClass();
629+
return dc_;
616630
}
617631

618632
public DataChunk restore(Frame b, Session s) throws Exception {
@@ -622,13 +636,11 @@ public DataChunk restore(Frame b, Session s) throws Exception {
622636
if (!(this.getHeader().getRowID().getFileId() == source.getHeader().getRowID().getFileId() && this.getHeader().getRowID().getFramePointer() == source.getHeader().getRowID().getFramePointer())) {
623637
final long srcFrameId = source.getHeader().getRowID().getFileId() + source.getHeader().getRowID().getFramePointer();
624638
final Frame srcFrame = Instance.getInstance().getFrameById(srcFrameId).getFrame();
625-
//final LLT llt = LLT.getLLT();
626-
// not need for use llt here
627-
srcFrame.removeChunk(source.getHeader().getRowID().getRowPointer(), null, true);
628-
//llt.commit();
639+
//todo ???
640+
srcFrame.removeChunk(source.getHeader().getRowID().getRowPointer(), null, false);
629641
}
630642
source.setHeader(this.getHeader());
631-
source.setEntity(this.getEntity(), false);
643+
source.updateEntity(this.getEntity());
632644
return source;
633645
}
634646

@@ -668,13 +680,15 @@ private synchronized DataChunk insertUC (FrameData cb, UndoChunk uc, Session s,
668680
final DataChunk dc = new DataChunk(uc, s);
669681
final int p = ub.getDataFrame().insertChunk(dc, s, true, llt);
670682
if (p == 0) {
671-
final Table t = Instance.getInstance().getTableByName("su.interference.persistent.UndoChunk");
683+
final Table t = Instance.getInstance().getTableByName(UndoChunk.class.getName());
672684
final FrameData nb = t.createNewFrame(ub, ub.getFile(), 0, 0, false, false, false, s, llt);
673685
s.getTransaction().setNewLB(ub, nb, false);
674686
nb.getDataFrame().insertChunk(dc, s, true, llt);
675-
s.getTransaction().storeFrame(cb, nb, 0, s, llt);
687+
dc.uframe = nb;
688+
//s.getTransaction().storeFrame(cb, nb, 0, s, llt);
676689
} else {
677-
s.getTransaction().storeFrame(cb, ub, 0, s, llt);
690+
dc.uframe = ub;
691+
//s.getTransaction().storeFrame(cb, ub, 0, s, llt);
678692
}
679693
ubw.release();
680694
return dc;
@@ -746,6 +760,10 @@ protected synchronized void undo(Session s, LLT llt) throws Exception {
746760
}
747761
}
748762

763+
public FrameData getUframe() {
764+
return uframe;
765+
}
766+
749767
public boolean isTerminate() {
750768
return terminate;
751769
}
@@ -754,6 +772,15 @@ public void setTerminate(boolean terminate) {
754772
this.terminate = terminate;
755773
}
756774

775+
public void setIc(DataChunk ic) {
776+
final Table t_ = ic.t == null ? Instance.getInstance().getTableByName(ic.getEntity().getClass().getName()) : ic.t;
777+
this.ics.put(t_.getObjectId(), ic);
778+
}
779+
780+
public Map<Integer, DataChunk> getIcs() {
781+
return this.ics;
782+
}
783+
757784
private byte[] getBytesFromHexString(String s) {
758785
byte b[] = new byte[s.length()/2];
759786
for (int i=0; i<s.length(); i+=2) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ this software and associated documentation files (the "Software"), to deal in
3232
import su.interference.serialize.ByteString;
3333

3434
import java.util.*;
35-
import java.io.IOException;
3635

3736
/**
3837
* @author Yuriy Glotanov
@@ -49,7 +48,7 @@ public DataFrame(FrameData bd, Table t) throws InternalException {
4948
super (bd, t);
5049
}
5150

52-
public DataFrame(int file, long pointer, int size, FrameData bd, Table t, Class c) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, InternalException {
51+
public DataFrame(int file, long pointer, int size, FrameData bd, Table t, Class c) throws Exception {
5352
super(null, file, pointer, size, bd, t, c);
5453

5554
int ptr = FRAME_HEADER_SIZE;

0 commit comments

Comments
 (0)