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

📄 t_recovery.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			p20.update(r20, rowP.getRow(), BS_COL_0);			p21.update(r21, rowP.getRow(), BS_COL_0);			p21.delete(r21, (LogicalUndo)null);			p20.unlatch();			p21.unlatch();			t2.resetContext();			REPORT("setup S100: container1 " + cid10 + " container2 " + cid11 + 				   " container3 " + cid20 + " container4 " + cid21);			register(key(100, 1), cid10);			register(key(100, 2), cid11);			register(key(100, 3), cid20);			register(key(100, 4), cid21);		}		finally		{			t_util.t_commit(t1);			t_util.t_close(t1);			t_util.t_commit(t2);			t_util.t_close(t2);		}	}	/* recover S100 */	protected void R100 () throws T_Fail, StandardException	{		long[] cid = new long[4];		cid[0] = find(key(100, 1));		if (cid[0] < 0)		{			REPORT("R100 not run");			return;		}					cid[1] = find(key(100, 2));		cid[2] = find(key(100, 3));		cid[3] = find(key(100, 4));		Transaction t = t_util.t_startTransaction();		try		{			ContainerHandle c;			Page page;			for (int i = 0; i < 4; i++)			{				c = t_util.t_openContainer(t, 0, cid[i], false);				page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);				if (i == 3)					t_util.t_checkRecordCount(page, 1, 0);				else					t_util.t_checkRecordCount(page, 1, 1);				t_util.t_checkFieldCount(page, 0, 2);				// each row has REC_005, REC_004				DataValueDescriptor column = new SQLChar();				t_util.t_checkFetchColFromSlot(page, 0, 0, column, false, REC_005);				t_util.t_checkFetchColFromSlot(page, 0, 1, column, false, REC_004);				page.unlatch();			}			PASS("R100 passed: container1 " + cid[0] + " container2 " + cid[1] + 				 " container3 " + cid[2] + " container4 " + cid[3]);		}		finally		{			t_util.t_commit(t);			t.close();		}	}	/*	 * test 101 - transaction with rollback to savepoint	 */	protected void S101() throws T_Fail, StandardException	{		Transaction t = t_util.t_startTransaction();		try		{			long cid = t_util.t_addContainer(t, 0);			t_util.t_commit(t);			ContainerHandle c = t_util.t_openContainer(t, 0, cid, true);			Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);			T_RawStoreRow row1 = new T_RawStoreRow(REC_001);			T_RawStoreRow row2 = new T_RawStoreRow(REC_002);			T_RawStoreRow row3 = new T_RawStoreRow(REC_003);			T_RawStoreRow row4 = new T_RawStoreRow(REC_004);			T_RawStoreRow row5 = new T_RawStoreRow(REC_005);					RecordHandle r0 = t_util.t_insertAtSlot(page, 0, row1);			if (t_util.t_insertAtSlot(page, 1, row2) == null)				return;			// test case not interesting			t_util.t_checkRecordCount(page, 2, 2);			t_util.t_checkFetchBySlot(page, 0, REC_001, false, false);			t_util.t_checkFetchBySlot(page, 1, REC_002, false, false);			/////////////////////////////////////////////////////			// At SP1, has 2 records of REC_001 and REC_002    //			/////////////////////////////////////////////////////			t.setSavePoint(SP1, null);			if (t_util.t_insertAtSlot(page, 2, row3) == null)				return;			// test case not interesting			page.purgeAtSlot(1, 1, true);			if (t_util.t_insertAtSlot(page, 1, row4) == null)				return;			t_util.t_checkRecordCount(page, 3, 3);			t_util.t_checkFetchBySlot(page, 0, REC_001, false, false);			t_util.t_checkFetchBySlot(page, 1, REC_004, false, false);			t_util.t_checkFetchBySlot(page, 2, REC_003, false, false);			////////////////////////////////////////////////////////////////			// At SP2, has 3 records of REC_001 and REC_004 and REC_003   //			////////////////////////////////////////////////////////////////			t.setSavePoint(SP2, null);			page.update(r0, row5.getRow(), (FormatableBitSet) null);			page.deleteAtSlot(1, true, (LogicalUndo)null);			t_util.t_checkRecordCount(page, 3, 2);			t_util.t_checkFetchBySlot(page, 0, REC_005, false, false);			t_util.t_checkFetchBySlot(page, 1, REC_004, true, false);			t_util.t_checkFetchBySlot(page, 2, REC_003, false, false);			page.unlatch();			t.rollbackToSavePoint(SP2, null);			page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);			t_util.t_checkRecordCount(page, 3, 3);			t_util.t_checkFetchBySlot(page, 0, REC_001, false, false);			t_util.t_checkFetchBySlot(page, 1, REC_004, false, false);			t_util.t_checkFetchBySlot(page, 2, REC_003, false, false);			// after a rollback to sp, do some more changes			page.update(r0, row5.getRow(), (FormatableBitSet) null);			page.deleteAtSlot(0, true, (LogicalUndo)null);			page.deleteAtSlot(1, true, (LogicalUndo)null);			page.deleteAtSlot(2, true, (LogicalUndo)null);			t_util.t_checkRecordCount(page, 3, 0);			t_util.t_checkFetchBySlot(page, 0, REC_005, true, false);			t_util.t_checkFetchBySlot(page, 1, REC_004, true, false);			t_util.t_checkFetchBySlot(page, 2, REC_003, true, false);			page.unlatch();			t.rollbackToSavePoint(SP1, null);			page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);			// note that an insert, when rolled back, becomes a deleted row but			// will not disappear.  A purge row will come back at the same slot			// and with the same record id.			t_util.t_checkRecordCount(page, 4, 2);			t_util.t_checkFetchBySlot(page, 0, REC_001, false, false);			t_util.t_checkFetchBySlot(page, 1, REC_002, false, false);			t_util.t_checkFetchBySlot(page, 2, REC_004, true, false);			t_util.t_checkFetchBySlot(page, 3, REC_003, true, false);			// add one more record to this			if (page.spaceForInsert())				t_util.t_insertAtSlot(page, 3, row5);			REPORT("setup S101: containerId " + cid + " recordCount " + page.recordCount());			register(key(101, 1), cid);			register(key(101, 2), page.recordCount());			page.unlatch();		}		finally		{			t_util.t_commit(t);			t.close();		}	}	/* recover test 101 */	protected void R101() throws T_Fail, StandardException	{		long cid = find(key(101, 1));		if (cid < 0)		{			REPORT("R101 not run");			return;		}		int recordCount = (int)find(key(101, 2));		Transaction t = t_util.t_startTransaction();		try		{			ContainerHandle c = t_util.t_openContainer(t, 0, cid, false);			Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);			t_util.t_checkRecordCount(page, recordCount, recordCount-2);			t_util.t_checkFetchBySlot(page, 0, REC_001, false, false);			t_util.t_checkFetchBySlot(page, 1, REC_002, false, false);			t_util.t_checkFetchBySlot(page, 2, REC_004, true, false);			if (recordCount == 5)			{				t_util.t_checkFetchBySlot(page, 3, REC_005, false, false);				t_util.t_checkFetchBySlot(page, 4, REC_003, true, false);			}			else				t_util.t_checkFetchBySlot(page, 3, REC_003, true, false);			page.unlatch();		}		finally		{			t_util.t_commit(t);			t.close();		}		PASS("R101: containerId " + cid + " recordCount " + recordCount);	}	/*	 * the following tests has recovery undo work, cannot test Rnnn during	 * setup because it hasn't been rolled back during setup yet.  Test the	 * state in Snnn.	 */	/*	 * test 200 - incomplete transaction	 */	protected void S200() throws T_Fail, StandardException	{		T_TWC ctx = t_util.t_startTransactionWithContext();		Transaction t = ctx.tran;		Page page = null;		try		{			long cid = t_util.t_addContainer(t, 0);			t_util.t_commit(t);			ContainerHandle c = t_util.t_openContainer(t, 0, cid, true);			ctx.switchTransactionContext();			page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);			T_RawStoreRow row1 = new T_RawStoreRow(REC_001);			int rowcount = 0;			while(page.spaceForInsert())			{				if (t_util.t_insertAtSlot(page, 0, row1) != null)					rowcount++;			}			t_util.t_checkRecordCount(page, rowcount, rowcount);			for (int i = 0; i < rowcount; i++)				t_util.t_checkFetchBySlot(page, i, REC_001, false, false);			REPORT("setup S200: containerId " + cid + " recordCount " + rowcount);			register(key(200, 1), cid);			register(key(200, 2), rowcount);		}		finally		{			if (page != null && page.isLatched())				page.unlatch();			ctx.resetContext();		}		// do not abort it at run time, abort it at recovery time		// t_util.t_abort(t);		// t.close();	}	/* recover test 200 */	protected void R200() throws T_Fail, StandardException	{		long cid = find(key(200, 1));		if (cid < 0)		{			REPORT("R200 not run");			return;		}		int recordCount = (int)find(key(200, 2));		Transaction t = t_util.t_startTransaction();		try		{			ContainerHandle c = t_util.t_openContainer(t, 0, cid, false);			Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);			// rollback of an insert is a deleted record			t_util.t_checkRecordCount(page, recordCount, 0);			for (int i = 0; i < recordCount; i++)				t_util.t_checkFetchBySlot(page, i, REC_001, true, false);			page.unlatch();			PASS("R200: containerId " + cid + " recordCount " + recordCount);		}		finally		{			t_util.t_commit(t);			t.close();		}	}	/*	 * test 201 - multiple intervening incomplete transaction	 */	protected void S201() throws T_Fail, StandardException	{		/* this is the same as S100 but left it at an incomplete state */		T_TWC t1 = t_util.t_startTransactionWithContext();		T_TWC t2 = t_util.t_startTransactionWithContext();		Page p10, p11, p20, p21;		p10 = p11 = p20 = p21 = null;		try		{			long cid10 = t_util.t_addContainer(t1,0);			long cid11 = t_util.t_addContainer(t1,0);			long cid20 = t_util.t_addContainer(t2, 0);			long cid21 = t_util.t_addContainer(t2, 0);			t_util.t_commit(t1);			t_util.t_commit(t2);			ContainerHandle c10 = t_util.t_openContainer(t1, 0, cid10, true);			ContainerHandle c11 = t_util.t_openContainer(t1, 0, cid11, true);			ContainerHandle c20 = t_util.t_openContainer(t2, 0, cid20, true);			ContainerHandle c21 = t_util.t_openContainer(t2, 0, cid21, true);			t1.switchTransactionContext();			p10 = t_util.t_getPage(c10, ContainerHandle.FIRST_PAGE_NUMBER);			p11 = t_util.t_getPage(c11, ContainerHandle.FIRST_PAGE_NUMBER);			t1.resetContext();			t2.switchTransactionContext();			p20 = t_util.t_getPage(c20, ContainerHandle.FIRST_PAGE_NUMBER);			p21 = t_util.t_getPage(c21, ContainerHandle.FIRST_PAGE_NUMBER);			// for each page, insert, update, updatefield, (some) delete			T_RawStoreRow row1 = new T_RawStoreRow(3);			row1.setColumn(0, REC_001);			row1.setColumn(1, REC_002);			row1.setColumn(2, (String) null);			T_RawStoreRow row2 = new T_RawStoreRow(2);			row2.setColumn(0, REC_003);			row2.setColumn(1, REC_004);			T_RawStoreRow rowP = new T_RawStoreRow(1);			rowP.setColumn(0, REC_005);			t2.resetContext();			t1.switchTransactionContext();			RecordHandle r10 = t_util.t_insertAtSlot(p10, 0, row1);			RecordHandle r11 = t_util.t_insertAtSlot(p11, 0, row1);			t1.resetContext();			t2.switchTransactionContext();			RecordHandle r20 = t_util.t_insertAtSlot(p20, 0, row1);			RecordHandle r21 = t_util.t_insertAtSlot(p21, 0, row1);			t2.resetContext();			t1.switchTransactionContext();			p10.update(r10, row2.getRow(), (FormatableBitSet) null);			p11.update(r11, row2.getRow(), (FormatableBitSet) null);			t1.resetContext();			t2.switchTransactionContext();			p20.update(r20, row2.getRow(), (FormatableBitSet) null);			p21.update(r21, row2.getRow(), (FormatableBitSet) null);			t2.resetContext();			t1.switchTransactionContext();			p10.update(r10, rowP.getRow(), BS_COL_0);			p11.update(r11, rowP.getRow(), BS_COL_0);			t1.resetContext();			t2.switchTransactionContext();			p20.update(r20, rowP.getRow(), BS_COL_0);			p21.update(r21, rowP.getRow(), BS_COL_0);			p21.delete(r21, (LogicalUndo)null);			t2.resetContext();			REPORT("setup S201: container1 " + cid10 + " container2 " + cid11 + 				   " container3 " + cid20 + " container4 " + cid21);			register(key(201, 1), cid10);			register(key(201, 2), cid11);			register(key(201, 3), cid20);			register(key(201, 4), cid21);		}		finally		{			if (p10 != null && p10.isLatched())				p10.unlatch();			if (p11 != null && p11.isLatched())				p11.unlatch();			if (p20 != null && p20.isLatched())				p20.unlatch();			if (p21 != null && p21.isLatched())				p21.unlatch();		}		// let recovery do the abort	}	/* recover test 201 */	protected void R201() throws T_Fail, StandardException	{		long[] cid = new long[4];		cid[0] = find(key(201, 1));		if (cid[0] < 0)		{			REPORT("R201 not run");			return;		}					cid[1] = find(key(201, 2));		cid[2] = find(key(201, 3));		cid[3] = find(key(201, 4));		Transaction t = t_util.t_startTransaction();		try		{			ContainerHandle c;			Page page;			for (int i = 0; i < 4; i++)			{				c = t_util.t_openContainer(t, 0, cid[i], false);				page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);				t_util.t_checkRecordCount(page, 1, 0);				// record has the following fields: REC_001, REC_002, null				DataValueDescriptor column = new SQLChar();				t_util.t_checkFetchColFromSlot(page, 0, 0, column, false, REC_001);				t_util.t_checkFetchColFromSlot(page, 0, 1, column, false, REC_002);				t_util.t_checkFetchColFromSlot(page, 0, 2, column, false, null);			}		}		finally		{			t_util.t_commit(t);				t.close();		}		PASS("R201 passed:  container1 " + cid[0] + " container2 " + cid[1] + 			   " container3 " + cid[2] + " container4 " + cid[3]);	}	/*	 * test 202 - incomplete transaction with rollback to savepoints	 */	protected void S202() throws T_Fail, StandardException	{		/* this is S101 which is left in an incomplete state */		T_TWC ctx = t_util.t_startTransactionWithContext();		Transaction t = ctx.tran;		Page page = null;		ctx.switchTransactionContext();		try		{			long cid = t_util.t_addContainer(t, 0);			t_util.t_commit(t);			ContainerHandle c = t_util.t_openContainer(t, 0, cid, true);			page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);			T_RawStoreRow row1 = new T_RawStoreRow(REC_001);			T_RawStoreRow row2 = new T_RawStoreRow(REC_002);			T_RawStoreRow row3 = new T_RawStoreRow(REC_003);			T_RawStoreRow row4 = new T_RawStoreRow(REC_004);			T_RawStoreRow row5 = new T_RawStoreRow(REC_005);			RecordHandle r0 = t_util.t_insertAtSlot(page, 0, row1);			if (t_util.t_insertAtSlot(page, 1, row2) == null)			{				page.unlatch();				t_util.t_abort(t);				t.close();				return;			// test case not interesting			}			/////////////////////////////////////////////////////			// At SP1, has 2 records of REC_001 and REC_002    //			/////////////////////////////////////////////////////			t.setSavePoin

⌨️ 快捷键说明

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