Storage Engine API
btree_logic.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include <string>
32 
35 #include "mongo/db/jsobj.h"
36 #include "mongo/db/operation_context.h"
41 
42 namespace mongo {
43 
44 class PseudoRandom;
45 class RecordStore;
46 class SavedCursorRegistry;
47 
48 // Used for unit-testing only
49 template <class BtreeLayout>
51 template <class BtreeLayout>
53 
58 template <class BtreeLayout>
59 class BtreeLogic {
60 public:
61  // AKA _keyNode
62  typedef typename BtreeLayout::FixedWidthKeyType KeyHeaderType;
63 
64  // AKA Key
65  typedef typename BtreeLayout::KeyType KeyDataType;
66 
67  // AKA KeyOwned
68  typedef typename BtreeLayout::KeyOwnedType KeyDataOwnedType;
69 
70  // AKA Loc
71  typedef typename BtreeLayout::LocType LocType;
72 
73  // AKA BucketBasics or BtreeBucket, either one.
74  typedef typename BtreeLayout::BucketType BucketType;
75 
83  RecordStore* store,
84  SavedCursorRegistry* cursors,
85  const Ordering& ordering,
86  const std::string& indexName,
87  bool isUnique)
88  : _headManager(head),
89  _recordStore(store),
90  _cursorRegistry(cursors),
91  _ordering(ordering),
92  _indexName(indexName),
93  _isUnique(isUnique) {}
94 
95  //
96  // Public-facing
97  //
98 
99  class Builder {
100  public:
101  typedef typename BtreeLayout::KeyOwnedType KeyDataOwnedType;
102  typedef typename BtreeLayout::KeyType KeyDataType;
103 
104  Status addKey(const BSONObj& key, const DiskLoc& loc);
105 
106  private:
107  friend class BtreeLogic;
108 
109  class SetRightLeafLocChange;
110 
111  Builder(BtreeLogic* logic, OperationContext* opCtx, bool dupsAllowed);
112 
118  DiskLoc newBucket(BucketType* leftSib, DiskLoc leftSibLoc);
119 
120  BucketType* _getModifiableBucket(DiskLoc loc);
121  BucketType* _getBucket(DiskLoc loc);
122 
123  // Not owned.
125 
126  DiskLoc _rightLeafLoc; // DiskLoc of right-most (highest) leaf bucket.
128  std::unique_ptr<KeyDataOwnedType> _keyLast;
129 
130  // Not owned.
131  OperationContext* _opCtx;
132  };
133 
138  Builder* newBuilder(OperationContext* opCtx, bool dupsAllowed);
139 
140  Status dupKeyCheck(OperationContext* opCtx, const BSONObj& key, const DiskLoc& loc) const;
141 
142  Status insert(OperationContext* opCtx,
143  const BSONObj& rawKey,
144  const DiskLoc& value,
145  bool dupsAllowed);
146 
155  bool locate(OperationContext* opCtx,
156  const BSONObj& key,
157  const DiskLoc& recordLoc,
158  const int direction,
159  int* posOut,
160  DiskLoc* bucketLocOut) const;
161 
162  void advance(OperationContext* opCtx,
163  DiskLoc* bucketLocInOut,
164  int* posInOut,
165  int direction) const;
166 
167  bool exists(OperationContext* opCtx, const KeyDataType& key) const;
168 
169  bool unindex(OperationContext* opCtx, const BSONObj& key, const DiskLoc& recordLoc);
170 
171  bool isEmpty(OperationContext* opCtx) const;
172 
173  long long fullValidate(OperationContext*,
174  long long* unusedCount,
175  bool strict,
176  bool dumpBuckets,
177  unsigned depth) const;
178 
179  DiskLoc getDiskLoc(OperationContext* opCtx,
180  const DiskLoc& bucketLoc,
181  const int keyOffset) const;
182 
183  BSONObj getKey(OperationContext* opCtx, const DiskLoc& bucketLoc, const int keyOffset) const;
184 
189  IndexKeyEntry getRandomEntry(OperationContext* opCtx) const;
190 
191  DiskLoc getHead(OperationContext* opCtx) const {
193  }
194 
195  Status touch(OperationContext* opCtx) const;
196 
197  //
198  // Composite key navigation methods
199  //
200 
201  void customLocate(OperationContext* opCtx,
202  DiskLoc* locInOut,
203  int* keyOfsInOut,
204  const IndexSeekPoint& seekPoint,
205  int direction) const;
206 
207  void advanceTo(OperationContext*,
208  DiskLoc* thisLocInOut,
209  int* keyOfsInOut,
210  const IndexSeekPoint& seekPoint,
211  int direction) const;
212 
213  void restorePosition(OperationContext* opCtx,
214  const BSONObj& savedKey,
215  const DiskLoc& savedLoc,
216  int direction,
217  DiskLoc* bucketInOut,
218  int* keyOffsetInOut) const;
219 
220  //
221  // Creation and deletion
222  //
223 
227  Status initAsEmpty(OperationContext* opCtx);
228 
229  //
230  // Size constants
231  //
232 
233  const RecordStore* getRecordStore() const {
234  return _recordStore;
235  }
236 
238  return _cursorRegistry;
239  }
240 
241  static int lowWaterMark();
242 
243  Ordering ordering() const {
244  return _ordering;
245  }
246 
247  int customBSONCmp(const BSONObj& inIndex_left,
248  const IndexSeekPoint& seekPoint_right,
249  int direction) const;
250 
251  bool isUnique() const {
252  return _isUnique;
253  }
254 
255 private:
256  friend class BtreeLogic::Builder;
257 
258  // Used for unit-testing only
259  friend class BtreeLogicTestBase<BtreeLayout>;
260  friend class ArtificialTreeBuilder<BtreeLayout>;
261 
270  struct FullKey {
271  FullKey(const BucketType* bucket, int i)
272  : header(getKeyHeader(bucket, i)),
273  prevChildBucket(header.prevChildBucket),
274  recordLoc(header.recordLoc),
275  data(bucket->data + header.keyDataOfs()) {}
276 
277  // This is actually a reference to something on-disk.
278  const KeyHeaderType& header;
279 
280  // These are actually in 'header'.
281  const LocType& prevChildBucket;
282  const LocType& recordLoc;
283 
284  // This is *not* memory-mapped but its members point to something on-disk.
285  KeyDataType data;
286  };
287 
288  //
289  // Functions that depend on the templated type info but nothing in 'this'.
290  //
291 
292  static LocType& childLocForPos(BucketType* bucket, int pos);
293 
294  static FullKey getFullKey(const BucketType* bucket, int i);
295 
296  static KeyHeaderType& getKeyHeader(BucketType* bucket, int i);
297 
298  static const KeyHeaderType& getKeyHeader(const BucketType* bucket, int i);
299 
300  static char* dataAt(BucketType* bucket, short ofs);
301 
302  static void markUnused(BucketType* bucket, int keypos);
303 
304  static int totalDataSize(BucketType* bucket);
305 
306  static void init(BucketType* bucket);
307 
308  static int _alloc(BucketType* bucket, int bytes);
309 
310  static void _unalloc(BucketType* bucket, int bytes);
311 
312  static void _delKeyAtPos(BucketType* bucket, int keypos, bool mayEmpty = false);
313 
314  static void popBack(BucketType* bucket, DiskLoc* recordLocOut, KeyDataType* keyDataOut);
315 
316  static bool mayDropKey(BucketType* bucket, int index, int refPos);
317 
318  static int _packedDataSize(BucketType* bucket, int refPos);
319 
320  static void setPacked(BucketType* bucket);
321 
322  static void setNotPacked(BucketType* bucket);
323 
324  static BucketType* btreemod(OperationContext* opCtx, BucketType* bucket);
325 
326  static int splitPos(BucketType* bucket, int keypos);
327 
328  static void reserveKeysFront(BucketType* bucket, int nAdd);
329 
330  static void setKey(BucketType* bucket,
331  int i,
332  const DiskLoc recordLoc,
333  const KeyDataType& key,
334  const DiskLoc prevChildBucket);
335 
336  static bool isHead(BucketType* bucket);
337 
338  static void dumpBucket(const BucketType* bucket, int indentLength = 0);
339 
340  static void assertValid(const std::string& ns,
341  BucketType* bucket,
342  const Ordering& ordering,
343  bool force = false);
344 
345  //
346  // 'this'-specific helpers (require record store, catalog information, or ordering, or type
347  // information).
348  //
349 
350  bool basicInsert(OperationContext* opCtx,
351  BucketType* bucket,
352  const DiskLoc bucketLoc,
353  int& keypos,
354  const KeyDataType& key,
355  const DiskLoc recordLoc);
356 
357  void dropFront(BucketType* bucket, int nDrop, int& refpos);
358 
359  void _pack(OperationContext* opCtx, BucketType* bucket, const DiskLoc thisLoc, int& refPos);
360 
361  void customLocate(OperationContext* opCtx,
362  DiskLoc* locInOut,
363  int* keyOfsInOut,
364  const IndexSeekPoint& seekPoint,
365  int direction,
366  std::pair<DiskLoc, int>& bestParent) const;
367 
368  Status _find(OperationContext* opCtx,
369  BucketType* bucket,
370  const KeyDataType& key,
371  const DiskLoc& recordLoc,
372  bool errorIfDup,
373  int* keyPositionOut,
374  bool* foundOut) const;
375 
376  bool customFind(OperationContext* opCtx,
377  int low,
378  int high,
379  const IndexSeekPoint& seekPoint,
380  int direction,
381  DiskLoc* thisLocInOut,
382  int* keyOfsInOut,
383  std::pair<DiskLoc, int>& bestParent) const;
384 
385  void advanceToImpl(OperationContext* opCtx,
386  DiskLoc* thisLocInOut,
387  int* keyOfsInOut,
388  const IndexSeekPoint& seekPoint,
389  int direction) const;
390 
391  bool wouldCreateDup(OperationContext* opCtx, const KeyDataType& key, const DiskLoc self) const;
392 
393  bool keyIsUsed(OperationContext* opCtx, const DiskLoc& loc, const int& pos) const;
394 
395  void skipUnusedKeys(OperationContext* opCtx, DiskLoc* loc, int* pos, int direction) const;
396 
397  DiskLoc advance(OperationContext* opCtx,
398  const DiskLoc& bucketLoc,
399  int* posInOut,
400  int direction) const;
401 
402  DiskLoc _locate(OperationContext* opCtx,
403  const DiskLoc& bucketLoc,
404  const KeyDataType& key,
405  int* posOut,
406  bool* foundOut,
407  const DiskLoc& recordLoc,
408  const int direction) const;
409 
410  long long _fullValidate(OperationContext* opCtx,
411  const DiskLoc bucketLoc,
412  long long* unusedCount,
413  bool strict,
414  bool dumpBuckets,
415  unsigned depth) const;
416 
417  DiskLoc _addBucket(OperationContext* opCtx);
418 
419  bool canMergeChildren(OperationContext* opCtx,
420  BucketType* bucket,
421  const DiskLoc bucketLoc,
422  const int leftIndex);
423 
424  // has to look in children of 'bucket' and requires record store
425  int _rebalancedSeparatorPos(OperationContext* opCtx, BucketType* bucket, int leftIndex);
426 
427  void _packReadyForMod(BucketType* bucket, int& refPos);
428 
429  void truncateTo(BucketType* bucket, int N, int& refPos);
430 
431  void split(OperationContext* opCtx,
432  BucketType* bucket,
433  const DiskLoc bucketLoc,
434  int keypos,
435  const DiskLoc recordLoc,
436  const KeyDataType& key,
437  const DiskLoc lchild,
438  const DiskLoc rchild);
439 
440  Status _insert(OperationContext* opCtx,
441  BucketType* bucket,
442  const DiskLoc bucketLoc,
443  const KeyDataType& key,
444  const DiskLoc recordLoc,
445  bool dupsAllowed,
446  const DiskLoc leftChild,
447  const DiskLoc rightChild);
448 
449  // TODO take a BucketType*?
450  void insertHere(OperationContext* opCtx,
451  const DiskLoc bucketLoc,
452  int pos,
453  const KeyDataType& key,
454  const DiskLoc recordLoc,
455  const DiskLoc leftChild,
456  const DiskLoc rightChild);
457 
458  std::string dupKeyError(const KeyDataType& key) const;
459 
460  void setInternalKey(OperationContext* opCtx,
461  BucketType* bucket,
462  const DiskLoc bucketLoc,
463  int keypos,
464  const DiskLoc recordLoc,
465  const KeyDataType& key,
466  const DiskLoc lchild,
467  const DiskLoc rchild);
468 
469  void fixParentPtrs(OperationContext* trans,
470  BucketType* bucket,
471  const DiskLoc bucketLoc,
472  int firstIndex = 0,
473  int lastIndex = -1);
474 
475  bool mayBalanceWithNeighbors(OperationContext* opCtx,
476  BucketType* bucket,
477  const DiskLoc bucketLoc);
478 
479  void doBalanceChildren(OperationContext* opCtx,
480  BucketType* bucket,
481  const DiskLoc bucketLoc,
482  int leftIndex);
483 
484  void doBalanceLeftToRight(OperationContext* opCtx,
485  BucketType* bucket,
486  const DiskLoc thisLoc,
487  int leftIndex,
488  int split,
489  BucketType* l,
490  const DiskLoc lchild,
491  BucketType* r,
492  const DiskLoc rchild);
493 
494  void doBalanceRightToLeft(OperationContext* opCtx,
495  BucketType* bucket,
496  const DiskLoc thisLoc,
497  int leftIndex,
498  int split,
499  BucketType* l,
500  const DiskLoc lchild,
501  BucketType* r,
502  const DiskLoc rchild);
503 
504  bool tryBalanceChildren(OperationContext* opCtx,
505  BucketType* bucket,
506  const DiskLoc bucketLoc,
507  int leftIndex);
508 
509  int indexInParent(OperationContext* opCtx, BucketType* bucket, const DiskLoc bucketLoc) const;
510 
511  void doMergeChildren(OperationContext* opCtx,
512  BucketType* bucket,
513  const DiskLoc bucketLoc,
514  int leftIndex);
515 
516  void replaceWithNextChild(OperationContext* opCtx, BucketType* bucket, const DiskLoc bucketLoc);
517 
518  void deleteInternalKey(OperationContext* opCtx,
519  BucketType* bucket,
520  const DiskLoc bucketLoc,
521  int keypos);
522 
523  void delKeyAtPos(OperationContext* opCtx, BucketType* bucket, const DiskLoc bucketLoc, int p);
524 
525  void delBucket(OperationContext* opCtx, BucketType* bucket, const DiskLoc bucketLoc);
526 
527  void deallocBucket(OperationContext* opCtx, BucketType* bucket, const DiskLoc bucketLoc);
528 
529  bool _keyIsAt(const BSONObj& savedKey,
530  const DiskLoc& savedLoc,
531  BucketType* bucket,
532  int keyPos) const;
533 
542  bool pushBack(BucketType* bucket,
543  const DiskLoc recordLoc,
544  const KeyDataType& key,
545  const DiskLoc prevChild);
546 
547 
548  BucketType* childForPos(OperationContext* opCtx, BucketType* bucket, int pos) const;
549 
550  BucketType* getBucket(OperationContext* opCtx, const DiskLoc dl) const {
551  return getBucket(opCtx, dl.toRecordId());
552  }
553  BucketType* getBucket(OperationContext* opCtx, const RecordId dl) const;
554 
555  BucketType* getRoot(OperationContext* opCtx) const;
556 
557  DiskLoc getRootLoc(OperationContext* opCtx) const;
558 
559  void recordRandomWalk(OperationContext* opCtx,
560  PseudoRandom* prng,
561  BucketType* curBucket,
562  int64_t nBucketsInCurrentLevel,
563  std::vector<int64_t>* nKeysInLevel,
564  std::vector<FullKey>* selectedKeys) const;
565 
566  //
567  // Data
568  //
569 
570  // Not owned here.
572 
573  // Not owned here.
575 
576  // Not owned Here.
578 
579  Ordering _ordering;
580 
581  std::string _indexName;
582 
583  // True if this is a unique index, i.e. if duplicate key values are disallowed.
584  const bool _isUnique;
585 };
586 
587 } // namespace mongo
Status _insert(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc, const KeyDataType &key, const DiskLoc recordLoc, bool dupsAllowed, const DiskLoc leftChild, const DiskLoc rightChild)
Definition: btree_logic.cpp:2171
std::string _indexName
Definition: btree_logic.h:581
void replaceWithNextChild(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc)
Definition: btree_logic.cpp:1290
FullKey(const BucketType *bucket, int i)
Definition: btree_logic.h:271
int ofs
Definition: btree_interface.cpp:337
void restorePosition(OperationContext *opCtx, const BSONObj &savedKey, const DiskLoc &savedLoc, int direction, DiskLoc *bucketInOut, int *keyOffsetInOut) const
Definition: btree_logic.cpp:1149
BucketType * _getModifiableBucket(DiskLoc loc)
Definition: btree_logic.cpp:210
bool locate(OperationContext *opCtx, const BSONObj &key, const DiskLoc &recordLoc, const int direction, int *posOut, DiskLoc *bucketLocOut) const
Navigates down the tree and locates the bucket and position containing a record with the specified <k...
Definition: btree_logic.cpp:2304
void recordRandomWalk(OperationContext *opCtx, PseudoRandom *prng, BucketType *curBucket, int64_t nBucketsInCurrentLevel, std::vector< int64_t > *nKeysInLevel, std::vector< FullKey > *selectedKeys) const
Does a random walk through the tree, recording information about the walk along the way...
Definition: btree_logic.cpp:1992
This is the logic for manipulating the Btree.
Definition: btree_logic.h:59
bool customFind(OperationContext *opCtx, int low, int high, const IndexSeekPoint &seekPoint, int direction, DiskLoc *thisLocInOut, int *keyOfsInOut, std::pair< DiskLoc, int > &bestParent) const
Definition: btree_logic.cpp:849
void delKeyAtPos(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc, int p)
May delete the bucket &#39;bucket&#39; rendering &#39;bucketLoc&#39; invalid.
Definition: btree_logic.cpp:1196
void doBalanceLeftToRight(OperationContext *opCtx, BucketType *bucket, const DiskLoc thisLoc, int leftIndex, int split, BucketType *l, const DiskLoc lchild, BucketType *r, const DiskLoc rchild)
Definition: btree_logic.cpp:1478
Collection *const const NamespaceString & ns
Definition: collection_info_cache_impl.cpp:53
void _packReadyForMod(BucketType *bucket, int &refPos)
Version when write intent already declared.
Definition: btree_logic.cpp:535
void setInternalKey(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc, int keypos, const DiskLoc recordLoc, const KeyDataType &key, const DiskLoc lchild, const DiskLoc rchild)
Definition: btree_logic.cpp:1678
Ordering _ordering
Definition: btree_logic.h:579
bool wouldCreateDup(OperationContext *opCtx, const KeyDataType &key, const DiskLoc self) const
Definition: btree_logic.cpp:977
BSONObj getKey(OperationContext *opCtx, const DiskLoc &bucketLoc, const int keyOffset) const
Definition: btree_logic.cpp:1900
OperationContext * _opCtx
Definition: btree_logic.h:131
KeyDataType data
Definition: btree_logic.h:285
int indexInParent(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc) const
Definition: btree_logic.cpp:1439
SavedCursorRegistry * _cursorRegistry
Definition: btree_logic.h:577
static void _unalloc(BucketType *bucket, int bytes)
Definition: btree_logic.cpp:307
void split(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc, int keypos, const DiskLoc recordLoc, const KeyDataType &key, const DiskLoc lchild, const DiskLoc rchild)
Definition: btree_logic.cpp:1763
HeadManager * _headManager
Definition: btree_logic.h:571
static bool mayDropKey(BucketType *bucket, int index, int refPos)
With this implementation, refPos == 0 disregards effect of refPos.
Definition: btree_logic.cpp:491
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
static int lowWaterMark()
Definition: btree_logic.cpp:291
OperationContext Database StringData BSONObj CollectionOptions::ParseKind bool const BSONObj &idIndex Status
Definition: database_impl.cpp:956
Builder(BtreeLogic *logic, OperationContext *opCtx, bool dupsAllowed)
Definition: btree_logic.cpp:88
bool _keyIsAt(const BSONObj &savedKey, const DiskLoc &savedLoc, BucketType *bucket, int keyPos) const
Definition: btree_logic.cpp:1177
void advance(OperationContext *opCtx, DiskLoc *bucketLocInOut, int *posInOut, int direction) const
Definition: btree_logic.cpp:684
BucketType * getRoot(OperationContext *opCtx) const
Definition: btree_logic.cpp:2401
bool keyIsUsed(OperationContext *opCtx, const DiskLoc &loc, const int &pos) const
Definition: btree_logic.cpp:2297
BtreeLayout::KeyType KeyDataType
Definition: btree_logic.h:65
bool pushBack(BucketType *bucket, const DiskLoc recordLoc, const KeyDataType &key, const DiskLoc prevChild)
Tries to push key into bucket.
Definition: btree_logic.cpp:390
long long fullValidate(OperationContext *, long long *unusedCount, bool strict, bool dumpBuckets, unsigned depth) const
Definition: btree_logic.cpp:2023
static void markUnused(BucketType *bucket, int keypos)
Definition: btree_logic.cpp:252
RecordStore * _recordStore
Definition: btree_logic.h:574
BucketType * getBucket(OperationContext *opCtx, const DiskLoc dl) const
Definition: btree_logic.h:550
BSONObj key
Definition: btree_interface.cpp:334
bool mayBalanceWithNeighbors(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc)
Definition: btree_logic.cpp:1589
Status initAsEmpty(OperationContext *opCtx)
Returns OK if the index was uninitialized before, error status otherwise.
Definition: btree_logic.cpp:1845
bool isEmpty(OperationContext *opCtx) const
Definition: btree_logic.cpp:1649
const KeyHeaderType & header
Definition: btree_logic.h:278
BucketType * _getBucket(DiskLoc loc)
Definition: btree_logic.cpp:215
static void setNotPacked(BucketType *bucket)
Definition: btree_logic.cpp:326
BucketType * childForPos(OperationContext *opCtx, BucketType *bucket, int pos) const
Definition: btree_logic.cpp:2412
static void setPacked(BucketType *bucket)
Definition: btree_logic.cpp:331
void doMergeChildren(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc, int leftIndex)
Definition: btree_logic.cpp:1394
static int splitPos(BucketType *bucket, int keypos)
In the standard btree algorithm, we would split based on the existing keys and the new key...
Definition: btree_logic.cpp:607
Builder * newBuilder(OperationContext *opCtx, bool dupsAllowed)
Caller owns the returned pointer.
Definition: btree_logic.cpp:82
static bool isHead(BucketType *bucket)
Definition: btree_logic.cpp:2381
static int _alloc(BucketType *bucket, int bytes)
We allocate space from the end of the buffer for data.
Definition: btree_logic.cpp:316
represents a disk location/offset on disk in a database.
Definition: diskloc.h:53
void advanceToImpl(OperationContext *opCtx, DiskLoc *thisLocInOut, int *keyOfsInOut, const IndexSeekPoint &seekPoint, int direction) const
find smallest/biggest value greater-equal/less-equal than specified
Definition: btree_logic.cpp:722
void customLocate(OperationContext *opCtx, DiskLoc *locInOut, int *keyOfsInOut, const IndexSeekPoint &seekPoint, int direction) const
Definition: btree_logic.cpp:672
RecordId toRecordId() const
Definition: diskloc.h:185
static char * dataAt(BucketType *bucket, short ofs)
Definition: btree_logic.cpp:258
static void _delKeyAtPos(BucketType *bucket, int keypos, bool mayEmpty=false)
Definition: btree_logic.cpp:336
SavedCursorRegistry * savedCursors() const
Definition: btree_logic.h:237
bool basicInsert(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc, int &keypos, const KeyDataType &key, const DiskLoc recordLoc)
Durability note:
Definition: btree_logic.cpp:436
virtual const RecordId getHead(OperationContext *opCtx) const =0
std::shared_ptr< void > data
Definition: ephemeral_for_test_record_store_test.cpp:74
Status insert(OperationContext *opCtx, const BSONObj &rawKey, const DiskLoc &value, bool dupsAllowed)
Definition: btree_logic.cpp:2151
BtreeLogic * _logic
Definition: btree_logic.h:124
Status touch(OperationContext *opCtx) const
Definition: btree_logic.cpp:2018
void doBalanceChildren(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc, int leftIndex)
Definition: btree_logic.cpp:1562
static DiskLoc fromRecordId(RecordId id)
Definition: diskloc.h:168
bool canMergeChildren(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc, const int leftIndex)
Definition: btree_logic.cpp:1310
static int _packedDataSize(BucketType *bucket, int refPos)
Definition: btree_logic.cpp:497
void delBucket(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc)
Definition: btree_logic.cpp:1126
IndexKeyEntry getRandomEntry(OperationContext *opCtx) const
Returns a pseudo-random element from the tree.
Definition: btree_logic.cpp:1923
static void dumpBucket(const BucketType *bucket, int indentLength=0)
Definition: btree_logic.cpp:1870
std::unique_ptr< KeyDataOwnedType > _keyLast
Definition: btree_logic.h:128
DiskLoc getRootLoc(OperationContext *opCtx) const
Definition: btree_logic.cpp:2407
const bool _isUnique
Definition: btree_logic.h:584
DiskLoc getHead(OperationContext *opCtx) const
Definition: btree_logic.h:191
int _rebalancedSeparatorPos(OperationContext *opCtx, BucketType *bucket, int leftIndex)
This implementation must respect the meaning and value of lowWaterMark.
Definition: btree_logic.cpp:1340
DiskLoc getDiskLoc(OperationContext *opCtx, const DiskLoc &bucketLoc, const int keyOffset) const
Definition: btree_logic.cpp:1891
void deleteInternalKey(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc, int keypos)
This function replaces the specified key (k) by either the prev or next key in the btree (k&#39;)...
Definition: btree_logic.cpp:1253
An abstraction used for storing documents in a collection or entries in an index. ...
Definition: record_store.h:282
DiskLoc bucket
Definition: btree_interface.cpp:336
bool unindex(OperationContext *opCtx, const BSONObj &key, const DiskLoc &recordLoc)
Definition: btree_logic.cpp:1632
bool isUnique() const
Definition: btree_logic.h:251
void advanceTo(OperationContext *, DiskLoc *thisLocInOut, int *keyOfsInOut, const IndexSeekPoint &seekPoint, int direction) const
Definition: btree_logic.cpp:703
BtreeLogic(HeadManager *head, RecordStore *store, SavedCursorRegistry *cursors, const Ordering &ordering, const std::string &indexName, bool isUnique)
&#39;head&#39; manages the catalog information.
Definition: btree_logic.h:82
static FullKey getFullKey(const BucketType *bucket, int i)
Definition: btree_logic.cpp:226
static int totalDataSize(BucketType *bucket)
Definition: btree_logic.cpp:270
DiskLoc _rightLeafLoc
Definition: btree_logic.h:126
static void popBack(BucketType *bucket, DiskLoc *recordLocOut, KeyDataType *keyDataOut)
Pull rightmost key from the bucket and set its prevChild pointer to be the nextChild for the whole bu...
Definition: btree_logic.cpp:363
BtreeLayout::KeyType KeyDataType
Definition: btree_logic.h:102
static void assertValid(const std::string &ns, BucketType *bucket, const Ordering &ordering, bool force=false)
Definition: btree_logic.cpp:2091
DiskLoc newBucket(BucketType *leftSib, DiskLoc leftSibLoc)
Creates and returns a new empty bucket to the right of leftSib, maintaining the internal consistency ...
Definition: btree_logic.cpp:164
Tool to construct custom tree shapes for tests.
Definition: btree_logic.h:52
long long _fullValidate(OperationContext *opCtx, const DiskLoc bucketLoc, long long *unusedCount, bool strict, bool dumpBuckets, unsigned depth) const
Definition: btree_logic.cpp:2032
std::string dupKeyError(const KeyDataType &key) const
Definition: btree_logic.cpp:1002
BtreeLayout::BucketType BucketType
Definition: btree_logic.h:74
DiskLoc _locate(OperationContext *opCtx, const DiskLoc &bucketLoc, const KeyDataType &key, int *posOut, bool *foundOut, const DiskLoc &recordLoc, const int direction) const
Recursively walk down the btree, looking for a match of key and recordLoc.
Definition: btree_logic.cpp:2329
BtreeLayout::FixedWidthKeyType KeyHeaderType
Definition: btree_logic.h:62
static void setKey(BucketType *bucket, int i, const DiskLoc recordLoc, const KeyDataType &key, const DiskLoc prevChildBucket)
Definition: btree_logic.cpp:647
const RecordStore * getRecordStore() const
Definition: btree_logic.h:233
void doBalanceRightToLeft(OperationContext *opCtx, BucketType *bucket, const DiskLoc thisLoc, int leftIndex, int split, BucketType *l, const DiskLoc lchild, BucketType *r, const DiskLoc rchild)
Definition: btree_logic.cpp:1518
static void init(BucketType *bucket)
Definition: btree_logic.cpp:296
BtreeLayout::KeyOwnedType KeyDataOwnedType
Definition: btree_logic.h:68
void _pack(OperationContext *opCtx, BucketType *bucket, const DiskLoc thisLoc, int &refPos)
When we delete things, we just leave empty space until the node is full and then we repack it...
Definition: btree_logic.cpp:518
BtreeLayout::LocType LocType
Definition: btree_logic.h:71
BtreeLayout::KeyOwnedType KeyDataOwnedType
Definition: btree_logic.h:101
void dropFront(BucketType *bucket, int nDrop, int &refpos)
Definition: btree_logic.cpp:662
Status dupKeyCheck(OperationContext *opCtx, const BSONObj &key, const DiskLoc &loc) const
Definition: btree_logic.cpp:965
An abstraction for setting and getting data about the &#39;head&#39; of an index.
Definition: head_manager.h:41
bool _dupsAllowed
Definition: btree_logic.h:127
Describes a query that can be compared against an IndexKeyEntry in a way that allows expressing exclu...
Definition: index_entry_comparison.h:104
Definition: btree_logic.h:99
int customBSONCmp(const BSONObj &inIndex_left, const IndexSeekPoint &seekPoint_right, int direction) const
NOTE: Currently the Ordering implementation assumes a compound index will not have more keys than an ...
Definition: btree_logic.cpp:903
Status _find(OperationContext *opCtx, BucketType *bucket, const KeyDataType &key, const DiskLoc &recordLoc, bool errorIfDup, int *keyPositionOut, bool *foundOut) const
Find a key within this btree bucket.
Definition: btree_logic.cpp:1025
Status addKey(const BSONObj &key, const DiskLoc &loc)
Definition: btree_logic.cpp:120
Represents a single item in an index.
Definition: index_entry_comparison.h:45
void deallocBucket(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc)
Definition: btree_logic.cpp:1140
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
void skipUnusedKeys(OperationContext *opCtx, DiskLoc *loc, int *pos, int direction) const
Definition: btree_logic.cpp:693
Class that stores active cursors that have been saved (as part of yielding) to allow them to be inval...
Definition: record_store_v1_base.h:104
DiskLoc _addBucket(OperationContext *opCtx)
Definition: btree_logic.cpp:1855
const LocType & prevChildBucket
Definition: btree_logic.h:281
This is an in memory wrapper for the variable length data associated with a KeyHeaderType.
Definition: btree_logic.h:270
static KeyHeaderType & getKeyHeader(BucketType *bucket, int i)
Definition: btree_logic.cpp:239
static BucketType * btreemod(OperationContext *opCtx, BucketType *bucket)
Definition: btree_logic.cpp:263
bool exists(OperationContext *opCtx, const KeyDataType &key) const
Definition: btree_logic.cpp:945
void insertHere(OperationContext *opCtx, const DiskLoc bucketLoc, int pos, const KeyDataType &key, const DiskLoc recordLoc, const DiskLoc leftChild, const DiskLoc rightChild)
insert a key in this bucket, splitting if necessary.
Definition: btree_logic.cpp:1712
void truncateTo(BucketType *bucket, int N, int &refPos)
Definition: btree_logic.cpp:585
Ordering ordering() const
Definition: btree_logic.h:243
bool tryBalanceChildren(OperationContext *opCtx, BucketType *bucket, const DiskLoc bucketLoc, int leftIndex)
Definition: btree_logic.cpp:1463
void fixParentPtrs(OperationContext *trans, BucketType *bucket, const DiskLoc bucketLoc, int firstIndex=0, int lastIndex=-1)
This can cause a lot of additional page writes when we assign buckets to different parents...
Definition: btree_logic.cpp:1658
static LocType & childLocForPos(BucketType *bucket, int pos)
Definition: btree_logic.cpp:2419
This class is made friend of BtreeLogic so we can add whatever private method accesses we need to it...
Definition: btree_logic.h:50
const LocType & recordLoc
Definition: btree_logic.h:282
static void reserveKeysFront(BucketType *bucket, int nAdd)
Definition: btree_logic.cpp:637