Beispiel #1
0
// recover the deleted record
INDEXWRITE_RETVAL IndexData::_recoverRecord(const std::string &externalRecordId,
		unsigned internalRecordId) {
	INDEXWRITE_RETVAL success =
			this->forwardIndex->recoverRecord(externalRecordId,
					internalRecordId) ? OP_SUCCESS : OP_FAIL;

	if(success == OP_SUCCESS){
		this->forwardIndex->getInternalRecordIdFromExternalRecordId(
				externalRecordId, internalRecordId);
		ForwardList* forwardList =
				this->forwardIndex->getForwardList_ForCommit(internalRecordId);

		this->permissionMap->appendResourceToRoles(externalRecordId, forwardList->getAccessList()->getRoles());

		if (this->schemaInternal->getIndexType()
						== srch2::instantsearch::LocationIndex) {

			StoredRecordBuffer buffer = forwardList->getInMemoryData();

			Schema * storedSchema = Schema::create();
			srch2::util::RecordSerializerUtil::populateStoredSchema(storedSchema,
					this->getSchema());
			srch2::util::RecordSerializer compactRecDeserializer =
					srch2::util::RecordSerializer(*storedSchema);

			// get the name of the attributes
			const string* nameOfLatitudeAttribute =
					this->getSchema()->getNameOfLatituteAttribute();
			const string* nameOfLongitudeAttribute =
					this->getSchema()->getNameOfLongitudeAttribute();

			unsigned idLat = storedSchema->getRefiningAttributeId(
					*nameOfLatitudeAttribute);
			unsigned latOffset = compactRecDeserializer.getRefiningOffset(idLat);

			unsigned idLong = storedSchema->getRefiningAttributeId(
					*nameOfLongitudeAttribute);
			unsigned longOffset = compactRecDeserializer.getRefiningOffset(idLong);
			Point point;
			point.x = *((float *) (buffer.start.get() + latOffset));
			point.y = *((float *) (buffer.start.get() + longOffset));
			this->quadTree->insert_ThreadSafe(point, internalRecordId);
		}
	}



	if (success == OP_SUCCESS) {
		this->mergeRequired = true; // need to tell the merge thread to merge

		// recover the changes to the counters made by _deleteRecordGetInternalId
		this->writeCounter->incDocsCounter();
		this->writeCounter->decWritesCounter();
	}

	return success;
}
Beispiel #2
0
// delete a record with a specific id //TODO Give the correct return message for delete pass/fail
// get the deleted internal recordID
INDEXWRITE_RETVAL IndexData::_deleteRecordGetInternalId(
		const std::string &externalRecordId, unsigned &internalRecordId) {
	bool hasRecord =
			this->forwardIndex->getInternalRecordIdFromExternalRecordId(
					externalRecordId, internalRecordId);
	if (hasRecord) {
		ForwardList* forwardList =
				this->forwardIndex->getForwardList_ForCommit(
						internalRecordId);
		this->permissionMap->deleteResourceFromRoles(externalRecordId, forwardList->getAccessList()->getRoles());

		if (this->schemaInternal->getIndexType()
				== srch2::instantsearch::LocationIndex) {

				StoredRecordBuffer buffer = forwardList->getInMemoryData();

				Schema * storedSchema = Schema::create();
				srch2::util::RecordSerializerUtil::populateStoredSchema(
						storedSchema, this->getSchema());
				srch2::util::RecordSerializer compactRecDeserializer =
						srch2::util::RecordSerializer(*storedSchema);

				// get the name of the attributes
				const string* nameOfLatitudeAttribute =
						this->getSchema()->getNameOfLatituteAttribute();
				const string* nameOfLongitudeAttribute =
						this->getSchema()->getNameOfLongitudeAttribute();

				unsigned idLat = storedSchema->getRefiningAttributeId(
						*nameOfLatitudeAttribute);
				unsigned latOffset = compactRecDeserializer.getRefiningOffset(
						idLat);

				unsigned idLong = storedSchema->getRefiningAttributeId(
						*nameOfLongitudeAttribute);
				unsigned longOffset = compactRecDeserializer.getRefiningOffset(
						idLong);
				Point point;
				point.x = *((float *) (buffer.start.get() + latOffset));
				point.y = *((float *) (buffer.start.get() + longOffset));
				this->quadTree->remove_ThreadSafe(point, internalRecordId);
		}
	}

	INDEXWRITE_RETVAL success =
			this->forwardIndex->deleteRecord(externalRecordId) ?
					OP_SUCCESS : OP_FAIL;


	if (success == OP_SUCCESS) {
		ForwardList * fwdList = this->forwardIndex->getForwardList_ForCommit(internalRecordId);
		if (fwdList) {
			unsigned keywordsCount = fwdList->getNumberOfKeywords();
			const unsigned * listofKeywordIds = fwdList->getKeywordIds();
			// Loop over the keyword-ids for the current forward list and get
			// the inverted-list-ids from the trie.
			TrieNodePath trieNodePath;
			trieNodePath.path = new vector<TrieNode *>();
			// first id: invertedListId; second id: keywordId
			vector<pair<unsigned, unsigned> > invertedListIdsToMerge;
			for (unsigned i = 0; i < keywordsCount; ++i) {
				unsigned keywordId = *(listofKeywordIds + i);
				// get the TrieNode path of the current keyword in write view based on its id.
				this->trie->getKeywordCorrespondingPathToTrieNode_WriteView(keywordId, &trieNodePath);
				if (trieNodePath.path->size() == 0) {
					// should not happen.
					ASSERT(false);
					continue;
				}
				TrieNode * leafNode = trieNodePath.path->back();
				if(leafNode && leafNode->isTerminalNode()) {
					invertedListIdsToMerge.push_back(make_pair(leafNode->invertedListOffset, leafNode->id));
				} else {
					// should not happen.
					ASSERT(false);
				}
				trieNodePath.path->clear();
			}
			delete trieNodePath.path;
			this->invertedIndex->appendInvertedListKeywordIdsForMerge(invertedListIdsToMerge);
		}

		this->mergeRequired = true; // need to tell the merge thread to merge
		this->writeCounter->decDocsCounter();
		this->writeCounter->incWritesCounter();
	}

	return success;
}