52
52
import static accord .impl .CommandChange .Field .EXECUTES_AT_LEAST ;
53
53
import static accord .impl .CommandChange .Field .EXECUTE_AT ;
54
54
import static accord .impl .CommandChange .Field .FIELDS ;
55
+ import static accord .impl .CommandChange .Field .MIN_UNIQUE_HLC ;
55
56
import static accord .impl .CommandChange .Field .PARTIAL_DEPS ;
56
57
import static accord .impl .CommandChange .Field .PARTIAL_TXN ;
57
58
import static accord .impl .CommandChange .Field .PARTICIPANTS ;
58
59
import static accord .impl .CommandChange .Field .PROMISED ;
59
60
import static accord .impl .CommandChange .Field .RESULT ;
60
61
import static accord .impl .CommandChange .Field .SAVE_STATUS ;
61
- import static accord .impl .CommandChange .Field .MIN_UNIQUE_HLC ;
62
62
import static accord .impl .CommandChange .Field .WAITING_ON ;
63
63
import static accord .impl .CommandChange .Field .WRITES ;
64
64
import static accord .local .Cleanup .NO ;
74
74
import static accord .local .Command .Truncated .invalidated ;
75
75
import static accord .local .Command .Truncated .vestigial ;
76
76
import static accord .local .StoreParticipants .Filter .LOAD ;
77
+ import static accord .primitives .Known .Definition .DefinitionErased ;
78
+ import static accord .primitives .Known .KnownDeps .DepsErased ;
77
79
import static accord .primitives .Known .KnownExecuteAt .ApplyAtKnown ;
80
+ import static accord .primitives .Known .KnownExecuteAt .ExecuteAtErased ;
81
+ import static accord .primitives .Known .Outcome .WasApply ;
78
82
import static accord .primitives .Status .Durability .NotDurable ;
79
83
80
84
public class CommandChange
@@ -101,6 +105,33 @@ public enum Field
101
105
public static final Field [] FIELDS = values ();
102
106
}
103
107
108
+ /**
109
+ * SaveStatus.Known contains information about erased / nullified fields,
110
+ * which we can use in order to mark the corresponding fields as changed
111
+ * and setting them to null when they are erased.
112
+ */
113
+ public static int [] saveStatusMasks ;
114
+
115
+ static
116
+ {
117
+ saveStatusMasks = new int [SaveStatus .values ().length ];
118
+ for (int i = 0 ; i < saveStatusMasks .length ; i ++)
119
+ {
120
+ SaveStatus saveStatus = SaveStatus .forOrdinal (i );
121
+ boolean isVestigial = saveStatus == SaveStatus .Vestigial ;
122
+ int mask = 0 ;
123
+ if (isVestigial || saveStatus .known .deps () == DepsErased )
124
+ mask |= setFieldIsNullAndChanged (PARTIAL_DEPS , mask );
125
+ if (isVestigial || saveStatus .known .executeAt () == ExecuteAtErased )
126
+ mask |= setFieldIsNullAndChanged (EXECUTE_AT , mask );
127
+ if (isVestigial || saveStatus .known .definition () == DefinitionErased )
128
+ mask |= setFieldIsNullAndChanged (PARTIAL_TXN , mask );
129
+ if (isVestigial || saveStatus .known .outcome () == WasApply )
130
+ mask |= setFieldIsNullAndChanged (RESULT , mask );
131
+ saveStatusMasks [i ] = mask ;
132
+ }
133
+ }
134
+
104
135
public static class Builder
105
136
{
106
137
protected final int mask ;
@@ -151,72 +182,16 @@ public Builder()
151
182
this (ALL );
152
183
}
153
184
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
185
public SaveStatus saveStatus ()
171
186
{
172
187
return saveStatus ;
173
188
}
174
189
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
190
public StoreParticipants participants ()
191
191
{
192
192
return participants ;
193
193
}
194
194
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
195
public void clear ()
221
196
{
222
197
flags = 0 ;
@@ -286,7 +261,7 @@ public Cleanup shouldCleanup(Input input, Agent agent, RedundantBefore redundant
286
261
287
262
public Builder maybeCleanup (Cleanup cleanup )
288
263
{
289
- if (saveStatus () == null )
264
+ if (saveStatus == null )
290
265
return this ;
291
266
292
267
switch (cleanup )
@@ -531,6 +506,10 @@ public static int getFlags(Command before, Command after)
531
506
flags = setChanged (PARTICIPANTS , flags );
532
507
flags = setChanged (SAVE_STATUS , flags );
533
508
}
509
+
510
+ if (after .saveStatus () != null )
511
+ flags |= saveStatusMasks [after .saveStatus ().ordinal ()];
512
+
534
513
return flags ;
535
514
}
536
515
0 commit comments