Each partition is stored as multiple physical copies to ensure data security and high availability of data services. Each copy is called a replica of the partition. Each replica may include three major types of data: static data stored in the SSTable on the disk, incremental data stored in the MemTable in the memory, and logs that record transactions. Several replica types are available depending on the types of data stored. This is to support the different business preferences in terms of data security, performance scalability, availability, and costs.
OceanBase Database supports the following four types of replicas:
Full-featured replica (FULL/F)
Log-only replica (LOGONLY/L)
Encrypted voting replica (ENCRYPTVOTE/E)
Read-only replica (READONLY/R)
The full-featured replica, log-only replica, and encrypted voting replica are Paxos replicas that can join a Paxos group. The read-only replica is a non-Paxos replica that cannot join a Paxos group.
Attributes of different replica types
Typically, you can execute the following statement to specify the locality to determine the types and distribution of replicas of partitions:
locality='F@z1,F@z2,F{1},R{ALL_SERVER}@z3,L@z4,L@z5'
In the statement, you can specify other attributes of a replica in the braces ({ }) following the replica type. The number in the braces ({ }) indicates the number of replicas of the specified type in the specified zone.
For F-, L-, and E-type replicas, the value can be 1 or not specified. If the value is not specified, the number of replicas is 1 by default.
For R-type replicas, the maximum value is the number of available resource units in the specified zone. You can set the value to ALL_SERVER or leave it unspecified. ALL_SERVER indicates that R-type replicas are to be preferentially created in the specified zone. If the value is not specified, the number of replicas is 1 by default.
To define the MemTable of a replica, OceanBase Database introduces the memstore_percent attribute, which indicates the ratio of the maximum memory usage of a replica MemStore to the maximum memory usage of the leader. The memstore_percent attribute applies to F- and R-type replicas. Sample statement:
locality='F@z1,F{memstore_percent:0}@z2,F{1,memstore_percent:100},R{ALL_SERVER}@z3,L@z4,L@z5'
Valid values of the memstore_percent attribute are 0 and 100.
If the memstore_percent attribute is not specified for a replica, it is equivalent to
memstore_percent=100, which indicates that the memory usage of the MemStore is not limited.If
memstore_percent=0is specified for a replica, the replica has no MemStore and logs are not replayed, which avoids the CPU costs for log replay and minor compactions. The replica must regularly pull minor compaction data from other replicas to ensure a controllable downtime recovery time.
A replica with the memstore_percent=0 setting is called a data replica (D replica).
When an F-type D replica is elected as a new leader, a longer downtime recovery time is required, which may last several minutes.
The MemTable of a D replica occupies no memory, and logs are not replayed.
If your business has limited resources and is insensitive to the downtime recovery time, you can use D replicas to significantly reduce the memory usage.