Skip to content

Commit

Permalink
[#186] Add Serial Consistency Level and Timestamp to Activity Log (#187)
Browse files Browse the repository at this point in the history
* [#186] Add Serial Consistency Level and Timestamp to Activity Log

Updates recorded queries in the ActivityLog to include Serial
Consistency Level and Timestamp if present in queries.  If the values
are not present, all the client implementations return null to indicate
that they weren't set.

Also fixes some bugs in the codec module:

- Use of Notations.consistency in favor of Consistency.codec caused
  NullPointerExceptions due to order of loading.  Use Consistency.codec
  instead in both Query and Batch.
- Bitmasking in BatchFlags was offset incorrectly.

* Fix version (1.1.2 was never released, so reuse)
  • Loading branch information
tolbertam authored Feb 24, 2017
1 parent bafb8b3 commit cc6ec71
Show file tree
Hide file tree
Showing 24 changed files with 317 additions and 103 deletions.
2 changes: 1 addition & 1 deletion codec/src/main/scala/org/scassandra/codec/Message.scala
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ object Batch {
("consistency" | Consistency.codec) ::
// only parse flags for protocol version 2+ since that's when they were added.
("flags" | withDefaultValue(conditional(protocolVersion.version > 2, Codec[BatchFlags]), DefaultBatchFlags)).consume { flags =>
("serialConsistency" | conditional(flags.withSerialConsistency, consistency)) ::
("serialConsistency" | conditional(flags.withSerialConsistency, Consistency.codec)) ::
("timestamp" | conditional(flags.withDefaultTimestamp, clong))
} { data => // derive flags from presence of serialConsistency and timestamp.
val serialConsistency = data.head
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ private[codec] case class BatchFlags(

private [codec] object BatchFlags {
implicit val codec: Codec[BatchFlags] = {
("reserved" | ignore(5)) ::
("reserved" | ignore(1)) ::
("namesForValues" | bool) :: // Note that namesForValues is not currently used, see CASSANDRA-10246
("defaultTimestamp" | bool) ::
("serialConsistency" | bool)
("serialConsistency" | bool) ::
("reserved" | ignore(4)) // the first 4 bits are unused.
}.as[BatchFlags]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object QueryParameters {
("skipMetadata" | provide[Boolean](flags.skipMetadata)) ::
("pageSize" | conditional(flags.pageSize, cint)) ::
("pagingState" | conditional(flags.withPagingState, cbytes)) ::
("serialConsistency " | conditional(flags.withSerialConsistency, consistency)) ::
("serialConsistency " | conditional(flags.withSerialConsistency, Consistency.codec)) ::
("timestamp" | conditional(flags.withDefaultTimestamp, clong))
} { data =>
// This is admittedly contrived, but allows us to forgo making QueryFlags part of QueryParameters as
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Tue, 17 Jan 2017 21:09:46 +0000
version=1.1.3
version=1.1.2-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ public final class BatchExecution {

private final List<BatchQuery> batchQueries;
private final String consistency;
private final String serialConsistency;
private final BatchType batchType;
private final Long timestamp;

private BatchExecution(List<BatchQuery> batchQueries, String consistency, BatchType batchType) {

private BatchExecution(List<BatchQuery> batchQueries, String consistency, String serialConsistency,
BatchType batchType, Long timestamp) {
this.batchQueries = batchQueries;
this.consistency = consistency;
this.serialConsistency = serialConsistency;
this.batchType = batchType;
this.timestamp = timestamp;
}

public List<BatchQuery> getBatchQueries() {
Expand All @@ -41,30 +47,40 @@ public String getConsistency() {
return consistency;
}

public String getSerialConsistency() {
return serialConsistency;
}

public BatchType getBatchType() {
return batchType;
}

public Long getTimestamp() {
return timestamp;
}

@Override
public boolean equals(Object o) {

if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

BatchExecution that = (BatchExecution) o;

if (batchQueries != null ? !batchQueries.equals(that.batchQueries) : that.batchQueries != null)
return false;
if (batchQueries != null ? !batchQueries.equals(that.batchQueries) : that.batchQueries != null) return false;
if (consistency != null ? !consistency.equals(that.consistency) : that.consistency != null) return false;
return batchType == that.batchType;

if (serialConsistency != null ? !serialConsistency.equals(that.serialConsistency) : that.serialConsistency != null)
return false;
if (batchType != that.batchType) return false;
return timestamp != null ? timestamp.equals(that.timestamp) : that.timestamp == null;
}

@Override
public int hashCode() {
int result = batchQueries != null ? batchQueries.hashCode() : 0;
result = 31 * result + (consistency != null ? consistency.hashCode() : 0);
result = 31 * result + (serialConsistency != null ? serialConsistency.hashCode() : 0);
result = 31 * result + (batchType != null ? batchType.hashCode() : 0);
result = 31 * result + (timestamp != null ? timestamp.hashCode() : 0);
return result;
}

Expand All @@ -73,7 +89,9 @@ public String toString() {
return "BatchExecution{" +
"batchQueries=" + batchQueries +
", consistency='" + consistency + '\'' +
", serialConsistency='" + serialConsistency + '\'' +
", batchType=" + batchType +
", timestamp=" + timestamp +
'}';
}

Expand All @@ -85,7 +103,9 @@ public static BatchExecutionBuilder builder() {
public static class BatchExecutionBuilder {
private List<BatchQuery> batchQueries;
private String consistency = "ONE";
private String serialConsistency;
private BatchType batchType = LOGGED;
private Long timestamp;

private BatchExecutionBuilder() {
}
Expand Down Expand Up @@ -119,6 +139,11 @@ public BatchExecutionBuilder withConsistency(String consistency) {
return this;
}

public BatchExecutionBuilder withSerialConsistency(String serialConsistency) {
this.serialConsistency = serialConsistency;
return this;
}

/**
* Defaults to LOGGED if not set.
*
Expand All @@ -130,8 +155,13 @@ public BatchExecutionBuilder withBatchType(BatchType batchType) {
return this;
}

public BatchExecutionBuilder withTimestamp(Long timestamp) {
this.timestamp = timestamp;
return this;
}

public BatchExecution build() {
return new BatchExecution(batchQueries, consistency, batchType);
return new BatchExecution(batchQueries, consistency, serialConsistency, batchType, timestamp);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@
public final class PreparedStatementExecution {
private final String preparedStatementText;
private final String consistency;
private final String serialConsistency;
private final List<Object> variables;
private final List<CqlType> variableTypes;
private final Long timestamp;

private PreparedStatementExecution(String preparedStatementText, String consistency, List<Object> variables, List<CqlType> variableTypes) {
private PreparedStatementExecution(String preparedStatementText, String consistency, String serialConsistency,
List<Object> variables, List<CqlType> variableTypes, Long timestamp) {
this.preparedStatementText = preparedStatementText;
this.consistency = consistency;
this.serialConsistency = serialConsistency;
this.variables = variables;
this.variableTypes = variableTypes;
this.timestamp = timestamp;
}

public String getPreparedStatementText() {
Expand All @@ -44,17 +49,16 @@ public String getConsistency() {
return consistency;
}

public List<Object> getVariables() {
return Collections.unmodifiableList(variables);
public String getSerialConsistency() {
return serialConsistency;
}

@Override
public String toString() {
return "PreparedStatementExecution{" +
"preparedStatementText='" + preparedStatementText + '\'' +
", consistency='" + consistency + '\'' +
", variables=" + variables +
'}';
public Long getTimestamp() {
return timestamp;
}

public List<Object> getVariables() {
return Collections.unmodifiableList(variables);
}

@Override
Expand All @@ -64,22 +68,38 @@ public boolean equals(Object o) {

PreparedStatementExecution that = (PreparedStatementExecution) o;

if (consistency != null ? !consistency.equals(that.consistency) : that.consistency != null) return false;
if (preparedStatementText != null ? !preparedStatementText.equals(that.preparedStatementText) : that.preparedStatementText != null)
return false;
if (consistency != null ? !consistency.equals(that.consistency) : that.consistency != null) return false;
if (serialConsistency != null ? !serialConsistency.equals(that.serialConsistency) : that.serialConsistency != null)
return false;
if (variables != null ? !variables.equals(that.variables) : that.variables != null) return false;

return true;
if (variableTypes != null ? !variableTypes.equals(that.variableTypes) : that.variableTypes != null)
return false;
return timestamp != null ? timestamp.equals(that.timestamp) : that.timestamp == null;
}

@Override
public int hashCode() {
int result = preparedStatementText != null ? preparedStatementText.hashCode() : 0;
result = 31 * result + (consistency != null ? consistency.hashCode() : 0);
result = 31 * result + (serialConsistency != null ? serialConsistency.hashCode() : 0);
result = 31 * result + (variables != null ? variables.hashCode() : 0);
result = 31 * result + (variableTypes != null ? variableTypes.hashCode() : 0);
result = 31 * result + (timestamp != null ? timestamp.hashCode() : 0);
return result;
}

public String toString() {
return "PreparedStatementExecution{" +
"preparedStatementText='" + preparedStatementText + '\'' +
", consistency='" + consistency + '\'' +
", serialConsistency='" + serialConsistency + "\'" +
", variables=" + variables +
", timestamp=" + timestamp +
'}';
}

public static PreparedStatementExecutionBuilder builder() {
return new PreparedStatementExecutionBuilder();
}
Expand Down Expand Up @@ -113,7 +133,9 @@ public static class PreparedStatementExecutionBuilder {
private List<CqlType> variableTypes = Collections.emptyList();
private String preparedStatementText;
private String consistency = "ONE";
private String serialConsistency;
private List<Object> variables = Collections.emptyList();
private Long timestamp;

private PreparedStatementExecutionBuilder() {
}
Expand Down Expand Up @@ -146,6 +168,11 @@ public PreparedStatementExecutionBuilder withConsistency(String consistency) {
return this;
}

public PreparedStatementExecutionBuilder withSerialConsistency(String serialConsistency) {
this.serialConsistency = serialConsistency;
return this;
}

public PreparedStatementExecutionBuilder withPreparedStatementText(String preparedStatementText) {
this.preparedStatementText = preparedStatementText;
return this;
Expand All @@ -161,11 +188,17 @@ public PreparedStatementExecutionBuilder withVariables(List<Object> variables) {
return this;
}

public PreparedStatementExecutionBuilder withTimestamp(Long timestamp) {
this.timestamp = timestamp;
return this;
}

public PreparedStatementExecution build() {
if (preparedStatementText == null) {
throw new IllegalStateException("Must set preparedStatementText in PreparedStatementExecutionBuilder");
}
return new PreparedStatementExecution(this.preparedStatementText, this.consistency, this.variables, this.variableTypes);
return new PreparedStatementExecution(this.preparedStatementText, this.consistency, this.serialConsistency,
this.variables, this.variableTypes, this.timestamp);
}
}
}
Loading

0 comments on commit cc6ec71

Please sign in to comment.