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
7 changes: 4 additions & 3 deletions src/main/java/su/interference/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,19 @@ public class Config {
public final String CODEPAGE;
public final String DATEFORMAT;
public final int TEST_DISTRIBUTE_MODE = 1;
public final int CHECK_AVAIL_FRAME_TIMEOUT = 200;
public final int CHECK_AVAIL_FRAME_TIMEOUT = 3000;
// transport
public final int REMOTE_SYNC_TIMEOUT = 60000;
public final int READ_BUFFER_SIZE = 33554432;
public final int WRITE_BUFFER_SIZE = 33554432;
// cleanup
public final int TRANS_CLEANUP_TIMEOUT = 5000;
public final int CLEANUP_ENABLE = 0;
public final int CLEANUP_TIMEOUT = 3000;
public final int CLEANUP_PROTECTION_THR = 1000;
public final int IX_CLEANUP_PROTECTION_THR = 5000;
public final int IX_CLEANUP_PROTECTION_THR = 2000;
public final int HEAP_USE_THR_DATA = 60;
public final int HEAP_USE_THR_INDX = 80;
public final int HEAP_USE_THR_INDX = 70;
public final int HEAP_USE_THR_TEMP = 40;
public final int HEAP_USE_THR_UNDO = 50;

Expand Down
50 changes: 26 additions & 24 deletions src/main/java/su/interference/core/DataChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class DataChunk implements Chunk {
private Comparable id;
private byte[] serializedId;
private volatile Object entity;
private volatile ValueSet dcs;
private Object undoentity;
private Map<Integer, DataChunk> ics = new HashMap<>();
private UndoChunk uc;
Expand All @@ -73,10 +74,21 @@ public class DataChunk implements Chunk {

//returns datacolumn set
public ValueSet getDcs() {
if (t.isIndex() && dcs != null) {
return dcs;
}
if (state == INIT_STATE) {
if (t.isIndex()) {
dcs = getDcsFromBytes();
return dcs;
}
return getDcsFromBytes();
}
if (state == NORMAL_STATE) {
if (t.isIndex()) {
dcs = getDcsFromEntity();
return dcs;
}
return getDcsFromEntity();
}
return null;
Expand Down Expand Up @@ -176,6 +188,7 @@ public Table getT() {
return t;
}

@Deprecated
public Comparable getId (Field idfield, Session s) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
if (serializedId==null) {
if (entity==null) {
Expand Down Expand Up @@ -220,30 +233,19 @@ public byte[] getSerializedId (Session s) throws InvocationTargetException, NoSu
if (entity==null) {
getEntity();
}
Class c = entity.getClass();
final TransEntity ta = (TransEntity)c.getAnnotation(TransEntity.class);
final SystemEntity sa = (SystemEntity)c.getAnnotation(SystemEntity.class);
if (ta!=null) {
//for Transactional Wrapper Entity we must get superclass (original Entity class)
c = c.getSuperclass();
}
Field[] f = c.getDeclaredFields();
for (int i=0; i<f.length; i++) {
final Id a = f[i].getAnnotation(Id.class);
if (a!=null) {
if (sa!=null) {
Method z = c.getMethod("get"+f[i].getName().substring(0,1).toUpperCase()+f[i].getName().substring(1,f[i].getName().length()), null);
Object v = z.invoke(entity, null);
id = (Comparable) v;
serializedId = sr.serialize(f[i].getType().getName(), v);
} else {
Method z = c.getMethod("get"+f[i].getName().substring(0,1).toUpperCase()+f[i].getName().substring(1,f[i].getName().length()), new Class<?>[]{Session.class});
Object v = z.invoke(entity, new Object[]{s});
id = (Comparable) v;
serializedId = sr.serialize(f[i].getType().getName(), v);
}
final Field idf = t.getIdField();
if (idf != null) {
if (t.isNoTran()) {
final Method z = t.getIdmethod();
id = (Comparable) z.invoke(entity, null);
serializedId = sr.serialize(idf.getType().getName(), id);
} else {
final Method z = t.getIdmethod_();
id = (Comparable) z.invoke(entity, new Object[]{s});
serializedId = sr.serialize(idf.getType().getName(), id);
}
}

}
return serializedId;
}
Expand Down Expand Up @@ -693,8 +695,8 @@ private synchronized DataChunk insertUC (UndoChunk uc, Session s, LLT llt) throw
final int p = ub.getDataFrame().insertChunk(dc, s, true, llt);
if (p == 0) {
final Table t = Instance.getInstance().getTableByName(UndoChunk.class.getName());
final FrameData nb = t.createNewFrame(ub, ub.getFile(), 0, 0, false, false, false, s, llt);
s.getTransaction().setNewLB(ub, nb, false);
final FrameData nb = t.createNewFrame(ub, ubw, ub.getFile(), 0, 0, false, false, false, s, llt);
s.getTransaction().setNewLB(ub, nb);
nb.getDataFrame().insertChunk(dc, s, true, llt);
dc.uframe = nb;
} else {
Expand Down
42 changes: 13 additions & 29 deletions src/main/java/su/interference/core/DataChunkId.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
The MIT License (MIT)

Copyright (c) 2010-2019 head systems, ltd
Copyright (c) 2010-2020 head systems, ltd

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand All @@ -26,10 +26,9 @@ this software and associated documentation files (the "Software"), to deal in

import su.interference.persistent.Session;
import su.interference.exception.InternalException;
import su.interference.persistent.Table;
import su.interference.serialize.CustomSerializer;

import javax.persistence.Entity;
import javax.persistence.Id;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -63,32 +62,17 @@ private byte[] getBytes(Field f, Object o) throws IllegalAccessException, Unsupp

//serializer
@SuppressWarnings("unchecked")
public DataChunkId (Object o, Session s) throws IOException, InvocationTargetException, NoSuchMethodException, InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException {
Class c = o.getClass();
final SystemEntity sa = (SystemEntity)c.getAnnotation(SystemEntity.class);
final TransEntity ta = (TransEntity)c.getAnnotation(TransEntity.class);
Entity ea = (Entity)c.getAnnotation(Entity.class);
if (ta!=null) {
//for Transactional Wrapper Entity we must get superclass (original Entity class)
c = c.getSuperclass();
ea = (Entity)c.getAnnotation(Entity.class);
}
if (ea==null) {
throw new InternalException();
}
final Field[] f = c.getDeclaredFields();
for (int i=0; i<f.length; i++) {
final Id a = f[i].getAnnotation(Id.class);
if (a!=null) {
if (sa!=null) {
final Method z = c.getMethod("get"+f[i].getName().substring(0,1).toUpperCase()+f[i].getName().substring(1,f[i].getName().length()), null);
id = z.invoke(o, null);
idb = sr.serialize(f[i].getType().getName(), id);
} else {
final Method z = c.getMethod("get"+f[i].getName().substring(0,1).toUpperCase()+f[i].getName().substring(1,f[i].getName().length()), new Class<?>[]{Session.class});
id = z.invoke(o, new Object[]{s});
idb = sr.serialize(f[i].getType().getName(), id);
}
public DataChunkId (Object o, Table t, Session s) throws IOException, InvocationTargetException, InternalException, ClassNotFoundException, InstantiationException, IllegalAccessException {
final Field idf = t.getIdField();
if (idf != null) {
if (t.isNoTran()) {
final Method z = t.getIdmethod();
id = z.invoke(o, null);
idb = sr.serialize(idf.getType().getName(), id);
} else {
final Method z = t.getIdmethod_();
id = z.invoke(o, new Object[]{s});
idb = sr.serialize(idf.getType().getName(), id);
}
}
}
Expand Down
61 changes: 28 additions & 33 deletions src/main/java/su/interference/core/IndexFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,14 @@ public void cleanICEntities() {
}
}

public IndexFrame add (DataChunk e, Table t, Session s, LLT llt) throws Exception {
public synchronized IndexFrame add (DataChunk e, Table t, Session s, LLT llt) throws Exception {
if (this.isFill(e)) {

final int nfileId = t.getIndexFileId(this.getFrameData());
final IndexFrame res = t.createNewFrame(this.getFrameData(), nfileId, this.getType(), 0, false, false, false, s, llt).getIndexFrame();
final IndexFrame res = t.createNewFrame(this.getFrameData(), null, nfileId, this.getType(), 0, false, false, false, s, llt).getIndexFrame();
//paranoid fix
llt.add(res);
llt.add(this);
res.setParentF(this.getParentF());
res.setParentB(this.getParentB());
final ValueSet max = this.sort();
Expand All @@ -159,19 +162,18 @@ public IndexFrame add (DataChunk e, Table t, Session s, LLT llt) throws Exceptio
}
this.setHasMV(1);
}
res.setLcF(this.getLcF());
res.setLcB(this.getLcB());
this.setLcF(0);
this.setLcB(0);
res.setLcId(this.getLcId());
this.setLcId(0);
} else {
final int cmv = e.getDcs().compareTo(this.getFrameData().getMv());
//final int cmv = e.getDcs().compareTo(this.getFrameData().getMv());
final int cmv = e.getDcs().compareTo(max);
if (cmv > 0) {
throw new InternalException();
} else {
res.setDivided(1);
this.insertChunk(e, s, false, llt);
final ValueSet max2 = this.sort();
final ArrayList<DataChunk> nlist = new ArrayList<DataChunk>();
final ArrayList<DataChunk> nlist = new ArrayList<>();
ValueSet pkey = null;
boolean keyrpt = false;
boolean norpt = false;
Expand Down Expand Up @@ -222,7 +224,7 @@ private boolean isFill(DataChunk ie) {
return ie.getBytesAmount() > this.getFrameFree();
}

public ValueSet sort() throws InternalException {
public synchronized ValueSet sort() throws InternalException {
if (!this.data.isSorted()) {
this.data.sort();
}
Expand All @@ -236,7 +238,7 @@ public ValueSet sort() throws InternalException {

//accepted only to node element lists
//for unique indexes
public DataChunk getChildElementPtr(ValueSet value) throws InternalException {
public synchronized DataChunk getChildElementPtr(ValueSet value) throws InternalException {
//todo if (!this.sorted) {
this.sort();
//}
Expand Down Expand Up @@ -348,7 +350,7 @@ public synchronized int removeObjects(ValueSet key, Object o) throws InternalExc
return len;
}

public ValueSet getMaxValue() throws InternalException {
public synchronized ValueSet getMaxValue() throws InternalException {
this.sort();
return ((DataChunk)this.data.get(this.data.size()-1)).getDcs();
}
Expand All @@ -364,59 +366,52 @@ public HashMap<Long, Long> getAllocateMap() {
return imap;
}

public int getType() {
public synchronized int getType() {
return this.getRes01();
}

public void setType(int type) {
public synchronized void setType(int type) {
this.setRes01(type);
}

public int getHasMV() {
public synchronized int getHasMV() {
return this.getRes02();
}

public void setHasMV(int hasMV) {
public synchronized void setHasMV(int hasMV) {
this.setRes02(hasMV);
}

public int getDivided() {
public synchronized int getDivided() {
return this.getRes03();
}

public void setDivided(int divided) {
public synchronized void setDivided(int divided) {
this.setRes03(divided);
}

public int getParentF() {
public synchronized int getParentF() {
return this.getRes04();
}

public void setParentF(int parentF) {
public synchronized void setParentF(int parentF) {
this.setRes04(parentF);
}

public long getParentB() {
public synchronized long getParentB() {
return this.getRes06();
}

public void setParentB(long parentB) {
public synchronized void setParentB(long parentB) {
this.setRes06(parentB);
}

public int getLcF() {
return this.getRes05();
public synchronized long getLcId() {
return this.getRes05() + this.getRes07();
}

public void setLcF(int lcF) {
this.setRes05(lcF);
}

public long getLcB() {
return this.getRes07();
}

public void setLcB(long lcB) {
this.setRes07(lcB);
public synchronized void setLcId(long lcId) {
this.setRes05((int)lcId%4096);
this.setRes07(lcId - lcId%4096);
}
}
9 changes: 4 additions & 5 deletions src/main/java/su/interference/core/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ this software and associated documentation files (the "Software"), to deal in
import su.interference.persistent.Process;
import su.interference.exception.*;

import java.beans.Transient;
import java.io.IOException;
import java.io.File;
import java.net.URL;
Expand All @@ -48,8 +47,8 @@ this software and associated documentation files (the "Software"), to deal in

public class Instance implements Interference {

public static final String RELEASE = "2020.2";
public static final int SYSTEM_VERSION = 20201205;
public static final String RELEASE = "2020.3";
public static final int SYSTEM_VERSION = 20201220;

public static final String DATA_FILE = "datafile";
public static final String INDX_FILE = "indxfile";
Expand Down Expand Up @@ -364,7 +363,7 @@ public void startupInstance(Session s) throws Exception, NoSuchMethodException,
if (ok) {

logger.info("interference is starting...");
Thread.currentThread().setName("interference-main-thread");
Thread.currentThread().setName("interference-main-thread-"+Thread.currentThread().getId());
Storage.getStorage().restoreJournal();
Storage.getStorage().openDataFiles();
initSystemTable();
Expand Down Expand Up @@ -433,7 +432,7 @@ private void checkInMemoryIndexes() {

private void checkOpenTransactions(Session s) {
for (Transaction t : getTransactions()) {
if (t.getCid() == 0 && t.getTransType() != Transaction.TRAN_THR) {
if (t.getCid() == 0 && t.getTransType() < Transaction.TRAN_THR) {
logger.info("Rollback incomplete transaction id="+t.getTransId());
t.retrieveTframes();
if (t.isLocal()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/su/interference/core/LLT.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static long getSyncId() {
return sync.get();
}

public static LLT getLLT() throws InterruptedException {
public static LLT getLLT() {
final long id_ = Thread.currentThread().getId();
if (pool.get(id_) != null) {
if (debug) {
Expand All @@ -82,7 +82,7 @@ public static LLT getLLT() throws InterruptedException {
return llt;
}

public static LLT getLLTAndLock() throws InterruptedException {
public static LLT getLLTAndLock() {
final long id_ = Thread.currentThread().getId();
if (pool.get(id_) != null) {
logger.error("an unexpected attempt to get llt with id = "+id_+" which already exists");
Expand Down
Loading