summaryrefslogtreecommitdiff
path: root/src/mongo/db/index/catalog_hack.h
blob: 17eaacf78e5c027c6ca68f1d133412b41f3852fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
*    Copyright (C) 2013 10gen Inc.
*
*    This program is free software: you can redistribute it and/or  modify
*    it under the terms of the GNU Affero General Public License, version 3,
*    as published by the Free Software Foundation.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU Affero General Public License for more details.
*
*    You should have received a copy of the GNU Affero General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "mongo/db/index/2d_access_method.h"
#include "mongo/db/index/btree_access_method.h"
#include "mongo/db/index/btree_access_method_internal.h"
#include "mongo/db/index/fts_access_method.h"
#include "mongo/db/index/hash_access_method.h"
#include "mongo/db/index/haystack_access_method.h"
#include "mongo/db/index/index_access_method.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/index/s2_access_method.h"
#include "mongo/db/index_names.h"
#include "mongo/db/keypattern.h"

namespace mongo {

    /**
     * Fake some catalog behavior until the catalog is finalized.
     */
    class CatalogHack {
    public:
        static IndexDescriptor* getDescriptor(NamespaceDetails* nsd, int idxNo) {
            IndexDetails& id = nsd->idx(idxNo);
            return new IndexDescriptor(nsd, idxNo, &id, id.info.obj());
        }

        static BtreeBasedAccessMethod* getBtreeBasedIndex(IndexDescriptor* desc) {
            string type = KeyPattern::findPluginName(desc->keyPattern());
            if (IndexNames::HASHED == type) {
                return new HashAccessMethod(desc);
            } else if (IndexNames::GEO_2DSPHERE == type) {
                return new S2AccessMethod(desc);
            } else if (IndexNames::TEXT == type || IndexNames::TEXT_INTERNAL == type) {
                return new FTSAccessMethod(desc);
            } else if (IndexNames::GEO_HAYSTACK == type) {
                return new HaystackAccessMethod(desc);
            } else if ("" == type) {
                return new BtreeAccessMethod(desc);
            } else if (IndexNames::GEO_2D == type) {
                return new TwoDAccessMethod(desc);
            } else {
                cout << "Can't find index for keypattern " << desc->keyPattern() << endl;
                verify(0);
                return NULL;
            }
        }

        static IndexAccessMethod* getIndex(IndexDescriptor* desc) {
            string type = KeyPattern::findPluginName(desc->keyPattern());
            if (IndexNames::HASHED == type) {
                return new HashAccessMethod(desc);
            } else if (IndexNames::GEO_2DSPHERE == type) {
                return new S2AccessMethod(desc);
            } else if (IndexNames::TEXT == type || IndexNames::TEXT_INTERNAL == type) {
                return new FTSAccessMethod(desc);
            } else if (IndexNames::GEO_HAYSTACK == type) {
                return new HaystackAccessMethod(desc);
            } else if ("" == type) {
                return new BtreeAccessMethod(desc);
            } else if (IndexNames::GEO_2D == type) {
                return new TwoDAccessMethod(desc);
            } else {
                cout << "Can't find index for keypattern " << desc->keyPattern() << endl;
                verify(0);
                return NULL;
            }
        }

        // The IndexDetails passed in might refer to a Btree-backed index that is not a proper Btree
        // index.  Each Btree-backed index uses a BtreeCursor.  The BtreeCursor doesn't want the AM
        // for the backed index; it wants to talk Btree directly.  So BtreeCursor always asks for a
        // Btree index.
        static IndexAccessMethod* getBtreeIndex(IndexDescriptor* desc) {
            return new BtreeAccessMethod(desc);
        }
    };

}  // namespace mongo