⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t_recoverfulllog.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		// 7) rollback SP2 on all transaction except the first		// 		// 8) update every rows		// 9) rollback t0 to SP1		//		// 10) leave transactions in the following state		// t0 - incomplete		// t1 - abort		// t2 - commit		// t3 - incomplete		// t4 - commit		// any other transactions - incomplete		//////////////////////// step 1 ////////////////////////		RecordHandle[][] rh = new RecordHandle[numtrans][numpages];		T_RawStoreRow row1 = new T_RawStoreRow(REC_001);		for (i = 0; i < numtrans; i++)			for (j = 0; j < numpages; j++)			{				t[i].switchTransactionContext();				rh[i][j] = t_util.t_insert(page[i][j], row1); 				t[i].resetContext();			}		t[0].setSavePoint(SP1, null);	// sp1		//////////////////////// step 2 ////////////////////////		T_RawStoreRow row2 = new T_RawStoreRow(REC_002);		for (i = 0; i < numtrans; i++)			for (j = 0; j < numpages; j++)			{				t[i].switchTransactionContext();				page[i][j].update(rh[i][j], row2.getRow(), (FormatableBitSet) null);				t[i].resetContext();			}		for (i = 1; i < numtrans; i++) // sp1		{			t[i].setSavePoint(SP1, null);		}		//////////////////////// step 3 ////////////////////////		T_RawStoreRow row3 = new T_RawStoreRow(REC_003);		for (i = 0; i < numtrans; i++)			for (j = 0; j < numpages; j++)				page[i][j].update(rh[i][j], row3.getRow(), (FormatableBitSet) null);		for (i = 0; i < numtrans; i++)			t[i].setSavePoint(SP2, null);	// sp2		//////////////////////// step 4 ////////////////////////		T_RawStoreRow row4 = new T_RawStoreRow(REC_004);		for (i = 0; i < numtrans; i++)		{			t[i].switchTransactionContext();			for (j = 0; j < numpages; j++)				page[i][j].update(rh[i][j], row4.getRow(), (FormatableBitSet) null);			t[i].resetContext();		}		//////////////////////// step 5 ////////////////////////		// unlatch relavante pages		t[0].switchTransactionContext();		for (j = 0; j < numpages; j++)			page[0][j].unlatch();		t[0].rollbackToSavePoint(SP1, null); // step 5		// relatch relavante pages		for (j = 0; j < numpages; j++)			page[0][j] = t_util.t_getPage(c[0], pagenum[0][j]);		t[0].resetContext();		//////////////////////// check ////////////////////////		for (i = 1; i < numtrans; i++)		{			t[i].switchTransactionContext();			for (j = 0; j < numpages; j++)				t_util.t_checkFetch(page[i][j], rh[i][j], REC_004);			t[i].resetContext();		}		t[0].switchTransactionContext();		for (j = 0; j < numpages; j++)			t_util.t_checkFetch(page[0][j], rh[0][j], REC_001);		t[0].resetContext();			//////////////////////// step 6 ////////////////////////		T_RawStoreRow row5 = new T_RawStoreRow(REC_005);		for (i = 0; i < numtrans; i++)		{			t[i].switchTransactionContext();			for (j = 0; j < numpages; j++)				page[i][j].update(rh[i][j], row5.getRow(), (FormatableBitSet) null);			t[i].resetContext();		}		//////////////////////// step 7 ////////////////////////		for (i = 1; i < numtrans; i++)		{			t[i].switchTransactionContext();			for (j = 0; j < numpages; j++)				page[i][j].unlatch();			t[i].rollbackToSavePoint(SP2, null);			for (j = 0; j < numpages; j++)				page[i][j] = t_util.t_getPage(c[i],pagenum[i][j]);			t[i].resetContext();		}		//////////////////////// check ////////////////////////		for (i = 1; i < numtrans; i++)		{			t[i].switchTransactionContext();			for (j = 0; j < numpages; j++)				t_util.t_checkFetch(page[i][j], rh[i][j], REC_003);			t[i].resetContext();		}		t[0].switchTransactionContext();		for (j = 0; j < numpages; j++)			t_util.t_checkFetch(page[0][j], rh[0][j], REC_005);		t[0].resetContext();		//////////////////////// step 8 ////////////////////////		T_RawStoreRow row6 = new T_RawStoreRow(REC_006);		for (i = 0; i < numtrans; i++)		{			t[i].switchTransactionContext();			for (j = 0; j < numpages; j++)				page[i][j].update(rh[i][j], row6.getRow(), (FormatableBitSet) null); // step 8			t[i].resetContext();		}		//////////////////////// step 9 ////////////////////////		// unlatch relavante pages		t[0].switchTransactionContext();		for (j = 0; j < numpages; j++)			page[0][j].unlatch();		t[0].rollbackToSavePoint(SP1, null); 		// relatch relevant pages		for (j = 0; j < numpages; j++)			page[0][j] = t_util.t_getPage(c[0], pagenum[0][j]);		t[0].resetContext();		//////////////////////// check ////////////////////////		for (i = 1; i < numtrans; i++)		{			t[i].switchTransactionContext();			for (j = 0; j < numpages; j++)			{				t_util.t_checkFetch(page[i][j], rh[i][j], REC_006);				t_util.t_checkRecordCount(page[i][j], 1, 1);			}			t[i].resetContext();		}		t[0].switchTransactionContext();		for (j = 0; j < numpages; j++)		{			t_util.t_checkFetch(page[0][j], rh[0][j], REC_001);			t_util.t_checkRecordCount(page[0][j], 1, 1);		}		t[0].resetContext();		//////////////////////// step 10 ////////////////////////		// unlatch all pages		for (i = 0; i < numtrans; i++)		{			t[i].switchTransactionContext();			for (j = 0; j < numpages; j++)				page[i][j].unlatch();			t[i].resetContext();		}		// t[0] incomplete		t_util.t_abort(t[1]);		t_util.t_commit(t[2]);		// t[3] incomplete		t_util.t_commit(t[4]);			// reopen containers 1, 2, and 4, where were closed when the			// transaction terminated.		c[1] = t_util.t_openContainer(t[1], 0, cid[1], false);		c[2] = t_util.t_openContainer(t[2], 0, cid[2], false);		c[4] = t_util.t_openContainer(t[4], 0, cid[4], false);		//////////////////////// check ////////////////////////		for (j = 0; j < numpages; j++)			{			t[0].switchTransactionContext();			t_util.t_checkFetch(c[0], rh[0][j], REC_001);			t[0].resetContext();			// t[1] has been aborted			// rh[1][j] (REC_001) is deleted			t[1].switchTransactionContext();			page[1][j] = t_util.t_getPage(c[1], pagenum[1][j]);			t_util.t_checkRecordCount(page[1][j], 1, 0);			t_util.t_checkFetchBySlot(page[1][j], Page.FIRST_SLOT_NUMBER,									  REC_001, true, false);			page[1][j].unlatch();			t[1].resetContext();			t[2].switchTransactionContext();			t_util.t_checkFetch(c[2], rh[2][j], REC_006);			t[2].resetContext();			t[3].switchTransactionContext();			t_util.t_checkFetch(c[3], rh[3][j], REC_006);			t[3].resetContext();			t[4].switchTransactionContext();			t_util.t_checkFetch(c[4], rh[4][j], REC_006);			t[4].resetContext();		}		for (i = 0; i < numtrans; i++)		{			register(key(testNumber, i+10), cid[i]);			String str = "container " + i + ":" + find(key(testNumber,i+10)) + " pages: ";			for (j = 0; j < numpages; j++)			{				str += pagenum[i][j] + " ";				register(key(testNumber, (i+1)*1000+j), pagenum[i][j]);			}			REPORT("\t" + str);		}		register(key(testNumber,1), numtrans); 		register(key(testNumber,2), numpages);		// let recovery try to roll back transactions t0, t3 	}	// fill up the log immediately	protected void fillUpLog() throws T_Fail, StandardException	{		SanityManager.DEBUG_SET(LogToFile.TEST_LOG_FULL);		System.getProperties().put(LogToFile.TEST_RECORD_TO_FILL_LOG, "1");		Transaction t = t_util.t_startTransaction();		try		{			long cid = t_util.t_addContainer(t, 0);		}		catch (StandardException se)		{			REPORT("_______________________________________________________");			REPORT("\n\tlog filled up as requested");			REPORT("_______________________________________________________");			return;		}		catch (NullPointerException npe)		{			// likely to be a null pointer exception being thrown because the			// system is forcibly shutdown due to corruption			REPORT("_______________________________________________________");			REPORT("\n\tlog filled up as requested");			REPORT("_______________________________________________________");			return;		}		throw T_Fail.testFailMsg("log should have filled but did not");	}	protected void logSwitchFail1() throws T_Fail, StandardException	{		SanityManager.DEBUG_SET(LogToFile.TEST_SWITCH_LOG_FAIL1);		factory.checkpoint(); // this should succeed, switch log is								   // optional before the end marker is written		SanityManager.DEBUG_CLEAR(LogToFile.TEST_SWITCH_LOG_FAIL1);	}		protected void logSwitchFail2() throws T_Fail, StandardException	{		SanityManager.DEBUG_SET(LogToFile.TEST_SWITCH_LOG_FAIL2);		int tries = 10;		try		{			// checkpoint should fail if it is attempted, after end marker is			// written, any error is fatal.  If another			// checkpoint is in progress, log some things and try again			// if we are extremely unlucky, it is possible that we will fail			// even after 10 tries.  It is better to keep trying than to			// disable the background checkpoint daemon because this is how the			// system actually runs in real life.  Do not manufacture a			// non-existant condition just to make the test pass.			for (int i = 10; i < 110 + tries; i++)			{				factory.checkpoint();				testBasic(i);			}		}		catch (StandardException se) {			REPORT("_______________________________________________________");			REPORT("\n\tlog switch failed as requested");			REPORT("_______________________________________________________");			return;		} catch (NullPointerException npe) {			REPORT("_______________________________________________________");			REPORT("\n\tlog switch failed as requested");			REPORT("_______________________________________________________");			return;		}		finally { SanityManager.DEBUG_CLEAR(LogToFile.TEST_SWITCH_LOG_FAIL2); }		throw T_Fail.testFailMsg("log switch should have failed but did not even after " + tries + " tries");	}	protected void checkRecovery() throws T_Fail, StandardException	{		// check for numTest=1, 2, 3				for(int numTest=1; numTest <= 3; numTest++)		{			int numtrans = (int)find(key(numTest, 1));			int numpages = (int)find(key(numTest, 2));			if (numtrans < 5 || numpages < 1)			{				REPORT("full log test " + numTest + " not run");				continue;			}			else			{				REPORT("Test recovery of test " + numTest);			}			Transaction t = t_util.t_startTransaction();			long[] cid = new long[numtrans];			ContainerHandle[] c = new ContainerHandle[numtrans];			long[][] pagenum = new long[numtrans][numpages];			Page[][] page = new Page[numtrans][numpages];			int i,j;			for	(i = 0; i < numtrans; i++)			{				cid[i] = find(key(numTest, i+10));				c[i] = t_util.t_openContainer(t, 0, cid[i], true);							for (j = 0; j < numpages; j++)				{					pagenum[i][j] = find(key(numTest, (i+1)*1000+j));					page[i][j] = t_util.t_getPage(c[i], pagenum[i][j]);				}			}			// transactions were left in the following state			// t0 - incomplete (rolled back)			// t1 - abort			// t2 - commit			// t3 - incomplete (rolled back)			// t4 - commit			// any other transactions - incomplete			//			// all the rolled back transaction should have a deleted REC_001			// all the committed transactions should have a REC_006			//			for (j = 0; j < numpages; j++)			{				t_util.t_checkRecordCount(page[0][j], 1, 0);				t_util.t_checkFetchBySlot(page[0][j], Page.FIRST_SLOT_NUMBER,										  REC_001, true, true);				t_util.t_checkRecordCount(page[1][j], 1, 0);				t_util.t_checkFetchBySlot(page[1][j], Page.FIRST_SLOT_NUMBER,										  REC_001, true, true);				t_util.t_checkRecordCount(page[2][j], 1, 1);				t_util.t_checkFetchBySlot(page[2][j], Page.FIRST_SLOT_NUMBER,										  REC_006, false, true);				t_util.t_checkRecordCount(page[3][j], 1, 0);				t_util.t_checkFetchBySlot(page[3][j], Page.FIRST_SLOT_NUMBER,										  REC_001, true, true);				t_util.t_checkRecordCount(page[4][j], 1, 1);				t_util.t_checkFetchBySlot(page[4][j], Page.FIRST_SLOT_NUMBER,										  REC_006, false, true);			}			for (i = 0; i < numtrans; i++)			{				String str = "container " + i + ":" + cid[i] + " pages: ";				for (j = 0; j < numpages; j++)					str += pagenum[i][j] + " ";				REPORT("\t" + str);			}			t_util.t_commit(t);			t.close();		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -