[Database] Implementation model of database recoverability goals, data integrity protection strategies for disaster-level failures

Countermeasures for system failure

专栏content

  • Handwritten database toadb
    This column mainly introduces how to develop from scratch, the steps of development, the principles involved in the development process, problems encountered, etc., so that everyone can keep up. And can be developed together so that everyone who needs it can become a participant.
    This column will be updated regularly, and the corresponding code will also be updated regularly. The code at each stage will be tagged to facilitate learning at each stage.

Open source contribution

Personal homepage:My homepage
Manage community: Open source database
Motto: When the sky is strong, a gentleman will strive to strive for self-improvement; when the terrain is weak, a gentleman will carry his wealth with kindness.

irect/407dc6c10d524f2f80cdeddc71f76a18.jpeg#pic_center)

Preface

With the rapid development of information technology, data has penetrated into various fields and become one of the most important assets of modern society. In this era of big data, database theory plays a vital role in data management, storage and processing. However, many readers may be confused about database theory and do not know how to choose a suitable database, how to design an effective database structure, and how to process and manage large amounts of data. Therefore, this column aims to provide readers with a comprehensive and in-depth guide to database theory to help them better understand and apply database technology.

Database theory is the study of how to effectively manage, store and retrieve data. In the modern information society, the amount of data is growing exponentially, and how to efficiently process and manage this data has become an important issue. At the same time, with the continuous development of emerging technologies such as cloud computing, the Internet of Things, and big data, the importance of database theory has become increasingly prominent.

Overview

In the database management system, we mainly have two major issues when considering failures:

  • When a system failure occurs, data must be protected; data integrity is guaranteed when certain system failures occur, mainly by supporting the recoverability characteristics of the data.
  • Data cannot be corrupted simply because several inherently error-free queries and database update operations are performed simultaneously. That is to say, the data must also be protected during concurrent database operations.

This article mainly shares the solutions to the first problem and the implementation model under the recoverable goal.

Type of fault

Before introducing the fault response model, let us also take a look at the faults we usually face:

  • Wrong data input; this type is an error. In this case, the database system cannot destroy the existing data; this is generally achieved through transaction concurrency control to achieve isolation and atomicity;
  • Media failure; such as disk failure, resulting in data loss, which is a temporary system failure;
  • Catastrophic failure; the industry often has such news, such as a power outage in a certain area, or the entire computer room cannot work; this kind of catastrophic failure cannot be solved by simple recovery;
  • System failure; failure of the database system itself may also be restored through logs, or may cause catastrophic failure;

Resumable operational model

How to achieve the goal of recovery is something that modern database management systems must face and solve.

The model of recoverable operation generally uses several data redundancy technologies. The most basic one is that the disk is configured with RAID redundancy. When a media-level failure occurs, recovery is achieved through the redundant backup of the disk itself;
In addition, the database itself will use logs and backups to achieve data redundancy while taking into account performance.

log

The basic technology that supports recoverability is logs, which are called undo, redo and undo/redo logs, which are common in various types of databases.

recover

The process of using logs to reconstruct updates to the database after a failure occurs is called recovery;

An important aspect of logging and recovery technology is to avoid the need to go back to logs long ago. In order to solve this problem, there is a technology called checkpoint in the database system. This technology is also widely used. It limits The log length that must be checked during recovery.

backup

The database must not only withstand temporary system failures, but also protect the integrity of the data when the data disk of the entire database fails.

Then this requires backup technology, which dumps data to a remote backup server through regular or real-time backup. In this way, in the event of an entire database failure, we only need to copy the most recent copy to restore to the most recent one. Data at a moment's notice.

Summarize

In addition to storing data and fast retrieval, protecting data security has become its second most important goal. How to maintain the latest data in disaster-level failures and even achieve uninterrupted business services has become a major issue in today's databases. Highlights.

The following is a sample code written in C language that uses mediation mode to output "Hello World":

#include <stdio.h>
#include <stdlib.h>

// 抽象中介者接口
typedef struct MediatorInterface {
    
    
    void (*notify)(char *message); // 通知方法
} MediatorInterface;

// 中介者实现
typedef struct Mediator {
    
    
    MediatorInterface *interface; // 中介者接口
} Mediator;

// 具体中介者实现:输出"Hello World"
void notify(char *message) {
    
    
    printf("Hello World\n");
}

// 具体中介者实现:注册到中介者
void registerMediator(Mediator *mediator, char *message) {
    
    
    mediator->interface->notify(message);
}

// 具体参与者实现:发送消息给中介者
void sendMessage(char *message) {
    
    
    Mediator mediator;
    mediator.interface = (MediatorInterface *)&mediator; // 中介者接口赋值
    registerMediator(&mediator, message); // 注册到中介者,并发送消息
}

int main() {
    
    
    char message[] = "Hello World"; // 消息内容为"Hello World"
    sendMessage(message); // 发送消息给中介者,并输出"Hello World"
    return 0;
}

In the above code, we define an abstract mediator interfaceMediatorInterface, which contains a notify method for notification. Then, we define a concrete mediator implementationMediator, which implements the notify method and outputs "Hello World". At the same time, we define a registerMediator method for registering participants to the mediator, and call the notify method to notify the message. Finally, we defined a specific participant to implement the sendMessage method, which sends a message to the mediator and calls the registerMediator method to register with the mediator, thereby outputting " Hello World". In the main function, we create a string with the message content "Hello World" and call the sendMessage method to send the message to the mediator, thereby outputting " "Hello World".

end

Thank you very much for your support. Don’t forget to leave your valuable comments while browsing. If you think it is worthy of encouragement, please like and save it. I will work harder!

Author’s email: [email protected]
If there are any errors or omissions, please point them out and learn from each other.

Guess you like

Origin blog.csdn.net/senllang/article/details/134698248