@@ -72,24 +72,40 @@ public Coordinator(DistributedStorage storage, ConsensusCommitConfig config) {
7272 keyManipulator = new CoordinatorGroupCommitKeyManipulator ();
7373 }
7474
75+ /**
76+ * Gets the coordinator state by ID. If the ID is a full ID for the coordinator group commit, it
77+ * will look up the state using the parent ID and the child ID. Otherwise, it will look up the
78+ * state only by ID.
79+ *
80+ * @param id the ID of the coordinator state
81+ * @return the coordinator state
82+ * @throws CoordinatorException if the coordinator state cannot be retrieved
83+ */
7584 public Optional <Coordinator .State > getState (String id ) throws CoordinatorException {
7685 if (keyManipulator .isFullKey (id )) {
7786 return getStateForGroupCommit (id );
7887 }
7988
80- Get get = createGetWith (id );
81- return get (get );
89+ return getStateInternal (id );
8290 }
8391
92+ /**
93+ * Gets the coordinator state for a group commit by ID. It first looks up the state using the
94+ * parent ID and then checks if the child ID is contained in the state. If the child ID is not
95+ * found, it will look up the state using the full ID.
96+ *
97+ * @param fullId the full ID for the coordinator group commit
98+ * @return the coordinator state
99+ * @throws CoordinatorException if the coordinator state cannot be retrieved
100+ */
84101 @ VisibleForTesting
85102 Optional <Coordinator .State > getStateForGroupCommit (String fullId ) throws CoordinatorException {
86103 // Scan with the parent ID for a normal group that contains multiple transactions.
87104 Keys <String , String , String > idForGroupCommit = keyManipulator .keysFromFullKey (fullId );
88105
89106 String parentId = idForGroupCommit .parentKey ;
90107 String childId = idForGroupCommit .childKey ;
91- Get get = createGetWith (parentId );
92- Optional <State > state = get (get );
108+ Optional <State > state = getStateByParentId (parentId );
93109 // The current implementation is optimized for cases where most transactions are
94110 // group-committed. It first looks up a transaction state using the parent ID with a single read
95111 // operation. If no matching transaction state is found (i.e., the transaction was delayed and
@@ -106,7 +122,41 @@ Optional<Coordinator.State> getStateForGroupCommit(String fullId) throws Coordin
106122 return stateContainingTargetTxId ;
107123 }
108124
109- return get (createGetWith (fullId ));
125+ return getStateByFullId (fullId );
126+ }
127+
128+ private Optional <Coordinator .State > getStateInternal (String id ) throws CoordinatorException {
129+ Get get = createGetWith (id );
130+ return get (get );
131+ }
132+
133+ /**
134+ * Gets the coordinator state by the parent ID for the coordinator group commit. Note: The scope
135+ * of this method has public visibility, but is intended for internal use. Also, the method only
136+ * calls {@link #getStateInternal(String)} with the parent ID, but it exists as a separate method
137+ * for clarifying this specific use case.
138+ *
139+ * @param parentId the parent ID of the coordinator state for the coordinator group commit
140+ * @return the coordinator state
141+ * @throws CoordinatorException if the coordinator state cannot be retrieved
142+ */
143+ public Optional <Coordinator .State > getStateByParentId (String parentId )
144+ throws CoordinatorException {
145+ return getStateInternal (parentId );
146+ }
147+
148+ /**
149+ * Gets the coordinator state by the full ID for the coordinator group commit. Note: The scope of
150+ * this method has public visibility, but is intended for internal use. Also, the method only
151+ * calls {@link #getStateInternal(String)} with the parent ID, but it exists as a separate method
152+ * for clarifying this specific use case.
153+ *
154+ * @param fullId the parent ID of the coordinator state for the coordinator group commit
155+ * @return the coordinator state
156+ * @throws CoordinatorException if the coordinator state cannot be retrieved
157+ */
158+ public Optional <Coordinator .State > getStateByFullId (String fullId ) throws CoordinatorException {
159+ return getStateInternal (fullId );
110160 }
111161
112162 public void putState (Coordinator .State state ) throws CoordinatorException {
@@ -332,6 +382,10 @@ public State(String id, TransactionState state) {
332382 this (id , state , System .currentTimeMillis ());
333383 }
334384
385+ public State (String id , List <String > childIds , TransactionState state ) {
386+ this (id , childIds , state , System .currentTimeMillis ());
387+ }
388+
335389 @ VisibleForTesting
336390 State (String id , List <String > childIds , TransactionState state , long createdAt ) {
337391 this .id = checkNotNull (id );
@@ -367,8 +421,9 @@ public long getCreatedAt() {
367421 return createdAt ;
368422 }
369423
370- @ VisibleForTesting
371- List <String > getChildIds () {
424+ @ SuppressFBWarnings ("EI_EXPOSE_REP" )
425+ @ Nonnull
426+ public List <String > getChildIds () {
372427 return childIds ;
373428 }
374429
0 commit comments