@@ -72,24 +72,40 @@ public Coordinator(DistributedStorage storage, ConsensusCommitConfig config) {
72
72
keyManipulator = new CoordinatorGroupCommitKeyManipulator ();
73
73
}
74
74
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
+ */
75
84
public Optional <Coordinator .State > getState (String id ) throws CoordinatorException {
76
85
if (keyManipulator .isFullKey (id )) {
77
86
return getStateForGroupCommit (id );
78
87
}
79
88
80
- Get get = createGetWith (id );
81
- return get (get );
89
+ return getStateInternal (id );
82
90
}
83
91
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
+ */
84
101
@ VisibleForTesting
85
102
Optional <Coordinator .State > getStateForGroupCommit (String fullId ) throws CoordinatorException {
86
103
// Scan with the parent ID for a normal group that contains multiple transactions.
87
104
Keys <String , String , String > idForGroupCommit = keyManipulator .keysFromFullKey (fullId );
88
105
89
106
String parentId = idForGroupCommit .parentKey ;
90
107
String childId = idForGroupCommit .childKey ;
91
- Get get = createGetWith (parentId );
92
- Optional <State > state = get (get );
108
+ Optional <State > state = getStateByParentId (parentId );
93
109
// The current implementation is optimized for cases where most transactions are
94
110
// group-committed. It first looks up a transaction state using the parent ID with a single read
95
111
// 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
106
122
return stateContainingTargetTxId ;
107
123
}
108
124
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 );
110
160
}
111
161
112
162
public void putState (Coordinator .State state ) throws CoordinatorException {
@@ -332,6 +382,10 @@ public State(String id, TransactionState state) {
332
382
this (id , state , System .currentTimeMillis ());
333
383
}
334
384
385
+ public State (String id , List <String > childIds , TransactionState state ) {
386
+ this (id , childIds , state , System .currentTimeMillis ());
387
+ }
388
+
335
389
@ VisibleForTesting
336
390
State (String id , List <String > childIds , TransactionState state , long createdAt ) {
337
391
this .id = checkNotNull (id );
@@ -367,8 +421,9 @@ public long getCreatedAt() {
367
421
return createdAt ;
368
422
}
369
423
370
- @ VisibleForTesting
371
- List <String > getChildIds () {
424
+ @ SuppressFBWarnings ("EI_EXPOSE_REP" )
425
+ @ Nonnull
426
+ public List <String > getChildIds () {
372
427
return childIds ;
373
428
}
374
429
0 commit comments