Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/su/interference/core/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public interface Chunk extends Comparable {
byte[] getChunk();
void setChunk(byte[] chunk);
int getBytesAmount();
ValueSet getDcs();
Object getEntity() throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException;
Object getUndoEntity() throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException;
void updateEntity(Object o) throws InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, MalformedURLException;
Expand Down
27 changes: 23 additions & 4 deletions src/main/java/su/interference/core/ChunkMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,26 @@ this software and associated documentation files (the "Software"), to deal in

public class ChunkMap {
private final ConcurrentHashMap<Integer, Chunk> hmap;
private final ConcurrentHashMap<ValueSet, Chunk> imap;
private final List<Chunk> list;
private volatile boolean sorted;

public ChunkMap() {
hmap = new ConcurrentHashMap<Integer, Chunk>();
list = new CopyOnWriteArrayList<Chunk>();
hmap = new ConcurrentHashMap<>();
imap = new ConcurrentHashMap<>();
list = new CopyOnWriteArrayList<>();
}

public void sort() {
Collections.sort(list);
sorted = true;
}

public void add(Chunk c) {
hmap.put(c.getHeader().getPtr(), c);
imap.put(c.getDcs(), c);
list.add(c);
sorted = false;
}

public List<Chunk> getChunks() {
Expand All @@ -63,10 +69,16 @@ public Chunk get(int i) {
return list.get(i);
}

public Chunk getByKey(ValueSet key) {
return imap.get(key);
}

public void removeByPtr(int i) {
final boolean x = list.remove(hmap.get(i));
final Object o = hmap.remove(i);
if (!x || o == null) {
final Chunk c = (Chunk)hmap.remove(i);
imap.remove(c.getDcs());
sorted = false;
if (!x || c == null) {
throw new RuntimeException("Internal error during remove object from frame");
}
}
Expand All @@ -75,6 +87,8 @@ public void remove(int i) {
final Chunk c = list.get(i);
list.remove(i);
hmap.remove(c.getHeader().getPtr());
imap.remove(c.getDcs());
sorted = false;
}

public int size() {
Expand All @@ -84,6 +98,11 @@ public int size() {
public void clear() {
hmap.clear();
list.clear();
imap.clear();
sorted = false;
}

public boolean isSorted() {
return sorted;
}
}
26 changes: 15 additions & 11 deletions src/main/java/su/interference/core/DataChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,25 @@ public class DataChunk implements Chunk {
private final CustomSerializer sr = new CustomSerializer();

//returns datacolumn set
public ValueSet getDcs() throws ClassNotFoundException, IllegalAccessException, InternalException, MalformedURLException {
public ValueSet getDcs() {
if (dcs==null) {
final Field[] f = t.getFields();
final Object[] vs = new Object[f.length];
for (int i=0; i<f.length; i++) {
final int m = f[i].getModifiers();
final Transient ta = f[i].getAnnotation(Transient.class);
if (ta==null) {
if (Modifier.isPrivate(m)) {
f[i].setAccessible(true);
try {
final Field[] f = this.t == null ? this.entity.getClass().getFields() : t.getFields();
final List<Object> vs = new ArrayList<>();
for (int i = 0; i < f.length; i++) {
final int m = f[i].getModifiers();
final Transient ta = f[i].getAnnotation(Transient.class);
if (ta == null) {
if (Modifier.isPrivate(m)) {
f[i].setAccessible(true);
}
vs.add(f[i].get(entity));
}
vs[i] = f[i].get(entity);
}
dcs = new ValueSet(vs.toArray(new Object[]{}));
} catch (Exception e) {
throw new RuntimeException(e);
}
dcs = new ValueSet(vs);
}
return dcs;
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/su/interference/core/DataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,18 @@ public interface DataObject {
long getIdValue(Session s, LLT llt) throws Exception;
long getIncValue(Session s, LLT llt) throws Exception;
void incFrameAmount ();
Class getSc();
Class getGenericClass();
boolean isNoTran() throws ClassNotFoundException, MalformedURLException;
boolean isIndex() throws ClassNotFoundException, MalformedURLException;
Object newInstance() throws IOException, InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException;
Object getInstance() throws IOException, InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException;
void usedSpace (FrameData bd, int used, boolean persist, Session s, LLT llt);
void addIndexValue (DataChunk dc) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException;
Field[] getColumns();
java.lang.reflect.Field[] getFields() throws ClassNotFoundException, InternalException, MalformedURLException;
java.lang.reflect.Field getIdField();
String getIdFieldType();
String getIdFieldGetter();
FrameData allocateFrame(DataFile df, DataObject t, Session s, LLT llt) throws Exception;

}
36 changes: 7 additions & 29 deletions src/main/java/su/interference/core/IndexElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@ this software and associated documentation files (the "Software"), to deal in
*/

public class IndexElement implements Comparable {
private IndexElementKey key;
private Object element;
final private IndexElementKey key;
private Object element;
final private boolean ex;

public IndexElement (IndexElementKey key, Object element) {
public IndexElement (IndexElementKey key, Object element, boolean ex) {
this.key = key;
this.element = element;
this.ex = ex;
}

public int compareTo(final Object obj) {
final IndexElement j = (IndexElement)obj;
final int res = this.getKey().compareTo(j.getKey());
final String clname = this.getElement().getClass().getSimpleName();
if (clname.equals("Integer")&&res==0) {
if (this.ex && res == 0) {
if ((Integer)this.getElement() < (Integer)j.getElement()) { return -1; } else if ((Integer)this.getElement() > (Integer)j.getElement()) { return 1; }
return 0;
}
Expand All @@ -55,10 +56,6 @@ public IndexElementKey getKey() {
return key;
}

public void setKey(IndexElementKey key) {
this.key = key;
}

public Object getElement() {
return element;
}
Expand All @@ -68,26 +65,7 @@ public void setElement(Object element) {
}

public String ElementToString () {
String clname = this.element.getClass().getSimpleName();
if (clname.equals("Integer")) {
return ""+ (Integer)this.element;
}
if (clname.equals("Long")) {
return ""+ (Long)this.element;
}
if (clname.equals("Float")) {
return ""+ (Float)this.element;
}
if (clname.equals("Double")) {
return ""+ (Double)this.element;
}
if (clname.equals("String")) {
return ""+ (String)this.element;
}
if (clname.equals("Date")) {
return ""+ (Date)this.element;
}
return "Datatype not recognized";
return "" + this.element;
}

}
9 changes: 7 additions & 2 deletions src/main/java/su/interference/core/IndexFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ private boolean isFill(DataChunk ie) {
}

public ValueSet sort() throws ClassNotFoundException, IllegalAccessException, InternalException, MalformedURLException {
this.data.sort();
if (!this.data.isSorted()) {
this.data.sort();
}
this.sorted = true;
if (this.data.size()>0) {
return ((DataChunk)this.data.get(this.data.size()-1)).getDcs();
Expand Down Expand Up @@ -255,13 +257,16 @@ public synchronized ArrayList<Long> getChildElementsPtr(ValueSet value) throws C
}

//return first element which found - for unique indexes
public DataChunk getObjectByKey(ValueSet key) throws ClassNotFoundException, IllegalAccessException, InternalException, MalformedURLException {
public DataChunk getObjectByKey(ValueSet key) {
/*
for (Chunk ie : this.data.getChunks()) {
if (((DataChunk)ie).getDcs().equals(key)) {
return (DataChunk)ie;
}
}
return null;
*/
return (DataChunk) this.data.getByKey(key);
}

//return all element which found - for non-unique indexes
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/su/interference/core/IndexList.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public synchronized void add (String id, Object element) {
}

public synchronized void add (IndexElementKey key, Object element) {
IndexElement e = new IndexElement(key, element);
IndexElement e = new IndexElement(key, element, false);

boolean cnue = true;
IndexElementList target = list.get(start);
Expand Down Expand Up @@ -92,9 +92,9 @@ public synchronized void add (IndexElementKey key, Object element) {
addElementList(newlist);
prevtg = target;
if (newlist.isDivided()) {
e = new IndexElement(newlist.getMaxValue(), new Integer(newlist.getPtr()));
e = new IndexElement(newlist.getMaxValue(), new Integer(newlist.getPtr()), true);
} else {
e = new IndexElement(prevtg.getMaxValue(), new Integer(prevtg.getPtr()));
e = new IndexElement(prevtg.getMaxValue(), new Integer(prevtg.getPtr()), true);
}
if (prevtg.getParent()==0) { //add parent ElementList - always type 2 (node)
target = new IndexElementList(2);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/su/interference/core/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ private static void registerMetrics() throws Exception {
Metrics.register(Metrics.TIMER, "executeQuery");
Metrics.register(Metrics.TIMER, "deallocateQuery");
Metrics.register(Metrics.TIMER, "syncFrames");
Metrics.register(Metrics.TIMER, "persistGetChunk");
Metrics.register(Metrics.TIMER, "persistInsertChunk");
Metrics.register(Metrics.TIMER, "persistInsertIndex");
Metrics.register(Metrics.HISTOGRAM, "recordRCount");
Metrics.register(Metrics.HISTOGRAM, "recordLCount");
Metrics.register(Metrics.HISTOGRAM, "syncQueue");
Expand Down
31 changes: 9 additions & 22 deletions src/main/java/su/interference/core/ValueSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ this software and associated documentation files (the "Software"), to deal in

package su.interference.core;

import java.util.Date;

/**
* @author Yuriy Glotanov
* @since 1.0
Expand Down Expand Up @@ -57,26 +55,9 @@ public int compare (Object obj, int thr) {
final ValueSet j = (ValueSet)obj;

for (int i=0; i<vs.length; i++) {
String clname = vs[i].getClass().getSimpleName();
if (clname.equals("Integer")) {
if ((Integer)this.vs[i] < (Integer)j.getValueSet()[i]) { return -1; } else if ((Integer)this.vs[i] > (Integer)j.getValueSet()[i]) { return 1; }
}
if (clname.equals("Long")) {
if ((Long)this.vs[i] < (Long)j.getValueSet()[i]) { return -1; } else if ((Long)this.vs[i] > (Long)j.getValueSet()[i]) { return 1; }
}
if (clname.equals("Float")) {
if ((Float)this.vs[i] < (Float)j.getValueSet()[i]) { return -1; } else if ((Float)this.vs[i] > (Float)j.getValueSet()[i]) { return 1; }
}
if (clname.equals("Double")) {
if ((Double)this.vs[i] < (Double)j.getValueSet()[i]) { return -1; } else if ((Double)this.vs[i] > (Double)j.getValueSet()[i]) { return 1; }
}
if (clname.equals("String")) {
int c = (((String)this.vs[i]).compareTo((String)j.getValueSet()[i]));
if (c!=0) { return c; }
}
if (clname.equals("Date")) {
int c = (((Date)this.vs[i]).compareTo((Date)j.getValueSet()[i]));
if (c!=0) { return c; }
final int ct = ((Comparable)this.vs[i]).compareTo(j.getValueSet()[i]);
if (ct != 0) {
return ct;
}
if (i==thr-1) {
break;
Expand All @@ -90,5 +71,11 @@ public boolean equals (Object obj) {
return this.compareTo(j)==0?true:false;
}

public int hashCode() {
int hashCode = 1;
for (Object o : vs)
hashCode = 31 * hashCode + (o == null ? 0 : o.hashCode());
return hashCode;
}

}
Loading