Logo
Mate User Manual

Introduction #

DBPlusEngine-Mate is a registry center designed for DBPlusEngine-Proxy. It helps users manage DBPlusEngine-Proxy in a more cloud-native way, making it easier to operate while also saving resources. It provides an operational experience that is suitable for SREs (Site Reliability Engineers) and DBAs (Database Administrators).

Features #

Currently, Mate supports the following features:

  • High Availability Support Mate currently uses a primary/secondary mode to support a high-availability architecture.

  • Event Subscription Support Mate uses a ZNode structure similar to ZooKeeper to store data. DBPlusEngine-Proxy interacts with Mate through bidirectional GRPC streams and subscribes to events related to specific paths. When events occur, Mate sends them to all subscribers.

  • Multiple Backend Data Persistence Support Mate supports data persistence using Kubernetes ConfigMap, object storage, MySQL, and PostgreSQL.

  • Support for Different Deployment Methods Mate supports deployment in both virtual machines and Kubernetes environments.

Architecture #

Mate Architecture #

Mate architecture

  • How It Works When Mate starts, it writes a value to a fixed location in the backend. Following the “first come, first served” principle, the Mate that successfully writes first becomes the primary node to provide services. Additionally, Mate periodically updates information.

Proxy Connecting to Mate Architecture Diagram #

Proxy Connecting to Mate Architecture Diagram

  • How It Works When DBPlusEngine-Proxy starts, it retrieves information about the current primary node through Mate’s interface. It accesses Mate’s service interface based on the obtained primary node information. If it cannot retrieve the information, it continues to periodically attempt to fetch the primary node information until successful.

Deployment #

Deployment in Virtual Machines #

Proxy 连接 Mate架构图

Explanation:

DBPlusEngine-Proxy retrieves information about all Mate instances via the internal LB address. It then constructs the RPC address of the Mate Leader based on the returned information and establishes a connection with the RPC address. The host IP address where DBPlusEngine-Proxy is located needs to have network connectivity with the host IP addresses of Mate instances. If you cannot create an LB in a private environment, you can use the following solutions: a. Deploy keepalived + VIP. b. Change the server-lists configuration in the DBPlusEngine-Proxy’s server.yaml configuration file to “machine1 ip:9090, machine2 ip:9090,” as shown below.

...
mode:
  type: Cluster
  repository:
    type: ZooKeeper
    props:
      namespace: governance_ds
      server-lists: 192.168.0.1:9090,192.168.0.2:9090
...

Installation #

sudo rpm -ivh sphereex-mate*.rpm

Explanation: RPM Package Files

The RPM package will create the following files:

FileDescription
/etc/sphereex-mate/mate.confThis is Mate’s configuration file, primarily containing command-line parameters for startup
/usr/lib/systemd/system/sphereex-mate.serviceThis is Mate’s service configuration file, managed by systems
/usr/local/sphereex-mate/mateThis is the executable file for Mate
/usr/local/sphereex-mate/mate-cliThis is a maintenance tool for Mate, mainly used for operations on the keys stored by the current Mate

Preparatory Steps

Before using Mate, follow these steps:

After installing the Mate RPM package, execute the following command to make the Mate service effective:

systemctl daemon-reload #只需运行一次
  1. Before starting Mate, modify the /etc/sphereex-mate/mate.conf configuration file according to your actual requirements. For example, if you’re using MySQL as the leader election and data storage backend for Mate, the configuration might look like this:
ARGS="-db-leader \
-mysql-backend \
-db-host=127.0.0.1 \
-db-port=13306 \
-db-user=root \
-db-password=123456 \

Startup #

To start Mate, use the following command:

sudo systemctl start sphereex-mate
  • Mate will by default start on the following ports:

|Port|Description| |21510| Mate GRPC service port, used for communication with DBPlusEngine-Proxy| |21511 |Mate GRPC-Web port, reserved for future use| |9090 |Mate metrics port, used by DBPlusEngine-Proxy to obtain Mate instance information|

  • Check Status
sudo systemctl status sphereex-mate
  • Shutdown
sudo systemctl stop sphereex-mate
  • Uninstall
sudo rpm -e sphereex-mate
  • Configure DBPlusEngine-Proxy

DBPlusEngine-Proxy 使用 Mate 需要做如下配置:

...
mode:
  type: Cluster
  repository:
    type: SphereEx:MATE
    props:
      namespace: governance_ds
      server-lists: ${LB IP}:9090 

Replace ${LB IP} with the actual IP address of your load balancer (LB).

  • List of Parameters
ParameterTypeDefaultValue Description
-grpc-addrstring:21510Address for the GRPC service listener
-grpc-web-addrstring:21511Address for the GRPC Web service listener (reserved for future use)
-metrics-addrstring:9090Address for the metrics service listener, used by DBPlusEngine-Proxy to obtain the current running Mate leader information
-kube-leaderbooleanfalseWhether to elect the leader through Kubernetes
-obs-leaderbooleanfalseWhether to elect the leader through object storage
-db-leaderbooleanfalseWhether to elect the leader through a database
-kube-backendbooleanfalseWhether to use Kubernetes ConfigMap for data persistence
-obs-backendbooleanfalseWhether to use object storage for data persistence
-pg-backendbooleanfalseWhether to use PostgreSQL for data persistence
-mysql-backendbooleanfalseWhether to use MySQL for data persistence
-null-backendbooleanfalseWhether to retain data only in memory (primarily used for testing, has no practical purpose)
-rateinteger0Rate limit
-kube-backend-namestringmate-backendName of the Kubernetes ConfigMap used for data persistence
-obs-access-keystring""Specify the access key for connecting to object storage
-obs-secret-keystring""Specify the secret key for connecting to object storage
-obs-endpointstring""Specify the address of the object storage
-obs-regionstring""Specify the region where the object storage bucket is located, can be left empty
-obs-bucketstring""Specify the bucket used in object storage
-obs-sslbooleanfalseWhether to enable SSL when connecting to object storage
-db-hoststring""Specify the database address
-db-portstring""Specify the database port
-db-userstring""Specify the username for connecting to the database
-db-passwordstring""Specify the password for connecting to the database
-db-dbnamestring""Specify the name of the connected database
-zap-log-levelstringinfoLog level, can be ‘debug’, ‘info’, or ’error’

Deployment in Kubernetes #

Proxy 连接 Mate架构图

In Kubernetes deployment, DBPlusEngine-Proxy retrieves information about all Mate instances via a Service address and connects to the RPC address of the Mate Leader, as constructed from the received information. Here are some important notes:

  1. DBPlusEngine-Proxy obtains information about all Mate PODs through the Service and constructs the Mate Leader’s RPC address for connection.
  2. The POD IP of DBPlusEngine-Proxy needs to be able to communicate with the POD IP of Mate.

Installation #

Before installing Mate in a Kubernetes environment, you need to modify the values.yaml file of the Helm Chart according to your actual requirements. Here’s an example configuration for electing a leader in Kubernetes with S3 as the Mate data persistence storage:

...

kubeLeader:
  ## @param kubeLeader.enabled Enable leader election in Kubernetes using Lease
  enabled: true

nullBackend:
  ## @param nullBackend.enabled Set to use in-memory mode; this mode is for testing purposes only
  enabled: false

kubeBackend:
  ## @param kubeBackend.enabled Enable kubeBackend for data persistence to Kubernetes ConfigMap
  enabled: false
  ## @param kubeBackend.backendName Name of the ConfigMap for data persistence
  backendName: "mate-backend"

obsBackend:
  ## @param obsBackend.enabled Enable obsBackend for data persistence to object storage
  enabled: true
  ## @param obsBackend.accessKey Authentication access key for object storage
  accessKey: "AKIAXRZPPZNGWHZDZX1Z"
  ## @param obsBackend.secretKey Authentication secret key for object storage
  secretKey: "1Reu8cOyTLl57jccjLMSTh5qFOH3Rayx0R2UWCUd"
  ## @param obsBackend.endpoint Address of the object storage
  endpoint: "s3.amazonaws.com"
  ## @param obsBackend.bucket Name of the bucket in object storage
  bucket: "mate-test-chaos"
  ## @param obsBackend.region Region where the object storage bucket is located
  region: ""
  ## @param obsBackend.useSSL Enable SSL when accessing object storage
  useSSL: true

...

To install, run the following command:

helm install release-name dbplusengine-mate [-n namespace]

This will create the following resources:

  • deployment: Mate’s deployment with a default replica count of 2.
  • service: Mate’s service exposing default ports 21510 and 9090.
  • secret: Created if imagePullAccount.enabled is set to true.

Configuring DBPlusEngine-Proxy To configure DBPlusEngine-Proxy to use Mate, modify your configuration as follows:

...
mode:
  type: Cluster
  repository:
    type: SphereEx:MATE
    props:
      namespace: governance_ds
      server-lists: ${Service Name}:9090 

Replace ${Service Name} with the actual ServiceName.

Uninstallation #

To uninstall, run the following command:

helm delete release-name

Parameter List #

Helm Chart List of Parameters

ParameterDefault ValueDescription
replicas2Number of Mate Replicas
image.repositoryuhub.service.ucloud.cn/cloud-ops/mateMate image name
image.taglatestMate image tag
image.pullPolicyAlwaysimage pull policy
imagePullAccount.enabledfalseAutomatically create a secret based on authentication information
imagePullAccount.username""Username for private repository authentication
imagePullAccount.password""Password for private repository authentication
imagePullSecrets.enabledtrueUse existing private repository authentication secrets
imagePullSecrets.secrets[0].name""Specify the name of an existing private repository authentication secret
resources{}Resources required by Mate
podTemplateAnnotations{}Annotations for the Pod template
grpcAddr:21510gRPC server listening address
grpcWebAddr:21511gRPC web server listening address
metricsAddr:9090Metrics server listening address
kubeLeader.enabledtrueEnable leader election in Kubernetes using Lease
nullBackend.enabledfalseSet to use in-memory mode (for testing only)
kubeBackend.enabledtrueEnable kubeBackend for data persistence to Kubernetes ConfigMap
kubeBackend.backendNamemate-backendName of the ConfigMap for data persistence
obsBackend.enabledfalseEnable obsBackend for data persistence to object storage
obsBackend.accessKey""Authentication access key for object storage
obsBackend.secretKey""Authentication secret key for object storage
obsBackend.endpoint""Object storage address
obsBackend.bucket""Name of the bucket in object storage
obsBackend.region""Region where the object storage bucket is located
obsBackend.useSSLfalseEnable SSL when accessing object storage
dbBackend.enabledfalseEnable dbBackend for data persistence to a database
dbBackend.kind.mysqltrueUse MySQL database
dbBackend.kind.pgfalseUse PostgreSQL database
dbBackend.host""Database address
dbBackend.user""Database authentication username
dbBackend.password""Database authentication password
dbBackend.db""Database name

MateCli Usage Guide #

Introduction #

MateCli provides functionality similar to zkCli.sh in Zookeeper. It allows you to interactively query the data stored within Mate, enhancing Mate’s maintainability.

Interactive Commands #

Prerequisite: #

For deployment in a virtual machine, execute the following command to enter the interactive terminal, for example:

# /mate-cli -mate-addr 127.0.0.1:9090
Mate[/]>  

For deployment in Kubernetes, you need to enter the container and execute the following command to access the interactive terminal, for example:

❯ kubectl exec -it -n ss mate-sphereex-dbplusengine-mate-d569b4b69-9zhbk sh
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
/ # ./mate-cli -mate-addr 127.0.0.1:9090
Mate[/]>  

Note: Replace the -mate-addr parameter with the actual address.

  1. ls Execute the following command:
ls

cli-ls

Execute the following command to recursively display all keys:

ls -r

cli-ls-r

  1. cd

Execute the following command to switch to a specific node:

cd /tm/nodes/compute_nodes/online/proxy/

cli-cd

  1. put

Execute the following command to create a key:

put /ts/a c

cli-put

  1. get

Execute the following command to view a key:

get /ts/a

cli-get

  1. stat

Execute the following command to view the metadata of a key:

stat /ts/a

cli-stat

  1. delete

Execute the following command to delete a key:

delete /ts/a

cli-del

  1. pwd

Execute the following command to view the current path:

pwd

cli-pwd

  1. help

Execute the following command to view the help information:

help

cli-help

Execute the following command to view specific command help information:

put -h

cli-put-h

  1. exit

To exit the terminal, simply use the exit command.

exit