private static void generateEntityLockUpgradeThread(TransactionSubsystem txnProvider) { int i; Thread t; int childCount = MAX_NUM_OF_THREAD_IN_A_JOB; if (MAX_NUM_OF_THREAD_IN_A_JOB != 0 && childCount == 0) { childCount = 1; } TransactionContext txnContext = generateTxnContext(txnProvider); for (i = 0; i < childCount - 1; i++) { System.out.println( "Creating " + txnContext.getJobId() + "," + i + "th EntityLockUpgradeThread(false).."); t = new Thread( new LockRequestProducer( txnProvider.getLockManager(), txnContext, false, true, false)); t.start(); } System.out.println( "Creating " + txnContext.getJobId() + "," + i + "th EntityLockUpgradeThread(true).."); t = new Thread( new LockRequestProducer(txnProvider.getLockManager(), txnContext, false, true, true)); t.start(); }
private static void generateDatasetLockThread(TransactionSubsystem txnProvider) { Thread t; // int childCount = rand.nextInt(MAX_NUM_OF_THREAD_IN_A_JOB); // if (MAX_NUM_OF_THREAD_IN_A_JOB != 0 && childCount == 0) { // childCount = 1; // } int childCount = 1; TransactionContext txnContext = generateTxnContext(txnProvider); for (int i = 0; i < childCount; i++) { System.out.println("Creating " + txnContext.getJobId() + "," + i + "th DatasetLockThread.."); t = new Thread( new LockRequestProducer( txnProvider.getLockManager(), txnContext, true, false, false)); t.start(); } }
private void runEntityLockTask() { int i; byte lockMode; int lockCount; int upgradeCount; int releaseCount; boolean mayRelease = false; lockCount = 1 + rand.nextInt(20); if (isUpgradeThreadJob) { if (isUpgradeThread) { upgradeCount = 1; // rand.nextInt(4) + 1; if (upgradeCount > lockCount) { upgradeCount = lockCount; } } else { upgradeCount = 0; } lockMode = LockMode.S; } else { upgradeCount = 0; lockMode = (byte) (this.txnContext.getJobId().getId() % 2); } releaseCount = rand.nextInt(5) % 3 == 0 ? 1 : 0; // lock for (i = 0; i < lockCount; i++) { try { produceEntityLockRequest(lockMode); if (isDone) { return; } } catch (ACIDException e) { e.printStackTrace(); return; } } // upgrade for (i = 0; i < upgradeCount; i++) { try { produceEntityLockUpgradeRequest(); if (isDone) { return; } } catch (ACIDException e) { e.printStackTrace(); return; } } // unlock or releaseLocks if (releaseCount == 0) { // unlock for (i = 0; i < lockCount; i++) { try { produceEntityUnlockRequest(); if (isDone) { return; } } catch (ACIDException e) { e.printStackTrace(); return; } } } else { try { synchronized (txnContext) { if (txnContext.getTxnState() != ITransactionManager.ABORTED) { txnContext.setTxnState(ITransactionManager.ABORTED); mayRelease = true; } } if (mayRelease) { produceEntityReleaseLocksRequest(); } } catch (ACIDException e) { e.printStackTrace(); return; } } }