mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
made output spreadsheet formattable
This commit is contained in:
@@ -21,19 +21,21 @@ public class DirtyReadIntolerant {
|
||||
|
||||
public static void main(String... ignored) throws Exception {
|
||||
|
||||
System.out.println("DirtyReadOffender,chrAig,DirtyReadVictim");
|
||||
|
||||
ChronicleMap<String, BondVOInterface> operand =
|
||||
DirtyReadIntolerant.acquireChronicleMapOperand(
|
||||
"C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP"
|
||||
"C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP"
|
||||
);
|
||||
ChronicleMap<Thread,Integer> operator =
|
||||
ChronicleMap<String, Integer> operator =
|
||||
DirtyReadIntolerant.acquireChronicleMapOperator(
|
||||
"C:\\Users\\buddy\\dev\\shm\\OPERATOR_CHRONICLE_MAP"
|
||||
"C:\\Users\\buddy\\dev\\shm\\OPERATOR_CHRONICLE_MAP"
|
||||
);
|
||||
ChronicleAcidIsolationGovernor chrAig = new ChronicleAcidIsolationGovernor();
|
||||
chrAig.setCompositeChronicleMap(operand);
|
||||
chrAig.setAutoCommit(Boolean.FALSE);
|
||||
chrAig.setTransactionIsolationMap(operator);
|
||||
System.out.println("Established chrAig");
|
||||
System.out.println(",Established chrAig,");
|
||||
|
||||
DirtyReadOffender offender = new DirtyReadOffender();
|
||||
offender.setCraig(chrAig);
|
||||
@@ -47,10 +49,8 @@ public class DirtyReadIntolerant {
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
static ChronicleMap<String, BondVOInterface> acquireChronicleMapOperand(String operand)
|
||||
throws IOException {
|
||||
throws IOException {
|
||||
// ensure thread ids are globally unique.
|
||||
AffinitySupport.setThreadId();
|
||||
return ChronicleMapBuilder.of(String.class, BondVOInterface.class)
|
||||
@@ -59,17 +59,17 @@ public class DirtyReadIntolerant {
|
||||
.createPersistedTo(
|
||||
new File(
|
||||
operand
|
||||
// "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP"
|
||||
// "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP"
|
||||
)
|
||||
);
|
||||
//.create();
|
||||
}
|
||||
|
||||
static ChronicleMap<Thread, Integer> acquireChronicleMapOperator(String operator)
|
||||
throws IOException {
|
||||
static ChronicleMap<String, Integer> acquireChronicleMapOperator(String operator)
|
||||
throws IOException {
|
||||
// ensure thread ids are globally unique.
|
||||
AffinitySupport.setThreadId();
|
||||
return ChronicleMapBuilder.of(Thread.class, Integer.class)
|
||||
return ChronicleMapBuilder.of(String.class, Integer.class)
|
||||
.entries(16)
|
||||
.averageKeySize("123456789".length())
|
||||
.createPersistedTo(
|
||||
@@ -80,44 +80,4 @@ public class DirtyReadIntolerant {
|
||||
);
|
||||
//.create();
|
||||
}
|
||||
|
||||
// static void offendPrice(ChronicleMap<String, BondVOInterface> chm, double _coupon,
|
||||
// double _coupon2, boolean setFirst, final String desc) {
|
||||
// BondVOInterface bond1 = newNativeReference(BondVOInterface.class);
|
||||
// BondVOInterface bond2 = newNativeReference(BondVOInterface.class);
|
||||
// BondVOInterface bond3 = newNativeReference(BondVOInterface.class);
|
||||
// BondVOInterface bond4 = newNativeReference(BondVOInterface.class);
|
||||
//
|
||||
// chm.acquireUsing("369604101", bond1);
|
||||
// chm.acquireUsing("369604102", bond2);
|
||||
// chm.acquireUsing("369604103", bond3);
|
||||
// chm.acquireUsing("369604104", bond4);
|
||||
// System.out.printf(
|
||||
// "\n\n" + desc +
|
||||
// ": Timing 1 x off-heap operations on /dev/shm/RDR_DIM_Mock\n"
|
||||
// );
|
||||
// if (setFirst) {
|
||||
// bond1.setCoupon(_coupon);
|
||||
// bond2.setCoupon(_coupon);
|
||||
// bond3.setCoupon(_coupon);
|
||||
// bond4.setCoupon(_coupon);
|
||||
// }
|
||||
// int timeToCallNanoTime = 30;
|
||||
// int runs = 1000000;
|
||||
// long[] timings = new long[runs];
|
||||
// for (int j = 0; j < 10; j++) {
|
||||
// for (int i = 0; i < runs; i++) {
|
||||
// long _start = System.nanoTime(); //
|
||||
// while (!bond1.compareAndSwapCoupon(_coupon, _coupon2)) ;
|
||||
// //while (!bond2.compareAndSwapCoupon(_coupon, _coupon2)) ;
|
||||
// //while (!bond3.compareAndSwapCoupon(_coupon, _coupon2)) ;
|
||||
// //while (!bond4.compareAndSwapCoupon(_coupon, _coupon2)) ;
|
||||
//
|
||||
// timings[i] = (System.nanoTime() - _start - timeToCallNanoTime) / 4;
|
||||
// }
|
||||
// Arrays.sort(timings);
|
||||
// System.out.printf("#%d: compareAndSwapCoupon() 50/90/99%%tile was %,d / %,d / %,d%n",
|
||||
// j, timings[runs / 2], timings[runs * 9 / 10], timings[runs * 99 / 100]);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -37,15 +37,22 @@ public class DirtyReadOffender implements Runnable {
|
||||
chrAig.setTransactionIsolation(ChronicleAcidIsolation.LOWEST_LATENCY);
|
||||
bond.setCoupon(4.55);
|
||||
chrAig.put("369604101", bond);
|
||||
System.out.println(
|
||||
" @t=" + System.currentTimeMillis() +
|
||||
" DirtyReadOffender calling chrAig.commit() ---------- "
|
||||
);
|
||||
sc.nextLine();
|
||||
chrAig.commit();
|
||||
|
||||
System.out.println(
|
||||
" @t=" + System.currentTimeMillis() +
|
||||
" DirtyReadOffender COMMITTED ---------- "
|
||||
" DirtyReadOffender sleeping 1 minute. ---------- "
|
||||
);
|
||||
Thread.sleep(60*1_000);
|
||||
System.out.println(
|
||||
" @t=" + System.currentTimeMillis() +
|
||||
" DirtyReadOffender calling chrAig.rollback() ---------- "
|
||||
);
|
||||
//sc.nextLine();
|
||||
//chrAig.commit();
|
||||
chrAig.rollback();
|
||||
System.out.println(
|
||||
" @t=" + System.currentTimeMillis() +
|
||||
" DirtyReadOffender ROLLED BACK ---------- "
|
||||
);
|
||||
} catch (Exception throwables) {
|
||||
try {
|
||||
|
||||
@@ -28,37 +28,41 @@ public class DirtyReadVictim implements Runnable {
|
||||
public void run() {
|
||||
Scanner sc= new Scanner(System.in);
|
||||
try {
|
||||
System.out.println(
|
||||
" ,,---------- @t="+System.currentTimeMillis()+
|
||||
" DirtyReadVictim sleeping 10 seconds"
|
||||
);
|
||||
Thread.sleep(10_000);
|
||||
BondVOInterface bond = newNativeReference(BondVOInterface.class);
|
||||
chrAig.getCompositeChronicleMap().acquireUsing("369604101", bond);
|
||||
System.out.println(
|
||||
" ---------- @t="+System.currentTimeMillis()+
|
||||
" DirtyReadVictim calling m.get('369604101')"
|
||||
" ,,---------- @t="+System.currentTimeMillis()+
|
||||
" DirtyReadVictim calling chrAig.get('369604101')"
|
||||
);
|
||||
//sc.nextLine();
|
||||
chrAig.setTransactionIsolation(ChronicleAcidIsolation.DIRTY_READ_INTOLERANT);
|
||||
bond = chrAig.getCompositeChronicleMap().get("369604101");
|
||||
bond = chrAig.get("369604101");
|
||||
Double coupon = bond.getCoupon();
|
||||
System.out.println(
|
||||
" ---------- @t="+System.currentTimeMillis()+
|
||||
" DirtyReadVictim calling chrAig.commmit()"
|
||||
" ,,---------- @t="+System.currentTimeMillis()+
|
||||
" DirtyReadVictim got() coupon="+coupon+" calling chrAig.commmit()"
|
||||
);
|
||||
//sc.nextLine();
|
||||
chrAig.commit();
|
||||
System.out.println(
|
||||
" ---------- @t="+System.currentTimeMillis()+
|
||||
" ,,---------- @t="+System.currentTimeMillis()+
|
||||
" DirtyReadVictim COMMITTED"
|
||||
);
|
||||
} catch (Exception throwables) {
|
||||
try {
|
||||
System.out.println(
|
||||
" ---------- @t="+System.currentTimeMillis()+
|
||||
" ,,---------- @t="+System.currentTimeMillis()+
|
||||
" DirtyReadVictim calling chrAig.rollback()"
|
||||
);
|
||||
sc.nextLine();
|
||||
//sc.nextLine();
|
||||
chrAig.rollback();
|
||||
System.out.println(
|
||||
" ---------- @t="+System.currentTimeMillis()+
|
||||
" ,,---------- @t="+System.currentTimeMillis()+
|
||||
" DirtyReadVictim ROLLED BACK"
|
||||
);
|
||||
} catch (SQLException e) {
|
||||
|
||||
Reference in New Issue
Block a user