maedhroz commented on code in PR #2220:
URL: https://github.com/apache/cassandra/pull/2220#discussion_r1139180984
##########
src/java/org/apache/cassandra/cql3/Operations.java:
##########
@@ -42,29 +44,46 @@ public final class Operations implements Iterable<Operation>
/**
* The operations on regular columns.
*/
- private final List<Operation> regularOperations = new ArrayList<>();
+ private final List<Operation> regularOperations;
/**
* The operations on static columns.
*/
- private final List<Operation> staticOperations = new ArrayList<>();
+ private final List<Operation> staticOperations;
- private final List<ReferenceOperation> regularSubstitutions = new
ArrayList<>();
- private final List<ReferenceOperation> staticSubstitutions = new
ArrayList<>();
+ private final List<ReferenceOperation> regularSubstitutions;
+ private final List<ReferenceOperation> staticSubstitutions;
public Operations(StatementType type)
{
this.type = type;
+ regularOperations = new ArrayList<>();
+ staticOperations = new ArrayList<>();
+ regularSubstitutions = new ArrayList<>();
+ staticSubstitutions = new ArrayList<>();
+ }
+
+ private Operations(Operations other)
+ {
+ type = other.type;
+ regularOperations = new ArrayList<>(other.regularOperations);
+ staticOperations = new ArrayList<>(other.staticOperations);
+ regularSubstitutions = new ArrayList<>(other.regularSubstitutions);
+ staticSubstitutions = new ArrayList<>(other.staticSubstitutions);
}
- public void migrateReadRequiredOperations()
+ @Nullable
+ public Operations migrateReadRequiredOperations()
{
- migrateReadRequiredOperations(staticOperations, staticSubstitutions);
- migrateReadRequiredOperations(regularOperations, regularSubstitutions);
+ Operations other = new Operations(this);
Review Comment:
I guess you could do something like this...
```
@Nullable
public Operations migrateReadRequiredOperations()
{
Operations other = null;
if (regularOperations.stream().anyMatch(Operation::requiresRead))
{
other = new Operations(this);
migrateReadRequiredOperations(other.regularOperations,
other.regularSubstitutions);
migrateReadRequiredOperations(other.staticOperations,
other.staticSubstitutions);
}
else if (staticOperations.stream().anyMatch(Operation::requiresRead))
{
other = new Operations(this);
migrateReadRequiredOperations(other.staticOperations,
other.staticSubstitutions);
}
return other;
}
```
This is cheaper in the case where we don't need any migrations, and
operations on static columns are probably the exceptional case...just not sure
what the probabilities are, as you say.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]