void StatServer::clearForward(AgentFlushRequest * agentFlushRequest) { std::tr1::unordered_map<std::string, Bucketizer> buckets; { grab aholdof(forwardMutex_); buckets.swap(forwardBuckets_); } ForwardList conns; for (ForwardList::iterator i = forward_.begin(); i < forward_.end(); ++i) { if ((*i)->opened()) { conns.push_back(*i); } } size_t count = conns.size(); if ((count > 0) && buckets.size()) { size_t forwardIndex = 0; // if not opened, then we lose this bucket std::stringstream ss[count]; for (std::tr1::unordered_map<std::string, Bucketizer>::iterator ptr(buckets.begin()), end (buckets.end()); ptr != end; ++ptr) { Bucketizer &bizer((*ptr).second); if ((*ptr).first[0] == '*') { for (unsigned int i = 0 ; i < bizer.BUCKET_COUNT; i++) { istat::Bucket b = bizer.get(i); if (b.count() > 0) { ss[forwardIndex] << (*ptr).first << " " << b.time() << " " << b.sum() << "\r\n"; } } } else { for (unsigned int i = 0 ; i < bizer.BUCKET_COUNT; i++) { istat::Bucket b = bizer.get(i); if (b.count() > 0) { ss[forwardIndex] << (*ptr).first << " " << b.time() << " " << b.sum() << " " << b.sumSq() << " " << b.min() << " " << b.max() << " " << b.count() << "\r\n"; } } } ++forwardIndex; forwardIndex %= count; } for (size_t i = 0; i < count; ++i) { std::string str(ss[i].str()); if (!str.empty()) { size_t pending = conns[i]->writeOut(str); if (agentFlushRequest != NULL) { agentFlushRequest->add(i, pending); } } } } }
// 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; }
int main(int argc, const char * argv[]) { int size = 0; //N scanf("%d", &size); int offset = 0; //k scanf("%d", &offset); ForwardList* list = new ForwardList(size); fill_list(*list, size); delete_every_offset(*list, offset); printf("%d", list->getHead()->numberOfNode); return 0; }
void delete_every_offset(ForwardList &list, int offset){ int counter = 0; ForwardList::node *node = list.getHead(); for (int i = 0; i < offset - 2; ++i) { //при первом удалении нужно пройти на 1 указатель меньше node = node -> next; } list.remove_after(node); for (; list.getHead()->next != list.getHead(); node = node->next) { if (counter == offset - 1) { list.remove_after(node); counter = 0; } counter++; } }
void fill_list(ForwardList &list, int number){ //заполняем список if (list.getHead() == 0) { list.push_back(list.getHead()); } for(int i = 0; ( i < list.max_size() - 1) && i < number; ++i) list.push_back(list.end(), list.order_number() + 1); }
// 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; }