11package com .scalar .db .transaction .consensuscommit ;
22
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+
5+ import com .scalar .db .api .DistributedStorageAdmin ;
6+ import com .scalar .db .api .DistributedTransactionAdmin ;
37import com .scalar .db .api .DistributedTransactionAdminRepairTableIntegrationTestBase ;
8+ import com .scalar .db .api .TableMetadata ;
9+ import com .scalar .db .config .DatabaseConfig ;
10+ import com .scalar .db .service .StorageFactory ;
11+ import com .scalar .db .service .TransactionFactory ;
412import java .util .Properties ;
13+ import org .junit .jupiter .api .Test ;
514
615public abstract class ConsensusCommitAdminRepairTableIntegrationTestBase
716 extends DistributedTransactionAdminRepairTableIntegrationTestBase {
@@ -18,4 +27,52 @@ protected final Properties getProperties(String testName) {
1827 }
1928
2029 protected abstract Properties getProps (String testName );
30+
31+ @ Test
32+ public void
33+ repairCoordinatorTables_WithExistingCoordinatorMissingChildIdsColumn_ShouldAddChildIdsColumn ()
34+ throws Exception {
35+ // Arrange: drop the Coordinator created in setUp and recreate it via a separate admin
36+ // instance that has group commit explicitly disabled, so the Coordinator table has no
37+ // CHILD_IDS column.
38+ admin .dropCoordinatorTables ();
39+
40+ Properties propertiesWithGroupCommitDisabled = new Properties ();
41+ propertiesWithGroupCommitDisabled .putAll (getProperties (TEST_NAME ));
42+ propertiesWithGroupCommitDisabled .setProperty (
43+ ConsensusCommitConfig .COORDINATOR_GROUP_COMMIT_ENABLED , "false" );
44+ try (DistributedTransactionAdmin adminWithGroupCommitDisabled =
45+ TransactionFactory .create (propertiesWithGroupCommitDisabled ).getTransactionAdmin ()) {
46+ waitForDifferentSessionDdl ();
47+ adminWithGroupCommitDisabled .createCoordinatorTables (getCreationOptions ());
48+ }
49+
50+ // Act: repair with group commit enabled. The existing Coordinator has no CHILD_IDS column,
51+ // so this should add the column via ALTER TABLE ADD COLUMN.
52+ Properties propertiesWithGroupCommitEnabled = new Properties ();
53+ propertiesWithGroupCommitEnabled .putAll (getProperties (TEST_NAME ));
54+ propertiesWithGroupCommitEnabled .setProperty (
55+ ConsensusCommitConfig .COORDINATOR_GROUP_COMMIT_ENABLED , "true" );
56+ try (DistributedTransactionAdmin adminWithGroupCommitEnabled =
57+ TransactionFactory .create (propertiesWithGroupCommitEnabled ).getTransactionAdmin ()) {
58+ waitForDifferentSessionDdl ();
59+ adminWithGroupCommitEnabled .repairCoordinatorTables (getCreationOptions ());
60+
61+ // Assert: the column now exists in the post-repair Coordinator metadata. We have to read the
62+ // metadata via DistributedStorageAdmin (not via the transaction admin) because
63+ // ConsensusCommitAdmin#getTableMetadata returns null for the coordinator namespace by design.
64+ waitForDifferentSessionDdl ();
65+ String coordinatorNamespace =
66+ new ConsensusCommitConfig (new DatabaseConfig (propertiesWithGroupCommitEnabled ))
67+ .getCoordinatorNamespace ()
68+ .orElse (Coordinator .NAMESPACE );
69+ try (DistributedStorageAdmin storageAdmin =
70+ StorageFactory .create (propertiesWithGroupCommitEnabled ).getStorageAdmin ()) {
71+ TableMetadata metadata =
72+ storageAdmin .getTableMetadata (coordinatorNamespace , Coordinator .TABLE );
73+ assertThat (metadata ).isNotNull ();
74+ assertThat (metadata .getColumnNames ()).contains (Attribute .CHILD_IDS );
75+ }
76+ }
77+ }
2178}
0 commit comments