mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
OPTIMISTIC success and failure (dirty read)
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 141 KiB After Width: | Height: | Size: 142 KiB |
+13
@@ -1,6 +1,19 @@
|
||||
package net.openhft.chronicle.map.fromdocs.acid.revelations;
|
||||
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.fromdocs.BondVOInterface;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.locks.StampedLock;
|
||||
|
||||
import static net.openhft.chronicle.values.Values.newNativeReference;
|
||||
|
||||
/**
|
||||
* ben.cotton@rutgers.edu
|
||||
* <p>
|
||||
* A totally hacked impl, awaiting OpenHFT's official ChronicleStampedLock API
|
||||
*/
|
||||
public class ChronicleStampedLock extends StampedLock {
|
||||
|
||||
}
|
||||
|
||||
+8
-3
@@ -17,6 +17,7 @@ public class DirtyReadOffender {
|
||||
|
||||
try {
|
||||
String isoLevel = args[0];
|
||||
long sleepMock = Long.parseLong(args[1]);
|
||||
|
||||
ChronicleMap<String, BondVOInterface> chm =
|
||||
DirtyReadTolerance.offHeap(
|
||||
@@ -27,12 +28,14 @@ public class DirtyReadOffender {
|
||||
" DirtyReadOffender established chm "
|
||||
);
|
||||
BondVOInterface bond = newNativeReference(BondVOInterface.class);
|
||||
BondVOInterface cslMock = newNativeReference(BondVOInterface.class);
|
||||
chm.acquireUsing("369604101", bond);
|
||||
chm.acquireUsing("Offender ", cslMock); // mock ChronicleStampLock
|
||||
System.out.println(
|
||||
" @t=" + System.currentTimeMillis() +
|
||||
" DirtyReadOffender sleeping 10 seconds "
|
||||
" DirtyReadOffender sleeping "+sleepMock+" seconds "
|
||||
);
|
||||
Thread.sleep(10 * 1_000);
|
||||
Thread.sleep(sleepMock * 1_000);
|
||||
System.out.println(
|
||||
" @t=" + System.currentTimeMillis() +
|
||||
" DirtyReadOffender awakening "
|
||||
@@ -51,7 +54,7 @@ public class DirtyReadOffender {
|
||||
" DirtyReadOffender ACQUIRING offHeapLock.writeLock();"
|
||||
);
|
||||
ChronicleStampedLock offHeapLock = new ChronicleStampedLock();
|
||||
while ((stamp = offHeapLock.writeLock()) == 0) {
|
||||
while ((stamp = offHeapLock.tryWriteLock()) == 0) {
|
||||
;
|
||||
}
|
||||
System.out.println(
|
||||
@@ -67,6 +70,8 @@ public class DirtyReadOffender {
|
||||
);
|
||||
bond.setCoupon(newCoupon);
|
||||
chm.put("369604101", bond);
|
||||
cslMock.setEntryLockState(System.currentTimeMillis()); //mock'd
|
||||
chm.put("Offender ",cslMock); //mock'd
|
||||
System.out.println(
|
||||
" @t=" + System.currentTimeMillis() +
|
||||
" DirtyReadOffender coupon=["+
|
||||
|
||||
+13
-3
@@ -9,6 +9,9 @@ public class DirtyReadVictim {
|
||||
|
||||
public static void main(String args[]) {
|
||||
try {
|
||||
String isoLevel = args[0];
|
||||
long sleepMock = Long.parseLong(args[1]);
|
||||
|
||||
/**
|
||||
* ben.cotton@rutgers.edu START
|
||||
*/
|
||||
@@ -18,6 +21,7 @@ public class DirtyReadVictim {
|
||||
);
|
||||
Double coupon = 0.00;
|
||||
BondVOInterface bond = newNativeReference(BondVOInterface.class);
|
||||
BondVOInterface cslMock = newNativeReference(BondVOInterface.class); //mock'd
|
||||
long stamp = 0;
|
||||
System.out.println(
|
||||
" ,,@t=" + System.currentTimeMillis() +
|
||||
@@ -33,6 +37,7 @@ public class DirtyReadVictim {
|
||||
);
|
||||
try {
|
||||
chm.acquireUsing("369604101", bond);
|
||||
chm.acquireUsing("Offender ", cslMock); //mock'd
|
||||
System.out.println(
|
||||
" ,,@t=" + System.currentTimeMillis() +
|
||||
" DirtyReadVictim calling chm.get('369604101').getCoupon()"
|
||||
@@ -45,15 +50,20 @@ public class DirtyReadVictim {
|
||||
);
|
||||
System.out.println(
|
||||
" ,,@t=" + System.currentTimeMillis() +
|
||||
" DirtyReadVictim sleeping 60 seconds"
|
||||
" DirtyReadVictim sleeping "+sleepMock+" seconds"
|
||||
);
|
||||
Thread.sleep(60_000);
|
||||
cslMock.setEntryLockState(0);
|
||||
chm.put("Offender ", cslMock); //mock'd
|
||||
Thread.sleep(sleepMock * 1_000);
|
||||
System.out.println(
|
||||
" ,,@t=" + System.currentTimeMillis() +
|
||||
" DirtyReadVictim awakening"
|
||||
);
|
||||
//cslMock = (BondVOInterface) chm.get("Offender "); //mock'd
|
||||
cslMock = (BondVOInterface) chm.get("Offender "); //mock'd
|
||||
|
||||
} finally {
|
||||
if (offHeapLock.validate(stamp)) {
|
||||
if (offHeapLock.validate(stamp) && (cslMock.getEntryLockState() == 0)) {
|
||||
System.out.println(
|
||||
" ,,@t=" + System.currentTimeMillis() +
|
||||
" DirtyReadVictim OPTIMISTICALLY_READ coupon=" +
|
||||
|
||||
Reference in New Issue
Block a user