Skip to content

Commit 0977619

Browse files
committed
Add TokenOnlyPrimaryKey class and replace isTokenOnly
It's part of the patch.
1 parent 479eb82 commit 0977619

File tree

7 files changed

+130
-45
lines changed

7 files changed

+130
-45
lines changed

src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyFactory.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@
3535
*/
3636
public class PartitionAwarePrimaryKeyFactory implements PrimaryKey.Factory
3737
{
38-
@Override
39-
public PrimaryKey createTokenOnly(Token token)
40-
{
41-
assert token != null;
42-
return new PartitionAwarePrimaryKey(token, null, null);
43-
}
44-
4538
@Override
4639
public PrimaryKey createDeferred(Token token, Supplier<PrimaryKey> primaryKeySupplier)
4740
{
@@ -76,6 +69,7 @@ public PrimaryKey loadDeferred()
7669
{
7770
this.partitionKey = primaryKeySupplier.get().partitionKey();
7871
primaryKeySupplier = null;
72+
assert this.token == this.partitionKey.getToken() : "Deferred primary key must contain the same token";
7973
}
8074
return this;
8175
}
@@ -86,12 +80,6 @@ public PartitionAwarePrimaryKey forStaticRow()
8680
return this;
8781
}
8882

89-
@Override
90-
public boolean isTokenOnly()
91-
{
92-
return partitionKey == null && primaryKeySupplier == null;
93-
}
94-
9583
@Override
9684
public Token token()
9785
{

src/java/org/apache/cassandra/index/sai/disk/v2/PrimaryKeyWithSource.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ public Token token()
8080
return primaryKey().token();
8181
}
8282

83-
@Override
84-
public boolean isTokenOnly()
85-
{
86-
return false;
87-
}
88-
8983
@Override
9084
public DecoratedKey partitionKey()
9185
{

src/java/org/apache/cassandra/index/sai/disk/v2/RowAwarePrimaryKeyFactory.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ public RowAwarePrimaryKeyFactory(ClusteringComparator clusteringComparator)
5050
this.hasEmptyClustering = clusteringComparator.size() == 0;
5151
}
5252

53-
@Override
54-
public PrimaryKey createTokenOnly(Token token)
55-
{
56-
return new RowAwarePrimaryKey(token, null, null, null);
57-
}
58-
5953
@Override
6054
public PrimaryKey createDeferred(Token token, Supplier<PrimaryKey> primaryKeySupplier)
6155
{
@@ -94,12 +88,6 @@ public RowAwarePrimaryKey forStaticRow()
9488
return new RowAwarePrimaryKey(token, partitionKey, Clustering.STATIC_CLUSTERING, primaryKeySupplier);
9589
}
9690

97-
@Override
98-
public boolean isTokenOnly()
99-
{
100-
return partitionKey == null && clustering == null && primaryKeySupplier == null;
101-
}
102-
10391
@Override
10492
public Token token()
10593
{
@@ -129,6 +117,7 @@ public PrimaryKey loadDeferred()
129117
this.partitionKey = deferredPrimaryKey.partitionKey();
130118
this.clustering = deferredPrimaryKey.clustering();
131119
primaryKeySupplier = null;
120+
assert this.token == this.partitionKey.getToken() : "Deferred primary key must contain the same token";
132121
}
133122
return this;
134123
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package org.apache.cassandra.index.sai.disk.v2;
2+
3+
import org.apache.cassandra.db.Clustering;
4+
import org.apache.cassandra.db.DecoratedKey;
5+
import org.apache.cassandra.dht.Token;
6+
import org.apache.cassandra.index.sai.utils.PrimaryKey;
7+
import org.apache.cassandra.utils.bytecomparable.ByteSource;
8+
9+
public class TokenOnlyPrimaryKey implements PrimaryKey
10+
{
11+
protected final Token token;
12+
13+
public TokenOnlyPrimaryKey(Token token)
14+
{
15+
this.token = token;
16+
}
17+
18+
@Override
19+
public boolean isTokenOnly()
20+
{
21+
return true;
22+
}
23+
24+
@Override
25+
public Token token()
26+
{
27+
return token;
28+
}
29+
30+
@Override
31+
public DecoratedKey partitionKey()
32+
{
33+
throw new UnsupportedOperationException();
34+
}
35+
36+
@Override
37+
public Clustering<?> clustering()
38+
{
39+
throw new UnsupportedOperationException();
40+
}
41+
42+
@Override
43+
public ByteSource asComparableBytes(Version version)
44+
{
45+
throw new UnsupportedOperationException();
46+
}
47+
48+
@Override
49+
public int compareTo(PrimaryKey o)
50+
{
51+
return token().compareTo(o.token());
52+
}
53+
54+
@Override
55+
public long ramBytesUsed()
56+
{
57+
// TODO Auto-generated method stub
58+
throw new UnsupportedOperationException("Unimplemented method 'ramBytesUsed'");
59+
}
60+
61+
@Override
62+
public PrimaryKey forStaticRow()
63+
{
64+
// TODO Auto-generated method stub
65+
throw new UnsupportedOperationException("Unimplemented method 'forStaticRow'");
66+
}
67+
68+
@Override
69+
public PrimaryKey loadDeferred()
70+
{
71+
// TODO Auto-generated method stub
72+
throw new UnsupportedOperationException("Unimplemented method 'loadDeferred'");
73+
}
74+
75+
@Override
76+
public ByteSource asComparableBytesMinPrefix(Version version)
77+
{
78+
// TODO Auto-generated method stub
79+
throw new UnsupportedOperationException("Unimplemented method 'asComparableBytesMinPrefix'");
80+
}
81+
82+
@Override
83+
public ByteSource asComparableBytesMaxPrefix(Version version)
84+
{
85+
// TODO Auto-generated method stub
86+
throw new UnsupportedOperationException("Unimplemented method 'asComparableBytesMaxPrefix'");
87+
}
88+
89+
// @Override
90+
// public int hashCode()
91+
// {
92+
// return Objects.hash(token(), clusteringComparator);
93+
// }
94+
95+
@Override
96+
public boolean equals(Object o)
97+
{
98+
if (o instanceof PrimaryKey)
99+
return compareTo((PrimaryKey) o) == 0;
100+
return false;
101+
}
102+
103+
// @Override
104+
// public boolean equals(Object o, boolean strict)
105+
// {
106+
// if (o == null)
107+
// return false;
108+
// if (o instanceof PrimaryKey)
109+
// return compareTo((PrimaryKey) o, strict) == 0;
110+
// return false;
111+
// }
112+
113+
@Override
114+
public String toString()
115+
{
116+
return String.format("PrimaryKey: { token: %s }", token());
117+
}
118+
}

src/java/org/apache/cassandra/index/sai/utils/PrimaryKey.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cassandra.index.sai.disk.format.IndexFeatureSet;
2828
import org.apache.cassandra.index.sai.disk.v1.PartitionAwarePrimaryKeyFactory;
2929
import org.apache.cassandra.index.sai.disk.v2.RowAwarePrimaryKeyFactory;
30+
import org.apache.cassandra.index.sai.disk.v2.TokenOnlyPrimaryKey;
3031
import org.apache.cassandra.utils.bytecomparable.ByteComparable;
3132
import org.apache.cassandra.utils.bytecomparable.ByteSource;
3233

@@ -55,7 +56,11 @@ interface Factory
5556
* @param token the {@link Token}
5657
* @return a {@link PrimaryKey} represented by a token only
5758
*/
58-
PrimaryKey createTokenOnly(Token token);
59+
default PrimaryKey createTokenOnly(Token token)
60+
{
61+
assert token != null;
62+
return new TokenOnlyPrimaryKey(token);
63+
}
5964

6065
/**
6166
* Creates a {@link PrimaryKey} that is represented by a {@link DecoratedKey}.
@@ -118,7 +123,10 @@ static Factory factory(ClusteringComparator clusteringComparator, IndexFeatureSe
118123
*/
119124
PrimaryKey forStaticRow();
120125

121-
boolean isTokenOnly();
126+
default boolean isTokenOnly()
127+
{
128+
return false;
129+
}
122130

123131
/**
124132
* Returns the {@link Token} associated with this primary key.

src/java/org/apache/cassandra/index/sai/utils/PrimaryKeyWithByteComparable.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ protected boolean isIndexDataEqualToLiveData(ByteBuffer value)
7676
}
7777
}
7878

79-
@Override
80-
public boolean isTokenOnly()
81-
{
82-
return false;
83-
}
84-
8579
@Override
8680
public int compareTo(PrimaryKey o)
8781
{

src/java/org/apache/cassandra/index/sai/utils/PrimaryKeyWithScore.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ protected boolean isIndexDataEqualToLiveData(ByteBuffer value)
6262
return true;
6363
}
6464

65-
@Override
66-
public boolean isTokenOnly()
67-
{
68-
return false;
69-
}
70-
7165
@Override
7266
public int compareTo(PrimaryKey o)
7367
{

0 commit comments

Comments
 (0)