Esempio n. 1
0
void
checkTreeContents(BPlusTree *tree)
{
	// reset counter
	for (int32 i = 0;i < gNum;i++)
		gKeys[i].count = 0;

	TreeIterator iterator(tree);
	char key[B_FILE_NAME_LENGTH];
	uint16 length,duplicate;
	off_t value;
	status_t status;
	while ((status = iterator.GetNextEntry(key,&length,B_FILE_NAME_LENGTH,&value,&duplicate)) == B_OK) {
		if (value < 0 || value >= gNum) {
			iterator.Dump();
			printf("\ninvalid value %Ld in tree: ",value);
			bailOutWithKey(key,length);
		}
		if (gKeys[value].value != value) {
			iterator.Dump();
			printf("\nkey pointing to the wrong value %Ld (should be %Ld)\n",value,gKeys[value].value);
			bailOutWithKey(key,length);
		}
		if (length != gKeys[value].length
			|| memcmp(key,gKeys[value].data,length)) {
			iterator.Dump();
			printf("\nkeys don't match (key index = %Ld, %ld times in tree, %ld. occassion):\n\tfound: ",value,gKeys[value].in,gKeys[value].count + 1);
			dumpKey(key,length);
			printf("\n\texpected: ");
			dumpKey(gKeys[value].data,gKeys[value].length);
			putchar('\n');
			bailOut();
		}

		gKeys[value].count++;
	}
	if (status != B_ENTRY_NOT_FOUND) {
		printf("TreeIterator::GetNext() returned: %s\n",strerror(status));
		iterator.Dump();
		bailOut();
	}

	for (int32 i = 0;i < gNum;i++) {
		if (gKeys[i].in != gKeys[i].count) {
			printf("Key ");
			dumpKey(gKeys[i].data,gKeys[i].length);
			printf(" found only %ld from %ld\n",gKeys[i].count,gKeys[i].in);
		}
	}
}
Esempio n. 2
0
	/*!
	 * \brief Opens the file at \a path and writes a random key file.
	 *
	 * Each key file will have #m_keyCount number of keys written into it,
	 * each on a line by itself.
	 */
	void generateKeyFile(const std::string & path)
	{
		std::ofstream outputStream(path.c_str(), std::ios_base::binary | std::ios_base::out | std::ios_base::trunc);
		if (outputStream.is_open())
		{
			int i;
			for (i = 0; i < m_keyCount; ++i)
			{
				AESKey<128> key;
				key.randomize();
				key.writeToStream(outputStream);
				
				// put a newline after the key
				outputStream.write("\n", 1);
				
				// dump it
				dumpKey(key);
			}
			
			Log::log(Logger::INFO, "wrote key file %s\n", path.c_str());
		}
		else
		{
			throw std::runtime_error("could not open output file");
		}
	}
Esempio n. 3
0
void
bailOutWithKey(void *key, uint16 length)
{
	dumpKey(key, length);
	putchar('\n');
	bailOut();
}
Esempio n. 4
0
void
duplicateTest(Transaction *transaction,BPlusTree *tree)
{
	int32 index = int32(1.0 * gNum * rand() / RAND_MAX);
	if (index == gNum)
		index = gNum - 1;

	printf("*** Duplicate test with key ");
	dumpKey(gKeys[index].data,gKeys[index].length);
	puts("...");

	status_t status;

	int32 insertTotal = 0;
	for (int32 i = 0;i < 8;i++) {
		int32 insertCount = int32(1000.0 * rand() / RAND_MAX);
		if (gVerbose)
			printf("* insert %ld to %ld old entries...\n",insertCount,insertTotal + gKeys[index].in);

		for (int32 j = 0;j < insertCount;j++) {
			status = tree->Insert(transaction,(uint8 *)gKeys[index].data,gKeys[index].length,insertTotal);
			if (status < B_OK) {
				printf("BPlusTree::Insert() returned: %s\n",strerror(status));
				bailOutWithKey(gKeys[index].data,gKeys[index].length);
			}
			insertTotal++;
			gTreeCount++;
	
			if (gExcessive)
				checkTree(tree);
		}

		int32 count;
		if (i < 7) {
			count = int32(1000.0 * rand() / RAND_MAX);
			if (count > insertTotal)
				count = insertTotal;
		} else
			count = insertTotal;

		if (gVerbose)
			printf("* remove %ld from %ld entries...\n",count,insertTotal + gKeys[index].in);

		for (int32 j = 0;j < count;j++) {
			status_t status = tree->Remove(transaction,(uint8 *)gKeys[index].data,gKeys[index].length,insertTotal - 1);
			if (status < B_OK) {
				printf("BPlusTree::Remove() returned: %s\n",strerror(status));
				bailOutWithKey(gKeys[index].data,gKeys[index].length);
			}
			insertTotal--;
			gTreeCount--;

			if (gExcessive)
				checkTree(tree);
		}
	}

	if (!gExcessive)
		checkTree(tree);
}
Esempio n. 5
0
void
dumpKeys()
{
	char *type;
	switch (gType) {
		case S_STR_INDEX:
			type = "string";
			break;
		case S_INT_INDEX:
			type = "int32";
			break;
		case S_UINT_INDEX:
			type = "uint32";
			break;
		case S_LONG_LONG_INDEX:
			type = "int64";
			break;
		case S_ULONG_LONG_INDEX:
			type = "uint64";
			break;
		case S_FLOAT_INDEX:
			type = "float";
			break;
		case S_DOUBLE_INDEX:
			type = "double";
			break;
	}
	printf("Dumping %ld keys of type %s\n",gNum,type);
	
	for (int32 i = 0;i < gNum;i++) {
		printf("% 8ld. (%3ld) key = ",i,gKeys[i].in);
		dumpKey(gKeys[i].data,gKeys[i].length);
		putchar('\n');
	}
}
Esempio n. 6
0
void
addAllKeys(Transaction *transaction, BPlusTree *tree)
{
	printf("*** Adding all keys to the tree...\n");
	for (int32 i = 0;i < gNum;i++) {
		status_t status = tree->Insert(transaction,(uint8 *)gKeys[i].data,gKeys[i].length,gKeys[i].value);
		if (status < B_OK) {
			printf("BPlusTree::Insert() returned: %s\n",strerror(status));
			printf("key: ");
			dumpKey(gKeys[i].data,gKeys[i].length);
			putchar('\n');
		}
		else {
			gKeys[i].in++;
			gTreeCount++;
		}
	}
	checkTree(tree);
}
Esempio n. 7
0
void
removeAllKeys(Transaction *transaction, BPlusTree *tree)
{
	printf("*** Removing all keys from the tree...\n");
	for (int32 i = 0;i < gNum;i++) {
		while (gKeys[i].in > 0) {
			status_t status = tree->Remove(transaction, (uint8 *)gKeys[i].data,
				gKeys[i].length, gKeys[i].value);
			if (status < B_OK) {
				printf("BPlusTree::Remove() returned: %s\n", strerror(status));
				printf("key: ");
				dumpKey(gKeys[i].data, gKeys[i].length);
				putchar('\n');
			}
			else {
				gKeys[i].in--;
				gTreeCount--;
			}
		}
	}
	checkTree(tree);
	
}
Esempio n. 8
0
void DHTNodeInfo::print(){

	cout << "for ip " << ip << " pirt " << port << endl;
	dumpKey(key);

}