A method for implementing CockroachDB to support multiple storage engines

By redesigning the libroach layer model and reconstructing the DBEngine and DBIterator classes, it supports multiple storage engine selections, solves RocksDB's performance issues in cloud computing and big data scenarios, and achieves more efficient storage and more flexible application scenarios.

CN111752996BActive Publication Date: 2024-09-06SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010616128.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-01
Publication Date
2024-09-06
Estimated Expiration
2040-07-01

AI Technical Summary

Technical Problem

RocksDB's LSM storage engine has problems with write amplification, poor support for large Value values, and weak read performance, and cannot adapt to the needs of cloud computing and big data scenarios.

Method used

Redesign the libroach layer model, reconstruct the DBEngine and DBIterator classes, abstract the data reading, writing and traversing methods of the underlying storage engine, support the selection of multiple storage engines, including RocksDB and KV-SSD engines, and realize the reading of different storage engines through subclass inheritance. Write, providing consistent operations.

Benefits of technology

It expands the application scenarios of CockroachDB to meet users' personalized storage needs, and improves performance and flexibility through the storage engine-KV SSD solution that integrates software and hardware.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111752996B
    Figure CN111752996B
Patent Text Reader

Abstract

The present invention particularly relates to an implementation method for CockroachDB to support multiple storage engines. The implementation method for CockroachDB to support multiple storage engines redesigns the libroach layer model, reconstructs the DBEngine and DBIterator classes, abstracts the data reading, writing and traversal methods of the underlying storage engine, and the underlying storage engine implements these data reading, writing and traversal methods. db.cc only operates the abstract interface of the DBEngine and DBIterator classes; when the CockroachDB cluster database node is started, different storage engines are selected through parameter markers, thereby realizing support for multiple storage engines. The implementation method for CockroachDB to support multiple storage engines not only expands the application scenarios of CockroachDB, but also uses the storage engine-KV SSD solution that integrates software and hardware to meet the more personalized storage needs of CockroachDB users.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of distributed databases, and in particular to an implementation method for CockroachDB to support multiple storage engines. Background Art

[0002] CockroachDB (CRDB) is an open source distributed database system built on the Google Spanner concept. It has the NoSQL storage and management capabilities for massive data, while maintaining the ACID and SQL features supported by traditional databases. It also supports cross-region, decentralization, high concurrency, strong consistency of multiple copies, and high availability.

[0003] CockroachDB is a program written in Go, and the internally integrated RocksDB is programmed in C++. The two are mixed programmed through the CGO framework. The storage layer architecture is shown in the attached Figure 1 shown.

[0004] The interface that encapsulates the underlying operations of RocksDB is mainly declared in engine.go, and the related structures are concentrated in rocksdb.go declaration and implementation. The structure implements the corresponding interface in engine.go, and the C function interface and data structure defined in libroach.h are called through CGO inside the structure. Other modules of CockroachDB, such as MVCC multi-version control, backup and recovery, and Range operations, interact with the underlying RocksDB through the functions provided by rocksdb.go according to actual functional requirements, or perform secondary encapsulation and provide it to other modules for use.

[0005] Most of the C function interfaces defined in libroach.h are implemented in the db.cc file. They can be divided into library operations, KV operations, DBBatch support, Iterator management, snapshot operations, SST file operations, Env object management, and Stats statistical information retrieval according to functional modules.

[0006] CockroachDB relies heavily on RocksDB, and the two are mixed through the CGO framework. RocksDB is a Key-Value storage engine that provides high-performance data writing capabilities, supports efficient search and range traversal, and makes full use of the high-speed read and write provided by the Flash or RAM subsystem.

[0007] However, RocksDB's LSM (Log-Structured Merge Tree) storage engine has disadvantages such as write amplification, poor support for large values, and weak read performance (some keys may need to traverse all levels), and cannot adapt to certain cloud computing and big data scenarios.

[0008] Based on this, the present invention proposes an implementation method for CockroachDB to support multiple storage engines. Summary of the invention

[0009] In order to make up for the defects of the prior art, the present invention provides a simple and efficient implementation method of CockroachDB supporting multiple storage engines.

[0010] The present invention is achieved through the following technical solutions:

[0011] A method for implementing CockroachDB to support multiple storage engines, characterized by: redesigning the libroach layer model, reconstructing the DBEngine and DBIterator classes, abstracting the data reading, writing and traversal methods of the underlying storage engine, and the underlying storage engine implementing these data reading, writing and traversal methods, and db.cc only operating the abstract interfaces of the DBEngine and DBIterator classes; and selecting different storage engines through parameter markers when starting a CockroachDB cluster database node, thereby implementing support for multiple storage engines.

[0012] The CockroachDB cluster database node sets the data storage engine type when it is started, including the RocksDB engine and the KV-SSD engine, and the storage of the two engines can be started at the same time to achieve the effect of using different storage engines for different data tables.

[0013] The present invention provides an implementation method for CockroachDB to support multiple storage engines, reconstructs the DBEngine and DBIterator classes, adds the rocksdb::DB and rocksdb::Iterator methods used in the libroach layer, enables other methods to read and traverse rocksDB data only through DBEngine and DBIterator, and implements the reading and writing of other storage engines through subclass inheritance.

[0014] The CockroachDB of the present invention supports the implementation method of multiple storage engines. The internal data type still uses the rocksdb::Slice of the rocksDB class. The types of other storage engines can be converted to rocksdb::Slice to provide consistent operations.

[0015] The CockroachDB of the present invention supports the implementation method of multiple storage engines, abstracts the reading and writing methods of the storage engine of the DBEngine and DBIterato classes, and the RocksDB storage engine implements its own subclasses RocksDBEngine and RocksDBIterator; the KV-SSD storage engine implements the subclasses ShanDBEngine, ShanDBIterator and ShanDBBatch.

[0016] The subclass RocksDBEngine includes three subclasses: RocksDBImpl-, RocksDBSnapshot- and RocksDBBatch-, among which RocksDBImpl- implements the actual reading and writing of rocksDB background storage, RocksDBSnapshot- implements the library snapshot function, and RocksDBBatch- implements the Batch operation method.

[0017] The present invention provides a method for implementing CockroachDB to support multiple storage engines. When db.cc and mvcc.cc implement libroach.h methods, they only use DBEngine and DBIterator parent class methods.

[0018] The libroach layer creates different DBEngine subclasses based on the passed-in database type parameter in the DBOpen method, and the rocksdb.go method of the Go layer passes the database type parameter when calling DBOpen.

[0019] The implementation device of CockroachDB supporting multiple storage engines of the present invention is characterized by comprising: at least one memory and at least one processor;

[0020] The at least one memory is used to store a machine-readable program;

[0021] The at least one processor is configured to call the machine-readable program to execute the above method.

[0022] The computer-readable medium is characterized in that computer instructions are stored on the computer-readable medium, and when the computer instructions are executed by a processor, the processor is caused to execute the above-mentioned method.

[0023] The beneficial effect of the present invention is that the implementation method of CockroachDB supporting multiple storage engines not only expands the application scenarios of CockroachDB, but also can use the storage engine-KV SSD solution of software and hardware fusion to meet the more personalized storage needs of CockroachDB users. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0025] Attached Figure 1 This is a schematic diagram of an implementation method of the present invention whereby CockroachDB supports multiple storage engines.

[0026] Attached Figure 2 This is a schematic diagram of the multi-storage engine class structure of the present invention. DETAILED DESCRIPTION

[0027] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0028] This CockroachDB supports the implementation method of multiple storage engines. It redesigns the libroach layer model, reconstructs the DBEngine and DBIterator classes, abstracts the data reading, writing, and traversal methods of the underlying storage engine, and the underlying storage engine implements these data reading, writing, and traversal methods. db.cc only operates the abstract interfaces of the DBEngine and DBIterator classes. When the database node of the CockroachDB cluster is started, different storage engines are selected through parameter markers to achieve support for multiple storage engines.

[0029] When opening a database, libroach creates implementation classes for different engines through parameters, thereby supporting multiple storage engines.

[0030] The CockroachDB cluster database node sets the data storage engine type when it is started, including the RocksDB engine and the KV-SSD engine, and the storage of the two engines can be started at the same time to achieve the effect of using different storage engines for different data tables.

[0031] #Using RocksDB engine

[0032] cockroach start--insecure--listen-addr=0.0.0.0--store= / data / cockroachDB,dbtype=RocksDB

[0033] #Use KV-SSD engine

[0034] cockroach start--insecure--listen-addr=0.0.0.0--store= / dev / sdg,dbtype=ShanDB

[0035] This CockroachDB supports the implementation method of multiple storage engines, refactors the DBEngine and DBIterator classes, adds the rocksdb::DB and rocksdb::Iterator methods used in the libroach layer, so that other methods can only read and traverse rocksDB data through DBEngine and DBIterator, and implements the reading and writing of other storage engines through subclass inheritance.

[0036] This CockroachDB supports multiple storage engines. The internal data type still uses the rocksdb::Slice of the rocksDB class. The types of other storage engines can be converted to rocksdb::Slice to provide consistent operations.

[0037] There can only be one implementation of file-related methods in the Libroach layer. Such methods should be used for backup / restore, import and export, and do not affect the storage engine.

[0038] The CockroachDB supports the implementation of multiple storage engines, abstracting the DBEngine and DBIterato classes to read and write storage engines. The RocksDB storage engine implements its own subclasses RocksDBEngine and RocksDBIterator; the KV-SSD storage engine implements the subclasses ShanDBEngine, ShanDBIterator, and ShanDBBatch.

[0039] The subclass RocksDBEngine includes three subclasses: RocksDBImpl-, RocksDBSnapshot- and RocksDBBatch-, among which RocksDBImpl- implements the actual reading and writing of rocksDB background storage, RocksDBSnapshot- implements the library snapshot function, and RocksDBBatch- implements the Batch operation method.

[0040] This CockroachDB supports multiple storage engine implementations. db.cc and mvcc.cc only use DBEngine and DBIterator parent class methods when implementing libroach.h methods.

[0041] The libroach layer creates different DBEngine subclasses based on the passed-in database type parameter in the DBOpen method, and the rocksdb.go method of the Go layer passes the database type parameter when calling DBOpen.

[0042] The CockroachDB implementation device supporting multiple storage engines includes: at least one memory and at least one processor;

[0043] The at least one memory is used to store a machine-readable program;

[0044] The at least one processor is configured to call the machine-readable program to execute the above method.

[0045] The computer readable medium stores computer instructions, which, when executed by a processor, cause the processor to perform the above-described method.

[0046] Compared with the current existing technologies, the CockroachDB implementation method that supports multiple storage engines has the following features:

[0047] First, the CockroachDB multi-storage engine method can support multiple underlying storage engine implementations, thereby expanding the application scenarios of CockroachDB. For example, in scenarios that require extremely high performance, the in-memory data storage engine can be used.

[0048] Second, you can use the KV SSD solution, a storage engine that integrates software and hardware, to meet the more personalized storage needs of CockroachDB users.

[0049] The embodiment described above is only one specific implementation of the present invention. Common changes and substitutions made by those skilled in the art within the scope of the technical solution of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for implementing CockroachDB to support multiple storage engines, characterized by: Redesign the libroach layer model, refactor the DBEngine and DBIterator classes, abstract the data reading, writing, and traversal methods of the underlying storage engine, and the underlying storage engine implements these data reading, writing, and traversal methods. db.cc only operates the abstract interfaces of the DBEngine and DBIterator classes. db.cc and mvcc.cc only use DBEngine and DBIterator parent class methods when implementing libroach.h methods; The libroach layer creates different DBEngine subclasses based on the database type parameter passed in the DBOpen method, and the rocksdb.go method of the Go layer passes the database type parameter when calling DBOpen; When starting a database node in a CockroachDB cluster, you can set the data storage engine type, including the RocksDB engine and the KV-SSD engine. You can also start the storage of both engines at the same time, so that different data tables can use different storage engines. The Libroach layer creates implementation classes for different engines through parameters when opening the database. When starting the CockroachDB cluster database node, different storage engines are selected through parameter markers to support multiple storage engines.

2. The method for implementing CockroachDB to support multiple storage engines according to claim 1, characterized in that: Refactor the DBEngine and DBIterator classes, add the rocksdb:: DB and rocksdb::Iterator methods used in the libroach layer, so that other methods can only read and traverse rocksDB data through DBEngine and DBIterator, and implement reading and writing of other storage engines through subclass inheritance.

3. The method for implementing CockroachDB to support multiple storage engines according to claim 2, characterized in that: The internal data type still uses the rocksdb::Slice of the rocksDB class, and the types of other storage engines are converted to rocksdb::Slice to provide consistent operations.

4. The method for implementing CockroachDB supporting multiple storage engines according to claim 3, characterized in that: The abstract DBEngine and DBIterato classes provide the reading and writing methods for the storage engine. The RocksDB storage engine implements its own subclasses RocksDBEngine and RocksDBIterator; the KV-SSD storage engine implements the subclasses ShanDBEngine, ShanDBIterator, and ShanDBBatch.

5. The method for implementing CockroachDB supporting multiple storage engines according to claim 4, characterized in that: The subclass RocksDBEngine includes three subclasses: RocksDBImpl-, RocksDBSnapshot- and RocksDBBatch-, among which RocksDBImpl- implements the actual reading and writing of rocksDB background storage, RocksDBSnapshot- implements the library snapshot function, and RocksDBBatch- implements the Batch operation method.

6. A device for implementing CockroachDB to support multiple storage engines, characterized in that: include: at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is configured to call the machine-readable program to execute the method according to any one of claims 1 to 5.

7. A computer-readable medium, characterized in that: The computer readable medium stores computer instructions, and when the computer instructions are executed by a processor, the processor executes the method according to any one of claims 1 to 5.