20
20
21
21
import java .util .function .BiPredicate ;
22
22
import java .util .function .Function ;
23
+ import java .util .function .Predicate ;
23
24
import java .util .function .ToLongFunction ;
24
25
25
26
import com .google .common .annotations .VisibleForTesting ;
52
53
import static accord .impl .CommandChange .Field .EXECUTES_AT_LEAST ;
53
54
import static accord .impl .CommandChange .Field .EXECUTE_AT ;
54
55
import static accord .impl .CommandChange .Field .FIELDS ;
56
+ import static accord .impl .CommandChange .Field .MIN_UNIQUE_HLC ;
55
57
import static accord .impl .CommandChange .Field .PARTIAL_DEPS ;
56
58
import static accord .impl .CommandChange .Field .PARTIAL_TXN ;
57
59
import static accord .impl .CommandChange .Field .PARTICIPANTS ;
58
60
import static accord .impl .CommandChange .Field .PROMISED ;
59
61
import static accord .impl .CommandChange .Field .RESULT ;
60
62
import static accord .impl .CommandChange .Field .SAVE_STATUS ;
61
- import static accord .impl .CommandChange .Field .MIN_UNIQUE_HLC ;
62
63
import static accord .impl .CommandChange .Field .WAITING_ON ;
63
64
import static accord .impl .CommandChange .Field .WRITES ;
64
65
import static accord .local .Cleanup .NO ;
74
75
import static accord .local .Command .Truncated .invalidated ;
75
76
import static accord .local .Command .Truncated .vestigial ;
76
77
import static accord .local .StoreParticipants .Filter .LOAD ;
78
+ import static accord .primitives .Known .Definition .DefinitionErased ;
79
+ import static accord .primitives .Known .KnownDeps .DepsErased ;
77
80
import static accord .primitives .Known .KnownExecuteAt .ApplyAtKnown ;
81
+ import static accord .primitives .Known .KnownExecuteAt .ExecuteAtErased ;
82
+ import static accord .primitives .Known .Outcome .WasApply ;
78
83
import static accord .primitives .Status .Durability .NotDurable ;
79
84
80
85
public class CommandChange
@@ -101,6 +106,37 @@ public enum Field
101
106
public static final Field [] FIELDS = values ();
102
107
}
103
108
109
+ /**
110
+ * SaveStatus.Known contains information about erased / nullified fields,
111
+ * which we can use in order to mark the corresponding fields as changed
112
+ * and setting them to null when they are erased.
113
+ */
114
+ public static int [] saveStatusMasks ;
115
+
116
+ static
117
+ {
118
+ saveStatusMasks = new int [SaveStatus .values ().length ];
119
+ for (int i = 0 ; i < saveStatusMasks .length ; i ++)
120
+ {
121
+ SaveStatus saveStatus = SaveStatus .forOrdinal (i );
122
+ int mask = 0 ;
123
+ if (forceFieldChangedToNullFlag (saveStatus , saveStatus .known ::is , DepsErased ))
124
+ mask |= setFieldIsNullAndChanged (PARTIAL_DEPS , mask );
125
+ if (forceFieldChangedToNullFlag (saveStatus , saveStatus .known ::is , ExecuteAtErased ))
126
+ mask |= setFieldIsNullAndChanged (EXECUTE_AT , mask );
127
+ if (forceFieldChangedToNullFlag (saveStatus , saveStatus .known ::is , DefinitionErased ))
128
+ mask |= setFieldIsNullAndChanged (PARTIAL_TXN , mask );
129
+ if (forceFieldChangedToNullFlag (saveStatus , saveStatus .known ::is , WasApply ))
130
+ mask |= setFieldIsNullAndChanged (RESULT , mask );
131
+ saveStatusMasks [i ] = mask ;
132
+ }
133
+ }
134
+
135
+ private static <T > boolean forceFieldChangedToNullFlag (SaveStatus saveStatus , Predicate <T > predicate , T erased )
136
+ {
137
+ return saveStatus == SaveStatus .Vestigial || predicate .test (erased );
138
+ }
139
+
104
140
public static class Builder
105
141
{
106
142
protected final int mask ;
@@ -151,72 +187,16 @@ public Builder()
151
187
this (ALL );
152
188
}
153
189
154
- public TxnId txnId ()
155
- {
156
- return txnId ;
157
- }
158
-
159
- public Timestamp executeAt ()
160
- {
161
- return executeAt ;
162
- }
163
-
164
- // TODO: why is this unused in BurnTest
165
- public Timestamp executeAtLeast ()
166
- {
167
- return executeAtLeast ;
168
- }
169
-
170
190
public SaveStatus saveStatus ()
171
191
{
172
192
return saveStatus ;
173
193
}
174
194
175
- public Status .Durability durability ()
176
- {
177
- return durability ;
178
- }
179
-
180
- public Ballot acceptedOrCommitted ()
181
- {
182
- return acceptedOrCommitted ;
183
- }
184
-
185
- public Ballot promised ()
186
- {
187
- return promised ;
188
- }
189
-
190
195
public StoreParticipants participants ()
191
196
{
192
197
return participants ;
193
198
}
194
199
195
- public PartialTxn partialTxn ()
196
- {
197
- return partialTxn ;
198
- }
199
-
200
- public PartialDeps partialDeps ()
201
- {
202
- return partialDeps ;
203
- }
204
-
205
- public CommandChange .WaitingOnProvider waitingOn ()
206
- {
207
- return waitingOn ;
208
- }
209
-
210
- public Writes writes ()
211
- {
212
- return writes ;
213
- }
214
-
215
- public Result result ()
216
- {
217
- return result ;
218
- }
219
-
220
200
public void clear ()
221
201
{
222
202
flags = 0 ;
@@ -286,7 +266,7 @@ public Cleanup shouldCleanup(Input input, Agent agent, RedundantBefore redundant
286
266
287
267
public Builder maybeCleanup (Cleanup cleanup )
288
268
{
289
- if (saveStatus () == null )
269
+ if (saveStatus == null )
290
270
return this ;
291
271
292
272
switch (cleanup )
@@ -531,6 +511,10 @@ public static int getFlags(Command before, Command after)
531
511
flags = setChanged (PARTICIPANTS , flags );
532
512
flags = setChanged (SAVE_STATUS , flags );
533
513
}
514
+
515
+ if (after .saveStatus () != null )
516
+ flags |= saveStatusMasks [after .saveStatus ().ordinal ()];
517
+
534
518
return flags ;
535
519
}
536
520
0 commit comments