“This is the first day of my participation in the August More Text Challenge. For details, see: August More Text Challenge juejin.cn/post/698796…”

SequoiaDB profile

SequoiaDB Sequoia Sequoia database is a financial level distributed relational database, which mainly provides high performance, reliable and stable database services and unlimited horizontal expansion for high concurrent online transaction scenarios.

SequoiaDB features

  • Fully compatible with traditional relational data, and data fragmentation is completely transparent to the application
  • High performance with unlimited horizontal elastic expansion capability
  • Distributed transactions and ACID capabilities
  • Supports both structured, semi-structured and unstructured data
  • Financial security feature: RPO=0 for disaster recovery between multiple data centers
  • HTAP mixes loads, running online transactions and batch tasks simultaneously without interfering with each other
  • Multi-tenant capability: Supports multiple levels of physical and logical isolation in the cloud environment

Docker deployment SequoiaDB

The configuration of Docker is not introduced in this article. It is not the main content of this article

Pull the mirror

Docker pull sequoiadb/sequoiadb: version 5.0.1 docker pull sequoiadb/sequoiasql - mysql: version 5.0.1Copy the code

(1) Build a single-copy cluster

The detailed steps

The following actions are recommended by the authors for a WSL environment

  1. Go to Ubuntu and create a folder ~/docker/SequoiaDB

    cd
    mkdir -p /docker/SequoiaDB
    Copy the code
  2. Go to the folder we created

    cd ~/docker/SequoiaDB
    Copy the code
  3. Create a docker-compose file

    touch docker-compose.yml
    Copy the code
  4. Use vi to add the following content to enter vi

    vi docker-compose.yml
    Copy the code

    Add the following,

    version: "3"
    services:
       # Engine configuration
       sdbserver:
          # Image used
          image: Sequoiadb/sequoiadb: version 5.0.1
          # container name
          container_name: sdbserver
          # the hostname
          hostname: "sdbserver"
          # Port mapping
          ports:
             - "11810:11810"
             - "11814:11814"
          Set whether to restart when the Docker daemon starts
          restart: always
    	  # Environment variables
          environment:
             # Whether cluster deployment is enabled
             SDB_DEPLOY:     "true"
             # Catalog node list
             SDB_CATALOG:    "sdbserver:11800"
             Coordinate the node list
             SDB_COORD:      "sdbserver:11810"
             # Data node list
             SDB_DATA:       "group1=sdbserver:11820; group2=sdbserver:11830"
             # Cluster time series service node Libiao
             SDB_STP_SERVER: "sdbserver:9622"
          # Network configuration
          networks:
             sdb-net:
                ipv4_address: "192.168.1.11"
          extra_hosts:
             - "Sdbmysql: 192.168.1.10"
             - "Sdbserver: 192.168.1.11"
          dns:
             - 223.5. 5. 5
             - 223.66.6.
       Example configuration
       sdbmysql:
          image: Sequoiadb/sequoiasql - mysql: version 5.0.1
          container_name: sdbmysql
          hostname: "sdbmysql"
          ports:
             - "3306:3306"
          restart: always
          environment:
             Coordinate the node list
             MYSQL_SDB_COORD: "sdbserver:11810"
          networks:
             sdb-net:
                ipv4_address: "192.168.1.10."
          extra_hosts:
             - "Sdbmysql: 192.168.1.10"
             - "Sdbserver: 192.168.1.11"
          dns:
             - 223.5. 5. 5
             - 223.66.6.
          depends_on:
             - sdbserver
    Docker network configuration
    networks:
       sdb-net:
          ipam:
             config:
                - subnet: 192.1681.. 0/ 16
    Copy the code
  5. Save to exit, press Esc on the keyboard, Shift + :, enter wq, and press enter

  6. Run the written docker-compose. Yml

    docker-compose -f docker-compose.yml up -d
    Copy the code
  7. Checking the Startup Status

    docker logs -f sdbmysql
    Copy the code

    Normally, the following output indicates a successful startup

    2021-08-08 06:25:47+00:00 INFO [Entrypoint]: MySQL Server 5.0.1 started. 2021-08-08 06:25:47+00:00 INFO [Entrypoint]: Starting init process ************ Deploy SequoiaSQL-MySQL ***************** Create instance: [name: MySQLInstance3306, port: 3306] 2021-08-08 06:25:55+00:00 INFO [Entrypoint]: MySQL init process done. Ready for start up. 2021-08-08 06:25:58+00:00 INFO [Entrypoint]: Mysql service startup is complete. 2021-08-08 06:26:03+00:00 INFO [Entrypoint]: Your sequoiadb-mysql service started successfully ! 2021-08-08 07:25:46+00:00 INFO [Entrypoint]: MySQL Server 5.0.1 started. 2021-08-08 07:25:46+00:00 INFO [Entrypoint]: Mysql instance MySQLInstance3306 already existed. 2021-08-08 07:25:48+00:00 INFO [Entrypoint]: Mysql service startup is complete.#This sentence represents a successful start
    2021-08-08 07:25:54+00:00 INFO  [Entrypoint]: Your sequoiadb-mysql service started successfully !
    Copy the code
  8. If you do not have this client in your WSL, you can use the following command to install it:

    Sudo apt install mysql - the client - core - 5.7Copy the code

    However, note that the reader may encounter an installation failure due to a missing dependency file. You can use the following command to reinstall the installation.

    Sudo apt-get update sudo apt install mysql-client-core-5.7 --fix-missingCopy the code
  9. Use the client to connect to the mysql instance

    Mysql -h127.0.0.1 -p3306 -uroot -pCopy the code

    Default is no password, so you can directly enter the connection!

  10. Method of destroying a cluster

    docker-compose -f docker-compose.yml down
    Copy the code

(2) Build a three-copy HA cluster

The detailed steps

Much the same as above, except for the docker-compose file

  1. Create the docker-compose-cluster.yml file

    touch docker-compose-cluster.yml
    Copy the code
  2. Add the following to the file and save and exit

    version: "3"
    services:
       sdbserver1:
          image: Sequoiadb/sequoiadb: version 5.0.1
          container_name: sdbserver1
          hostname: "sdbserver1"
          ports:
             - "11810:11810"
          restart: always
          environment:
             SDB_DEPLOY:     "true"
             SDB_COORD:      "sdbserver1:11810,sdbserver2:11810,sdbserver3:11810"
             SDB_CATALOG:    "sdbserver1:11800,sdbserver2:11800,sdbserver3:11800"
             SDB_DATA:       "group1=sdbserver1:11820,sdbserver2:11820,sdbserver3:11820; group2=sdbserver1:11830,sdbserver2:11830,sdbserver3:11830"
             SDB_STP_SERVER: "sdbserver1:9622,sdbserver2:9622,sdbserver3:9622"
          networks:
             sdb-net:
                ipv4_address: "192.168.1.11"
          extra_hosts:
             - "Sdbmysql: 192.168.1.10"
             - "sdbserver1:192.168.1.11"
             - "sdbserver2:192.168.1.12"
             - "sdbserver3:192.168.1.13"
          dns:
             - 223.5. 5. 5
             - 223.66.6.
          depends_on:
             - sdbserver2
             - sdbserver3
       sdbserver2:
          image: Sequoiadb/sequoiadb: version 5.0.1
          container_name: sdbserver2
          hostname: "sdbserver2"
          restart: always
          networks:
             sdb-net:
                ipv4_address: "192.168.1.12"
          extra_hosts:
             - "Sdbmysql: 192.168.1.10"
             - "sdbserver1:192.168.1.11"
             - "sdbserver2:192.168.1.12"
             - "sdbserver3:192.168.1.13"
          dns:
             - 223.5. 5. 5
             - 223.66.6.
       sdbserver3:
          image: Sequoiadb/sequoiadb: version 5.0.1
          container_name: sdbserver3
          hostname: "sdbserver3"
          restart: always
          networks:
             sdb-net:
                ipv4_address: "192.168.1.13"
          extra_hosts:
             - "Sdbmysql: 192.168.1.10"
             - "sdbserver1:192.168.1.11"
             - "sdbserver2:192.168.1.12"
             - "sdbserver3:192.168.1.13"
          dns:
             - 223.5. 5. 5
             - 223.66.6.
       sdbmysql:
          image: Sequoiadb/sequoiasql - mysql: version 5.0.1
          container_name: sdbmysql
          hostname: "sdbmysql"
          ports:
             - "3306:3306"
          restart: always
          environment:
             MYSQL_SDB_COORD: "sdbserver1:11810,sdbserver2:11810,sdbserver3:11810"
          networks:
             sdb-net:
                ipv4_address: "192.168.1.10."
          extra_hosts:
             - "Sdbmysql: 192.168.1.10"
             - "sdbserver1:192.168.1.11"
             - "sdbserver2:192.168.1.12"
             - "sdbserver3:192.168.1.13"
          dns:
             - 223.5. 5. 5
             - 223.66.6.
          depends_on:
             - sdbserver1
    networks:
       sdb-net:
          ipam:
             config:
                - subnet: 192.1681.. 0/ 16
    Copy the code
  3. Run YML to start the cluster

    docker-compose -f docker-compose-cluster.yml up  -d
    Copy the code
  4. Viewing the Startup Status

    docker logs -f sdbmysql
    Copy the code
  5. Method of destroying a cluster

    docker-compose -f docker-compose-cluster.yml down
    Copy the code

Spring integration of the Boot

1. Preparation

1.1 Creating a Database User

grant all privileges on*. *to lwj@The '%' identified by '123456';
Copy the code

Here, in order to be lazy, create a user whose user name is LWJ and password is 123456, and have the highest permission. However, if you want to go online, you should consider it by yourself

1.2 Testing the Connection

  1. The author used the DataGrip tool here, but readers can use other tools to do the same.

  1. Next we create a Springboot_DB database, where we do most of our integration work

    create database springboot_db;
    Copy the code
  2. Create a table in the database

    create table User
    (
        id       int auto_increment
            primary key,
        username varchar(32) not null comment 'Username',
        age      int         not null
    );
    Copy the code

2. Configure the Spring Boot project

2.1 Creating and Adding a Spring Boot Dependency

2.2 Database Configuration

Modify the application. Properties file to the following content:

# Application name
spring.application.name=SequoiaDB-demo
# Database driver:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# Data source name
spring.datasource.name=springboot_db
# Database connection address
spring.datasource.url=jdbc:mysql://localhost:3306/springboot_db? serverTimezone=UTC
# Database username & password:
spring.datasource.username=lwj
spring.datasource.password=123456
# Application service WEB access port
server.port=8080
Copy the code

2.3 Engineering Structure

2.4 the entity

The contents of user.class are as follows,

@Data
@TableName("User")
public class User {
    @TableId(type = IdType.AUTO)
    private int id;
    private String username;
    private int age;
}
Copy the code

@data from Lombok dependency

2.5 mapper

We use MyBatis – Plus as the ORM framework, UserMapper content is as follows,

@Mapper
public interface UserMapper extends BaseMapper<User> {}Copy the code

2.6 the service

UserService.class

public interface UserService {

    boolean insertUser(User user);

    boolean deleteUser(String username);

    User getUser(String username);

    List<User> getAllUser(a);
}
Copy the code

Its implementation class, UserServiceImp.class

@Service
public class UserServiceImpl implements UserService {

    private UserMapper userMapper;

    @Autowired
    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public boolean insertUser(User user) {
        return userMapper.insert(user) == 1;
    }

    @Override
    public boolean deleteUser(String username) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        return userMapper.delete(queryWrapper) == 1;
    }

    @Override
    public User getUser(String username) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public List<User> getAllUser(a) {
        return userMapper.selectList(null); }}Copy the code

To achieve the basic increase, delete, change and check

2.7 the controller

@RequestMapping("/user")
@RestController
public class UserController {
    private UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @RequestMapping("/add/{username}/{age}")
    public String addUser(@PathVariable String username, @PathVariable int age) {
        User user = new User();
        user.setUsername(username);
        user.setAge(age);
        if (userService.insertUser(user)) {
            return "User added successfully";
        }
        return "Failed to add user";
    }

    @RequestMapping("/remove/{username}")
    public String removeUser(@PathVariable String username) {
        if (userService.deleteUser(username)) {
            return "User removed successfully";
        }
        return "Failed to remove user";
    }

    @RequestMapping("/get/")
    public List<User> listUser(a) {
        return userService.getAllUser();
    }

    @RequestMapping("/get/{username}")
    public User getUser(@PathVariable String username) {
        returnuserService.getUser(username); }}Copy the code

3. Test results

1. Add the User

We in the browser input, localhost: 8080 / user/add/LWJ / 18

2. Look for the User

We enter to get just add user, localhost: 8080 / user/get/LWJ

3. Obtain all users

So let’s go ahead and add a bunch of users,

Localhost: 8080 / user/add/xiao Ming / 21

Localhost: 8080 / user/add/yellow / 23

Find all users,

localhost:8080/user/get/

4. Delete the user

localhost:8080/user/remove/lwj

localhost:8080/user/get/

So far the main content of our article is gone!

Possible problems and solutions

1. The port is occupied

Port 3306 is usually occupied because another database product has been installed on the host. In this case, you can change the port mapping by modifying the docker-compose.

      ports:
         - "3307:3306"
Copy the code

Reference documentation

sequoiadb/sequoiadb – Docker Image | Docker Hub

Product Overview _SequoiaDB Introduction _ Document center _SequoiaDB Sequoiadb Sequoia Sequoia Database