In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly shows you "SylixOS how to migrate DB database", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "SylixOS how to migrate DB database" this article.
Brief introduction of 1.DB Database
Berkeley DB (DB) is an embedded database system with a long history, which is mainly used in UNIX/LINUX operating system. Its design idea is simple, compact, reliable and high performance.
DB is a high-performance, embedded database programming library, and the C language, Clipper PerlGrad Java PerthonGradePerthonGrainPythonGradePerthonGrainPythonMagol TCL and many other languages have bindings. Berkeley DB can save any type of key / value pair, and can save multiple data for a key. Berkeley DB can support thousands of concurrent threads to operate the database at the same time, and supports the data of the largest 256TB. It is widely used in a variety of operating systems, including most Unix operating systems, Windows operating systems and real-time operating systems.
two。 Transplant idea
For the idea of porting Linux middleware to SylixOS, please refer to "the method of porting TN0029_SylixOS third-party middleware".
3. Transplant implementation
Download the source code of Berkeley's DB database from Berkeley's official website and choose version 4.7.25 (official website http://www.oracle.com/database/berkeley-db/index.html).
3.1. Generate configuration files under Linux
The source code downloaded from the official website is compiled and executed in the Linux environment to generate a configuration file.
1. Import the source code project into Ubuntu for decompression
two。 Create a new build_arm directory under db-4.7.25 and enter the command.. / dist/configure CC=arm-linux-gcc to configure it. Generate the configuration file and Makefile under the build_arm directory, as shown in figure 3-1.
Figure 3-1 generated configuration file and Makefile
In this way, the configuration file is generated in the Linux environment, and then the entire source package is exported.
3.2. Migrate to SylixOS
Import the source code project into the RealEvo-IDE development environment for development and compilation.
3.2.1. Create a SylixOS project
Create a dynamic library project libdb in the SylixOS development environment RealEvo-IDE, and copy the db source code with configuration files to the src directory under the project, as shown in figure 3-2.
Figure 3-2 libdb Project
In order not to destroy the structure of the source project, the migration needs to manually modify the Makefile and set the project properties to expert mode, as shown in figure 3-3.
Figure 3-3 sets the expert mode
3.2.2. Modify the Makefile of SylixOS by referring to Makefile under Linux
Open Makefile under Linux and find out which * .c files you need to rely on for compilation, as shown in figure 3-4.
Figure 3-4 Makefile under Linux
Find the specific dependent * .c file based on C_OBJS on Makefile, as shown in figure 3-5.
Figure 3-5 original files on which the DB database depends
Manually modify the libdb.mk file of the libdb project on IDE according to the Makefile under Linux, as shown in figure 3-6.
Figure 3-6 manually modify the Makefile of IDE
3.2.3. Modify compilation errors
When compiling the libdb project, there will be an error about the invalid header file and modify the header file of the original file, as shown in figure 3-7.
Figure 3-7 change the format of the header file name
After modifying the header file name format on which the file depends, there is still an error, as shown in figure 3-8.
Compilation error in figure 3-8
There is an undefined macro about LOAD_ACTUAL_MUTEX_CODE in the mutex_int.h file, which is defined in Makefile. The function of this macro is to open an ARM/gcc assembly code about mutexes, as shown in figure 39.
Figure 3-9 defines macros in Makefile
After modification, the compilation is successful, and the libdb.so file is generated and imported into the virtual machine.
3.2.4. Test the DB database
Write the test code, which is shown in listing 3-1.
Listing 3-1 DB database test code
# include # define DESCRIPTION_SIZE 20int main () {DB * dbp; / * DB structure handle * / u_int32_t flags; / * database open flags * / int ret / * function return value * / char * description = "Grocery bill."; char * revision 1 [description _ SIZE + 1]; DBT key, data; float money; / * Initialize the structure. This * database is not opened in an environment, * so the environment pointer is NULL. * / ret = db_create (& dbp, NULL, 0); if (ret! = 0) {/ * Error handling goes here * / printf ("Create fail!\ n"); return-1 } / * Database open flags * / flags = DB_CREATE / * If the database does not exist,create it.*/ / * open the database * / ret = dbp- > open (dbp / * DB structure pointer * / NULL, / * Transaction pointer * / "/ apps/db_test/my_db.db", / * On-disk file that holds the database. * / NULL, / * Optional logical database name * / DB_BTREE, / * Database access method * / flags / * Open flags * / 0) / * File mode (using defaults) * / if (ret! = 0) {/ * Error handling goes here * / printf ("Created new database.\ n");} money = 122.45; / * Zero out the DBTs before using them. * / memset (& key, 0, sizeof (DBT)); memset (& data, 0, sizeof (DBT)); key.data = & money; key.size = sizeof (float); data.data = description; data.size = strlen (description) + 1; ret = dbp- > put (dbp, NULL, & key, & data, DB_NOOVERWRITE) If (ret = = DB_KEYEXIST) {dbp- > err (dbp, ret, "Put failed because key% f already exists", money);} memset (& data, 0, sizeof (DBT)); data.data = & description1; data.ulen = DESCRIPTION_SIZE + 1; data.flags = DB_DBT_USERMEM; dbp- > get (dbp, NULL, & key, & data, 0) Printf ("data:% s\ n", (char *) data.data); / * When we're done with the database, close it. * / if (dbp! = NULL) dbp- > close (dbp, 0); return 0;}
The program runs as shown in figure 3-10.
Figure 3-10 Test phenomenon
The test produces a DB database and reads the data "Grocery bill." from the database.
4. Transplant summary 4.1. Migration proc
The migration process is as follows:
Download the source code on the official website
Run the implementation function under Linux
There are transplant notes on the general middleware network, please refer to
Use configure function to generate configuration files under Linux (configuration files such as configure.h and Makefile are very important)
Refer to Makefile to modify the project * .mk file of IDE (mainly know the source file on which the middleware depends)
Please make a good migration record during the migration process in order to query the modification information
If you have to modify or add functional implementation, please create a new file.
4.2. Transplant principle
The principles of migration are as follows:
To do subtraction, cut out the main functions first.
The kernel source code is not modified. If the functional SylixOS is not implemented yet, the functional function can be written according to the functional semantics or the function can be cut off.
In the process of porting and compiling, there will be a variety of errors, need to carefully find the error location according to the error information, and modify the implementation according to the SylixOS function.
These are all the contents of the article "how SylixOS transplants DB databases". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.