Skip to content

Commit f3b7459

Browse files
komamitsubrfrn169
andauthored
Add the replication related APIs to DistributedAdmin for SSR (#2603)
Co-authored-by: Toshihiro Suzuki <[email protected]>
1 parent 435584a commit f3b7459

File tree

4 files changed

+178
-1
lines changed

4 files changed

+178
-1
lines changed

core/src/main/java/com/scalar/db/api/DistributedTransactionAdmin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
* An administrative interface for distributed transaction implementations. The user can execute
99
* administrative operations with it like createNamespace/createTable/getTableMetadata.
1010
*/
11-
public interface DistributedTransactionAdmin extends Admin, AuthAdmin, AbacAdmin, AutoCloseable {
11+
public interface DistributedTransactionAdmin
12+
extends Admin, AuthAdmin, AbacAdmin, ReplicationAdmin, AutoCloseable {
1213

1314
/**
1415
* Creates coordinator namespace and tables.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.scalar.db.api;
2+
3+
import com.scalar.db.common.error.CoreError;
4+
import com.scalar.db.exception.storage.ExecutionException;
5+
import java.util.Collections;
6+
import java.util.Map;
7+
8+
/** An administrative interface for the replication feature. */
9+
public interface ReplicationAdmin {
10+
11+
/**
12+
* Creates the replication-related namespace and tables in the replication database.
13+
*
14+
* @param options options to create namespace and tables
15+
* @throws ExecutionException if the operation fails
16+
*/
17+
default void createReplicationTables(Map<String, String> options) throws ExecutionException {
18+
throw new UnsupportedOperationException(CoreError.REPLICATION_NOT_ENABLED.buildMessage());
19+
}
20+
21+
/**
22+
* Creates the replication-related namespace and tables in the replication database.
23+
*
24+
* @param ifNotExist if set to true, the replication-related namespace and tables will be created
25+
* only if they do not exist. If set to false, it will throw an exception if they already
26+
* exist
27+
* @param options options to create namespace and tables
28+
* @throws IllegalArgumentException if the replication-related namespace or tables already exist
29+
* and ifNotExist is set to false
30+
* @throws ExecutionException if the operation fails
31+
*/
32+
default void createReplicationTables(boolean ifNotExist, Map<String, String> options)
33+
throws ExecutionException {
34+
if (ifNotExist && replicationTablesExist()) {
35+
return;
36+
}
37+
createReplicationTables(options);
38+
}
39+
40+
/**
41+
* Creates the replication-related namespace and tables in the replication database.
42+
*
43+
* @param ifNotExist if set to true, the replication-related namespace and tables will be created
44+
* only if they do not exist. If set to false, it will throw an exception if they already
45+
* exist
46+
* @throws IllegalArgumentException if the replication-related namespace or tables already exist
47+
* and ifNotExist is set to false
48+
* @throws ExecutionException if the operation fails
49+
*/
50+
default void createReplicationTables(boolean ifNotExist) throws ExecutionException {
51+
if (ifNotExist && replicationTablesExist()) {
52+
return;
53+
}
54+
createReplicationTables(Collections.emptyMap());
55+
}
56+
57+
/**
58+
* Creates the replication-related namespace and tables in the replication database.
59+
*
60+
* @throws ExecutionException if the operation fails
61+
*/
62+
default void createReplicationTables() throws ExecutionException {
63+
createReplicationTables(Collections.emptyMap());
64+
}
65+
66+
/**
67+
* Drops the replication-related namespace and tables in the replication database.
68+
*
69+
* @throws IllegalArgumentException if the replication-related tables do not exist
70+
* @throws ExecutionException if the operation fails
71+
*/
72+
default void dropReplicationTables() throws ExecutionException {
73+
throw new UnsupportedOperationException(CoreError.REPLICATION_NOT_ENABLED.buildMessage());
74+
}
75+
76+
/**
77+
* Drops the replication-related namespace and tables in the replication database.
78+
*
79+
* @param ifExist if set to true, the replication-related namespace and tables will be dropped
80+
* only if they exist. If set to false, it will throw an exception if they do not exist
81+
* @throws IllegalArgumentException if the replication-related tables do not exist if ifExist is
82+
* set to false
83+
* @throws ExecutionException if the operation fails
84+
*/
85+
default void dropReplicationTables(boolean ifExist) throws ExecutionException {
86+
if (ifExist && !replicationTablesExist()) {
87+
return;
88+
}
89+
dropReplicationTables();
90+
}
91+
92+
/**
93+
* Truncates the replication-related tables in the replication database.
94+
*
95+
* @throws IllegalArgumentException if the replication-related tables do not exist
96+
* @throws ExecutionException if the operation fails
97+
*/
98+
default void truncateReplicationTables() throws ExecutionException {
99+
throw new UnsupportedOperationException(CoreError.REPLICATION_NOT_ENABLED.buildMessage());
100+
}
101+
102+
/**
103+
* Repairs the replication-related tables in the replication database which may be in an unknown
104+
* state.
105+
*
106+
* @param options options to repair
107+
* @throws IllegalArgumentException if the replication-related tables do not exist
108+
* @throws ExecutionException if the operation fails
109+
*/
110+
default void repairReplicationTables(Map<String, String> options) throws ExecutionException {
111+
throw new UnsupportedOperationException(CoreError.REPLICATION_NOT_ENABLED.buildMessage());
112+
}
113+
114+
/**
115+
* Checks whether all the replication-related tables exist in the replication database.
116+
*
117+
* @return true if all the replication-related tables exist, false otherwise
118+
* @throws ExecutionException if the operation fails
119+
*/
120+
default boolean replicationTablesExist() throws ExecutionException {
121+
throw new UnsupportedOperationException(CoreError.REPLICATION_NOT_ENABLED.buildMessage());
122+
}
123+
}

core/src/main/java/com/scalar/db/common/DecoratedDistributedTransactionAdmin.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,52 @@ public List<TablePolicy> getTablePolicies() throws ExecutionException {
558558
return distributedTransactionAdmin.getTablePolicies();
559559
}
560560

561+
@Override
562+
public void createReplicationTables(Map<String, String> options) throws ExecutionException {
563+
distributedTransactionAdmin.createReplicationTables(options);
564+
}
565+
566+
@Override
567+
public void createReplicationTables(boolean ifNotExist, Map<String, String> options)
568+
throws ExecutionException {
569+
distributedTransactionAdmin.createReplicationTables(ifNotExist, options);
570+
}
571+
572+
@Override
573+
public void createReplicationTables(boolean ifNotExist) throws ExecutionException {
574+
distributedTransactionAdmin.createReplicationTables(ifNotExist);
575+
}
576+
577+
@Override
578+
public void createReplicationTables() throws ExecutionException {
579+
distributedTransactionAdmin.createReplicationTables();
580+
}
581+
582+
@Override
583+
public void dropReplicationTables() throws ExecutionException {
584+
distributedTransactionAdmin.dropReplicationTables();
585+
}
586+
587+
@Override
588+
public void dropReplicationTables(boolean ifExist) throws ExecutionException {
589+
distributedTransactionAdmin.dropReplicationTables(ifExist);
590+
}
591+
592+
@Override
593+
public void truncateReplicationTables() throws ExecutionException {
594+
distributedTransactionAdmin.truncateReplicationTables();
595+
}
596+
597+
@Override
598+
public void repairReplicationTables(Map<String, String> options) throws ExecutionException {
599+
distributedTransactionAdmin.repairReplicationTables(options);
600+
}
601+
602+
@Override
603+
public boolean replicationTablesExist() throws ExecutionException {
604+
return distributedTransactionAdmin.replicationTablesExist();
605+
}
606+
561607
@Override
562608
public void close() {
563609
distributedTransactionAdmin.close();

core/src/main/java/com/scalar/db/common/error/CoreError.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,13 @@ public enum CoreError implements ScalarDbError {
848848
Category.USER_ERROR, "0186", "The CSV row: %s does not match header: %s.", "", ""),
849849
DATA_LOADER_JSON_CONTENT_START_ERROR(
850850
Category.USER_ERROR, "0187", "Expected JSON file content to be an array", "", ""),
851+
REPLICATION_NOT_ENABLED(
852+
Category.USER_ERROR,
853+
"0188",
854+
// TODO: Update the message once the licence type is determined.
855+
"The replication feature is not enabled. To use this feature, you must enable it",
856+
"",
857+
""),
851858

852859
//
853860
// Errors for the concurrency error category

0 commit comments

Comments
 (0)