linux視頻-教程專用mongodb數(shù)據(jù)存儲模型_第1頁
linux視頻-教程專用mongodb數(shù)據(jù)存儲模型_第2頁
linux視頻-教程專用mongodb數(shù)據(jù)存儲模型_第3頁
linux視頻-教程專用mongodb數(shù)據(jù)存儲模型_第4頁
linux視頻-教程專用mongodb數(shù)據(jù)存儲模型_第5頁
免費預(yù)覽已結(jié)束,剩余100頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

主講 , 分布式系統(tǒng)理數(shù) 模副本集(replica分片21998,2009,非關(guān)系分布不提供弱一

優(yōu)高吞高水平擴展能力和 不使用對象-關(guān)系映劣不支持功能3CAP

PickTolerancetonetwork4ACID&

BasicallySoft5ACIDvs.StrongFocusonNestedDifficultevolution

WeakAvailabilityBestApproximateAgressiveEasier6DatabaseRelationalKey-valueWidecolumnstores(BigTableandGraph7RelationalACID(AtomicityConsistencyIsolationandMySQL,PostgreSQL,Oracle,8WhatisNo-ReplicationSimpleEventually9Key-value“Onekey,onevalue,noduplicatesandveryIt’saThevalueisabinaryobjectaka“blob”–theDBdoesn’tunderstanditanddoesn’twanttounderstandAmazonDynamo,MemcacheDB,Key-valuestores,butthevalueis(usually)structuredand“understood”bytheDB.Queryingdataispossible(bymeansotherthanjustaAmazonSimpleDB,CouchDB,MongoDB,Riak,WhyMassivedataSomeservicessimplertoimplementthanusingGreatfitformanyWeb2.0WhyNOTRDBMSesanditstoolsareNoSQLimplementationsareoftenintheirDataconsistency,“Don’tscaleuntilyouneedRDBMSvsStrongconsistencyvsEventualBigdatasetvsHUGEScalingispossiblevsScalingisGoodavailabilityvsVeryhighIntroductiontoMongoDB(from"humongous")isascalable,high-performance,opensource,schemafree,Scalability&no-sqlScalability&DepthofWhatisHumongous(huge+SchemaOpen

GNUAGPLv3.0OSX,Linux,Windows,Solaris|32bit,64bitDevelopmentandSupportby10genandwasfirstreleasedinFebruary2009Whatis-orientedUsesJSON(BSONWritteninFullindexNotransactions(hasatomicMemory-mappedfiles(delayedCommerciallySupportedLots Whatis-based queriesexpressedinFlexibleaggregationanddataQueriesruninparallelonallStorefilesofanysizeGeospatialFindobjectbasedonlocation.(i.e.findclosesnitemstox)ManyProductionCollectionorientedstorage:easystorageofobject/JSON-styledataDynamicFullindexsupport,includingoninnerobjectsandembeddedarraysQueryReplicationandfail-overEfficientstorageofbinarydataincludinglargeobjects(e.g.photosand Auto-shardingforcloud-levelscalability(currentlyinGreatHighvolume,lowHighStorageofprogramobjectsandNotasgreatHighlyAd-hocbusiness Problemsrequiring主講 , 面向collection的數(shù)據(jù)數(shù)據(jù)庫:但數(shù)據(jù)庫無須創(chuàng)集合無須事先定義CRUD快速入門主講 , 客戶端工具MongoDBCRUD獲取幫helpondbhelponcollectionshardingreplicasethelpadministrative

helpconnectingtoadbhelpkeyhelpmiscthingstohelp顯示類命fileentrieswithtime>=showshowtheaccessibleloggershowlogprintsoutthelastsegmentofloginmemory,'global'isMongoDBCRUDMongoDBprovidesrichsemanticsforreadingandmanipulatingdataCRUDstandsforcreate,read,update,and MongoDBstoresdataintheformof s,whichareJSON-likefieldandvaluepairs sare ogoustostructuresinprogramminglanguagesthatassociatekeyswithvalues,wherekeysmayholdotherpairsofkeysandvalues(e.g.dictionaries,hashes,maps,andassociativearrays)Formally,MongoDB sareBSON s,whichisabinaryrepresentationofJSONwithadditionaltypeStoredincollection,thinkrecordorCanhave_idkeythatworkslikeprimarykeyinMySQLTwooptionsforrelationships:sub dbreferenceMongoDBMongoDBstores sinAcollectionisagroupofrelated sthathaveasetofsharedcommonindexesCollectionsare ogoustoatableinrelationalThinktable,butwithnoFor intosmallerquerysetsEachtopentityinyourappwouldhaveitsowncollection(users,articles,etc.)FullindexDatabaseOperations:InMongoDBaquerytargetsaspecificcollectionofQueriesspecifycriteria,orconditions,thatidentify sthatMongoDBreturnstotheclientsAquerymayincludeaprojectionthatspecifiesthefieldsfromthematching storeturnYoucanoptionallymodifyqueriestoimposelimits,skips,andsortordersDatabaseOperations:QueryForqueryoperations,MongoDBprovideadb.collection.find()methodThemethodacceptsboththequerycriteriaandprojectionsandreturnsacursortothematchingsSELECT&QueryAllqueriesinMongoDBaddressasingleYoucanmodifythequerytoimposelimits,skips,andsortordersTheorderof sreturnedbyaqueryisnotdefinedandisnotnecessarilyconsistentunlessyouspecifyasort()Operationsthatmodifyexisting s(i.e.updates)usethesamequerysyntaxasqueriesto stoupdateInaggregationpipeline,the$matchpipelinestageprovidesaccesstoMongoDBqueriesDataDatamodificationreferstooperationsthatcreate,update,ordeletedataInMongoDB,theseoperationsmodifythedataofasinglecollectionAllwriteoperationsinMongoDBareatomiconthelevelofasingleFortheupdateanddeleteoperations,youcanspecifythecriteriatoselectthe stoupdateorThestagesofaMongoDBinsertINSERTvs.SQLUPDATEvs.SQLDELETEvs.SQLSQLmongoDB使用示find的高級操“db.collection.find(<query>,<projection>如果使用的find()方法中不包含<query>,則意味著要返回對collection的所有文db.collection.find(高級操MongoDB的查詢操作支持挑選機制有“comparison”、“l(fā)ogical”“element”和“JavaScript”等幾比較運算value}}”;$gte:挑選指定字段值大于等于指定值的文檔,語法格式“{$gte:value}{$in:[<value1>,<value2>,...<valueN>]}value}}”;$lte:挑選指定字段值小于等于指定值的文檔,語法格式“{$lte:value}value}}”;格式field:$in[<value1<value2><valueN;使用示使用下 令生成一個含有100個文檔的>use>for{db.testColl.insert({ }>db.testColl.find({hostname:{$gt: {"_id":ObjectId("525d1e5bd249bfb8ae8c702e"),"hostname": "}{"_id":ObjectId("525d1e5bd249bfb8ae8c702f"),"hostname": "}{"_id":ObjectId("525d1e5bd249bfb8ae8c7030"),"hostname": "}{"_id":ObjectId("525d1e5bd249bfb8ae8c7031"),"hostname": "}db.collection.find(高級操邏輯運“y$or:或運算,語法格式$or:<expression1{<expression2>},...,{<expressionN>}]$and:與運算,語法格式$and:<expression1{<expression2>},...,{<expressionN>}]$not非運算,語法格式field$notoperator-expression>}}}”$nor反運算,即返回不符合所有指定條件的文檔,語法格式$nor:[{<expression1>},{<expression2>},...{<expressionN>}]使用示例如,查詢testColl中hostname的值小 ”或大于 ”的文>db.testColl.find({$or:[{hostname:{$lt: db.collection.find(高級操元素查詢$exists<boolean,指定<boolean>的值為“true”則返回存在檔;語法格式“{field:{$mod:[divisor,remainder]}}”;{$type:<BSONtype>}可用類型的列表請參 文使用示l>db.testColl.insert({"hostname":" "url":"index.html"})>db.testColl.insert({"hostname":" "url":"index.html"})>db.testColl.find({url:{$exists:{"_id":ObjectId("521083cfb639c917f2cd86e8"),"hostname":" ","url":"index.html"}更新操update()“db.collection.update(<query>,而<update>相當于附帶了“LIMIT1”的SET,如果在更新操“Field”類常用的操作如下$inc:增大指定字段的值“db.collection.update(field:value$incfield1:amount,其中field:value用于指定挑選標準,$inc:field1amount用于指定要提升其值的字段及提升大小$rename更改字段名,使用格式為“{$rename:<old<newname1>,<oldname2>:<newname2>,...}$set:修改字段的值為新指定的值,使用格式“db.collection.update(field:value1$set:field1:value2}})”;value1$unset:field1;使用示例如,更新其hostname為www15的url為MongoDB主講 , indexIndexesarespecialdatastructuresthatstoreasmallportionofthecollection’sdatasetinaneasytotraverseformTheindexstoresthevalueofaspecificfieldorsetoffields,orderedbythevalueofthefieldMongoDBdefinesindexesatthecollectionlevelandsupportsindexesonanyfieldorsub-fieldofthesinaMongoDBquerywithIndexSingleFieldAsinglefieldindexonlyincludesdatafromasinglefieldofthe sinacollectionMongoDBsupportssinglefieldindexesonfieldsatthetoplevelofa andonfieldsinsub- CompoundAcompoundindexincludesmorethanonefieldofthesinacollectionMultikeyAmultikeyindexreferencesanarrayandrecordsamatchifaqueryincludesanyvalueinthearrayGeospatialIndexesandGeospatialindexessupportlocation-basedsearchesondatathatisstoredaseitherGeoJSONobjectsorlegacycoordinatepairsTextTextindexessupportssearchofstringcontentinHashedHashedindexesmaintainentrieswithhashesofthevaluesoftheindexedfieldIndexMongoDBprovidesseveraloptionsthatonlyaffectthecreationoftheindexSpecifytheseoptionsina asthesecondargumenttothedb.collection.ensureIndex()methoduniquedb.addresses.ensureIndex({"user_id":1},{unique:true}sparsedb.addresses.ensureIndex({"xmpp_id":1},{sparse:true}Replication主講 , 架AReplicaAC CBPurposeofReplicationprovidesredundancyandincreasesdataWithmultiplecopiesofdataondifferentdatabaseservers,replicationprotectsadatabasefromthelossofasingleserverReplicationalsoallowsyoutorecoverfromhardwarefailureandserviceinterruptionsWithadditionalcopiesofthedata,youcandedicateonetodisasterrecovery,reporting,orbackupReplicationinReplicationinAreplicasetisagroupofmongodinstancesthathostthesamedatasetOnemongod,theprimary,receivesallwriteAllotherinstances,secondaries,applyoperationsfromtheprimarysothattheyhavethesamedatasetTheprimaryacceptsallwriteoperationsfromclients.ReplicasetcanhaveonlyoneprimaryBecauseonlyonemembercanacceptwriteoperations,replicasetsprovidestrictconsistencyTosupportreplication,theprimarylogsallchangestoitsdatasetsinitsoplogThesecondariesreplicatetheprimary’soplogandapplytheoperationstotheirdatasetsSecondaries’datasetsreflecttheprimary’sdataIftheprimaryisunavailable,thereplicasetwillelectasecondarytobeprimaryBydefault,clientsreadfromtheprimary,however,clientscanspecifyareadpreferencestosendreadoperationstosecondariesYoumayaddanextramongodinstanceareplicasetasanarbiterArbitersdonotmaintainadataset.ArbitersonlyexisttovoteinelectionsIfyourreplicasethasanevennumberofmembers,addanarbitertoobtainamajorityofvotesinanelectionforprimaryArbitersdonotrequirededicatedAutomaticWhenaprimarydoesnotcommunicatewiththeothermembersofthesetformorethan10seconds,thereplicasetwillattempttoselectanothermembertoethenewThefirstsecondarythatreceivesamajorityofthe esprimaryAutomaticPriority0ReplicaSetApriority0memberisasecondarythatcannoteprimaryPriority0memberscannottriggerOtherwisethesemembersfunctionasnormalApriority0membermaintainsacopyofthedataset,acceptsreadoperations,andvotesinelectionsConfigureapriority0membertopreventsecondariesfromingprimary,whichisparticularlyusefulinmulti-datacenterdeploymentsPriority0ReplicaSetInathree-memberreplicaset,inonedatacenterhoststheprimaryandasecondaryAseconddatacenterhostsonepriority0memberthatcannot eprimaryMongoDB主講 , ShardingistheprocessofstoringdatarecordsacrossmultiplemachinesandisMongoDB’sapproachtomeetingthedemandsofdatagrowthAsthesizeofthedataincreases,asinglemachinemaynotbesufficienttostorethedatanorprovideanacceptablereadandwritethroughputShardingsolvestheproblemwithhorizontalWithsharding,youaddmoremachinestosupportdatagrowthandthedemandsofreadandwritePurposeofDatabasesystemswithlargedatasetsandhighthroughputapplicationscanchallengethecapacityofasingleserverHighqueryratescanexhausttheCPUcapacityoftheLargerdatasetsexceedthestoragecapacityofasinglemachineFinally,workingsetsizeslargerthantheRAMstresstheI/OcapacityofdiskShardingShardingin ShardinginShardedclusterhasthefollowingcomponents:shards,queryroutersandconfigserversShardsstorethedata.Toprovidehighavailabilityanddataconsistency,inaproductionshardedcluster,eachshardisareplicasetQueryRouters,ormongosinstances,interfacewithclientapplicationsanddirectoperationstotheappropriateshardorThequeryrouterprocessesandtargetsoperationstoshardsandthenreturnsresultstotheclientsAshardedclustercancontainmorethanonequeryroutertodividetheclientrequestloadAclientsendsrequeststoonequeryMostshardedclusterhavemanyqueryConfigserversstorethecluster’sThisdatacontainsamap ofthecluster’sdatasettotheThequeryrouterusesthismetadatatotargetoperationsspecificProductionshardedclustershaveexactly3configDataShardToshardacollection,youneedtoselectashardAshardkeyiseitheranindexedfieldoranindexedcompoundfieldthatexistsinevery intheMongoDBdividestheshardkeyvaluesintochunksanddistributesthechunksevenlyacrosstheshardsTodividetheshardkeyvaluesintochunks,MongoDBuseseitherrangebasedpartitioningandhashbasedRangeBasedForrange-basedsharding,MongoDBdividesthedatasetintorangesdeterminedbytheshardkeyvaluestoproviderangebasedpartitioningHashBasedForhashbasedpartitioning,MongoDBcomputesahashofafield’svalue,andthenusesthesehashestocreatechunksPerformanceDistinctionsbetweenRangeandHashBasedPartitioningRangebasedpartitioningsupportsmoreefficientrangeHowever,rangebasedpartitioningcanresultinanunevendistributionofdata,whichmaynegatesomeofthebenefitsofshardingHashbasedpartitioning,bycontrast,ensuresanevendistributionofdataattheexpenseofefficientrangeButrandomdistributionmakesitmorelikelythatarangequeryontheshardkeywillnotbeabletotargetafewshardsbutwouldmorelikelyqueryeveryshardinordertoreturnaresultMaintainingaBalancedDataMongoDBensuresabalancedclusterusingtwobackgroundprocess:splittingandthebalancerAbackgroundprocessthatkeepschunksfromgrowingtooWhenachunkgrowsbeyondaspecifiedchunksize,MongoDBsplitsthechunkinhalfInsertsandupdatestriggersSplitsareaefficientmeta-data Tocreatesplits,MongoDBdoesnotmigrateanydataoraffecttheshardsThebalancerisabackgroundprocessthatmanageschunkThebalancerrunsinallofthequeryroutersinaWhenthedistrib

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論