summaryrefslogtreecommitdiff
path: root/src/mongo/db/index/columns_access_method.h
blob: 91004d3c0636cc55389866013ceb4f26d00ad9a4 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
 *    Copyright (C) 2022-present MongoDB, Inc.
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the Server Side Public License, version 1,
 *    as published by MongoDB, Inc.
 *
 *    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
 *    Server Side Public License for more details.
 *
 *    You should have received a copy of the Server Side Public License
 *    along with this program. If not, see
 *    <http://www.mongodb.com/licensing/server-side-public-license>.
 *
 *    As a special exception, the copyright holders give permission to link the
 *    code of portions of this program with the OpenSSL library under certain
 *    conditions as described in each individual source file and distribute
 *    linked combinations including the program with the OpenSSL library. You
 *    must comply with the Server Side Public License in all respects for
 *    all of the code used other than as permitted herein. If you modify file(s)
 *    with this exception, you may extend this exception to your version of the
 *    file(s), but you are not obligated to do so. If you do not wish to do so,
 *    delete this exception statement from your version. If you delete this
 *    exception statement from all source files in the program, then also delete
 *    it in the license file.
 */

#pragma once

#include "mongo/db/index/column_cell.h"
#include "mongo/db/index/column_key_generator.h"
#include "mongo/db/index/index_access_method.h"
#include "mongo/db/storage/column_store.h"

namespace mongo {

class ColumnStoreAccessMethod : public IndexAccessMethod {
    ColumnStoreAccessMethod(const ColumnStoreAccessMethod&) = delete;
    ColumnStoreAccessMethod& operator=(const ColumnStoreAccessMethod&) = delete;

public:
    //
    // Column-specific APIs
    //


    ColumnStoreAccessMethod(IndexCatalogEntry* ice, std::unique_ptr<ColumnStore>);

    const column_keygen::ColumnKeyGenerator& getKeyGen() const {
        return _keyGen;
    }

    /**
     * Returns a pointer to the ColumnstoreProjection owned by the underlying ColumnKeyGenerator.
     */
    const ColumnStoreProjection* getColumnstoreProjection() const {
        return _keyGen.getColumnstoreProjection();
    }

    //
    // Generic IndexAccessMethod APIs
    //

    Status insert(OperationContext* opCtx,
                  SharedBufferFragmentBuilder& pooledBufferBuilder,
                  const CollectionPtr& coll,
                  const std::vector<BsonRecord>& bsonRecords,
                  const InsertDeleteOptions& options,
                  int64_t* keysInsertedOut) final;

    void remove(OperationContext* opCtx,
                SharedBufferFragmentBuilder& pooledBufferBuilder,
                const CollectionPtr& coll,
                const BSONObj& obj,
                const RecordId& rid,
                bool logIfError,
                const InsertDeleteOptions& options,
                int64_t* keysDeletedOut,
                CheckRecordId checkRecordId) final;

    Status update(OperationContext* opCtx,
                  SharedBufferFragmentBuilder& pooledBufferBuilder,
                  const BSONObj& oldDoc,
                  const BSONObj& newDoc,
                  const RecordId& rid,
                  const CollectionPtr& coll,
                  const InsertDeleteOptions& options,
                  int64_t* keysInsertedOut,
                  int64_t* keysDeletedOut) final;

    Status applyIndexBuildSideWrite(OperationContext* opCtx,
                                    const CollectionPtr& coll,
                                    const BSONObj& operation,
                                    const InsertDeleteOptions& unusedOptions,
                                    KeyHandlerFn&& unusedFn,
                                    int64_t* keysInserted,
                                    int64_t* keysDeleted) final;

    Status initializeAsEmpty(OperationContext* opCtx) final;

    IndexValidateResults validate(OperationContext* opCtx, bool full) const final;

    int64_t numKeys(OperationContext* opCtx) const final;

    bool appendCustomStats(OperationContext* opCtx,
                           BSONObjBuilder* result,
                           double scale) const final;

    long long getSpaceUsedBytes(OperationContext* opCtx) const final;

    long long getFreeStorageBytes(OperationContext* opCtx) const final;

    Status compact(OperationContext* opCtx) final;

    std::unique_ptr<IndexAccessMethod::BulkBuilder> initiateBulk(
        size_t maxMemoryUsageBytes,
        const boost::optional<IndexStateInfo>& stateInfo,
        StringData dbName) final;

    std::shared_ptr<Ident> getSharedIdent() const final;

    void setIdent(std::shared_ptr<Ident> ident) final;

    const ColumnStore* storage() const {
        return _store.get();
    }

    ColumnStore* writableStorage() const {
        return _store.get();
    }

    class BulkBuilder;

    const std::string& indexName() const {
        return _descriptor->indexName();
    }

    /**
     * Returns true iff 'compressor' is a recognized name of a block compression module that is
     * supported for use with the column store index.
     *
     * Actual support for the module depends on the storage engine, however. This method does _not_
     * guarantee that creating a column store index with 'compressor' will always work.
     */
    static bool supportsBlockCompressor(StringData compressor);

private:
    void _visitCellsForIndexInsert(OperationContext* opCtx,
                                   PooledFragmentBuilder& pooledFragmentBuilder,
                                   const std::vector<BsonRecord>& bsonRecords,
                                   function_ref<void(StringData, const BsonRecord&)> cb) const;

    const std::unique_ptr<ColumnStore> _store;
    IndexCatalogEntry* const _indexCatalogEntry;  // owned by IndexCatalog
    const IndexDescriptor* const _descriptor;
    const column_keygen::ColumnKeyGenerator _keyGen;
};
}  // namespace mongo