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

📄 t_recovery.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			page = t_util.t_getPage(c, page3_Id);			t_util.t_checkRecordCount(page, 1, 1);			t_util.t_checkFetchBySlot(page, 0, REC_003, false, false);			page.unlatch();			page = t_util.t_getLastPage(c);			t_util.t_checkPageNumber(page, page3_Id);			page.unlatch();		}		finally		{			t_util.t_commit(t);			t.close();		}		PASS("R006: containerId " + cid );	}	/*	 * test 7 - page deallocation	 */	protected void S007() 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 page1 = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);			long p1 = page1.getPageNumber();			Page page2 = t_util.t_addPage(c);			long p2 = page2.getPageNumber();			Page page3 = t_util.t_addPage(c);			long p3 = page3.getPageNumber();			t_util.t_removePage(c, page2);			t_util.t_removePage(c, page3);			t_util.t_removePage(c, page1);			if (page1.isLatched())				throw T_Fail.testFailMsg("page is still latched after remove");			if (page2.isLatched())				throw T_Fail.testFailMsg("page is still latched after remove");			if (page3.isLatched())				throw T_Fail.testFailMsg("page is still latched after remove");			register(key(7,0), cid);			register(key(7,1), p1);			register(key(7,2), p2);			register(key(7,3), p3);			REPORT("setup S007: containerId " + cid);		}		finally		{			t_util.t_commit(t);			t.close();		}	}	/* recover test 7 */	protected void R007() throws T_Fail, StandardException	{		long cid = find(key(7,0));		if (cid < 0)		{			REPORT("R007 not run");			return;		}		long p1 = find(key(7,1));		long p2 = find(key(7,2));		long p3 = find(key(7,3));		Transaction t = t_util.t_startTransaction();		try		{			ContainerHandle c = t_util.t_openContainer(t, 0, cid, false);			Page p = c.getPage(p1);			if (p != null)				throw T_Fail.testFailMsg("got a deallcated page " + p1);			p = c.getPage(p2);			if (p != null)				throw T_Fail.testFailMsg("got a deallcated page " + p2);			p = c.getPage(p3);			if (p != null)				throw T_Fail.testFailMsg("got a deallcated page " + p3);			p = c.getPage(p3+1);			if (p != null)				throw T_Fail.testFailMsg("got a non-existant page " + p3+100);			p = c.getFirstPage();			if (p != null)				throw T_Fail.testFailMsg("got a non-existant first page ");			p = t_util.t_getLastPage(c);			if (p != null)				throw T_Fail.testFailMsg("got a non-existant last page ");			PASS("R007: containerId " + cid);		}		finally		{			t_util.t_commit(t);			t.close();		}	}	/*	 * test 8 - page deallocation with rollback	 */	protected void S008() 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 page1 = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);			long p1 = page1.getPageNumber();			Page page2 = t_util.t_addPage(c);			long p2 = page2.getPageNumber();			Page page3 = t_util.t_addPage(c);			long p3 = page3.getPageNumber();			Page page4 = t_util.t_addPage(c);			long p4 = page4.getPageNumber();			Page page5 = t_util.t_addPage(c);			long p5 = page5.getPageNumber();			t_util.t_removePage(c, page1);			t_util.t_removePage(c, page3);			t_util.t_removePage(c, page5);			t_util.t_commit(t);			c = t_util.t_openContainer(t, 0, cid, true);			page3 = t_util.t_getPage(c, p2);			page1 = t_util.t_getPage(c, p4);			// page 2 and page 4 are not removed			t_util.t_removePage(c, page2); 			t_util.t_removePage(c, page4);			register(key(8,0), cid);			register(key(8,1), p1);			register(key(8,2), p2);			register(key(8,3), p3);			register(key(8,4), p4);			register(key(8,5), p5);			REPORT("setup S008: containerId " + cid);		}		finally		{			t_util.t_abort(t);			t.close();		}	}	/* recover test 8 */	protected void R008() throws T_Fail, StandardException	{		long cid = find(key(8,0));		if (cid < 0)		{			REPORT("R008 not run");			return;		}		long p1 = find(key(8,1));		long p2 = find(key(8,2));		long p3 = find(key(8,3));		long p4 = find(key(8,4));		long p5 = find(key(8,5));		Transaction t = t_util.t_startTransaction();		try		{			ContainerHandle c = t_util.t_openContainer(t, 0, cid, false);		/* page 1, 3, 5 has been removed, page 2, 4 has not */			Page p = c.getPage(p1);			if (p != null)				throw T_Fail.testFailMsg("got a deallcated page " + p1);			p = t_util.t_getPage(c,p2);			p.unlatch();			p = c.getPage(p3);			if (p != null)				throw T_Fail.testFailMsg("got a deallcated page " + p3);			p = t_util.t_getPage(c,p4);			p.unlatch();			p = c.getPage(p5);			if (p != null)				throw T_Fail.testFailMsg("got a deallcated page " + p5);			p = c.getPage(p5+1);			if (p != null)				throw T_Fail.testFailMsg("got a non-existant page " + p5+1);		// make sure get first page skips over p1			p = c.getFirstPage();			if (p == null || p.getPageNumber() != p2)				throw T_Fail.testFailMsg("get first page failed");			p.unlatch();			// make sure get next page skips over p3			p = c.getNextPage(p2);				if (p == null || p.getPageNumber() != p4)				throw T_Fail.testFailMsg("get next page failed");			p.unlatch();			// make sure get next page skips over p5			p = c.getNextPage(p4);			if (p != null)			{				p.unlatch();				throw T_Fail.testFailMsg("get next page failed to terminate");			}			p = t_util.t_getLastPage(c);	// make sure it skips over p5			if (p == null || p.getPageNumber() != p4)				throw T_Fail.testFailMsg("getLastPage failed");			p.unlatch();			PASS("R008: containerId " + cid);		}		finally		{			t_util.t_commit(t);			t.close();		}	}	/*	 * test 9 - deallocation and reuse pag	 */	protected void S009() 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);			int numpages = 10;			Page[] origpage = new Page[numpages];			int[] origrid = new int[numpages];			long[] origpnum = new long[numpages];			T_RawStoreRow row1 = new T_RawStoreRow(REC_001);			for (int i = 0; i < numpages; i++)			{				if (i == 0)					origpage[i] = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);				else					origpage[i] = t_util.t_addPage(c);				origrid[i] = t_util.t_insert(origpage[i], row1).getId();				origpnum[i] = origpage[i].getPageNumber();				t_util.t_removePage(c, origpage[i]);			}			t_util.t_commit(t);			// check that pages are not reused before transaction is committed			for (int i = 0; i < numpages-1; i++)			{				for (int j = i+1; j < numpages; j++)				{					if (origpnum[i] == origpnum[j])						throw T_Fail.testFailMsg("page reused before transaction is committed");				}			}			register(key(9,0), cid);			register(key(9,1), numpages);			for (int i = 0; i < numpages; i++)			{				register(key(9,i+10), origpnum[i]);				register(key(9,i+numpages+10), origrid[i]);			}			// now see if we can reuse them			c = t_util.t_openContainer(t, 0, cid, true);			Page[] newpage = new Page[numpages];			int[] newrid = new int[numpages];			long[] newpnum = new long[numpages];			T_RawStoreRow row2 = new T_RawStoreRow(REC_002);			for (int i = 0; i < numpages; i++)			{				newpage[i] = t_util.t_addPage(c);				newpnum[i] = newpage[i].getPageNumber();				newrid[i] = t_util.t_insert(newpage[i], row2).getId();			}			// if any page is reused, make sure the rid is not reused			int reuse = 0;			for (int i = 0; i < numpages; i++)			{				for (int j = 0; j < numpages; j++)				{					if (origpnum[i] == newpnum[j])					{						reuse++;						if (origrid[i] == newrid[j])							throw T_Fail.testFailMsg("resued page rid is not preserved");											break;		// inner loop					}				}			}			for (int i = 0; i < numpages; i++)			{				register(key(9,i+100), newpnum[i]);				register(key(9,i+numpages+100), newrid[i]);			}			REPORT("setup S009: containerId " + cid + " of " +				   numpages + " original pages," +				   reuse + " pages were reused.");		}		finally		{			t_util.t_commit(t);			t.close();		}	}	/* recover test 9 */	protected void R009() throws T_Fail, StandardException	{		long cid = find(key(9,0));		if (cid < 0)		{			REPORT("R009 not run");			return;		}		int numpages = (int)find(key(9,1));		int[] newrid = new int[numpages];		long[] newpnum = new long[numpages];		Page[] newpage = new Page[numpages];		Transaction t = t_util.t_startTransaction();		try		{			ContainerHandle c = t_util.t_openContainer(t, 0, cid, false);			for (int i = 0; i < numpages; i++)			{				newrid[i] = (int)find(key(9, i+numpages+100));				newpnum[i] = find(key(9,i+100));				newpage[i] = t_util.t_getPage(c, newpnum[i]);				t_util.t_checkRecordCount(newpage[i], 1, 1);				RecordHandle rh = t_util.t_checkFetchFirst(newpage[i], REC_002);				if (rh.getId() != newrid[i])					throw T_Fail.testFailMsg("recordId not match");			}			REPORT("R009: containerId " + cid);		}		finally		{			t_util.t_commit(t);			t.close();		}	}	/*	 * test 10 - allocation/deallocation with overflow page	 */	protected void S010() throws T_Fail,StandardException	{		// maufacture a container with the first and last page being overflow		// pages 		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);			int numpages = 10;			Page[] page = new Page[numpages];			long[] pnum = new long[numpages];			RecordHandle[] recordHandles = new RecordHandle[numpages];			T_RawStoreRow row1 = new T_RawStoreRow(REC_001);			for (int i = 0; i < numpages; i++)			{				if (i == 0)					page[i] = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);				else					page[i] = t_util.t_addPage(c);				pnum[i] = page[i].getPageNumber();				// remove first two and last page as we go, pages are not reused				// until after commit. These pages have no rows in them				if (i < 2 || i == numpages-1)				{					t_util.t_checkEmptyPage(page[i]);					t_util.t_removePage(c, page[i]); 				}				else					recordHandles[i] = t_util.t_insert(page[i], row1);			}			t_util.t_commit(t);			c = t_util.t_openContainer(t, 0, cid, true);			Page p = c.getFirstPage();			if (p.getPageNumber() != pnum[2])				throw T_Fail.testFailMsg("first page expected to be page " +										 pnum[2] + ", got " + p.getPageNumber() + 										 " instead");			p.unlatch();			p = t_util.t_getLastPage(c);			if (p.getPageNumber() != pnum[numpages-2])				throw T_Fail.testFailMsg("last page expected to be page " +										 pnum[numpages-2] + ", got " + p.getPageNumber() + 										 " instead");			p.unlatch();		// now make rows on the rest of the page overflow			RecordHandle rh;			T_RawStoreRow big = new T_RawStoreRow(String.valueOf(new char[1500]));			REPORT("start reusing pages hopefully");			for (int i = 2; i < numpages-1; i++)			{				T_RawStoreRow row2 = new T_RawStoreRow(REC_002);				p = t_util.t_getPage(c, pnum[i]);				while(p.spaceForInsert(row2.getRow(), (FormatableBitSet) null, 100))					t_util.t_insert(p, row2);				// now page is filled                rh = p.fetchFromSlot(                        (RecordHandle) null,                         0,                         row2.getRow(),                         (FetchDescriptor) null,                         true);				p.update(rh, big.getRow(), (FormatableBitSet) null);				p.unlatch();			}			register(key(10, 1), cid);			register(key(10, 2), numpages);			for (int i = 0; i < numpages; i++)				register(key(10, 10+i), pnum[i]);			REPORT("setup S010");		}		finally		{			t_util.t_commit(t);			t.close();		}	}	protected void R010() throws T_Fail, StandardException	{		long cid = find(key(10, 1));		if (cid < 0)		{			REPORT("R010 not run");			return;		}		int numpages = (int)find(key(10,2));		long[] pnum = new long[numpages];		for (int i = 0; i < numpages; i++)			pnum[i] = find(key(10, 10+i));		// now check the pages, 0, 1 and last page (...) are all overflowpages		Transaction t = t_util.t_startTransaction();

⌨️ 快捷键说明

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