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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ Next, specify the necessary set of keys in the project
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Xms256m
-Xmn512m
-Xms1g
-Xmx4g
-XX:MaxMetaspaceSize=256m
-XX:ParallelGCThreads=8
Expand Down
28 changes: 18 additions & 10 deletions src/main/java/su/interference/core/DataChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ this software and associated documentation files (the "Software"), to deal in
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import static su.interference.persistent.Table.SYSTEM_PKG_PREFIX;

/**
* @author Yuriy Glotanov
* @since 1.0
Expand Down Expand Up @@ -355,7 +353,7 @@ public DataChunk (byte[] b, int file, long frame, int hsize, Table t, Class c)
this.chunk = bsc.getBytes();
}

//constructor for clone method - de-serialize chunk only without header
//constructor for clone method - de-serialize chunk only without header
public DataChunk (byte[] b, Table t, RowHeader h, DataChunk source) {
this.chunk = b;
this.header = h;
Expand Down Expand Up @@ -695,13 +693,13 @@ public DataChunk cloneEntity(Session s) throws InternalException {
return dc_;
}

public DataChunk restore(UndoChunk uc) throws Exception {
public DataChunk restore(UndoChunk uc, Session s, LLT llt) throws Exception {
// since we are using a dirty hack with changing the header in a source chunk for rollback his,
// we need to first delete the source chunk in the target block to prevent inconsistency within ChunkMap / chunk headers
if (!(this.getHeader().getRowID().getFileId() == uc.getFile() && this.getHeader().getRowID().getFramePointer() == uc.getFrame())) {
final long srcFrameId = uc.getFile() + uc.getFrame();
final Frame srcFrame = Instance.getInstance().getFrameById(srcFrameId).getFrame();
srcFrame.removeChunk(uc.getPtr(), null, true);
srcFrame.removeChunk(uc.getPtr(), llt, true);
}
return this;
}
Expand All @@ -727,7 +725,6 @@ public void setHeader(Header header) {
}

//lock mechanism

private synchronized DataChunk insertUC (UndoChunk uc, Session s, LLT llt) throws Exception {
final WaitFrame ubw = s.getTransaction().getAvailableFrame(uc, true);
final FrameData ub = ubw.getBd();
Expand Down Expand Up @@ -827,13 +824,12 @@ protected void cleanUpIcs() {
}

public DataChunk getIc(IndexDescript ids, Session s) throws Exception {
final Table ixt = Instance.getInstance().getTableByName(SYSTEM_PKG_PREFIX + ids.getName());
final DataChunk ic = this.ics.get(ixt.getObjectId());
final DataChunk ic = this.ics.get(ids.getIndex().getObjectId());
if (ic == null) {
final ValueSet key = this.getValueByColumnName(ids.getColumns(), s);
final DataChunk ic_ = ixt.getObjectByKey(key, s);
final DataChunk ic_ = ids.getIndex().getObjectByKey(key, s);
if (ic_ != null) {
this.ics.put(ixt.getObjectId(), ic_);
this.ics.put(ids.getIndex().getObjectId(), ic_);
return ic_;
} else {
throw new RuntimeException("Unable to retrieve index chunk: " + ids.getName());
Expand All @@ -842,6 +838,13 @@ public DataChunk getIc(IndexDescript ids, Session s) throws Exception {
return ic;
}

public DataChunk getIcForUpdate(IndexDescript ids, Session s, LLT llt) throws Exception {
final DataChunk ic = getIc(ids, s);
llt.add(ic.getFrameData().getFrame());
this.ics.remove(ids.getIndex().getObjectId());
return getIc(ids, s);
}

public ValueSet getValueByColumnName(String[] columns, Session s) throws Exception {
final Class c = this.getEntity().getClass();
final SystemEntity sa = (SystemEntity)c.getAnnotation(SystemEntity.class);
Expand Down Expand Up @@ -874,4 +877,9 @@ public synchronized String getHexByChunk() {
return sb.toString();
}

public FrameData getFrameData() {
final long ptr = this.getHeader().getRowID().getFileId() + this.getHeader().getRowID().getFramePointer();
return Instance.getInstance().getFrameById(ptr);
}

}
7 changes: 4 additions & 3 deletions src/main/java/su/interference/core/DataFrame.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-2021 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 Down Expand Up @@ -130,8 +130,9 @@ public DataFrame(byte[] b, int file, long pointer, Map<Long, Long> imap, Map<Lon
final UndoChunk uc = (UndoChunk)dc.getEntity();
final long allocId = imap.get(uc.getFile() + uc.getFrame());
final long bptr = hmap.get(allocId) != null ? hmap.get(allocId) : Instance.getInstance().getFrameByAllocId(allocId).getFrameId();
uc.setFile((int) bptr % 4096);
uc.setFrame(bptr - (bptr % 4096));
final long fbptr = bptr%4096;
uc.setFile((int) fbptr);
uc.setFrame(bptr - fbptr);
data.add(dc);
ptr = ptr + ROW_HEADER_SIZE + h.getLen();
} else {
Expand Down
28 changes: 16 additions & 12 deletions src/main/java/su/interference/core/Frame.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
The MIT License (MIT)

Copyright (c) 2010-2020 head systems, ltd
Copyright (c) 2010-2021 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 Down Expand Up @@ -123,14 +123,14 @@ public Frame(int file, long pointer, int size, Table t) {
}

public Frame(FrameData bd, Table t) {
this.file = bd.getFile();
this.pointer = bd.getPtr();
this.allocFile = (int)bd.getAllocId()%4096;
this.allocPointer = bd.getAllocId() - (bd.getAllocId()%4096);
this.rowCntr = 1;
this.frameData = bd;
this.dataObject = t;
this.frameSize = bd.getSize();
this.file = bd.getFile();
this.pointer = bd.getPtr();
this.allocFile = (int)bd.getAllocFile();
this.allocPointer = bd.getAllocPtr();
this.rowCntr = 1;
this.frameData = bd;
this.dataObject = t;
this.frameSize = bd.getSize();
if (this.frameSize<MIN_FRAME_SIZE) {
throw new InternalException();
}
Expand Down Expand Up @@ -486,6 +486,10 @@ public synchronized boolean checkChunk(int ptr) {
return data.getByPtr(ptr) != null;
}

public synchronized Chunk getChunkByPtr(int ptr) {
return data.getByPtr(ptr);
}

public synchronized void removeChunk (int ptr, LLT llt, boolean ignore) {
final long sync = LLT.getSyncId();
final Chunk chunk = data.getByPtr(ptr);
Expand Down Expand Up @@ -563,6 +567,8 @@ public ArrayList<Chunk> getFrameChunks (Session s) {

public synchronized void rollbackTransaction(Transaction tran, ArrayList<FrameData> ubs, Session s) throws Exception {
data.check();
final LLT llt = LLT.getLLT();
llt.add(this);

//rollback inserted records
final ArrayList<Integer> r = new ArrayList<>();
Expand All @@ -585,7 +591,7 @@ public synchronized void rollbackTransaction(Transaction tran, ArrayList<FrameDa
final int ucfile = uc.getDataChunk().getHeader().getRowID().getFileId();
final long frameptr = uc.getDataChunk().getHeader().getRowID().getFramePointer();
if (uc.getTransId() == tran.getTransId() && ucfile == this.file && frameptr == this.pointer) {
final DataChunk rc = uc.getDataChunk().restore(uc);
final DataChunk rc = uc.getDataChunk().restore(uc, s, llt);
if (this instanceof IndexFrame && rc.getExistingEntity() != null) {
((IndexChunk) rc.getExistingEntity()).setDataChunk(null);
}
Expand All @@ -594,8 +600,6 @@ public synchronized void rollbackTransaction(Transaction tran, ArrayList<FrameDa
}
}
}
final LLT llt = LLT.getLLT();
llt.add(this);
llt.commit();
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/su/interference/core/IndexChunk.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
The MIT License (MIT)

Copyright (c) 2010-2020 head systems, ltd
Copyright (c) 2010-2021 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 Down Expand Up @@ -32,6 +32,7 @@ this software and associated documentation files (the "Software"), to deal in
public interface IndexChunk {

DataChunk getDataChunk();
DataChunk getDataChunkForUpdate(LLT llt);
RowId getFramePtrRowId();
void setDataChunk(DataChunk c);
void setFramePtrRowId(RowId r);
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/su/interference/core/IndexDescript.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-2021 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 Down Expand Up @@ -31,18 +31,22 @@ this software and associated documentation files (the "Software"), to deal in
import java.util.ArrayList;
import java.lang.reflect.Field;

import static su.interference.persistent.Table.SYSTEM_PKG_PREFIX;

/**
* @author Yuriy Glotanov
* @since 1.0
*/

public class IndexDescript {

private final Table t;
private final String name;
private final Table t;
private final Table index;
private final String name;
private final String className;
private final String[] columns;
private final Field[] fields;
private final boolean unique;
private final Field[] fields;
private final boolean unique;

public IndexDescript(Table t, String name, String columns, boolean unique) throws InternalException {
this.t = t;
Expand All @@ -67,6 +71,8 @@ public IndexDescript(Table t, String name, String columns, boolean unique) throw
}

this.name = name;
this.className = SYSTEM_PKG_PREFIX + name;
this.index = Instance.getInstance().getTableByName(this.className);
this.columns = cs.toArray(new String[]{});
this.fields = fs.toArray(new Field[]{});
this.unique = unique;
Expand All @@ -88,6 +94,10 @@ public Table getT() {
return t;
}

public Table getIndex() {
return index;
}

public boolean isUnique() {
return unique;
}
Expand Down
34 changes: 23 additions & 11 deletions src/main/java/su/interference/core/IndexFrame.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
The MIT License (MIT)

Copyright (c) 2010-2020 head systems, ltd
Copyright (c) 2010-2021 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 Down Expand Up @@ -127,6 +127,8 @@ public IndexFrame(byte[] b, int file, long pointer, Map<Long, Long> imap, Map<Lo
@Override
public synchronized void rollbackTransaction(Transaction tran, ArrayList<FrameData> ubs, Session s) throws Exception {
data.check();
final LLT llt = LLT.getLLT();
llt.add(this);
final Map<Integer, DataChunk> ucmap = new HashMap();

if (ubs!=null) {
Expand All @@ -143,20 +145,29 @@ public synchronized void rollbackTransaction(Transaction tran, ArrayList<FrameDa
}

//rollback modified index records
final ArrayList<Integer> r = new ArrayList<>();
for (Chunk c : data.getChunks()) {
if (c.getHeader().getTran().getTransId() == tran.getTransId()) {
final DataChunk dc = ucmap.get(c.getHeader().getPtr());
final DataChunk dc_ = ((IndexChunk) c.getEntity()).getDataChunk().getUndoChunk().getDataChunk();
((DataChunk) c).setUndoChunk(null);
((DataChunk) c).cleanUpIcs();
((IndexChunk)c.getEntity()).setDataChunk(dc_);
((IndexChunk)c.getEntity()).setFramePtrRowId(dc_.getHeader().getRowID());
((DataChunk)c).getHeader().setFramePtr(dc_.getHeader().getRowID());
if (dc != null) {
final DataChunk dc_ = ((IndexChunk) c.getEntity()).getDataChunk().getUndoChunk().getDataChunk();
((DataChunk) c).setUndoChunk(null);
((DataChunk) c).cleanUpIcs();
((IndexChunk) c.getEntity()).setDataChunk(dc_);
((IndexChunk) c.getEntity()).setFramePtrRowId(dc_.getHeader().getRowID());
((DataChunk) c).getHeader().setFramePtr(dc_.getHeader().getRowID());
c.getHeader().setState(Header.RECORD_NORMAL_STATE);
} else {
if (c.getHeader().getState() == Header.RECORD_NORMAL_STATE) {
r.add(c.getHeader().getPtr());
}
}
}
}
for (Integer i : r) {
data.removeByPtr(i);
}

final LLT llt = LLT.getLLT();
llt.add(this);
llt.commit();
}

Expand Down Expand Up @@ -445,7 +456,8 @@ public synchronized long getLcId() {
}

public synchronized void setLcId(long lcId) {
this.setRes05((int)lcId%4096);
this.setRes07(lcId - lcId%4096);
final long lcF = lcId%4096;
this.setRes05((int)lcF);
this.setRes07(lcId - lcF);
}
}
Loading