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

📄 t_filesystemdata.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		  test remove and reuse of page		*/		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);		// create 5 pages, each insert a row into it, then remove 2 of them			Page page1 = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);			long p1 = page1.getPageNumber();			T_RawStoreRow row1 = new T_RawStoreRow(REC_001);			t_util.t_insert(page1, row1);			Page page2 = t_util.t_addPage(c);			long p2 = page2.getPageNumber();			T_RawStoreRow row2 = new T_RawStoreRow(REC_002);			int rid2 = t_util.t_insert(page2, row2).getId();			Page page3 = t_util.t_addPage(c);			long p3 = page3.getPageNumber();			T_RawStoreRow row3 = new T_RawStoreRow(REC_003);			t_util.t_insert(page3, row3);			Page page4 = t_util.t_addPage(c);			long p4 = page4.getPageNumber();			T_RawStoreRow row4 = new T_RawStoreRow(REC_004);			int rid4 = t_util.t_insert(page4, row4).getId();			Page page5 = t_util.t_addPage(c);			long p5 = page5.getPageNumber();			T_RawStoreRow row5 = new T_RawStoreRow(REC_005);			t_util.t_insert(page5, row5);			t_util.t_removePage(c, page2);			t_util.t_removePage(c, page4);			t_util.t_commit(t);		// now all the pages are unlatched		// pages 2, 4 has been removed, pages 1, 3, 5 has not		// make sure pages that are removed cannot be found again			c = t_util.t_openContainer(t, 0, cid, true);            if (SanityManager.DEBUG)                SanityManager.DEBUG("SpaceTrace", "containeropened");			Page p = c.getFirstPage();			if (p == null)				throw T_Fail.testFailMsg("get first page failed: expect " + p1 + " got null");			if (p.getPageNumber() != p1)				throw T_Fail.testFailMsg("get first page failed: expect " + p1										 + " got " + p.getPageNumber());			t_util.t_commit(t);				// closing the transaction many times to see if we can get the		// deallocated page to free			c = t_util.t_openContainer(t, 0, cid, true);			p = c.getNextPage(p1);			if (p == null || p.getPageNumber() != p3)				throw T_Fail.testFailMsg("get next page failed");			t_util.t_commit(t);			c = t_util.t_openContainer(t, 0, cid, true);			p = c.getNextPage(p3);			if (p == null || p.getPageNumber() != p5)				throw T_Fail.testFailMsg("get next page failed");			t_util.t_commit(t);					c = t_util.t_openContainer(t, 0, cid, true);			p = t_util.t_getLastPage(c);	// make sure it skips over p5			if (p == null || p.getPageNumber() != p5)				throw T_Fail.testFailMsg("getLastPage failed");			t_util.t_commit(t);		// see if we can get any deallocated page back in 10 attempts		// of add page			int tries = 100;			T_RawStoreRow row6 = new T_RawStoreRow(REC_001);			long pnums[] = new long[tries];			int  rids[] = new int[tries];			pnums[0] = p2;			// pages 2 and 4 have been removed for a long time			rids[0] = rid2;			pnums[1] = p4;			rids[1] = rid4;			int match = -1;			int i;			for (i = 2 ; match < 0 && i < tries; i++)			{				c = t_util.t_openContainer(t, 0, cid, true);				p = t_util.t_addPage(c);				pnums[i] =  p.getPageNumber();				for (int j = 0; j < i-1; j++)				{					if (pnums[j] == pnums[i])					{						match = j;						break;					}				}				if (match >= 0)				{					// p is a reused one, make sure it is empty					t_util.t_checkEmptyPage(p);					RecordHandle rh = t_util.t_insert(p, row6);					if (rh.getId() == rids[match])						throw T_Fail.testFailMsg("reused page recordId is not preserved");					break;				}				else					rids[i] = t_util.t_insert(p, row6).getId();				t_util.t_removePage(c, p);				t_util.t_commit(t);			}			t_util.t_dropContainer(t, 0, cid); // cleanup			if (match >= 0)				PASS("AllocTest1 success in " + i + " tries");			else				REPORT("AllocTest1 Not successful in " + i + 					   " tries.  This is a timing depenedent test so this is not necessarily an indication of failure.");		}		finally		{			t_util.t_commit(t);			t.close();		}	}	protected void AllocTest2() throws StandardException, T_Fail 	{		/**		  More Test remove and reuse of page		*/		Transaction t = t_util.t_startTransaction();		int numpages = 30;		try		{			long cid = t_util.t_addContainer(t, 0);			ContainerHandle c = t_util.t_openContainer(t, 0, cid, true);			Page[] page = new Page[numpages];			for (int i = 0; i < numpages; i++)			{				page[i] = t_util.t_addPage(c);				t_util.t_removePage(c, page[i]);			}			// make sure a dropped container does not cause problem for page			// that's been removed			t_util.t_dropContainer(t, 0, cid); 			t_util.t_commit(t);			if (testRollback)			{				cid = t_util.t_addContainer(t, 0);				c = t_util.t_openContainer(t, 0, cid, true);				for (int i = 0; i < numpages; i++)				{					page[i] = t_util.t_addPage(c);					t_util.t_removePage(c, page[i]);				}				t_util.t_abort(t);			}		}		finally		{			t_util.t_commit(t);			t.close();		}		PASS("AllocTest2");	}	protected void AllocTest3() throws StandardException, T_Fail 	{		/* test multiple alloc pages */		if (!SanityManager.DEBUG)		{			REPORT("allocTest3 cannot be run on an insane server");			return;		}        else        {            SanityManager.DEBUG_SET(AllocPage.TEST_MULTIPLE_ALLOC_PAGE);            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);                T_RawStoreRow row = new T_RawStoreRow(REC_001);                int numrows = 10; // create 10 pages with 1 row each                                String threadName = Thread.currentThread().getName();                Page page;                for (int i = 0; i < numrows; i++)                {                    page = t_util.t_addPage(c);                    t_util.t_insert(page, row);                    page.unlatch();                }                int checkrows = 0;                long pnum;                for (page = c.getFirstPage();                     page != null;                     page = c.getNextPage(pnum))                {                    pnum = page.getPageNumber();                    if (page.recordCount() > 0)                    {                        t_util.t_checkFetchFirst(page, REC_001);                        checkrows++;                    }                    page.unlatch();                }                if (checkrows != numrows)                    throw T_Fail.testFailMsg("number of rows differ");                t.setSavePoint(SP1, null);                // now remove 1/2 of the pages and check results                int removedPages = 0;                for (page = c.getFirstPage();                     page != null;                     page = c.getNextPage(pnum))                {                    pnum = page.getPageNumber();                    if ((pnum % 2) == 0)                    {                        t_util.t_removePage(c, page);                        removedPages++;                    }                    else                        page.unlatch();                }                checkrows = 0;                for (page = c.getFirstPage();                     page != null;                     page = c.getNextPage(pnum))                {                    pnum = page.getPageNumber();                    if (page.recordCount() > 0)                    {                        t_util.t_checkFetchFirst(page, REC_001);                        checkrows++;                    }                    page.unlatch();                }                if (checkrows != numrows - removedPages)                    throw T_Fail.testFailMsg("number of rows differ");                // remove every page backwards                long lastpage = ContainerHandle.INVALID_PAGE_NUMBER;                while((page = t_util.t_getLastPage(c)) != null)	// remove the last page                {                    if (lastpage == page.getPageNumber())                        throw T_Fail.testFailMsg("got a removed last page");                    lastpage = page.getPageNumber();                    t_util.t_removePage(c, page);                }                if (c.getFirstPage() != null)                    throw T_Fail.testFailMsg("get last page returns null but get fisrt page retuns a page");                t.rollbackToSavePoint(SP1, null);	// roll back removes                c = t_util.t_openContainer(t, 0, cid, true);                checkrows = 0;                for (page = c.getFirstPage();                     page != null;                     page = c.getNextPage(pnum))                {                    pnum = page.getPageNumber();                    if (page.recordCount() > 0)                    {                        t_util.t_checkFetchFirst(page, REC_001);                        checkrows++;                    }                    page.unlatch();                }                if (checkrows != numrows)                    throw T_Fail.testFailMsg(threadName + "number of rows differ expect " +                                             numrows + " got " + checkrows);                t_util.t_abort(t);	// abort the whole thing, no rows left                c = t_util.t_openContainer(t, 0, cid, true);                int countPages = 0;                for (page = c.getFirstPage();                     page != null;                     page = c.getNextPage(pnum))                {                    countPages++;                    pnum = page.getPageNumber();                    if (page.nonDeletedRecordCount() > 0)                    {                        throw T_Fail.testFailMsg("failed to remove everything " +                                                 page.nonDeletedRecordCount() +                                                  " rows left on page " + pnum);                    }                    page.unlatch();                }			                if (countPages < numrows)                    throw T_Fail.testFailMsg("rollback of user transaction should not remove allocated pages");                t_util.t_dropContainer(t, 0, cid);             }            finally            {                SanityManager.DEBUG_CLEAR(AllocPage.TEST_MULTIPLE_ALLOC_PAGE);                t_util.t_commit(t);                t.close();            }            PASS("AllocTest3");        }	}	protected void AllocTest4() throws StandardException, T_Fail	{		if (!SanityManager.DEBUG)		{			REPORT("allocTest3 cannot be run on an insane server");			return;		}        else        {            SanityManager.DEBUG_SET(AllocPage.TEST_MULTIPLE_ALLOC_PAGE);            Transaction t = t_util.t_startTransaction();            try            {                ////////////////////////////////////////////////////////                // first test preallocation large table                ////////////////////////////////////////////////////////                Properties tableProperties = new Properties();                tableProperties.put(Property.PAGE_SIZE_PARAMETER, Integer.toString(1024));                tableProperties.put(RawStoreFactory.CONTAINER_INITIAL_PAGES, Integer.toString(100));

⌨️ 快捷键说明

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