Example #1
0
void releaseRange()
{
	LBIDRange r;
	r.start = 12345;
	r.size = 5;
	copylocks.lock(CopyLocks::WRITE);
	copylocks.releaseRange(r);

	r.start = 12350;
	copylocks.releaseRange(r);
	copylocks.release(CopyLocks::WRITE);


	cout << "OK\n";
}
Example #2
0
void lockRange()
{
	LBIDRange r;
	r.start = 12345;
	r.size = 5;
	copylocks.lock(CopyLocks::WRITE);
	if (copylocks.isLocked(r))
		cout << "already locked\n";
	else {
		copylocks.lockRange(r, -1);
		cout << "got the 1st lock\n";
	}

	r.start = 12349;
	if (copylocks.isLocked(r))
		cout << "2nd range is locked\n";
	else
		cout << "2nd range is NOT locked\n";


	r.start = 12350;
	if (copylocks.isLocked(r))
		cout << "3rd range is locked\n";
	else {
		copylocks.lockRange(r, -1);
		cout << "got the 3rd lock\n";
	}

	copylocks.release(CopyLocks::WRITE);
}
Example #3
0
	// cut & pasted from brm_good_2(), but with rollback instead of commit.
	void brm_good_3()
	{
		DBRM brm;
		VBBM vbbm;
		VSS vss;
		CopyLocks cl;
		int i, err, size;
		vector<LBID_t> lbids;
		vector<LBID_t>::iterator lbid;
		vector<EMEntry> extents;
		LBIDRange_v ranges;
		LBIDRange_v::iterator lbidRangeIT;
		VBRange_v vbRanges, vbRanges2;
		VBRange_v::iterator vbRangesIT;
		LBIDRange_v tmp;
		EMEntry em;
		OID_t oid;
		uint32_t fbo;
		LBIDRange range;
		VBRange vbRange;
		VER_t verID;
		bool vbFlag;
		bool caughtException;
		
		// Buildbot times out on the getBlocks() call during leakcheck b/c it takes
		// > 5 mins for some reason.  Have to ping it before 300 seconds go by.
		void (*oldsig)(int);
		
 		cerr << "brm_good_3" << endl;

		oldsig = signal(SIGALRM, keepalive);
		alarm(290);
		
 		err = brm.lookup(0, 0, false, oid, fbo);
 		CPPUNIT_ASSERT(err != 0); 
		err = brm.lookup(0, 0, true, oid, fbo);
		CPPUNIT_ASSERT(err != 0);
		
 		err = brm.createExtent(8000, 1, lbids, size);
 		CPPUNIT_ASSERT(err == 0);
 		CPPUNIT_ASSERT(size == brm.getExtentSize());
 		CPPUNIT_ASSERT(lbids.size() == 1);
  		CPPUNIT_ASSERT(*(lbids.begin()) == 0);
		
		err = brm.getExtents(1, extents);
		CPPUNIT_ASSERT(err == 0);
		CPPUNIT_ASSERT(extents.size() == 1);
		
		em = *(extents.begin());
 		CPPUNIT_ASSERT(em.range.start == 0);
		CPPUNIT_ASSERT(em.range.size*1024 == static_cast<uint32_t>(brm.getExtentSize()));
		CPPUNIT_ASSERT(em.HWM == 0);
		CPPUNIT_ASSERT(em.blockOffset == 0);
		
		for (i = 0; i < 5; i++) {
			range.start = i * 100;
			range.size = 100;
			ranges.push_back(range);
		}

		CPPUNIT_ASSERT(brm.checkConsistency() == 0);
		
		err = brm.beginVBCopy(1, ranges, vbRanges);
		CPPUNIT_ASSERT(err == 0);
		
		CPPUNIT_ASSERT(brm.checkConsistency() == 0);
		
		cl.lock(CopyLocks::READ);
		for (lbidRangeIT = ranges.begin(); lbidRangeIT != ranges.end(); 
				   lbidRangeIT++)
			CPPUNIT_ASSERT(cl.isLocked(*lbidRangeIT));
		cl.release(CopyLocks::READ);
		
		err = brm.beginVBCopy(1, ranges, vbRanges2);
		CPPUNIT_ASSERT(err != 0);
		
		CPPUNIT_ASSERT(brm.checkConsistency() == 0);
		
		cl.lock(CopyLocks::READ);
		for (lbidRangeIT = ranges.begin(); lbidRangeIT != ranges.end(); 
				   lbidRangeIT++)
			CPPUNIT_ASSERT(cl.isLocked(*lbidRangeIT));
		cl.release(CopyLocks::READ);
		
		for (i = 0; i < 500; i++) {
			verID = MAXINT;
			err = brm.vssLookup(i, verID, 1, vbFlag);
			CPPUNIT_ASSERT(err != 0);
		}
		
		vbRange = *(vbRanges.begin());
// 		CPPUNIT_ASSERT(vbRange.vbFBO == 0);
		for (i = 0; i < (int)vbRange.size; i++) {
			err = brm.writeVBEntry(1, i, vbRange.vbOID, vbRange.vbFBO + i);
			CPPUNIT_ASSERT(err == 0);
		}
		
		CPPUNIT_ASSERT(brm.checkConsistency() == 0);
		
		for (i = 0; i < (int)vbRange.size; i++) { 
			verID = MAXINT;
			err = brm.vssLookup(i, verID, 1, vbFlag);
			CPPUNIT_ASSERT(err == 0);
			CPPUNIT_ASSERT(verID == 1);
			CPPUNIT_ASSERT(vbFlag == false);
			verID = MAXINT;
			err = brm.vssLookup(i, verID, 0, vbFlag);
			CPPUNIT_ASSERT(err == 0);
			CPPUNIT_ASSERT(verID == 0);
			CPPUNIT_ASSERT(vbFlag == true);
		}
		
		for (; i < 500; i++) {
			verID = MAXINT;
			err = brm.vssLookup(i, verID, 1, vbFlag);
			CPPUNIT_ASSERT(err != 0);
		}
					
		err = brm.endVBCopy(0, ranges);
			
		CPPUNIT_ASSERT(brm.checkConsistency() == 0);
		
		cl.lock(CopyLocks::READ);
		for (lbidRangeIT = ranges.begin(); lbidRangeIT != ranges.end(); 
				   lbidRangeIT++)
			CPPUNIT_ASSERT(!cl.isLocked(*lbidRangeIT));
		cl.release(CopyLocks::READ);
		
		err = brm.getUncommittedLBIDs(1, lbids);
		CPPUNIT_ASSERT(err == 0);
		CPPUNIT_ASSERT(lbids.size() == vbRange.size);
		sort<vector<LBID_t>::iterator>(lbids.begin(), lbids.end());
		lbid = lbids.begin();
		for (i = 0; i < static_cast<int>(lbids.size()); i++, lbid++)
			CPPUNIT_ASSERT((*lbid) == static_cast<LBID_t>(i));
		
		range.start = 0;
		range.size = i;
		tmp.push_back(range);
		err = brm.vbRollback(1, tmp);
		CPPUNIT_ASSERT(err == 0);
		
		CPPUNIT_ASSERT(brm.checkConsistency() == 0);
		
		for (i = 0; i < (int)vbRange.size; i++) { 
			verID = MAXINT;
			
			err = brm.vssLookup(i, verID, 0, vbFlag);
			CPPUNIT_ASSERT(err == 0);
			CPPUNIT_ASSERT(verID == 0);
			CPPUNIT_ASSERT(vbFlag == false);
			
			err = brm.lookup(i, verID, vbFlag, oid, fbo);
			CPPUNIT_ASSERT(err == 0);
 			CPPUNIT_ASSERT(oid == 1);
			CPPUNIT_ASSERT(fbo == static_cast<uint32_t>(i));
			
			vbbm.lock(VBBM::WRITE);
			vss.lock(VSS::WRITE);

#ifdef BRM_DEBUG
 			caughtException = false;
			try {
				vbbm.removeEntry(i, verID);
				vbbm.confirmChanges();
			}
			catch (logic_error &e) {
				vbbm.undoChanges();
				caughtException = true;
			}
			CPPUNIT_ASSERT(caughtException);
			caughtException = false;
			try {
				vss.removeEntry(i, 1);
				vss.confirmChanges();
			}
			catch (logic_error &e) {
				vss.undoChanges();
				caughtException = true;
			}
			CPPUNIT_ASSERT(caughtException);
#endif

			vss.removeEntry(i, verID);
			vss.confirmChanges();
			vss.release(VSS::WRITE);
			vbbm.release(VBBM::WRITE);
		}
		
		CPPUNIT_ASSERT(brm.checkConsistency() == 0);
		
		brm.deleteOID(1);
		
		vbbm.lock(VBBM::READ);
		vss.lock(VSS::READ);
		CPPUNIT_ASSERT(vbbm.size() == 0);
		CPPUNIT_ASSERT(vbbm.hashEmpty());
		CPPUNIT_ASSERT(vss.size() == 0);
		CPPUNIT_ASSERT(vss.hashEmpty());
		vss.release(VSS::READ);
		vbbm.release(VBBM::READ);
		
		CPPUNIT_ASSERT(brm.checkConsistency() == 0);

		err = brm.saveState();
		CPPUNIT_ASSERT(err==0);
	}
    void brm_good_2()
    {
        BlockResolutionManager brm;
        VBBM vbbm;
        VSS vss;
        CopyLocks cl;
        int i, err, size;
        vector<LBID_t> lbids;
        vector<EMEntry> extents;
        LBIDRange_v ranges;
        LBIDRange_v::iterator lbidRangeIT;
        VBRange_v vbRanges, vbRanges2;
        VBRange_v::iterator vbRangesIT;
        EMEntry em;
        OID_t oid;
        uint32_t fbo;
        LBIDRange range;
        VBRange vbRange;
        VER_t verID;
        bool vbFlag;

        // Buildbot times out on the getBlocks() call during leakcheck b/c it takes
        // > 5 mins for some reason.  Have to ping it before 300 seconds go by.
        void (*oldsig)(int);

        CPPUNIT_ASSERT(brm.checkConsistency() == 0);

        oldsig = signal(SIGALRM, keepalive);
        alarm(290);

        err = brm.lookup(0, 0, false, oid, fbo);
        CPPUNIT_ASSERT(err == -1);
        err = brm.lookup(0, 0, true, oid, fbo);
        CPPUNIT_ASSERT(err == -1);

        err = brm.createExtent(10000, 0, lbids, size);
        CPPUNIT_ASSERT(err == 0);
        CPPUNIT_ASSERT(size == brm.getExtentSize());
        CPPUNIT_ASSERT(lbids.size() == 1);
//  		CPPUNIT_ASSERT(*(lbids.begin()) == 0);

        err = brm.getExtents(0, extents);
        CPPUNIT_ASSERT(err == 0);
        CPPUNIT_ASSERT(extents.size() == 1);

        em = *(extents.begin());
// 		CPPUNIT_ASSERT(em.range.start == 0);
        CPPUNIT_ASSERT(em.range.size * 1024 == static_cast<uint32_t>(brm.getExtentSize()));
        CPPUNIT_ASSERT(em.HWM == 0);
        CPPUNIT_ASSERT(em.blockOffset == 0);

        for (i = 0; i < 50; i++)
        {
            range.start = i * 100;
            range.size = 100;
            ranges.push_back(range);
        }

        CPPUNIT_ASSERT(brm.checkConsistency() == 0);

        err = brm.beginVBCopy(1, ranges, vbRanges);
        CPPUNIT_ASSERT(err == 0);

        CPPUNIT_ASSERT(brm.checkConsistency() == 0);

        cl.lock(CopyLocks::READ);

        for (lbidRangeIT = ranges.begin(); lbidRangeIT != ranges.end();
                lbidRangeIT++)
            CPPUNIT_ASSERT(cl.isLocked(*lbidRangeIT));

        cl.release(CopyLocks::READ);

        err = brm.beginVBCopy(1, ranges, vbRanges2);
        CPPUNIT_ASSERT(err == -1);

        cl.lock(CopyLocks::READ);

        for (lbidRangeIT = ranges.begin(); lbidRangeIT != ranges.end();
                lbidRangeIT++)
            CPPUNIT_ASSERT(cl.isLocked(*lbidRangeIT));

        cl.release(CopyLocks::READ);

        for (i = 0; i < 5000; i++)
        {
            verID = MAXINT;
            err = brm.vssLookup(i, verID, 1, vbFlag);
            CPPUNIT_ASSERT(err == -1);
        }

        vbRange = *(vbRanges.begin());

// 		CPPUNIT_ASSERT(vbRange.vbFBO == 0);
        for (i = 0; i < (int)vbRange.size; i++)
        {
            err = brm.writeVBEntry(1, i, vbRange.vbOID, vbRange.vbFBO + i);
            CPPUNIT_ASSERT(err == 0);
        }

        CPPUNIT_ASSERT(brm.checkConsistency() == 0);

        for (i = 0; i < (int)vbRange.size; i++)
        {
            verID = MAXINT;
            err = brm.vssLookup(i, verID, 1, vbFlag);
            CPPUNIT_ASSERT(err == 0);
            CPPUNIT_ASSERT(verID == 1);
            CPPUNIT_ASSERT(vbFlag == false);
            verID = MAXINT;
            err = brm.vssLookup(i, verID, 0, vbFlag);
            CPPUNIT_ASSERT(err == 0);
            CPPUNIT_ASSERT(verID == 0);
            CPPUNIT_ASSERT(vbFlag == true);
        }

        for (; i < 5000; i++)
        {
            verID = MAXINT;
            err = brm.vssLookup(i, verID, 1, vbFlag);
            CPPUNIT_ASSERT(err == -1);
        }

        err = brm.endVBCopy(0, ranges);

        CPPUNIT_ASSERT(brm.checkConsistency() == 0);

        cl.lock(CopyLocks::READ);

        for (lbidRangeIT = ranges.begin(); lbidRangeIT != ranges.end();
                lbidRangeIT++)
            CPPUNIT_ASSERT(!cl.isLocked(*lbidRangeIT));

        cl.release(CopyLocks::READ);

        brm.vbCommit(1);

        CPPUNIT_ASSERT(brm.checkConsistency() == 0);

        for (i = 0; i < (int)vbRange.size; i++)
        {
            verID = MAXINT;
            err = brm.vssLookup(i, verID, 0, vbFlag);
            CPPUNIT_ASSERT(err == 0);
            CPPUNIT_ASSERT(verID == 1);
            CPPUNIT_ASSERT(vbFlag == false);

            verID = 0;
            err = brm.vssLookup(i, verID, 0, vbFlag);
            CPPUNIT_ASSERT(err == 0);
            CPPUNIT_ASSERT(verID == 0);
            CPPUNIT_ASSERT(vbFlag == true);

            err = brm.lookup(i, verID, vbFlag, oid, fbo);
            CPPUNIT_ASSERT(err == 0);
            CPPUNIT_ASSERT(oid == vbRange.vbOID);
            CPPUNIT_ASSERT(fbo == static_cast<uint32_t>(i + vbRange.vbFBO));

            vbbm.lock(VBBM::WRITE);
            vss.lock(VSS::WRITE);
            vbbm.removeEntry(i, verID);
// 			vss.removeEntry(i, 1);
            vss.removeEntry(i, verID);
            vss.release(VSS::WRITE);
            vbbm.release(VBBM::WRITE);
        }

        CPPUNIT_ASSERT(brm.checkConsistency() == 0);

        brm.deleteOID(0);

        vss.lock(VSS::READ);
        vbbm.lock(VBBM::READ);
        CPPUNIT_ASSERT(vbbm.size() == 0);
        CPPUNIT_ASSERT(vbbm.hashEmpty());
        CPPUNIT_ASSERT(vss.size() == 0);
        CPPUNIT_ASSERT(vss.hashEmpty());
        vss.release(VSS::READ);
        vbbm.release(VBBM::READ);

        CPPUNIT_ASSERT(brm.checkConsistency() == 0);

    }
    void copyLocks_good_1()
    {
        CopyLocks cl;
        LBIDRange range;
        int i, iterations = 1000;

        cl.lock(CopyLocks::WRITE);
        range.start = 5;
        range.size = 2;
        cl.lockRange(range, 0);
        CPPUNIT_ASSERT(cl.isLocked(range) == true);
        range.start++;
        CPPUNIT_ASSERT(cl.isLocked(range) == true);
        range.start++;
        CPPUNIT_ASSERT(cl.isLocked(range) == false);
        range.start = 0;
        CPPUNIT_ASSERT(cl.isLocked(range) == false);
        range.start = 3;
        CPPUNIT_ASSERT(cl.isLocked(range) == false);
        range.start++;
        CPPUNIT_ASSERT(cl.isLocked(range) == true);
        range.start = 5;
        range.size = 1;
        CPPUNIT_ASSERT(cl.isLocked(range) == true);
        range.size = 2;
        cl.releaseRange(range);

        //make sure it can grow
        for (i = 0; i < iterations * 2; i += 2)
        {
            range.start = i;
            cl.lockRange(range, 0);
        }

        range.size = 1;

        for (i = 0; i < iterations * 2; i++)
        {
            range.start = i;
            CPPUNIT_ASSERT(cl.isLocked(range) == true);
        }

        range.start = i;
        CPPUNIT_ASSERT(cl.isLocked(range) == false);

        for (i = 0; i < iterations * 2; i += 2)
        {
            range.start = i;
            cl.releaseRange(range);
        }

        cl.release(CopyLocks::WRITE);
    }