Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
removed references to clock per latest changes in cassandra trunk, up…
Browse files Browse the repository at this point in the history
…dated snapshot cassandra reference
  • Loading branch information
zznate committed Sep 22, 2010
1 parent 4b7bec3 commit b41255a
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 59 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -187,7 +187,7 @@
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>apache-cassandra</artifactId>
<version>0.7.0-beta2-r999050</version>
<version>0.7.0-beta2-r999745</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Expand Up @@ -8,7 +8,6 @@
import me.prettyprint.cassandra.service.Keyspace;
import me.prettyprint.hector.api.exceptions.HectorException;

import org.apache.cassandra.thrift.Clock;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.ColumnParent;
import org.apache.cassandra.thrift.ColumnPath;
Expand Down Expand Up @@ -37,7 +36,7 @@ public static void main(String[] args) throws HectorException {
columnPath.setColumn(bytes("column-name"));

// insert
keyspace.insert(bytes("key"), columnParent, new Column(bytes("column-name"), bytes("value"), new Clock(keyspace.createClock())));
keyspace.insert(bytes("key"), columnParent, new Column(bytes("column-name"), bytes("value"), keyspace.createClock()));

// read
Column col = keyspace.getColumn(bytes("key"), columnPath);
Expand Down
Expand Up @@ -9,7 +9,6 @@
import me.prettyprint.hector.api.exceptions.HNotFoundException;
import me.prettyprint.hector.api.exceptions.HectorException;

import org.apache.cassandra.thrift.Clock;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.ColumnParent;
import org.apache.cassandra.thrift.ColumnPath;
Expand Down Expand Up @@ -59,7 +58,7 @@ public <K >void insert(final K key, final String value, final Serializer<K> keyS
execute(new Command<Void>() {
@Override
public Void execute(final Keyspace ks) throws HectorException {
ks.insert(keySerializer.toBytes(key), new ColumnParent(CF_NAME), new Column(bytes(COLUMN_NAME), bytes(value), new Clock(ks.createClock())));
ks.insert(keySerializer.toBytes(key), new ColumnParent(CF_NAME), new Column(bytes(COLUMN_NAME), bytes(value), ks.createClock()));
return null;
}
});
Expand Down
Expand Up @@ -10,7 +10,6 @@
import me.prettyprint.hector.api.exceptions.HNotFoundException;
import me.prettyprint.hector.api.exceptions.HectorException;

import org.apache.cassandra.thrift.Clock;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.ColumnParent;
import org.apache.cassandra.thrift.ColumnPath;
Expand Down Expand Up @@ -46,7 +45,7 @@ public <K> void insert(final K key, final String value, final Serializer<K> keyS
execute(new SpringCommand<Void>(cassandraClientPool){
@Override
public Void execute(final Keyspace ks) throws HectorException {
ks.insert(keySerializer.toBytes(key), new ColumnParent(columnFamilyName), new Column(bytes(columnName), bytes(value), new Clock(ks.createClock())));
ks.insert(keySerializer.toBytes(key), new ColumnParent(columnFamilyName), new Column(bytes(columnName), bytes(value), ks.createClock()));
return null;
}
});
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/me/prettyprint/cassandra/model/HColumn.java
Expand Up @@ -4,7 +4,6 @@

import me.prettyprint.cassandra.serializers.SerializerTypeInferer;

import org.apache.cassandra.thrift.Clock;
import org.apache.cassandra.thrift.Column;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
Expand Down Expand Up @@ -44,7 +43,7 @@ public HColumn(Column thriftColumn, Serializer<N> nameSerializer,
notNull(thriftColumn, "thriftColumn is null");
name = nameSerializer.fromBytes(thriftColumn.getName());
value = valueSerializer.fromBytes(thriftColumn.getValue());
clock = thriftColumn.clock.getTimestamp();
clock = thriftColumn.timestamp;
}

public HColumn(Serializer<N> nameSerializer, Serializer<V> valueSerializer) {
Expand Down Expand Up @@ -98,15 +97,15 @@ public long getClock() {
}

public Column toThrift() {
return ttl > 0 ? new Column(nameSerializer.toBytes(name), valueSerializer.toBytes(value), new Clock(clock)).setTtl(ttl) :
new Column(nameSerializer.toBytes(name), valueSerializer.toBytes(value), new Clock(clock));
return ttl > 0 ? new Column(nameSerializer.toBytes(name), valueSerializer.toBytes(value), clock).setTtl(ttl) :
new Column(nameSerializer.toBytes(name), valueSerializer.toBytes(value), clock);
}

public HColumn<N, V> fromThrift(Column c) {
notNull(c, "column is null");
name = nameSerializer.fromBytes(c.name);
value = valueSerializer.fromBytes(c.value);
clock = c.clock.timestamp;
clock = c.timestamp;
ttl = c.ttl;
return this;
}
Expand Down
Expand Up @@ -7,7 +7,6 @@
import java.util.Collections;
import java.util.List;

import org.apache.cassandra.thrift.Clock;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.SuperColumn;

Expand Down
Expand Up @@ -8,7 +8,6 @@
import me.prettyprint.hector.api.ConsistencyLevelPolicy.OperationType;
import me.prettyprint.hector.api.exceptions.HectorException;

import org.apache.cassandra.thrift.Clock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/me/prettyprint/cassandra/model/Mutator.java
Expand Up @@ -8,7 +8,6 @@
import me.prettyprint.cassandra.service.Keyspace;
import me.prettyprint.hector.api.exceptions.HectorException;

import org.apache.cassandra.thrift.Clock;
import org.apache.cassandra.thrift.Deletion;
import org.apache.cassandra.thrift.SlicePredicate;

Expand Down Expand Up @@ -103,7 +102,7 @@ public <SN,N,V> Mutator<K> addInsertion(K key, String cf, HSuperColumn<SN,N,V> s
public <N> Mutator<K> addDeletion(K key, String cf, N columnName, Serializer<N> nameSerializer) {
SlicePredicate sp = new SlicePredicate();
sp.addToColumn_names(nameSerializer.toBytes(columnName));
Deletion d = columnName != null ? new Deletion(new Clock(ko.createClock())).setPredicate(sp) : new Deletion(new Clock(ko.createClock()));
Deletion d = columnName != null ? new Deletion(ko.createClock()).setPredicate(sp) : new Deletion(ko.createClock());
getPendingMutations().addDeletion(key, Arrays.asList(cf), d);
return this;
}
Expand Down
@@ -1,7 +1,5 @@
package me.prettyprint.cassandra.service;

import org.apache.cassandra.thrift.Clock;

/**
* Resolution used to create clocks.
* Clients may wish to use millisec, micro or sec, depending on the application
Expand Down
Expand Up @@ -12,7 +12,6 @@

import org.apache.cassandra.thrift.Cassandra;
import org.apache.cassandra.thrift.CfDef;
import org.apache.cassandra.thrift.Clock;
import org.apache.cassandra.thrift.KsDef;
import org.apache.cassandra.thrift.TokenRange;
import org.slf4j.Logger;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/me/prettyprint/cassandra/service/Keyspace.java
Expand Up @@ -8,7 +8,6 @@
import me.prettyprint.hector.api.exceptions.HNotFoundException;
import me.prettyprint.hector.api.exceptions.HectorException;

import org.apache.cassandra.thrift.Clock;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.ColumnParent;
import org.apache.cassandra.thrift.ColumnPath;
Expand Down Expand Up @@ -167,7 +166,7 @@ Map<byte[], List<SuperColumn>> multigetSuperSlice(List<byte[]> keys,
/**
* Same as two argument version, but the caller must specify their own clock
*/
void remove(byte[] key, ColumnPath columnPath, Clock clock) throws HectorException;
void remove(byte[] key, ColumnPath columnPath, long timestamp) throws HectorException;

void remove(String key, ColumnPath columnPath) throws HectorException;

Expand Down
16 changes: 6 additions & 10 deletions src/main/java/me/prettyprint/cassandra/service/KeyspaceImpl.java
Expand Up @@ -15,7 +15,6 @@

import org.apache.cassandra.thrift.Cassandra;
import org.apache.cassandra.thrift.CfDef;
import org.apache.cassandra.thrift.Clock;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.ColumnOrSuperColumn;
import org.apache.cassandra.thrift.ColumnParent;
Expand Down Expand Up @@ -347,7 +346,7 @@ public void insert(String key, ColumnPath columnPath, byte[] value) throws Hecto
if (columnPath.isSetSuper_column()) {
columnParent.setSuper_column(columnPath.getSuper_column());
}
Column column = new Column(columnPath.getColumn(), value, createClockInternal());
Column column = new Column(columnPath.getColumn(), value, createClock());
insert(key.getBytes(), columnParent, column);
}

Expand All @@ -358,7 +357,7 @@ public void insert(String key, ColumnPath columnPath, byte[] value, long timesta
if (columnPath.isSetSuper_column()) {
columnParent.setSuper_column(columnPath.getSuper_column());
}
Column column = new Column(columnPath.getColumn(), value, new Clock(timestamp));
Column column = new Column(columnPath.getColumn(), value, timestamp);
insert(key.getBytes(), columnParent, column);
}

Expand Down Expand Up @@ -507,7 +506,7 @@ public Map<byte[], List<Column>> execute(Cassandra.Client cassandra)

@Override
public void remove(byte[] key, ColumnPath columnPath) {
this.remove(key, columnPath, createClockInternal());
this.remove(key, columnPath, createClock());
}

@Override
Expand All @@ -529,14 +528,14 @@ public Map<byte[], Integer> execute(Cassandra.Client cassandra) throws HectorExc
}

@Override
public void remove(final byte[] key, final ColumnPath columnPath, final Clock clock)
public void remove(final byte[] key, final ColumnPath columnPath, final long timestamp)
throws HectorException {
Operation<Void> op = new Operation<Void>(OperationType.WRITE) {

@Override
public Void execute(Cassandra.Client cassandra) throws HectorException {
try {
cassandra.remove(key, columnPath, clock, consistency);
cassandra.remove(key, columnPath, timestamp, consistency);
return null;
} catch (Exception e) {
throw xtrans.translate(e);
Expand All @@ -556,7 +555,7 @@ public void remove(String key, ColumnPath columnPath) throws HectorException {
*/
@Override
public void remove(String key, ColumnPath columnPath, long timestamp) throws HectorException {
remove(key.getBytes(), columnPath, new Clock(timestamp));
remove(key.getBytes(), columnPath, timestamp);
}


Expand Down Expand Up @@ -623,9 +622,6 @@ public long createClock() {
return client.getClockResolution().createClock();
}

private Clock createClockInternal() {
return new Clock(createClock());
}

private CfDef getCfDef(String cf) {
List<CfDef> cfDefs = keyspaceDesc.getCf_defs();
Expand Down
Expand Up @@ -7,7 +7,6 @@
import me.prettyprint.cassandra.serializers.LongSerializer;
import me.prettyprint.cassandra.serializers.StringSerializer;

import org.apache.cassandra.thrift.Clock;
import org.apache.cassandra.thrift.Column;
import org.junit.Test;

Expand All @@ -28,12 +27,12 @@ public void testConstruction() {
ColumnSlice<String, Long> slice = new ColumnSlice<String, Long>(tColumns, se, le);
Assert.assertTrue(slice.getColumns().isEmpty());

tColumns.add(new Column(new byte[]{}, new byte[]{}, new Clock(0)));
tColumns.add(new Column(new byte[]{}, new byte[]{}, 0L));
slice = new ColumnSlice<String, Long>(tColumns, se, le);
Assert.assertEquals(1, slice.getColumns().size());

tColumns = new ArrayList<Column>();
tColumns.add(new Column(se.toBytes("1"), le.toBytes(1L), new Clock(0)));
tColumns.add(new Column(se.toBytes("1"), le.toBytes(1L), 0L));
slice = new ColumnSlice<String, Long>(tColumns, se, le);
Assert.assertEquals((Long) 1L, slice.getColumnByName("1").getValue());
}
Expand Down
Expand Up @@ -9,7 +9,6 @@
import me.prettyprint.cassandra.serializers.LongSerializer;
import me.prettyprint.cassandra.serializers.StringSerializer;

import org.apache.cassandra.thrift.Clock;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.SuperColumn;
import org.junit.Test;
Expand All @@ -33,7 +32,7 @@ public void testConstruction() {
Assert.assertTrue(slice.getSuperColumns().isEmpty());

// non-empty one
Column c = new Column(le.toBytes(5L), be.toBytes(new byte[] { 1 }), new Clock(2));
Column c = new Column(le.toBytes(5L), be.toBytes(new byte[] { 1 }), 2L);
tColumns.add(new SuperColumn(se.toBytes("super"), Arrays.asList(c)));
slice = new SuperSlice<String, Long, byte[]>(tColumns, se, le, be);
Assert.assertEquals(1, slice.getSuperColumns().size());
Expand Down
Expand Up @@ -10,7 +10,6 @@

import me.prettyprint.cassandra.serializers.StringSerializer;

import org.apache.cassandra.thrift.Clock;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.Deletion;
import org.apache.cassandra.thrift.Mutation;
Expand All @@ -33,7 +32,7 @@ public void setup() {

@Test
public void testAddInsertion() {
Column column = new Column(bytes("c_name"), bytes("c_val"), new Clock(System.currentTimeMillis()));
Column column = new Column(bytes("c_name"), bytes("c_val"), System.currentTimeMillis());
batchMutate.addInsertion("key1", columnFamilies, column);
// assert there is one outter map row with 'key' as the key
Map<String, Map<String, List<Mutation>>> mutationMap = batchMutate.getRawMutationMap();
Expand All @@ -42,39 +41,39 @@ public void testAddInsertion() {

// add again with a different column and verify there is one key and two mutations underneath
// for "standard1"
Column column2 = new Column(bytes("c_name2"), bytes("c_val2"), new Clock(System.currentTimeMillis()));
Column column2 = new Column(bytes("c_name2"), bytes("c_val2"), System.currentTimeMillis());
batchMutate.addInsertion("key1",columnFamilies, column2);
assertEquals(2, mutationMap.get("key1").get("Standard1").size());
}

@Test
public void testAddSuperInsertion() {
SuperColumn sc = new SuperColumn(bytes("c_name"),
Arrays.asList(new Column(bytes("c_name"), bytes("c_val"), new Clock(System.currentTimeMillis()))));
Arrays.asList(new Column(bytes("c_name"), bytes("c_val"), System.currentTimeMillis())));
batchMutate.addSuperInsertion("key1", columnFamilies, sc);
// assert there is one outter map row with 'key' as the key
assertEquals(1, batchMutate.getRawMutationMap().get("key1").size());

// add again with a different column and verify there is one key and two mutations underneath
// for "standard1"
SuperColumn sc2 = new SuperColumn(bytes("c_name2"),
Arrays.asList(new Column(bytes("c_name"), bytes("c_val"), new Clock(System.currentTimeMillis()))));
Arrays.asList(new Column(bytes("c_name"), bytes("c_val"), System.currentTimeMillis())));
batchMutate.addSuperInsertion("key1", columnFamilies, sc2);
assertEquals(2, batchMutate.getRawMutationMap().get("key1").get("Standard1").size());
}


@Test
public void testAddDeletion() {
Deletion deletion = new Deletion(new Clock(System.currentTimeMillis()));
Deletion deletion = new Deletion(System.currentTimeMillis());
SlicePredicate slicePredicate = new SlicePredicate();
slicePredicate.addToColumn_names(bytes("c_name"));
deletion.setPredicate(slicePredicate);
batchMutate.addDeletion("key1", columnFamilies, deletion);

assertEquals(1,batchMutate.getRawMutationMap().get("key1").size());

deletion = new Deletion(new Clock(System.currentTimeMillis()));
deletion = new Deletion(System.currentTimeMillis());
slicePredicate = new SlicePredicate();
slicePredicate.addToColumn_names(bytes("c_name2"));
deletion.setPredicate(slicePredicate);
Expand Down
Expand Up @@ -49,7 +49,7 @@ public void testDescribeClusterName() throws Exception {
*/
@Test
public void testDescribeThriftVersion() throws Exception {
assertEquals("16.0.0",cassandraCluster.describeThriftVersion());
assertEquals("17.0.0",cassandraCluster.describeThriftVersion());
}

@Test
Expand Down

0 comments on commit b41255a

Please sign in to comment.