|
24 | 24 | #include "mongo/db/index_update.h" |
25 | 25 | #include "mongo/db/jsobj.h" |
26 | 26 | #include "mongo/db/namespace_details.h" |
| 27 | +#include "mongo/db/repl/rs.h" |
27 | 28 |
|
28 | 29 | namespace mongo { |
29 | 30 |
|
@@ -67,23 +68,58 @@ namespace mongo { |
67 | 68 | void prefetchIndexPages(NamespaceDetails *nsd, const BSONObj& obj) { |
68 | 69 | DiskLoc unusedDl; // unused |
69 | 70 | IndexInterface::IndexInserter inserter; |
70 | | - |
71 | | - // includes all indexes, including ones |
72 | | - // in the process of being built |
73 | | - int indexCount = nsd->nIndexesBeingBuilt(); |
74 | 71 | BSONObjSet unusedKeys; |
75 | | - for ( int indexNo = 0; indexNo < indexCount; indexNo++ ) { |
76 | | - // This will page in all index pages for the given object. |
| 72 | + ReplSetImpl::IndexPrefetchConfig prefetchConfig = theReplSet->getIndexPrefetchConfig(); |
| 73 | + switch (prefetchConfig) { |
| 74 | + case ReplSetImpl::PREFETCH_NONE: |
| 75 | + return; |
| 76 | + case ReplSetImpl::PREFETCH_ID_ONLY: |
| 77 | + { |
| 78 | + int indexNo = nsd->findIdIndex(); |
| 79 | + if (indexNo == -1) return; |
77 | 80 | try { |
78 | | - fetchIndexInserters(/*out*/unusedKeys, inserter, nsd, indexNo, obj, unusedDl, /*allowDups*/true); |
| 81 | + fetchIndexInserters(/*out*/unusedKeys, |
| 82 | + inserter, |
| 83 | + nsd, |
| 84 | + indexNo, |
| 85 | + obj, |
| 86 | + unusedDl, |
| 87 | + /*allowDups*/true); |
79 | 88 | } |
80 | 89 | catch (const DBException& e) { |
81 | 90 | LOG(2) << "ignoring exception in prefetchIndexPages(): " << e.what() << endl; |
82 | 91 | } |
83 | | - unusedKeys.clear(); |
| 92 | + break; |
| 93 | + } |
| 94 | + case ReplSetImpl::PREFETCH_ALL: |
| 95 | + { |
| 96 | + // indexCount includes all indexes, including ones |
| 97 | + // in the process of being built |
| 98 | + int indexCount = nsd->nIndexesBeingBuilt(); |
| 99 | + for ( int indexNo = 0; indexNo < indexCount; indexNo++ ) { |
| 100 | + // This will page in all index pages for the given object. |
| 101 | + try { |
| 102 | + fetchIndexInserters(/*out*/unusedKeys, |
| 103 | + inserter, |
| 104 | + nsd, |
| 105 | + indexNo, |
| 106 | + obj, |
| 107 | + unusedDl, |
| 108 | + /*allowDups*/true); |
| 109 | + } |
| 110 | + catch (const DBException& e) { |
| 111 | + LOG(2) << "ignoring exception in prefetchIndexPages(): " << e.what() << endl; |
| 112 | + } |
| 113 | + unusedKeys.clear(); |
| 114 | + } |
| 115 | + break; |
| 116 | + } |
| 117 | + default: |
| 118 | + fassertFailed(16427); |
84 | 119 | } |
85 | 120 | } |
86 | 121 |
|
| 122 | + |
87 | 123 | void prefetchRecordPages(const char* ns, const BSONObj& obj) { |
88 | 124 | BSONElement _id; |
89 | 125 | if( obj.getObjectID(_id) ) { |
|
0 commit comments