1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef RD_SINGLE_VER_STORAGE_ENGINE_H
17 #define RD_SINGLE_VER_STORAGE_ENGINE_H
18 
19 #include "db_common.h"
20 #include "grd_db_api.h"
21 #include "param_check_utils.h"
22 #include "platform_specific.h"
23 #include "runtime_context.h"
24 #include "single_ver_utils.h"
25 #include "sqlite_utils.h"
26 #include "storage_engine.h"
27 
28 namespace DistributedDB {
29 class RdSingleVerStorageEngine : public StorageEngine {
30 public:
31     RdSingleVerStorageEngine();
32     ~RdSingleVerStorageEngine() override;
33 
34     int InitRdStorageEngine(const StorageEngineAttr &poolSize, const OpenDbProperties &option,
35         const std::string &identifier = std::string());
36 
37 protected:
38     int CreateNewExecutor(bool isWrite, StorageExecutor *&handle) override;
39 
40 private:
41     int PreCreateExecutor(bool isWrite);
42 
43     int GetExistedSecOption(SecurityOption &secOption) const;
44 
45     int CheckDatabaseSecOpt(const SecurityOption &secOption) const;
46 
47     int CreateNewDirsAndSetSecOpt() const;
48 
49     int TryToOpenMainDatabase(bool isWrite, GRD_DB *&db);
50 
51     int GetDbHandle(bool isWrite, const SecurityOption &secOpt, GRD_DB *&dbHandle);
52 
53     int OpenGrdDb(const OpenDbProperties &option, GRD_DB *&db);
54 
55     int IndexPreLoad(GRD_DB *&db, const char *collectionName);
56 
57     std::atomic<bool> crcCheck_ = false;
58     std::atomic<bool> isFirstTimeOpenDb_ = true;
59 };
60 } // namespace DistributedDB
61 #endif // RD_SINGLE_VER_STORAGE_ENGINE_H