Skip to content

JAVA-936: Adapt schema metadata parsing logic to new storage format of CQL types in C* 3.0#467

Merged
adutra merged 1 commit into
3.0from
java936
Nov 16, 2015
Merged

JAVA-936: Adapt schema metadata parsing logic to new storage format of CQL types in C* 3.0#467
adutra merged 1 commit into
3.0from
java936

Conversation

@adutra
Copy link
Copy Markdown
Contributor

@adutra adutra commented Oct 6, 2015

NOTE: can now be tested against the newly-released C* 3.0.0.

Majors changes:

Several columns in the schema metadata tables used to contain internal cassandra types. They now contain a CQL representation of the type, instead of internal Cassandra names. DataTypeParser is now used to parse them (instead of CassandraTypeParser).

This poses a problem for UDTs: they are now simply represented by their names (whereas before the column would contain enough information to build the UserType from scratch). The problem is even worse for nested UDTs.

From now on, this problem is solved by two techniques:

  • Topological sort of UDTs: when the entire schema (or keyspace) is rebuilt, we have enough information to be able to build the dependency graph for UDTs. This allows us to process them in topological sort order, and all UDTs are resolved (note that nested udts now reference the same instance, whereas before we would construct a different, but equivalent instance).
  • during a partial refresh, if a UDT definition references a nested UDT u2, and u2 is not part of the refresh, we look for the definition of u2 in the "old" metadata as it was before the start of the refresh. Thanks to the topological sort, we're sure that we won't reference a stale definition that would be updated later in the refresh.

The only case were UDT resolution should fail is if Cassandra sends us notifications out of order. In this case we abort the whole refresh and log a warning that the metadata will be out of date.

The other noticeable difference is initconds. They used to be stored as blobs; now they are stored as CQL literals.

See CASSANDRA-10365 and CASSANDRA-10650 for details.

@adutra adutra changed the title JAVA-912: Use native CQL names to store data types in schema 'columns' table JAVA-938: Adapt schema metadata parsing logic to new storage format of CQL types in C* 3.0 Oct 6, 2015
@adutra adutra changed the title JAVA-938: Adapt schema metadata parsing logic to new storage format of CQL types in C* 3.0 JAVA-936: Adapt schema metadata parsing logic to new storage format of CQL types in C* 3.0 Oct 6, 2015
@adutra adutra force-pushed the java936 branch 6 times, most recently from 8ef28c7 to db16d19 Compare October 30, 2015 10:16
@tolbertam tolbertam added this to the 3.0.0-beta1 milestone Nov 3, 2015
Comment thread driver-core/pom.xml Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to be able to build DAGs (directed acyclic graphs) for inter-UDT dependencies. See SchemaParser and UserType.

@adutra adutra force-pushed the java936 branch 3 times, most recently from 5add345 to 16d63e2 Compare November 5, 2015 10:26
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initconds are back to text type thanks to CASSANDRA-10650.

@adutra adutra force-pushed the java936 branch 6 times, most recently from 5009c79 to 04f9430 Compare November 10, 2015 11:18
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle the case where stateType is an UnresolvedUserType?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was surprised by the call to handleId here, but Cassandra does indeed quote mixed-case names in its type columns:

cqlsh:test> create type "MixedCaseType"(i int);
cqlsh:test> create table foo(k int primary key, t frozen<"MixedCaseType">);
cqlsh:test> select type from system_schema.columns where keyspace_name = 'test' and table_name = 'foo' and column_name = 't';

 type
-------------------------
 frozen<"MixedCaseType">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem like an inconsistency, but I'm guessing it needs to be done otherwise someone could throw a '>' in a quoted identifier to throw the parsing off.

For example:

cqlsh:test> create type "Mixe>dCase>Type"(i int);
cqlsh:test> create table foo3 ("Key" int primary key, v list<frozen<"Mixe>dCase>Type">>);
cqlsh:test> select * from system_schema.columns where keyspace_name='test' and table_name='foo3';

 keyspace_name | table_name | column_name | clustering_order | column_name_bytes | kind          | position | type
---------------+------------+-------------+------------------+-------------------+---------------+----------+---------------------------------
          test |       foo3 |         Key |             none |          0x4b6579 | partition_key |        0 |                             int
          test |       foo3 |           v |             none |              0x76 |       regular |       -1 | list<frozen<"Mixe>dCase>Type">>

This typename seems to throw off of the DataTypeParser due the appearance of '>' in the typename:

    657    [main] ERROR com.datastax.driver.core.SchemaParser  - Error parsing schema for table test.foo3: Cluster.getMetadata().getKeyspace("test").getTable("foo3") will be missing or incomplete
com.datastax.driver.core.exceptions.DriverInternalError: Excepting single parameter for list, got [frozen<"Mixe>, dCase]
    at com.datastax.driver.core.DataTypeParser.parse(DataTypeParser.java:84)
    at com.datastax.driver.core.TableMetadata.build(TableMetadata.java:188)
    at com.datastax.driver.core.SchemaParser.buildTables(SchemaParser.java:171)
    at com.datastax.driver.core.SchemaParser.buildKeyspaces(SchemaParser.java:123)
    at com.datastax.driver.core.SchemaParser.refresh(SchemaParser.java:64)
    at com.datastax.driver.core.ControlConnection.refreshSchema(ControlConnection.java:329)
    at com.datastax.driver.core.ControlConnection.tryConnect(ControlConnection.java:260)
    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:187)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:79)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1398)
    at com.datastax.driver.core.Cluster.init(Cluster.java:167)
    at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:346)
    at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:319)
    at com.datastax.driver.core.Cluster.connect(Cluster.java:257)

@olim7t
Copy link
Copy Markdown
Contributor

olim7t commented Nov 12, 2015

Pushed changes in UDT resolution as discussed privately with Alexandre. I've updated the PR description.

@tolbertam
Copy link
Copy Markdown
Contributor

Looks good to me! 👍

@olim7t
Copy link
Copy Markdown
Contributor

olim7t commented Nov 13, 2015

I'm 👍 with @tolbertam's latest change.
Once JAVA-988 is on 3.0, we can rebase this. Then we just need to remove sanitizedType in DataTypeCqlNameParser and it will be good to go.

…f CQL types in C* 3.0.

This commit also migrates the 'initcond' column type in table
'system_schema.aggregates' from blob to varchar (see CASSANDRA-10650).
@olim7t
Copy link
Copy Markdown
Contributor

olim7t commented Nov 13, 2015

Force-pushed to rebase on current 3.0 and squash the commits.

adutra added a commit that referenced this pull request Nov 16, 2015
JAVA-936: Adapt schema metadata parsing logic to new storage format of CQL types in C* 3.0
@adutra adutra merged commit c092320 into 3.0 Nov 16, 2015
@adutra adutra deleted the java936 branch November 16, 2015 18:16
@adutra adutra modified the milestones: 3.0.0-beta1, 3.0.0-alpha5 Nov 17, 2015
Sfurti-yb pushed a commit to yugabyte/cassandra-java-driver that referenced this pull request Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants