Skip to content

Commit

Permalink
Fix scylladb backend doesn't support label query in page (#455)
Browse files Browse the repository at this point in the history
Fix scylladb backend doesn't support label query in page

Use version <= 20 exist bug: "Paging state mismatch, this means that either the paging state contents were altered, or you're trying to apply it to a different statement"

Change-Id: I579a49cdbd586a60dbfbe2a508dafc0f8e66e8fa
  • Loading branch information
Linary authored and zhoney committed Apr 16, 2019
1 parent a05002c commit 802ffb1
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public String version() {
* [1.0] HugeGraph-1328: supports backend table version checking
* [1.1] HugeGraph-1322: add support for full-text search
* [1.2] #296: support range sortKey feature
* [1.3] #455: fix scylladb backend doesn't support label query in page
*/
return "1.2";
return "1.3";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,16 @@ public void init(CassandraSessionPool.Session session) {
ImmutableMap<HugeKeys, DataType> pkeys = ImmutableMap.of(
HugeKeys.ID, DATATYPE_IL
);
ImmutableMap<HugeKeys, DataType> ckeys = ImmutableMap.of(
HugeKeys.BASE_TYPE, DataType.tinyint(),
HugeKeys.BASE_VALUE, DATATYPE_SL
);
ImmutableMap<HugeKeys, DataType> columns = ImmutableMap.of(
HugeKeys.NAME, DataType.text(),
HugeKeys.INDEX_TYPE, DataType.tinyint(),
HugeKeys.FIELDS, DataType.list(DATATYPE_PK),
HugeKeys.STATUS, DataType.tinyint()
);
ImmutableMap<HugeKeys, DataType> ckeys = ImmutableMap.of();
ImmutableMap<HugeKeys, DataType> columns = ImmutableMap
.<HugeKeys, DataType>builder()
.put(HugeKeys.NAME, DataType.text())
.put(HugeKeys.BASE_TYPE, DataType.tinyint())
.put(HugeKeys.BASE_VALUE, DATATYPE_SL)
.put(HugeKeys.INDEX_TYPE, DataType.tinyint())
.put(HugeKeys.FIELDS, DataType.list(DATATYPE_PK))
.put(HugeKeys.STATUS, DataType.tinyint())
.build();

this.createTable(session, pkeys, ckeys, columns);
this.createIndex(session, NAME_INDEX, HugeKeys.NAME);
Expand Down Expand Up @@ -297,6 +297,10 @@ protected Directions direction() {
return this.direction;
}

protected String labelIndexTable() {
return this.table();
}

@Override
public void init(CassandraSessionPool.Session session) {
ImmutableMap<HugeKeys, DataType> pkeys = ImmutableMap.of(
Expand Down Expand Up @@ -397,7 +401,7 @@ protected void deleteEdgesByLabel(CassandraSessionPool.Session session,
final String OTHER_VERTEX = formatKey(HugeKeys.OTHER_VERTEX);

// Query edges by label index
Select select = QueryBuilder.select().from(this.table());
Select select = QueryBuilder.select().from(this.labelIndexTable());
select.where(formatEQ(HugeKeys.LABEL, label.asLong()));

ResultSet rs;
Expand All @@ -421,7 +425,7 @@ protected void deleteEdgesByLabel(CassandraSessionPool.Session session,
session.add(buildDelete(label, otherVertex, Directions.IN));

count += 2;
if (count > COMMIT_DELETE_BATCH - 2) {
if (count >= COMMIT_DELETE_BATCH - 2) {
session.commit();
count = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public PropertyKey getPropertyKey(Id id) {
@Watched(prefix = "schema")
public PropertyKey getPropertyKey(String name) {
E.checkArgumentNotNull(name, "Property key name can't be null");
E.checkArgument(!name.isEmpty(), "Property key name can't be empty");
return this.getSchema(HugeType.PROPERTY_KEY, name);
}

Expand Down Expand Up @@ -170,6 +171,7 @@ public VertexLabel getVertexLabel(Id id) {
@Watched(prefix = "schema")
public VertexLabel getVertexLabel(String name) {
E.checkArgumentNotNull(name, "Vertex label name can't be null");
E.checkArgument(!name.isEmpty(), "Vertex label name can't be empty");
return this.getSchema(HugeType.VERTEX_LABEL, name);
}

Expand All @@ -194,6 +196,7 @@ public EdgeLabel getEdgeLabel(Id id) {
@Watched(prefix = "schema")
public EdgeLabel getEdgeLabel(String name) {
E.checkArgumentNotNull(name, "Edge label name can't be null");
E.checkArgument(!name.isEmpty(), "Edge label name can't be empty");
return this.getSchema(HugeType.EDGE_LABEL, name);
}

Expand Down Expand Up @@ -225,6 +228,7 @@ public IndexLabel getIndexLabel(Id id) {
@Watched(prefix = "schema")
public IndexLabel getIndexLabel(String name) {
E.checkArgumentNotNull(name, "Index label name can't be null");
E.checkArgument(!name.isEmpty(), "Index label name can't be empty");
return this.getSchema(HugeType.INDEX_LABEL, name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class ScyllaDBStoreProvider extends CassandraStoreProvider {

private static final Logger LOG = Log.logger(CassandraStore.class);

// TODO: read ScyllaDB version from conf
private static final int VERSION = 20;

private static final BackendFeatures FEATURES = new ScyllaDBFeatures();

@Override
Expand Down Expand Up @@ -80,14 +83,25 @@ public ScyllaDBSchemaStore(BackendStoreProvider provider,
String keyspace, String store) {
super(provider, keyspace, store);

registerTableManager(HugeType.VERTEX_LABEL,
new ScyllaDBTables.VertexLabel());
registerTableManager(HugeType.EDGE_LABEL,
new ScyllaDBTables.EdgeLabel());
registerTableManager(HugeType.PROPERTY_KEY,
new ScyllaDBTables.PropertyKey());
registerTableManager(HugeType.INDEX_LABEL,
new ScyllaDBTables.IndexLabel());
if (VERSION >= 20) {
registerTableManager(HugeType.VERTEX_LABEL,
new ScyllaDBTablesWithMV.VertexLabel());
registerTableManager(HugeType.EDGE_LABEL,
new ScyllaDBTablesWithMV.EdgeLabel());
registerTableManager(HugeType.PROPERTY_KEY,
new ScyllaDBTablesWithMV.PropertyKey());
registerTableManager(HugeType.INDEX_LABEL,
new ScyllaDBTablesWithMV.IndexLabel());
} else {
registerTableManager(HugeType.VERTEX_LABEL,
new ScyllaDBTables.VertexLabel());
registerTableManager(HugeType.EDGE_LABEL,
new ScyllaDBTables.EdgeLabel());
registerTableManager(HugeType.PROPERTY_KEY,
new ScyllaDBTables.PropertyKey());
registerTableManager(HugeType.INDEX_LABEL,
new ScyllaDBTables.IndexLabel());
}
}

@Override
Expand All @@ -103,10 +117,7 @@ public ScyllaDBGraphStore(BackendStoreProvider provider,
String keyspace, String store) {
super(provider, keyspace, store);

// TODO: read Scylla version from conf
int version = 17;

if (version >= 20) {
if (VERSION >= 20) {
registerTableManager(HugeType.VERTEX,
new ScyllaDBTablesWithMV.Vertex(store));
registerTableManager(HugeType.EDGE_OUT,
Expand Down
Loading

0 comments on commit 802ffb1

Please sign in to comment.