add comments to DatabaseStateMachine
Change-Id: I775e2f6c0250ac158e301408e423ebdb29d75668
Showing
1 changed file
with
7 additions
and
0 deletions
... | @@ -89,6 +89,8 @@ public class DatabaseStateMachine implements StateMachine { | ... | @@ -89,6 +89,8 @@ public class DatabaseStateMachine implements StateMachine { |
89 | 89 | ||
90 | @Command | 90 | @Command |
91 | public List<InternalWriteResult> write(List<WriteRequest> requests) { | 91 | public List<InternalWriteResult> write(List<WriteRequest> requests) { |
92 | + | ||
93 | + // applicability check | ||
92 | boolean abort = false; | 94 | boolean abort = false; |
93 | List<InternalWriteResult.Status> validationResults = new ArrayList<>(requests.size()); | 95 | List<InternalWriteResult.Status> validationResults = new ArrayList<>(requests.size()); |
94 | for (WriteRequest request : requests) { | 96 | for (WriteRequest request : requests) { |
... | @@ -132,8 +134,13 @@ public class DatabaseStateMachine implements StateMachine { | ... | @@ -132,8 +134,13 @@ public class DatabaseStateMachine implements StateMachine { |
132 | return results; | 134 | return results; |
133 | } | 135 | } |
134 | 136 | ||
137 | + // apply changes | ||
135 | for (WriteRequest request : requests) { | 138 | for (WriteRequest request : requests) { |
136 | Map<String, VersionedValue> table = state.getTables().get(request.tableName()); | 139 | Map<String, VersionedValue> table = state.getTables().get(request.tableName()); |
140 | + // FIXME: If this method could be called by multiple thread, | ||
141 | + // synchronization scope is wrong. | ||
142 | + // Whole function including applicability check needs to be protected. | ||
143 | + // Confirm copycat's thread safety requirement for StateMachine | ||
137 | synchronized (table) { | 144 | synchronized (table) { |
138 | VersionedValue previousValue = | 145 | VersionedValue previousValue = |
139 | table.put(request.key(), new VersionedValue(request.newValue(), state.nextVersion())); | 146 | table.put(request.key(), new VersionedValue(request.newValue(), state.nextVersion())); | ... | ... |
-
Please register or login to post a comment