Beispiel #1
0
bool BTreeDriver::TestLargeWorkload()
{
	Status status;
	BTreeFile *btf;
	bool res;

	btf = new BTreeFile(status, "BTreeTest4");

	if (status != OK) {
		std::cerr << "ERROR: Couldn't create a BTreeFile" << std::endl;
		minibase_errors.show_errors();

		std::cerr << "Hit [enter] to continue..." << std::endl;
		std::cin.get();
		exit(1);
	}

	std::cout << "Starting Test 4..." << std::endl;
	std::cout << "BTreeIndex created successfully." << std::endl;

	res = InsertRange(btf, 1, 1000, 1, 5, true);
	res = res && TestNumEntries(btf, 1000);

	res = InsertRange(btf, 1, 1000, 2, 5, false);
	res = res && TestNumEntries(btf, 2000);

	res = InsertRange(btf, 501, 1500, 3, 5, false);
	res = res && TestNumEntries(btf, 3000);

	res = InsertRange(btf, 2001, 4000, 1, 5, false);
	res = res && TestNumEntries(btf, 5000);

	char low[MAX_KEY_LENGTH];
	char high[MAX_KEY_LENGTH];

	toString(1000, low, 5);
	toString(1000, high, 5);
	BTreeFileScan *scan = btf->OpenScan(low, high);
	res = res && TestScanCount(scan, 3);
	delete scan;

	toString(3000, low, 5);
	toString(3000, high, 5);
	scan = btf->OpenScan(low, high);
	res = res && TestScanCount(scan, 1);
	delete scan;

	res = res && TestAbsent(btf, 1700, 1, 5);

	if (btf->DestroyFile() != OK) {
		std::cerr << "Error destroying BTreeFile" << std::endl;
		res = false;
	}

	delete btf;

	return res;
}
Beispiel #2
0
/***********************************************************************************
 ** Constructor
 **
 ** ImapCommands::MessageSet::MessageSet
 ***********************************************************************************/
ImapCommands::MessageSet::MessageSet(UINT32 start, UINT32 end)
    : m_count(0)
{
    OP_ASSERT(start == 0 || end == 0 || start <= end);

    if (start > 0)
        OpStatus::Ignore(InsertRange(start, end));
};
Beispiel #3
0
/***********************************************************************************
 ** Insert a sequence specified as integer vector
 **
 ** ImapCommands::MessageSet::InsertSequence
 ** @param sequence Sequence to insert into this sequence
 ***********************************************************************************/
OP_STATUS ImapCommands::MessageSet::InsertSequence(const OpINT32Vector& sequence)
{
    for (UINT32 i = 0; i < sequence.GetCount(); i++)
    {
        RETURN_IF_ERROR(InsertRange(sequence.Get(i), sequence.Get(i)));
    }

    return OpStatus::OK;
}
Beispiel #4
0
HRESULT CBaseStream::EnlargeStreamLength(UINT nAdditionalMs)
{
   m_nStreamLength += nAdditionalMs;
   
   // in order to have proper undo information
   InsertRange(m_nStreamLength, nAdditionalMs, NULL, 0, true); 

   return S_OK;
}
Beispiel #5
0
/***********************************************************************************
 ** Merge with another message set
 **
 ** ImapCommands::MessageSet::Merge
 ***********************************************************************************/
OP_STATUS ImapCommands::MessageSet::Merge(const MessageSet& merge_from)
{
    for (unsigned i = 0; i < merge_from.m_ranges.GetCount(); i++)
    {
        Range* range = merge_from.m_ranges.GetByIndex(i);

        RETURN_IF_ERROR(InsertRange(range->start, range->end));
    }

    return OpStatus::OK;
}
Beispiel #6
0
bool BTreeDriver::TestDeleteCurrent() {
	Status status;
	BTreeFile *btf;
	bool res;

	btf = new BTreeFile(status, "BTreeTest6");

	if (status != OK) {
		std::cerr << "ERROR: Couldn't create a BTreeFile" << std::endl;
		minibase_errors.show_errors();

		std::cerr << "Hit [enter] to continue..." << std::endl;
		std::cin.get();
		exit(1);
	}

	std::cout << "Starting Test 6..." << std::endl;
	std::cout << "BTreeIndex created successfully." << std::endl;
	std::cout << "Inserting entries..." << std::endl;
	InsertRange(btf, 1, 10);
	char low[MAX_KEY_LENGTH];
	toString(3, low);
	BTreeFileScan* scan = btf->OpenScan(low, NULL);

	std::cout << "Deleting entries..." << std::endl;
	RecordID rid;
	char* keyPtr;
	scan->GetNext(rid, keyPtr); // 3
	scan->GetNext(rid, keyPtr); // 4
	scan->DeleteCurrent(); // 5
	scan->GetNext(rid, keyPtr); // 6
	scan->GetNext(rid, keyPtr); // 7
	scan->GetNext(rid, keyPtr); // 8
	scan->DeleteCurrent();
	delete scan;

	res = TestAbsent(btf, 4);
	res = TestAbsent(btf, 8);

	std::cout << "Inserting duplicate entry..." << std::endl;
	InsertKey(btf, 1, 3);
	toString(1, low);
	scan = btf->OpenScan(low, NULL);

	std::cout << "Deleting entry..." << std::endl;
	scan->GetNext(rid, keyPtr); // 1
	scan->DeleteCurrent(); // 1
	delete scan;

	res = TestAbsent(btf, 1, 1);
	res = TestPresent(btf, 1, 3);
	
	if (btf->DestroyFile() != OK) {
		std::cerr << "Error destroying BTreeFile" << std::endl;
		res = false;
	}

	delete btf;

	return res;
}
Beispiel #7
0
bool BTreeDriver::TestBufferPool() {
	// does some operations
	// at the end check if there's anything left in the buffer pool
	std::cout << "Starting Test 5..." << std::endl;
	unsigned int pinnedPages = MINIBASE_BM->GetNumOfBuffers() - MINIBASE_BM->GetNumOfUnpinnedBuffers();
	std::cout << "# pinned pages: " << pinnedPages << std::endl;

	BTreeFile* btf;
	Status status;
	bool res = true;

	btf = new BTreeFile(status, "BTreeTest5");

	if (status != OK) {
		std::cerr << "ERROR: Couldn't create a BTreeFile" << std::endl;
		minibase_errors.show_errors();

		std::cerr << "Hit [enter] to continue..." << std::endl;
		std::cin.get();
		exit(1);
	}

	std::cout << "BTreeIndex created successfully." << std::endl;

	std::cout << "Performing various operations on BTreeFile." << std::endl;
	InsertRange(btf, 1, 1000, 1, 5, true);
	InsertRange(btf, 1, 1000, 2, 5, false);
	InsertRange(btf, 501, 1500, 3, 5, false);
	InsertRange(btf, 2001, 4000, 1, 5, false);

	char low[MAX_KEY_LENGTH];
	char high[MAX_KEY_LENGTH];

	BTreeFileScan *scan = btf->OpenScan(NULL, NULL);

	RecordID rid;
	char* key;
	int count = 0;
	while (scan->GetNext(rid, key) != DONE) {
		count++;
	}

	if (count != 5000) {
		std::cerr << "Number of pages inserted doesn't equal 5000. Check insert." << std::endl;
		res = false;
	}

	delete scan;
	if (btf->DestroyFile() != OK) {
		std::cerr << "Error destroying BTreeFile" << std::endl;
		res = false;
	}

	delete btf;

	unsigned int numPinned = MINIBASE_BM->GetNumOfBuffers() - MINIBASE_BM->GetNumOfUnpinnedBuffers();
	
	if (pinnedPages - numPinned != 0) {
		std::cerr << pinnedPages - numPinned << " pages still left in buffer pool after clean up." << std::endl;
		res = false;
	}
	return res;
}
Beispiel #8
0
bool BTreeDriver::TestInsertsWithIndexSplits()
{
	Status status;
	BTreeFile *btf;
	bool res;

	btf = new BTreeFile(status, "BTreeTest3");

	if (status != OK) {
		std::cerr << "ERROR: Couldn't create a BTreeFile" << std::endl;
		minibase_errors.show_errors();

		std::cerr << "Hit [enter] to continue..." << std::endl;
		std::cin.get();
		exit(1);
	}

	std::cout << "Starting Test 3..." << std::endl;
	std::cout << "BTreeIndex created successfully." << std::endl;

	// Insert a bunch of long keys into the tree until we cause the root
	// node to split.
	std::cout << "Inserting 31 large keys..."	<< std::endl;
	res = InsertRange(btf, 1, 31, 1, 20);
	res = res && TestNumLeafPages(btf, 2);
	res = res && TestNumEntries(btf, 31);

	std::cout << "Inserting keys until root splits." << std::endl;

	PageID rootId = btf->header->GetRootPageID();
	PageID newRootId;
	int key = 32;
	int numInserted = 0;

	PageID leftPid, rightPid;
	IndexPage *leftPage;
	IndexPage *rightPage;

	while (true) {
		res = res && InsertKey(btf, key, 1, 20);
		newRootId = btf->header->GetRootPageID();

		// there was a split. Check balance.
		if (newRootId != rootId) {
			IndexPage *ip;

			if (MINIBASE_BM->PinPage(newRootId, (Page *&) ip) == FAIL) {
				std::cerr << "Error pinning root page." << std::endl;
				res = false;
			}

			if (ip->GetNumOfRecords() != 1) {
				std::cerr << "Error: Expected 1 key in root, got "
						  << ip->GetNumOfRecords() << std::endl;
				res = false;
			}

			leftPid = ip->GetPrevPage();

			char *rightKey;
			ip->GetMinKeyValue(rightKey, rightPid);

			if (MINIBASE_BM->PinPage(leftPid, (Page *&) leftPage) == FAIL) {
				std::cerr << "Error pinning left leaf page." << std::endl;
				res = false;
			}

			if (MINIBASE_BM->PinPage(rightPid, (Page *&) rightPage) == FAIL) {
				std::cerr << "Error pinning right leaf page." << std::endl;
				res = false;
			}

			res = res && TestBalance(btf, leftPage, rightPage);

			if (MINIBASE_BM->UnpinPage(leftPid, CLEAN) == FAIL) {
				std::cerr << "Error unpinning left leaf page." << std::endl;
				res = false;
			}

			if (MINIBASE_BM->UnpinPage(rightPid, CLEAN) == FAIL) {
				std::cerr << "Error unpinning right leaf page." << std::endl;
				res = false;
			}

			if (MINIBASE_BM->UnpinPage(newRootId, CLEAN) == FAIL) {
				std::cerr << "Error unpinning root page." << std::endl;
				res = false;
			}

			break;
		}

		key++;
		numInserted++;
	}

	res = res && TestNumEntries(btf, key);

	if (btf->DestroyFile() != OK) {
		std::cerr << "Error destroying BTreeFile" << std::endl;
		res = false;
	}

	delete btf;

	return res;
}
Beispiel #9
0
bool BTreeDriver::TestInsertsWithLeafSplits()
{
	Status status;
	BTreeFile *btf;
	bool res;
	LeafPage *leftPage;
	LeafPage *rightPage;
	btf = new BTreeFile(status, "BTreeTest2");

	if (status != OK) {
		std::cerr << "ERROR: Couldn't create a BTreeFile" << std::endl;
		minibase_errors.show_errors();

		std::cerr << "Hit [enter] to continue..." << std::endl;
		std::cin.get();
		exit(1);
	}

	std::cout << "Starting Test 2..." << std::endl;
	std::cout << "BTreeIndex created successfully." << std::endl;

	std::cout << "Inserting 30 large keys..."	<< std::endl;
	res = InsertRange(btf, 1, 30, 1, 20);
	res = res && TestNumLeafPages(btf, 1);
	res = res && TestNumEntries(btf, 30);

	// Insert some more long keys. This should cause the tree to split.
	std::cout << "Causing split with new key in right node..."	<< std::endl;
	res = res && InsertKey(btf, 31, 1, 20);
	res = res && TestNumLeafPages(btf, 2);
	res = res && TestNumEntries(btf, 31);

	// Make sure that the split happened as expected.
	PageID leftPid = btf->GetLeftLeaf();

	if (MINIBASE_BM->PinPage(leftPid, (Page *&) leftPage) == FAIL) {
		std::cerr << "Error pinning left leaf page." << std::endl;
		res = false;
	}

	PageID rightPid = leftPage->GetNextPage();

	if (MINIBASE_BM->PinPage(rightPid, (Page *&) rightPage) == FAIL) {
		std::cerr << "Error pinning right leaf page." << std::endl;
		res = false;
	}

	res = res && TestBalance(btf, leftPage, rightPage);

	if (MINIBASE_BM->UnpinPage(leftPid, CLEAN) == FAIL) {
		std::cerr << "Error unpinning left leaf page." << std::endl;
		res = false;
	}

	if (MINIBASE_BM->UnpinPage(rightPid, CLEAN) == FAIL) {
		std::cerr << "Error unpinning right leaf page." << std::endl;
		res = false;
	}

	// We destroy and rebuild the file before to reduce
	// dependence on working Delete function.
	if (btf->DestroyFile() != OK) {
		std::cerr << "Error destroying BTreeFile" << std::endl;
		res = false;
	}

	delete btf;

	// Create a new tree.
	btf = new BTreeFile(status, "BTreeTest2");

	if (status != OK) {
		std::cerr << "ERROR: Couldn't create a BTreeFile" << std::endl;
		minibase_errors.show_errors();

		std::cerr << "Hit [enter] to continue..." << std::endl;
		std::cin.get();
		exit(1);
	}

	// Insert 30 long keys.
	std::cout << "Inserting 30 large keys..."	<< std::endl;
	res = InsertRange(btf, 2, 31, 1, 20);

	res = res && TestNumLeafPages(btf, 1);
	res = res && TestNumEntries(btf, 30);

	// Insert some more nodes with long keys into the tree.
	// This should cause the tree to split.
	std::cout << "Causing split with new key in left node..."	<< std::endl;
	res = res && InsertKey(btf, 1, 1, 20);

	res = res && TestNumLeafPages(btf, 2);
	res = res && TestNumEntries(btf, 31);

	// Make sure that the tree is balanced.
	leftPid = btf->GetLeftLeaf();

	if (MINIBASE_BM->PinPage(leftPid, (Page *&) leftPage) == FAIL) {
		std::cerr << "Error pinning left leaf page." << std::endl;
		res = false;
	}

	rightPid = leftPage->GetNextPage();

	if (MINIBASE_BM->PinPage(rightPid, (Page *&) rightPage) == FAIL) {
		std::cerr << "Error pinning right leaf page." << std::endl;
		res = false;
	}

	res = res && TestBalance(btf, leftPage, rightPage);

	if (MINIBASE_BM->UnpinPage(leftPid, CLEAN) == FAIL) {
		std::cerr << "Error unpinning left leaf page." << std::endl;
		res = false;
	}

	if (MINIBASE_BM->UnpinPage(rightPid, CLEAN) == FAIL) {
		std::cerr << "Error unpinning right leaf page." << std::endl;
		res = false;
	}

	if (btf->DestroyFile() != OK) {
		std::cerr << "Error destroying BTreeFile" << std::endl;
		res = false;
	}

	delete btf;

	// That's all, folks.
	return res;
}
Beispiel #10
0
bool BTreeDriver::TestSinglePage()
{
	Status status;
	BTreeFile *btf;

	btf = new BTreeFile(status, "BTreeTest1");

	if (status != OK) {
		std::cerr << "ERROR: Couldn't create a BTreeFile" << std::endl;
		minibase_errors.show_errors();

		std::cerr << "Hit [enter] to continue..." << std::endl;
		std::cin.get();
		exit(1);
	}

	std::cout << "Starting Test 1..." << std::endl;
	std::cout << "BTreeIndex created successfully." << std::endl;

	bool res;

	std::cout << "Inserting 59 initial keys..."	<< std::endl;
	res = InsertRange(btf, 1, 59);
	res = res && TestNumLeafPages(btf, 1);
	res = res && TestNumEntries(btf, 59);

	std::cout << "Checking a few individual keys..." << std::endl;
	res = res && TestAbsent(btf, 0);
	res = res && TestPresent(btf, 2);
	res = res && TestPresent(btf, 59);
	res = res && TestAbsent(btf, 60);

	std::cout << "Checking scans..." << std::endl;

	char low[MAX_KEY_LENGTH];
	char high[MAX_KEY_LENGTH];
	toString(5, low);
	toString(15, high);
	BTreeFileScan *scan = btf->OpenScan(low, high);
	res = res && TestScanCount(scan, 11);
	delete scan;

	toString(58, low);
	toString(64, high);
	scan = btf->OpenScan(low, high);
	res = res && TestScanCount(scan, 2);
	delete scan;

	toString(0, low);
	toString(5, high);
	scan = btf->OpenScan(low, high);
	res = res && TestScanCount(scan, 5);
	delete scan;

	// We destroy and rebuild the file before to reduce
	// dependence on working Delete function.
	if (btf->DestroyFile() != OK) {
		std::cerr << "Error destroying BTreeFile" << std::endl;
		res = false;
	}

	delete btf;

	btf = new BTreeFile(status, "BTreeTest2");

	if (status != OK) {
		std::cerr << "ERROR: Couldn't create a BTreeFile" << std::endl;
		minibase_errors.show_errors();

		std::cerr << "Hit [enter] to continue..." << std::endl;
		std::cin.get();
		exit(1);
	}

	std::cout << "Inserting 124 duplicates." << std::endl;
	res = res && InsertDuplicates(btf, 3, 124);
	res = res && TestNumLeafPages(btf, 1);
	res = res && TestNumEntries(btf, 124);

	if (btf->DestroyFile() != OK) {
		std::cerr << "Error destroying BTreeFile" << std::endl;
		res = false;
	}

	delete btf;
	return res;
}