|
| 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 | +} |
0 commit comments