Status RocksEngine::dropIdent(OperationContext* opCtx, StringData ident) { // TODO optimize this using CompactionFilterV2 rocksdb::WriteBatch wb; wb.Delete(kMetadataPrefix + ident.toString()); std::string prefix = _getIdentPrefix(ident); rocksdb::Slice prefixSlice(prefix.data(), prefix.size()); boost::scoped_ptr<rocksdb::Iterator> _iter(_db->NewIterator(rocksdb::ReadOptions())); for (_iter->Seek(prefixSlice); _iter->Valid() && _iter->key().starts_with(prefixSlice); _iter->Next()) { ROCKS_STATUS_OK(_iter->status()); wb.Delete(_iter->key()); } auto s = _db->Write(rocksdb::WriteOptions(), &wb); if (!s.ok()) { return toMongoStatus(s); } { boost::mutex::scoped_lock lk(_identPrefixMapMutex); _identPrefixMap.erase(ident); } return Status::OK(); }
static PyObject * keymap_iterspecial(PyKeyMapObject *self, PyObject *pymode) { int mode = -1; mode = PyInt_AsLong(pymode); // nope, no safety check. return (PyObject *)_iter(self, mode); }
void MultizoneIndividualTabForm::getLoadedBoundaryValues() { if (!_configVal->isEmpty()) { QHashIterator<QString,QString> _iter(*_configVal); while (_iter.hasNext()) { _iter.next(); QString _keyVal = _iter.key(); QString _val = _iter.value(); if( (!_keyVal.isEmpty()) && (!_val.isEmpty()) ) if (( (_keyVal.contains(MARKER_PREFIX)) || (_keyVal.contains(BC_PREFIX))) && (!_val.contains("NONE") ) ) { if (_val.contains("(")) _val.remove("("); if (_val.contains(")")) _val.remove(")"); _bndValuesSolver->insert(_keyVal,_val); } } } }
bool uninit_shared_memory() { if(vShared.empty()) return true; for(std::vector<shm_st*>::const_iterator _iter(vShared.begin());_iter!=vShared.end();++_iter) { shmdt((const void*)*_iter); } vShared.empty(); return true; }
void get_read_part() { //std::fprintf(stderr, "vShared size = %d\n",vShared.size() ); std::vector<shm_st*> _n_status; _n_status.reserve(vShared.size()); for(std::vector<shm_st*>::const_iterator _iter(vShared.begin());_iter!=vShared.end();++_iter) { if((*_iter)->nRWState==(unsigned int)SAFT_READING) { _n_status.push_back(*_iter); } } if(0==_n_status.size()) { global_vcamgetpic_current_shm=0; } else if(1==_n_status.size()) { global_vcamgetpic_current_shm=_n_status.at(0); } else { //std::sort(_n_status.begin(),_n_status.end(),get_min_shm_st_nState); std::vector<uint64_t> vState; vState.reserve(_n_status.size()); for(uint32_t i(0);i<_n_status.size();++i) { vState.push_back(_n_status[i]->nState); } std::vector<uint64_t> vState_(vState.begin(),vState.end()); std::sort(vState.begin(),vState.end(),get_min_nState); uint32_t index(-1); for (uint32_t i(0); i < vState.size(); ++i) { if(vState[0]==vState_[i]) { index=i; break; } } if(-1!=index) { global_vcamgetpic_current_shm=_n_status.at(index); } else { global_vcamgetpic_current_shm=0; } } //return 0; }
RocksEngine::RocksEngine(const std::string& path, bool durable) : _path(path), _durable(durable) { { // create block cache uint64_t cacheSizeGB = 0; ProcessInfo pi; unsigned long long memSizeMB = pi.getMemSizeMB(); if (memSizeMB > 0) { double cacheMB = memSizeMB / 2; cacheSizeGB = static_cast<uint64_t>(cacheMB / 1024); } if (cacheSizeGB < 1) { cacheSizeGB = 1; } _block_cache = rocksdb::NewLRUCache(cacheSizeGB * 1024 * 1024 * 1024LL); } // open DB rocksdb::DB* db; auto s = rocksdb::DB::Open(_options(), path, &db); ROCKS_STATUS_OK(s); _db.reset(db); // open iterator boost::scoped_ptr<rocksdb::Iterator> _iter(_db->NewIterator(rocksdb::ReadOptions())); // find maxPrefix _maxPrefix = 0; _iter->SeekToLast(); if (_iter->Valid()) { // otherwise the DB is empty, so we just keep it at 0 bool ok = extractPrefix(_iter->key(), &_maxPrefix); // this is DB corruption here invariant(ok); } // load ident to prefix map { boost::mutex::scoped_lock lk(_identPrefixMapMutex); for (_iter->Seek(kMetadataPrefix); _iter->Valid() && _iter->key().starts_with(kMetadataPrefix); _iter->Next()) { rocksdb::Slice ident(_iter->key()); ident.remove_prefix(kMetadataPrefix.size()); // this could throw DBException, which then means DB corruption. We just let it fly // to the caller BSONObj identConfig(_iter->value().data()); BSONElement element = identConfig.getField("prefix"); // TODO: SERVER-16979 Correctly handle errors returned by RocksDB // This is DB corruption invariant(!element.eoo() || !element.isNumber()); uint32_t identPrefix = static_cast<uint32_t>(element.numberInt()); _identPrefixMap[StringData(ident.data(), ident.size())] = identPrefix; } } }
void MultizoneIndividualTabForm::removeAssociatedMeshValues() { if (!_configVal->isEmpty()) { QHashIterator<QString,QString> _iter(*_configVal); while(_iter.hasNext()) { _iter.next(); QString _keyName = _iter.key(); if( (_keyName.contains(MARKER_PREFIX)) || (_keyName.contains(BC_PREFIX)) ) _configVal->insert(_keyName,"NONE"); } } }
void MultizoneIndividualTabForm::updateBoundaryValues() { removeAssociatedMeshValues(); if (!_bndValuesSolver->isEmpty()) { QHashIterator<QString,QString> _iter(*_bndValuesSolver); while (_iter.hasNext()) { _iter.next(); QString _keyname = _iter.key(); QString _value = _iter.value(); _configVal->insert(_keyname,_value); } } }
static PyObject * keymap_iteritems(PyKeyMapObject *self) { return (PyObject *)_iter(self, 2); }
static PyObject * keymap_itervalues(PyKeyMapObject *self) { return (PyObject *)_iter(self, 1); }
static PyObject * keymap_iterkeys(PyKeyMapObject *self) { return (PyObject *)_iter(self, 0); }
bool init_getpic(const char* rt_path) { //using namespace xsetpic; if(!rt_path || 0==&vShmKey) { std::fprintf(stderr, "****init_getpic error :%s\n","invalid parameter !"); return false; } if(!AutoMove(boost::filesystem::exists(AutoMove(boost::filesystem::path(rt_path))))) { std::fprintf(stderr, "****init_getpic error :%s\n","invalid runtime path,not exists !"); return false; } else { if(!AutoMove(boost::filesystem::is_directory(AutoMove(boost::filesystem::path(rt_path))))) { std::fprintf(stderr, "****init_getpic error :%s\n","invalid runtime path,is not a directory !"); return false; } } boost::filesystem::path tmp_path(rt_path); boost::filesystem::path tmp_path2(boost::filesystem::system_complete(tmp_path));; //std::string str_strart_up_dir(strart_up_dir.string()); boost::filesystem::path _rt_path(tmp_path2); char vir_dir_sub[256]; std::memset(vir_dir_sub,0x00,sizeof(vir_dir_sub)); std::sprintf(vir_dir_sub,"%s/%s",_rt_path.string().c_str(),"map"); vir_dir_sub[sizeof(vir_dir_sub)-1]='\0'; boost::filesystem::path dir_map(std::string(vir_dir_sub).c_str()); if(!boost::filesystem::exists(dir_map)) { boost::filesystem::create_directories(dir_map); } else { if(!boost::filesystem::is_directory(dir_map)) { boost::filesystem::remove(dir_map); boost::filesystem::create_directories(dir_map); } } std::list<boost::filesystem::path> list_shm_lua_file_path; list_shm_lua_file_path.clear(); int32_t n_max_shared_memory_count(16); vShmKey.clear(); vShmKey.reserve(16); while(n_max_shared_memory_count>0) { char _sz_file_path[256]; std::memset(_sz_file_path,0x00,sizeof(_sz_file_path)); std::sprintf(_sz_file_path,"%s/%d.lua",dir_map.string().c_str(),n_max_shared_memory_count-1); const boost::filesystem::path shminfo_path(std::string(_sz_file_path).c_str()); lable_recheck_shminfo_file_flag: if(boost::filesystem::exists(shminfo_path)) { if(!boost::filesystem::is_directory(shminfo_path)) { //bool b_over_write(false); uint32_t set_pic_base(_SETPIC_IPC_FLAG_); key_t real_key(ftok(shminfo_path.string().c_str(),set_pic_base)); lua_script shm_info_script(shminfo_path.string().c_str()); std::string _shm_file_path("."); //key_t shm_info_id(0); long shm_info_id(0); shm_info_script.get<std::string>("path",&_shm_file_path); shm_info_script.get<long>("id",&shm_info_id); if(0!=std::strcmp(_shm_file_path.c_str(),shminfo_path.string().c_str()) || real_key!=shm_info_id) { std::fstream _file_shm_info(shminfo_path.c_str(),std::ios::out); if(_file_shm_info) { try { std::string _shm_info_open_app( "#!/usr/bin/env lua\n"); _file_shm_info<<_shm_info_open_app<<std::endl; std::string _shm_info_open_tip( "--[[\n\n" " ATTENTION : THIS FILE IS AUTO CREATED BY CAMERA SERVICE SETPIC V3 ,USING FOR SHARED MEMORY.\n" "DO NOT CHANGE OR MOVE IT . ANY CHANGED IN THIS FILE MAY MAKE SHARED MEMORY NOT WORK .\n\n" " wangbin <*****@*****.**>\n" "]]--\n"); _file_shm_info<<_shm_info_open_tip<<std::endl; _file_shm_info<<"path =\""<<shminfo_path.string()<<"\""<<std::endl; _file_shm_info<<"id ="<<real_key; char _shm_info_delete_function[512]; std::memset(_shm_info_delete_function,0x00,sizeof(_shm_info_delete_function)); std::sprintf(_shm_info_delete_function,"\n\n--delete command: ipcrm -m shmid \n" "function delete_this_shared_memory(...)\n" " io.write(tostring(_VERSION) .. tostring(\"\\t\") .. tostring(os.date()) .. tostring(\"\\n\"))\n" " if os.getenv [[USER]] ~= tostring(\"root\") then\n" " io.write(tostring(\"For Better Execute,Suggest You Login As \\\"root\\\"\\n\"))\n" " end\n" " os.execute(\"ipcrm -m %ld\")\n" "end\n" ,real_key); _shm_info_delete_function[sizeof(_shm_info_delete_function)-1]='\0'; _file_shm_info<<std::string(_shm_info_delete_function)<<std::endl; } catch(std::exception& e) { std::fprintf(stderr, "%s\n",e.what()); } _file_shm_info.close(); } } else { vShmKey.push_back(real_key); --n_max_shared_memory_count; } } else // exist ,but is dir { boost::filesystem::remove_all(shminfo_path);//recursive delete dir std::fstream _file_shm_info(shminfo_path.string().c_str(),std::ios::out); if(_file_shm_info) { _file_shm_info.close(); } goto lable_recheck_shminfo_file_flag; } } else //not exists { std::fstream _file_shm_info(shminfo_path.string().c_str(),std::ios::out); if(_file_shm_info) { _file_shm_info.close(); } goto lable_recheck_shminfo_file_flag; } } std::reverse(vShmKey.begin(),vShmKey.end()); for(std::vector<long>::const_iterator _iter(vShmKey.begin());_iter!=vShmKey.end();++_iter) { std::fprintf(stderr, "%ld\n",*_iter); } return true; }
bool get_image_test(cv::Mat& output_src,unsigned long long int& ulldTimeStamp) { if(0==&output_src) return false; //get_read_part(); shm_st* temp_vcamgetpic_current_shm(NULL); std::vector<shm_st*> _n_status; _n_status.reserve(vShared.size()); for(std::vector<shm_st*>::const_iterator _iter(vShared.begin());_iter!=vShared.end();++_iter) { if((*_iter)->nRWState==(unsigned int)SAFT_READING) { _n_status.push_back(*_iter); } } if(0==_n_status.size()) { temp_vcamgetpic_current_shm=0; } else if(1==_n_status.size()) { temp_vcamgetpic_current_shm=_n_status.at(0); } else { //std::sort(_n_status.begin(),_n_status.end(),get_min_shm_st_nState); std::vector<uint64_t> vState; vState.reserve(_n_status.size()); for(uint32_t i(0);i<_n_status.size();++i) { vState.push_back(_n_status[i]->nState); } std::vector<uint64_t> vState_(vState.begin(),vState.end()); std::sort(vState.begin(),vState.end(),get_min_nState); uint32_t index(-1); for (uint32_t i(0); i < vState.size(); ++i) { if(vState[0]==vState_[i]) { index=i; break; } } if(-1!=index) { temp_vcamgetpic_current_shm=_n_status.at(index); } else { temp_vcamgetpic_current_shm=0; } } if(!temp_vcamgetpic_current_shm) return false; shm_st* _pshm=temp_vcamgetpic_current_shm; if(_pshm->uSizeX <=0 || _pshm->uSizeY <=0 || _pshm-> uImageSize <=0 || _pshm->uImageSize < (_pshm->uSizeX*_pshm->uSizeY)) { return false; } if(_pshm->ExtendIntA==SAFT_DELETED) return false; _pshm->ExtendIntA=LOCK_READING; cv::Mat _img; char ch((char)(_pshm->uImageSize/(_pshm->uSizeX*_pshm->uSizeY))); _img.create(_pshm->uSizeY,_pshm->uSizeX,CV_MAKETYPE(CV_8U,ch)); std::memcpy(_img.data,_pshm->szImageDataSrc,_img.rows*_img.step); ulldTimeStamp==_pshm->ulldTimeStamp; _pshm->ExtendIntA=SAFT_DELETED; if(_img.empty()) { _img.copyTo(output_src); _img.release(); return true; } else { return false; } }